Skip to content

Reconcile draft activation before retrying - #1777

Closed
eowca wants to merge 2 commits into
mainfrom
lean178/1500-retry-draft-activation-v2
Closed

eowca wants to merge 2 commits into
mainfrom
lean178/1500-retry-draft-activation-v2

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Context and goal

Re-read the PR after an ambiguous activation. Resume when GitHub applied it or retry a still-eligible draft once within the original deadline. Zero-second waits observe activation once and keep genuine GitHub errors visible.

Closes #1500. Supersedes #1561 after the delta identified two more timeout cases.

Validation

Recorded for ae76e20847ab

  • uv run --group dev ruff check src tests: exit 0
  • uv run --group dev tach check: exit 0
  • uv run --python 3.14 python scripts/check_architecture_docs.py: exit 0
  • scripts/size_budget.sh: exit 0
  • uv run --group dev pytest -q: exit 0

Focused draft readiness and write read-back tests passed, including a moved head, zero-wait recovery, and a non-retryable zero-wait rate limit. The replacement head will get its full local check and primary review. Python source +56 lines, tests +0.


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Review

  • primary, claude, e7f0a74, approve
  • delta, codex, ae76e20, request_changes

Architecture-Review: unchanged; readiness continues to observe the existing head, receipt, publishers, and wait deadline before reissuing the activation.
Co-Authored-By: Codex <noreply@openai.com>

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero primary review by claude on e7f0a74b488a3bf901ea6962828857957161b41d, 67.6s: approve (0 critical, 0 important, 5 suggestion)

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model claude-opus-5-5 (effort medium); CLI-reported model claude-opus-5-5 (effort unknown); configured model claude-opus-5-5 (effort medium)

Native Claude output is retained in the restricted local review receipt.

Comment thread src/loopzero/cli.py
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: CLI now depends on three private github helpers for retry policy

_activate_draft/_recover_draft_activation call github._transient_error, github._retry_pause and github._read_timeout. No other code in cli.py touches github's private helpers. This rebuilds part of _gh's retry policy (transient classification, scoped back-off, budget clamp) in the CLI, so the two copies can drift if one changes. Smallest fix: add one public helper in github.py, for example mark_ready(..., deadline=...) that returns whether a single retry is allowed, or retry_pause_within_scope(), and call that from cli.py.

Comment thread src/loopzero/cli.py
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)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Mergeability briefly showing UNKNOWN blocks the single retry and exits 1

Before the second write, recovery requires readiness.ready or _draft_checks_waiting(...). _draft_checks_waiting drops MERGEABILITY_PENDING and then returns (). So if GitHub is still recomputing mergeability 5 s after the failed write, recovery raises a hard CliError (exit 1), when this is really a pending state that the wait loop already treats as waitable. If this case should be retried, also accept MERGEABILITY_PENDING as a non-blocker here. Otherwise, document that it counts as a 'new blocker'.

Comment thread src/loopzero/cli.py
pr, readiness, kicked = waited
assert readiness is not None
except github.ReadDeadline:
_print_check_wait_timeout(pr, args)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Timeout message hides that draft activation is unconfirmed

With --wait=0, or when the deadline passes during recovery, _recover_draft_activation raises ReadDeadline. cmd_ready, or _wait_with_deadline on the wait/merge path, then prints only 'timed out waiting for required checks … resume'. The user is never told that gh pr ready failed and that the PR may still be a draft. Smallest fix: put the activation failure into the ReadDeadline tail and print it next to the timeout hint.

Comment thread src/loopzero/cli.py
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The retry write can get a very short timeout and then reports an unconfirmed write

github._read_timeout(120) clamps the second gh pr ready to whatever budget is left after the pause, two reads and a readiness evaluation. That can be under a second. The write may then still land on GitHub after ProcTimeout, and the command exits 1 with 'Draft activation unconfirmed' and no reconciliation. Consider requiring a minimum remaining budget, such as RETRY_DELAY, before sending the second write, and otherwise treating the case as a timeout (exit 3).

Comment thread tests/test_cli.py

@pytest.mark.parametrize("settles", [True, False])
def test_ready_wait_resumes_after_draft_transition(wt, gh, capsys, monkeypatch, head, settles):
@pytest.mark.parametrize("settles,fault,error", [(True, "interrupt", ""), (False, "interrupt", ""), (True, "lost", ""), (False, "lost_zero", ""), (True, "retry", ""), (False, "moved", "head changed"), (False, "throttle", "HTTP 403")])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Replay test packs seven scenarios into hard-to-read one-liners

Keeping the line count the same was done by putting the parametrize, the exception-selection dict .get and the combined assertions on single long lines. When one case fails, it is hard to tell which expectation broke. Consider pytest.param(..., id=...) and splitting the compound assert ... and ... so failures point to the exact condition. Ruff's E501 is not enabled, so this is about readability only.

…aft-activation-v2

# Conflicts:
#	src/loopzero/cli.py

@loopzero-feder-positronics loopzero-feder-positronics Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loopzero delta review by codex on ae76e20847ab695d54d66a64754844b5de104545, 43.8s: request_changes (0 critical, 3 important, 0 suggestion)

Same-family fallback: independent reviewers failed: claude: not authenticated. Cross-family review is preferred.

Settings per native call (launch configuration and CLI claims, not backend attestation):

  • Call 1: requested model gpt-6.2-astra (effort medium); CLI-reported model gpt-6.2-astra (effort medium); configured model gpt-6.2-astra (effort medium)
Raw reviewer output
Native Codex transcript retained in the restricted local review receipt; public evidence is publisher-derived, not backend attestation. Exact raw SHA256: 02861ddc0f667863130f67b077ec951dcc3f69adc47cd1be63a9542eb161fff5

Comment thread src/loopzero/cli.py
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)):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important: Require known mergeability before retrying activation

When mergeability is UNKNOWN and a required check is missing or skipped, _draft_checks_waiting removes MERGEABILITY_PENDING and returns the check name. Recovery therefore issues a second write while mergeability is still unknown. Add a retry-specific mergeability guard and cover this combination in the existing replay.

Comment thread src/loopzero/cli.py
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))
_prequeue_size_budget(wt, config, current, readiness)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important: Recheck retry eligibility after the size-budget check

The last PR observation precedes the clone, remote fetch and budget script. If the head moves, a hold is added, or activation takes effect during that work, mark_ready still writes by PR number using the earlier snapshot. After a budget check actually runs, observe the PR again and confirm the same head, draft status and retry eligibility immediately before writing.

Comment thread src/loopzero/cli.py
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))
_prequeue_size_budget(wt, config, current, readiness)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

important: Bound recovery subprocesses by the remaining wait

Each Git command and the budget script gets its own 60-second timeout. With one second left in the wait, a slow fetch can keep recovery running for a minute before _read_timeout checks the deadline at the write. Pass the recovery deadline into the budget helper, cap each subprocess timeout by the remaining time, and use the existing wait-timeout path when it expires.

@eowca

eowca commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Closed by Lean ruling on #1500: three verified delta blockers, both rounds spent. Branch kept.

@eowca eowca closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recover draft activation from one transient GitHub failure

1 participant