Repository navigation
Reconcile draft activation before retrying #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3eca5fd
d26ca8b
9d9d15f
55f218b
44e7683
9b2fdeb
71a4432
71a8ff7
67df7d4
da45c03
20e1147
feff835
0234af9
2cd175e
a5d06c5
1aae039
0c68daf
b945542
db8a695
6c65b6a
251719a
e780406
e0ae254
1e7cd89
c1d8bb7
6ac05fd
96980d0
4122d5b
d630ae1
2beb1bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1213,43 +1213,97 @@ def _cleanup(wt: Path, pr: github.PR) -> None: | |
| print(f"warning: merged but worktree cleanup failed: {exc}{retry}", file=sys.stderr) | ||
|
|
||
|
|
||
| def _activate_draft(wt: Path, config: Config, pr: github.PR, deadline: float | None, | ||
| args: argparse.Namespace | None) -> None: | ||
| try: | ||
| github.mark_ready(config.repo, pr.number) | ||
| return | ||
| except (github.GhUnavailable, _proc.ProcTimeout) as exc: | ||
| if deadline is None: | ||
| raise | ||
| failure = f"Draft activation unconfirmed for PR #{pr.number}: {exc}" | ||
| retryable = isinstance(exc, _proc.ProcTimeout) or github._transient_error(exc.tail, False) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: cli.py now depends on private GitHub retry helpers
Consider moving the observe-and-retry-once logic into a public helper in github.py, such as |
||
| try: | ||
| _recover_draft_activation(wt, config, pr, deadline, args, retryable) | ||
| except github.ReadDeadline: | ||
| raise | ||
| except (CliError, github.GhError, _proc.ProcTimeout, OSError) as exc: | ||
| raise CliError(f"{failure} | recovery: {exc}") from exc | ||
|
|
||
|
|
||
| def _recover_draft_activation(wt: Path, config: Config, pr: github.PR, deadline: float, | ||
| args: argparse.Namespace | None, retryable: bool) -> None: | ||
| def observe() -> github.PR: | ||
| current = github.pr_view(config.repo, pr.number) | ||
| _verify_wait_snapshot(args, wt, config, pr.head_sha, current.head_sha) | ||
| if current.state != "OPEN" or current.number != pr.number: | ||
| raise CliError(f"no open PR #{pr.number} to activate") | ||
| return current | ||
|
|
||
| single_observation = args is not None and args.wait == 0 | ||
| observation_deadline = time.monotonic() + 5 if single_observation else deadline | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The hard-coded 5 s grace only applies to
Consider one rule for both cases, such as a single unbounded-but-short observation whenever the budget is already exhausted. At minimum, make the 5 s a named constant shared with the other single-observation timeouts. |
||
| with github.bounded_reads(observation_deadline, token=None): | ||
| if not observe().is_draft: | ||
| return | ||
| if single_observation: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important: When The same instance exists for a positive budget: once the deadline has expired, Smallest fix: only turn the outcome into a timeout when the failure was retryable. Check |
||
| raise github.ReadDeadline(("gh", "pr", "ready"), "draft activation is still unconfirmed") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important:
Compared with Fix: handle the |
||
| if not retryable or not github._retry_pause(github.RETRY_DELAY, 120): | ||
| raise CliError("retry is unavailable in this ready wait") | ||
| current = observe() | ||
| if not current.is_draft: | ||
| return | ||
| readiness = _readiness(wt, config, current, pr.head_sha, workflow_wait=True) | ||
| if not (readiness.ready or _draft_checks_waiting(config, current, readiness)): | ||
| raise CliError("; ".join(readiness.reasons)) | ||
| github.mark_ready(config.repo, pr.number, github._read_timeout(120)) | ||
|
|
||
|
|
||
| def cmd_ready(args: argparse.Namespace) -> int: | ||
| wt, config = _context(args, pin_checks=True) | ||
| pr, readiness = _pr_readiness(wt, config, workflow_wait=args.wait is not None) | ||
| assert readiness is not None | ||
| waiting = _draft_checks_waiting(config, pr, readiness) | ||
| kicked = bool(waiting) | ||
| started = time.monotonic() | ||
| if waiting: | ||
| github.mark_ready(config.repo, pr.number) | ||
| if args.wait is None: | ||
| pending = f"; {MERGEABILITY_PENDING}" if pr.mergeable == "UNKNOWN" else "" | ||
| print(f"marked ready; waiting for required checks: {', '.join(waiting)}{pending}; {NEXT_WAIT}") | ||
| return 3 | ||
| print("marked ready; " + "; ".join(readiness.reasons)) | ||
| if args.wait is not None and ( | ||
| waiting or _pending_checks(config, pr, readiness, allow_skipped=not pr.is_draft) | ||
| ): | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=kicked, started=started, | ||
| shown=readiness.reasons if kicked else (), args=args, | ||
| allow_skipped=True, initial=None if kicked else readiness) | ||
| if waited is None: | ||
| return 3 | ||
| pr, readiness, kicked = waited | ||
| assert readiness is not None | ||
| if readiness.ready and pr.is_draft and not kicked: | ||
| github.mark_ready(config.repo, pr.number) | ||
| if args.wait is not None: | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=True, started=started, | ||
| args=args, allow_skipped=True) | ||
| deadline = None if args.wait is None else started + args.wait | ||
|
eowca marked this conversation as resolved.
Resolved
|
||
| try: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: The broad The whole body of |
||
| if waiting: | ||
| _activate_draft(wt, config, pr, deadline, args) | ||
| if args.wait is None: | ||
| pending = f"; {MERGEABILITY_PENDING}" if pr.mergeable == "UNKNOWN" else "" | ||
| print(f"marked ready; waiting for required checks: {', '.join(waiting)}{pending}; {NEXT_WAIT}") | ||
| return 3 | ||
| print("marked ready; " + "; ".join(readiness.reasons)) | ||
| if args.wait is not None and ( | ||
| waiting or _pending_checks(config, pr, readiness, allow_skipped=not pr.is_draft) | ||
| ): | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=kicked, started=started, | ||
| shown=readiness.reasons if kicked else (), args=args, | ||
| allow_skipped=True, initial=None if kicked else readiness) | ||
| if waited is None: | ||
| return 3 | ||
| pr, readiness, kicked = waited | ||
| assert readiness is not None | ||
| assert readiness is not None | ||
| if readiness.ready and pr.is_draft and not kicked: | ||
| _activate_draft(wt, config, pr, deadline, args) | ||
| if args.wait is not None: | ||
| waited = _wait_with_deadline(wt, config, pr, args.wait, kicked=True, started=started, | ||
| args=args, allow_skipped=True) | ||
| if waited is None: | ||
| return 3 | ||
| pr, readiness, kicked = waited | ||
| assert readiness is not None | ||
| except github.ReadDeadline: | ||
| _print_check_wait_timeout(pr, args) | ||
| return 3 | ||
| return _report_ready(pr, readiness, config, args.wait) | ||
|
|
||
|
|
||
| def _report_ready(pr: github.PR, readiness: github.Readiness, config: Config, wait: float | None) -> int: | ||
| for reason in _readiness_messages(pr, readiness): | ||
| print(f"not ready: {reason}") | ||
| if not readiness.ready: | ||
| if args.wait is None and _pending_checks(config, pr, readiness): | ||
| if wait is None and _pending_checks(config, pr, readiness): | ||
| print(NEXT_WAIT) | ||
| return 1 | ||
| print(f"ready: {pr.url}") | ||
|
|
@@ -1407,7 +1461,7 @@ def _wait_for_checks( | |
| return current, None, kicked | ||
| readiness = _readiness(wt, config, current, pr.head_sha, workflow_wait=True) | ||
| if not kicked and _draft_checks_waiting(config, current, readiness): | ||
| github.mark_ready(config.repo, pr.number) | ||
| _activate_draft(wt, config, current, started + timeout, args) | ||
| print("marked ready; " + "; ".join(readiness.reasons)) | ||
| return _wait_for_checks(wt, config, pr, timeout, kicked=True, started=started, | ||
| shown=readiness.reasons, args=args, bounded=bounded, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: The first activation attempt can outlast the wait budget
The first
github.mark_ready(config.repo, pr.number)call still uses the fixed 120 s timeout, while the retry is capped with_read_timeout(120). A hung first write can run past--wait, which guarantees the recovery path then fails on an expired deadline.Capping the first attempt with
min(120, deadline - now)whenever a deadline exists would make the two attempts consistent.