Repository navigation
Conversation
Architecture-Review: unchanged; queue admission and landing verification are unchanged while queue I/O now shares the existing wait deadline. Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the deadline applies to observations and leaves the merge request timeout in place. Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; the resolution preserves both branches’ CLI tests. Co-Authored-By: Codex <noreply@openai.com>
Architecture-Review: unchanged; existing wait semantics now bound queue observations while retaining current merge verification and transport behavior. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero primary review by claude on b586954bc8492f795d45374a507ff792f1deaa2f, 121.2s: 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.
| _gh(*argv, timeout=300) | ||
| except GhError as exc: | ||
| raise MergeFailed(exc.command, exc.tail) from exc | ||
| budget = (bounded_reads(observation_deadline, token=None, retry=True) |
There was a problem hiding this comment.
important: A completed direct merge is reported as a merge-queue timeout when its verification runs past the deadline
merge() now runs _verify_merge_request inside bounded_reads(admit_by, retry=True). The pr merge write itself is unbounded (timeout=300), and cmd_merge admits it while now <= admit_by. This breaks in two cases. First, the merge is admitted with little budget left. Second, the write itself runs past admit_by, which is likely when source-check waiting used most of --wait. In either case the first merged_sha read raises ReadDeadline, or bounded_reads.__exit__'s read_timeout(0) raises after a SHA was already verified. _merge_and_follow (cli.py:1554) turns that into None, and cmd_merge prints "timed out waiting for the merge queue to land PR #N" and exits 3. That happens even for a squash/merge/rebase strategy with no queue, where GitHub merged the PR synchronously. Cleanup is skipped and the message is wrong. A rerun recovers, but the merge is misreported.
_queue_wait has the same flaw (cli.py:1489-1501): if the poll returns a SHA that _landed has already checked against the deadline, the exit check in bounded_reads can still throw it away in the window between the return and the scope exit. That contradicts "a landing verified before the deadline proceeds to cleanup".
Smallest fix: keep the first post-write merged_sha unbounded, or apply observation_deadline only after it returns None (to merge_pending and the follow-up read). In _merge_and_follow and _queue_wait, never discard a SHA that is already in hand: return it before the scope's exit check, or catch ReadDeadline only around the poll call.
| code = proc.wait() | ||
| t.join() | ||
| t.join(timeout=1) | ||
| if t.is_alive(): |
There was a problem hiding this comment.
important: Unrelated ai-accounts change silently disables the usage-limit account switch and retry
This change is outside #1155's scope. The task describes only the queue-wait diff and the CLI test merge resolution. It also changes behavior. When any descendant process (for example a provider CLI's background or MCP helper) inherits stderr and outlives the leader, t.is_alive() is true after 1s and cmd_run returns code immediately. That skips the USAGE_LIMIT_RE check, exhausted() and the one-time retry, even when the usage-limit text has already arrived in seen. So the case this fixes is exactly the one where account rotation stops working. The new test also leaves a stray sleep 6 process behind.
Smallest fix: after join(timeout=1), fall through and evaluate the stderr collected so far instead of returning. Better, move this to its own PR with a test that covers the retry path when stderr is inherited.
| return None | ||
|
|
||
|
|
||
| def _report_closed_observation(closed: list[github.GhError]) -> None: |
There was a problem hiding this comment.
suggestion: A persistent closed-unmerged PR is now always exit 3 for positive waits, and the raise branch is effectively unreachable from the CLI
In the bounded path, the _poll_until loop ends only after the deadline, either normally or through a suppressed ReadDeadline. So _report_closed_observation always takes the ReadDeadline branch and prints "last queue observation". It never raises closed[0]. Before this change, a PR that stayed closed-unmerged until the deadline was a hard error; now merge --wait=N reports it as a timeout (exit 3), which can lead automation to retry a PR that is actually closed. The existing _closed_unmerged_wait tests call _wait_for_merge with no read scope, so they only cover the unbounded path and no longer reflect production behavior. If the downgrade is intended, state it in the docstring and make the existing tests cover the scoped path. If it isn't, re-raise closed[0] when the closed observation arrived before the deadline.
| if not defer_landing and (sha := _landed(config, pr, closed)): | ||
| return sha | ||
| if state is not None and not confirmed: | ||
| mergify.mark_confirmed(config.repo, pr.number, pr.head_sha, queue) |
There was a problem hiding this comment.
suggestion: The mark_confirmed write inside the bounded Mergify loop can overrun the budget
mergify.mark_confirmed posts a PR comment. Writes are not scoped by bounded_reads, so the default 120s gh timeout applies even when only milliseconds of --wait remain. Reads are capped, but this write can still push a short --wait well past its budget before the loop sees the deadline. Consider checking github.read_timeout(0) before the write and capping its timeout to the remaining budget, or accept and document the overrun.
Architecture-Review: unchanged; synchronous merge verification and cleanup retain their existing contract, with the deadline scoped to queue observation. Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
loopzero delta review by claude on 6216b2a44f6fa502b1c20bfadaaa4753872ffab6, 43.1s: request_changes (0 critical, 1 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.
| import fcntl | ||
| import hashlib | ||
| import json | ||
| import math |
There was a problem hiding this comment.
Reviewer location scripts/ai-accounts/ai-accounts:1067 is not in the diff; anchored here.
important: Unrelated revert brings back the ai-accounts stderr hang and deletes its regression test
This delta changes t.join(timeout=1) plus the early return code back to a bare t.join(). It also deletes test_run_returns_after_leader_exits_with_inherited_stderr from tests/test_ai_accounts.py. That brings back the hang the test guarded against. When the wrapped command starts a descendant that inherits the stderr pipe and then exits, proc.stderr.read1 does not return EOF until the descendant exits. The bare join then blocks ai-accounts run for as long as the descendant lives, even though the leader has already returned its exit code. None of this relates to #1155, which covers merge queue polling, and the task text does not mention it. It looks like a bad merge resolution of the main fix. Smallest fix: drop the ai-accounts and test_ai_accounts.py hunks from this branch so main's version stays.
| if time.monotonic() >= deadline: | ||
| _print_check_wait_timeout(pr, args) | ||
| return None | ||
| sha = None |
There was a problem hiding this comment.
suggestion: Unused sha = None in _wait_with_deadline
_wait_with_deadline never reads or assigns sha. It uses waited, and the ReadDeadline handler returns None without looking at sha. The line seems to have been copied from the _queue_wait change. Remove it so readers don't assume this function also keeps an observation across scope exit.
| return sha | ||
| if strategy != "queue": | ||
| # A synchronous merge already in flight still needs verification and cleanup. | ||
| if sha := merged_sha(repo, number, expected_head=head_sha): |
There was a problem hiding this comment.
suggestion: Direct-merge fallback is still budget-bound when the first unbounded read misses the landing
For non-queue strategies, the first merged_sha now runs outside the budget. If it returns None, for example because GitHub has not yet shown the synchronous merge or because protection turned the request into auto-merge, _verify_merge_request then runs merge_pending inside bounded_reads. If gh pr merge used up the wait (as in the new test, where 2s pass against --wait=1), that read raises ReadDeadline straight away. _merge_and_follow then returns None and the command exits 3, even though the direct merge may have succeeded. The new test only covers the case where the first read already shows MERGED. Consider a test for a first read that returns OPEN, and decide whether direct merges should get one more unbounded check before timing out.
Keep merge queue polling inside the wait budget
Context and goal
Closes #1155
Acceptance
Notes
Supersedes Keep merge queue polling inside the wait budget #1214 and Keep merge queue polling inside the wait budget #1269. Carries the approved diff from
cd4bf5ff0e2bplus the merge resolution in the CLI tests.Keep the existing admission rules and read endpoints. Bound polling with the deadline already used for source checks. Preserve timeout diagnostics that can be rendered using observations already received.
Pre-fix: GitHub accepted the fake late response and started with a 120-second read timeout. Mergify raised HTTP 503 after its normal retries. The focused merge and queue regression suite passed after the fixes.
Base
main @ fb5640f
Validation
(no
loopzero checkrun recorded)Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Review