Skip to content

Reconcile draft activation before retrying - #1561

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

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

Conversation

@eowca

@eowca eowca commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Context and goal

Re-read the current PR and head when activation is ambiguous. Resume the wait after a confirmed transition or retry a still-eligible draft once within the original deadline.

Closes #1500. This draft depends on #1560.

Validation

Recorded for 2beb1bc80581

  • 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 readiness cases passed, including an applied write, a retry, and a moved head. Source +35 lines, tests +0.


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

Review

  • primary, claude, d630ae1, request_changes
  • delta, claude, 2beb1bc, request_changes

eowca and others added 25 commits November 26, 2026 04:31
Architecture-Review: unchanged; remains fail-closed while trusted evidence is unavailable, with the same status context and publisher.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; remains fail-closed while trusted evidence is unavailable, with the same status context and publisher.
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; evidence and publication failures remain distinguishable within the existing hosted trust boundary.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; transient fetch diagnostics remain inside the existing isolated checkout.
Co-Authored-By: Codex <noreply@openai.com>
…e-observation-retry

# Conflicts:
#	src/loopzero/github.py
#	src/loopzero/hosted.py
#	tests/test_hosted.py
Architecture-Review: unchanged; readiness observes the existing head, receipt and policy before reissuing the same draft transition.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; hosted eligibility still requires verified Git objects before accepting inherited evidence.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; remains fail-closed while trusted evidence is unavailable, with the same status context and publisher.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; evidence and publication failures remain distinguishable within the existing hosted trust boundary.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; transient fetch diagnostics remain inside the existing isolated checkout.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; hosted eligibility still requires verified Git objects before accepting inherited evidence.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the evidence outcome changes while the existing retry and wait behavior remains in force until #1502.
Co-Authored-By: Codex <noreply@openai.com>
…safe-observation-retry

# Conflicts:
#	src/loopzero/github.py
#	src/loopzero/hosted.py
#	tests/test_hosted.py
…ervation-retry

# Conflicts:
#	src/loopzero/github.py
#	tests/test_hosted.py
Co-Authored-By: Codex <noreply@openai.com>
@eowca
eowca changed the base branch from lean178/1502-safe-observation-retry to main November 26, 2026 07:40
eowca and others added 4 commits November 26, 2026 09:07
Architecture-Review: unchanged; scoped deadlines are still applied only to reads, and non-idempotent writes keep their original outcomes.
Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the initial write and the existing readiness guards remain in place.
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 d630ae123e5b2f100d298e3d1b1973d0ca97e793, 51.1s: request_changes (0 critical, 2 important, 3 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 Resolved
Comment thread src/loopzero/cli.py Resolved
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.py now depends on private GitHub retry helpers

_activate_draft calls github._transient_error, github._retry_pause and github._read_timeout, and re-derives the transient classification even though _gh already chose between GhUnavailable and GhError for the write. Checking isinstance(exc, GhUnavailable) again with _transient_error duplicates that classification and can drift from it (for example, a rate-limited GhUnavailable is treated differently here than in _gh).

Consider moving the observe-and-retry-once logic into a public helper in github.py, such as mark_ready(..., deadline) that returns whether a retry is allowed. The CLI would then not need these private helpers.

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

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 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.

Comment thread tests/test_cli.py Outdated

@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", [(True, "interrupt"), (False, "interrupt"), (True, "lost"), (True, "retry"), (False, "moved")])

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 replay does not cover a new blocker or an unknown state

The acceptance criteria say that a new blocker or an unknown state must prevent a second write. The parametrization only covers moved (a changed head). No case has the observed draft gain a non-waitable blocker, or a transient failure where _transient_error is false. Either case would confirm that pr ready is called exactly once and that the error carries the receipt.

Architecture-Review: unchanged; zero-second waits still observe once, and positive waits retain the original deadline and exit guidance.
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 delta review by claude on 2beb1bc80581501de27a8887a23c5a44617c6f11, 54.4s: request_changes (0 critical, 2 important, 2 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
with github.bounded_reads(observation_deadline, token=None):
if not observe().is_draft:
return
if single_observation:

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: --wait 0 hides permanent activation failures as a resumable timeout

When single_observation is true and the PR is still a draft, the code raises ReadDeadline("draft activation is still unconfirmed") before it checks retryable. Take ready --wait 0 where mark_ready failed with a non-transient GhUnavailable, such as a 403/permission tail where _transient_error is False. cmd_ready catches the synthetic ReadDeadline at line 1296 and prints "timed out waiting for required checks … Run loopzero ready --wait to resume", then exits 3. The original failure (failure/exc) is dropped, and the user is told to retry something that will fail the same way every time. Before this change, the same path raised CliError("Draft activation unconfirmed …: <cause> | recovery: …") and exited 1.

The same instance exists for a positive budget: once the deadline has expired, observe()'s ReadDeadline is now re-raised at line 1228. A non-retryable activation failure is then reported as a plain timeout with exit 3 instead of the combined error.

Smallest fix: only turn the outcome into a timeout when the failure was retryable. Check if not retryable: raise CliError(...) before the single_observation raise. In _activate_draft, re-raise ReadDeadline only when retryable; otherwise keep wrapping it with failure so the cause is kept.

Comment thread src/loopzero/cli.py
if not observe().is_draft:
return
if single_observation:
raise github.ReadDeadline(("gh", "pr", "ready"), "draft activation is still unconfirmed")

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: merge --wait 0 now gets a bare ReadDeadline with no cause or timeout handling

_activate_draft is also called from _wait_for_checks (line 1464). It is reached by cmd_merge through _wait_with_deadline (line 1709). When timeout == 0, _wait_with_deadline (line 1389) calls _wait_for_checks outside its try/except github.ReadDeadline. So the new synthetic ReadDeadline for single_observation (and the re-raise at 1228) skips both the timeout printer and the failure wrapper and goes up to _run. There, as a GhError, it is printed as loopzero merge: draft activation is still unconfirmed and exits 1.

Compared with ready --wait 0, the same condition gives exit 3 plus a resume hint there. For merge, the exit code differs and the original mark_ready error text is lost. Only cmd_ready got the new except github.ReadDeadline wrapper. cmd_merge (the other caller of this defect class) was missed.

Fix: handle the ReadDeadline in one shared place for both callers. For example, move the timeout == 0 branch of _wait_with_deadline inside its existing try, or catch it there. Then drop the large try added around cmd_ready.

Comment thread src/loopzero/cli.py
return current

single_observation = args is not None and args.wait == 0
observation_deadline = time.monotonic() + 5 if single_observation else deadline

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 hard-coded 5 s grace only applies to wait == 0, not to other expired budgets

wait == 0 gets a fresh 5-second observation window. A positive budget that has already run out (for example, --wait 1 after slow initial reads) gets no observation, because bounded_reads(deadline) raises right away on the first pr_view. The acceptance criterion ("observe the same PR and head after a transient activation failure") therefore holds only for that one literal value. The magic number also lets --wait 0 exceed what the user asked for.

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.

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

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 broad try in cmd_ready adds a second timeout handler alongside _wait_with_deadline's

The whole body of cmd_ready is wrapped to catch ReadDeadline. _wait_with_deadline already converts ReadDeadline into a printed timeout plus None. This gives two places that print the timeout for one cause, and cmd_merge doesn't get the same behaviour (see the related finding). It's simpler and less likely to drift if ReadDeadline is caught only in _wait_with_deadline and the two direct _activate_draft calls in cmd_ready. Then the _report_ready split isn't needed just to keep the function readable.

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