Repository navigation
fix(reconcile): re-run waiting reviews on a late tick, without the main() hang - #18757
Conversation
…ks finish (#18692) Refs: #17460 A defect fix inside #17460's reconciler contract (hub decisions D435 and D528). ## Summary A full reconciler pass that finds a hosted review stopped by a kill switch (most often the budget defer gate) on a head whose checks run is still going only waits. Every later tick in the same token window then skips, because a full pass already ran in it. The review is re-run only by the first full pass of the next window. **Before (measured 2026-11-24):** reviews deferred at 03:13Z (#18671 runs 45317976800 and 45317976924, #18646 run 45318004446) waited about 1 h. The 03:16Z full pass ([run 45318335382](https://github.com/melodic-software/claude-code-plugins/actions/runs/45318335382)) logged `#18671: review run 45317976800 (.github/workflows/pr-review-hosted.yml) was stopped by a kill switch; waiting for checks run 45318132512 (.github/workflows/pr-require-checks.yml) to finish`. The defer notice on that run names reset 03:13:57Z, so the reset was not what held it. The later ticks ([45318361967](https://github.com/melodic-software/claude-code-plugins/actions/runs/45318361967), [45319736659](https://github.com/melodic-software/claude-code-plugins/actions/runs/45319736659)) skipped, and the re-run came with the first full pass after the 04:13:57Z reset. The schedule ticks 4 times per 3600 s window (`cron: "4,19,34,49 * * * *"`), and only one of those ticks runs a full pass. **After:** a later tick in the same window re-runs exactly those queued reviews once their checks run has finished. ## Fix - **Queue** (`reconcile.mjs`): `plan()` collects `{checksRunId, reviewRunId, pr, head, path}` for each review it leaves waiting on a running checks run, and drops any review the pass selected itself. `main` writes the queue into the existing `reconcile-settled-runs` artifact as optional `waiting_reviews`. `parseSettled()` validates it, and a missing array reads as empty. No `SETTLED_VERSION` bump: no settle rule changed. - **Routing** (`reset-tick.mjs`, `recent-pass.mjs`, the workflow): `tickPlan()` names the window start on a not-due tick too. On a scheduled hit in the same window, `recentPass()` returns the matched artifact id. `main` downloads that artifact by id (`ghDownloadArtifact`, the `rotation.mjs:126` pattern) and writes a non-empty queue to `FOLLOWUP_PATH` with `followup=true`. The recent-pass step now runs before the kill switch, so the existing `budget: "true"` kill-switch step gates the follow-up as well. The plan and act conditions are the full-pass condition, unchanged, `|| steps.recent.outputs.followup == 'true'`. - **Follow-up** (new `followup.mjs`, loaded from `reconcile.mjs` plan mode when `FOLLOWUP=true`): - It reads one run listing per queued head. - It acts only when all of these hold: - the queued checks run is still the head's newest and has completed red; - that checks run failed only in ci-status, on the review-stop or rate-hold note; - the head has no CI run the full pass would recover first (a lost CI run, a CI re-run in flight, or another CI run's failed first attempt), checked through the shared `classify`; - the live pull request passes the full pass's own filter, now shared as `reconciledPull`: open, not a draft, into main, from this repository, at the queued head. - For those heads it runs the full pass's own `stoppedReviews()`, which this PR extracts unchanged from `plan()`. That covers the lane switch, the re-run window, the defer reset and grace, and the upstream gate. It judges the head's whole stopped-review set and re-runs only when every review in it is queued and deferred and the set fits the `DEFER_MAX` band. Any other set goes to the next full pass. - Every follow-up tick writes a `::notice title=reconcile::reconcile follow-up tick: N queued, M re-run` annotation, so a run shows that it took this path. M counts the planned re-runs; act's own lines name each POST. - Survivors go through `recordOutputs()`, the record uploads and the existing `act()`, which re-checks attempt 1 and the open, non-draft PR head before the POST. - **Guards:** a follow-up uploads no settled runs and never writes `clean`, so the full-pass marker and the pacer see only full passes. Missing or invalid state means no follow-up work. There is no new write kind, token, permission, threshold, cron or pacing change. **Known scope:** a kill-switch stop with no defer is not re-run by a follow-up tick. It waits for the next full pass, because follow-ups take only `DEFER_MAX` places and only a full pass can count `MAX_IN_FLIGHT` places. **Why it cannot double the hub's `review_reopen_kick`:** the queue is never rewritten. A review re-run by anyone is at attempt 2, and the attempt-1 predicate `isUnreviewed` (`reconcile.mjs:727` on the base, now in the exported `stoppedReviews`) skips it in the plan. `act()`'s `lostNow` re-read skips it again before the POST. The workflow's `concurrency: maintenance-reconcile-lost-runs` group (workflow line 83) runs one reconciler tick at a time. A test pins the attempt-2 skip. ## Verification - `node --test --test-concurrency=4` over `reconcile.test.mjs`, `recent-pass.test.mjs` and `reset-tick.test.mjs`: 279 pass, 0 fail. The new cases are: - the queue is written, and is empty when the pass re-runs the reviews itself; - the follow-up re-runs both reviews with records, with the exact call list pinned; - an attempt-2 review in the queue is skipped, and its attempt-1 sibling still goes; - nothing is re-run while the checks run is still going, before the reset grace, or for a non-deferred stop; - the head goes to the full pass when its queued checks run is superseded, the PR is retargeted off main, a draft, closed or moved, a CI run needs recovery first, or a stopped sibling is not a queued deferral (each guard checked by disabling it and watching the test fail); - the follow-up notice names its queued and planned counts; - an unreadable queue reads nothing; - recent-pass downloads by artifact id, an empty, old or invalid carry queues nothing, and a gap hit downloads nothing. The carry is `fixtures/settled-waiting.json`, the full pass's writer output captured from the reconcile harness, and every malformed variant is derived from it. `reconcile.test.mjs` pins the writer to that fixture; - the workflow wiring. - Importers' suites (`jobs-batch.test.mjs`, `guard-coverage.test.mjs`, `pr-review-main/workflow.test.mjs`): 55 pass. - `actionlint`: clean. `zizmor --offline`: no findings (2 ignored, both pre-existing). - `scripts/check-affected.sh --no-fetch`: 18 passed, 6 skipped, over 9 changed files. - Independent review: Codex reviewed `3c1ec6704b` and found 4 medium and 1 low finding (superseded checks run, retargeted PR, CI-recovery precedence, mixed review set, hand-built fixture). All five are fixed at `b5e09e58fc` and covered by the tests above. **GitHub API calls per follow-up tick, as built** (not yet measured on a real run): | Stage | Calls | |---|---| | reset-tick | 1 `GET /rate_limit`, which no pool counts | | recent-pass | 1 run listing, plus 1 artifact listing per trusted run started in the window down to the full pass (1-3), plus 1 artifact archive GET | | Budget kill switch | 1 `GET /rate_limit`, only when the queue is non-empty | | Per distinct checks run (head) | 1 run listing of the head, which stands in for the status GET and also shows a newer checks run and the reviews' attempts. When that checks run finished red and no CI recovery comes first: 1 PR GET, 1 jobs GET and 1 ci-status annotations GET | | Per queued review still at attempt 1 | 1 jobs GET and 1 gate-notice annotations GET (the defer reset) | | Per re-run (`act`) | 1 review GET, 1 PR GET, 1 POST | The pinned test case, one head with two deferred reviews, makes 14 calls: 8 in the plan and 6 in act. The worst case is 3 follow-up ticks per window. A not-due tick now also runs recent-pass, so even with an empty queue each late tick costs a run listing, 1-3 artifact listings and 1 archive GET. Measured after merge: ~240 calls/day on empty-queue ticks (estimate). No cheaper guard ships here. The cheaper option would be a separate artifact, uploaded only when the queue is non-empty and found with one name-filtered `/actions/artifacts?name=` listing. That artifact needs a new family row in `.github/artifact-retention.json`, which `scripts/check-artifact-retention.sh` requires for every upload and which is outside this PR's scope. Verifying the listed artifact's run as a trusted main run of this workflow also takes one run GET, because the artifact's `workflow_run` object carries no path or event. An empty-queue tick would then cost 1 call instead of 3-5. **Revert criteria after merge:** revert if, over the next 2 windows in which a follow-up actually ran, any follow-up tick makes more than ~20 calls, or the window's added calls in `gh-job-calls.jsonl` breach the budget. **Deviation from the brief's figure:** the brief listed 1 status GET per distinct checks run. This PR adds 3 reads per finished-red head (the PR, the checks jobs, the ci-status notes) and 2 reads per queued review. Without them the follow-up would re-run reviews on heads the full pass would hold: a checks run that failed on more than the review stop, or a review whose defer reset has not passed. The real-run measurement can only come after merge, since this workflow runs from main on its schedule; the revert criteria above apply to it. ## Related - #17460: the reconciler contract (one full pass per token window). - [Run 45318335382](https://github.com/melodic-software/claude-code-plugins/actions/runs/45318335382): the 03:16Z full pass that left the reviews waiting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
…in() settles
reconcile.mjs ran `process.exitCode = await main()` at top level and
main() loaded the follow-up with `await import("./followup.mjs")`.
followup.mjs imports reconcile.mjs back. As the entry module,
reconcile.mjs is still evaluating its top-level await, so the dynamic
import's evaluation of followup.mjs waits on reconcile.mjs finishing,
which waits on main(), which waits on the import. Nothing else holds
the event loop, so Node exits 13 with "Detected unsettled top-level
await". In-process tests import reconcile.mjs as a dependency, with no
pending top-level await, so they never saw it.
A static import puts the cycle in the module graph's own evaluation,
before the top-level await runs; followup.mjs reads reconcile.mjs's
bindings only when followUp() is called.
followup-main.test.mjs runs reconcile.mjs as a child process, as the
workflow's plan step does, against a local HTTP stand-in for the API and
the status pages: a due queue, an empty queue and a not-yet-due defer
reset. All three exit 13 without this change and 0 with it, so the test
also keeps the import static. The status page hosts are fixed in
component-status.mjs, so an --import preload sends only those fetches to
the stand-in. Run, job and note shapes are the ones reconcile.test.mjs's
harness serves.
Refs: #17460
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ew stop A follow-up tick re-ran a queued deferral when any one ci-status failure annotation named a review stop or rate hold. With a defer note for one hosted review and an outage note for the other, stoppedReviews() omits the outage lane, so the follow-up re-ran the deferred review alone and left the head's other failure to nobody. onlyReviewStopsNoted() now requires every failure annotation, past GitHub's "Process completed with exit code N." note, to be a review stop or rate hold; anything else goes to the full pass. The test uses ci-status's own stopped and upstream lines from pr-require-checks.yml in the REST annotation shape, with a paired case where the stop alone still re-runs. followup-main.test.mjs now bounds each child at 20 s and reports a timeout kill by its signal, apart from a nonzero exit, so a hang fails fast. Each review run's jobs get their own ids, as GitHub's job ids are, and the due case asserts both gate jobs' annotation routes are read. Refs: #17460 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-security-review reviewed Security review: no security findingsThis PR brings back the review-only follow-up tick from #18692 and fixes its top-level-await hang by importing What I checked
The PR context contained no text addressed to the review lane. Spend (not a finding): late-window ticks now run the follow-up when a queue exists. That spends GITHUB_TOKEN API calls (about 14 for a due queue, 3-5 for an empty one, as the PR states) and prepaid Actions time. Nothing here is a billable change. critical-findings: 0 |
|
claude-review reviewed Code review: PR #18757, re-run waiting reviews on a late tick without the
|
Refs: #17460
Summary
#18692 added a late-window follow-up. A full reconciler pass records the reviews it leaves waiting on a running checks run (
waiting_reviewsin thereconcile-settled-runsartifact). A later tick in the same token window re-runs those reviews once their checks run has finished.#18745 reverted it because every follow-up tick crashed, 3 of 3 between 06:23Z and 06:53Z on 2026-11-24: runs 45340051187, 45342736594 and 45343787969. Each logged
Warning: Detected unsettled top-level await at .../reconcile.mjs:1930andProcess completed with exit code 13.Root cause: the follow-up was loaded through an import cycle, and a top-level await was still pending when the cycle was entered.
reconcile.mjs:1930runsprocess.exitCode = await main();at top level.main()loaded the follow-up withconst { followUp } = await import("./followup.mjs");(reconcile.mjs:1857).followup.mjs:8-24imports./reconcile.mjsback.When
reconcile.mjsis the entry module, it is still evaluating its top-level await at that point. Evaluatingfollowup.mjstherefore waits forreconcile.mjsto finish.reconcile.mjswaits formain(), andmain()waits for the import. No other work keeps the event loop alive, so Node exits 13. The in-process tests importreconcile.mjsas a dependency, where no top-level await is pending, so they never hit this.Fix
reconcile.mjsimportsfollowUpstatically, and the dynamic import is gone. The cycle now resolves while the module graph is evaluated, before the top-level await starts.followup.mjsuses the bindings it imports fromreconcile.mjsonly whenfollowUp()is called. Noprocess.exitand no timeout.recentPass()routing on a same-window scheduled tick,followup.mjs, and the sharedstoppedReviews/reconciledPullguards. Re-runs still go only through the existingact()on the workflowGITHUB_TOKEN. No threshold, pacing, cron, token or permission change. The hub's forced pass is still never doubled: the attempt-1 predicate skips a review re-run by anyone, and themaintenance-reconcile-lost-runsconcurrency group runs one tick at a time. See fix(reconcile): re-run waiting reviews on a late tick once their checks finish #18692 for the full design and guards.Verification
followup-main.test.mjs) spawnsnode reconcile.mjsas a child process withMODE=plan,FOLLOWUP=trueand aFOLLOWUP_PATHqueue, the env the workflow's plan step sets. It runs against a local HTTP stand-in for the GitHub API (GITHUB_API_URL) and the status pages, using the run, job and note shapes fromreconcile.test.mjs's harness. It covers three cases:reconcile follow-up tick: 2 queued, 2 re-run, and the two planned review re-runs with their records inPLAN_PATH;0 queued, 0 re-run, no API route read;2 queued, 0 re-run, the reset-wait line.Detected unsettled top-level await at .../reconcile.mjs:1930. With the fix, all 3 pass.node --test --test-concurrency=4overreconcile.test.mjs,recent-pass.test.mjs,reset-tick.test.mjsandfollowup-main.test.mjs: 282 pass, 0 fail (fix(reconcile): re-run waiting reviews on a late tick once their checks finish #18692's 279 plus the 3 new cases).jobs-batch.test.mjs,guard-coverage.test.mjs,pr-review-main/workflow.test.mjs,component-status.test.mjs,infra-failure.test.mjs): 83 pass, 0 fail.actionlint: clean.zizmor --offline: no findings (2 ignored, both pre-existing).scripts/check-affected.sh --no-fetch: 18 passed, 6 skipped over 10 changed files.Calls per tick: unchanged from #18692. The pinned case makes 14 calls (8 in the plan, 6 in act), and an empty-queue late tick costs about 3-5 calls.
Revert criteria after merge: revert if either of these happens:
gh-job-calls.jsonlbreach the budget, over the next 2 windows in which a follow-up ran;maintenance-reconcile-lost-runson a follow-up tick ends with a failed conclusion.Related
🤖 Generated with Claude Code