Skip to content

fix(reconcile): re-run waiting reviews on a late tick, without the main() hang - #18757

Merged
kyle-sexton merged 3 commits into
mainfrom
fix/reconcile-followup-tick-reland
Nov 24, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
fix/reconcile-followup-tick-reland

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

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_reviews in the reconcile-settled-runs artifact). 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:1930 and Process 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.

When reconcile.mjs is the entry module, it is still evaluating its top-level await at that point. Evaluating followup.mjs therefore waits for reconcile.mjs to finish. reconcile.mjs waits for main(), and main() waits for the import. No other work keeps the event loop alive, so Node exits 13. The in-process tests import reconcile.mjs as a dependency, where no top-level await is pending, so they never hit this.

Fix

  • Cause: reconcile.mjs imports followUp statically, and the dynamic import is gone. The cycle now resolves while the module graph is evaluated, before the top-level await starts. followup.mjs uses the bindings it imports from reconcile.mjs only when followUp() is called. No process.exit and no timeout.
  • Re-applied design: the fix(reconcile): re-run waiting reviews on a late tick once their checks finish #18692 commit is cherry-picked unchanged (it applied cleanly to current main): the queue in the settled artifact, recentPass() routing on a same-window scheduled tick, followup.mjs, and the shared stoppedReviews/reconciledPull guards. Re-runs still go only through the existing act() on the workflow GITHUB_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 the maintenance-reconcile-lost-runs concurrency 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

  • New e2e test (followup-main.test.mjs) spawns node reconcile.mjs as a child process with MODE=plan, FOLLOWUP=true and a FOLLOWUP_PATH queue, 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 from reconcile.test.mjs's harness. It covers three cases:
    • due queue: exit 0, the notice reconcile follow-up tick: 2 queued, 2 re-run, and the two planned review re-runs with their records in PLAN_PATH;
    • empty queue: exit 0, 0 queued, 0 re-run, no API route read;
    • not-due (defer reset 10 minutes ahead): exit 0, 2 queued, 0 re-run, the reset-wait line.
  • Fails without the fix: on the re-applied fix(reconcile): re-run waiting reviews on a late tick once their checks finish #18692 code, all 3 cases exit 13 with the production warning Detected unsettled top-level await at .../reconcile.mjs:1930. With the fix, all 3 pass.
  • node --test --test-concurrency=4 over reconcile.test.mjs, recent-pass.test.mjs, reset-tick.test.mjs and followup-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).
  • Importer suites (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:

  • any follow-up tick makes more than ~20 calls, or the window's added calls in gh-job-calls.jsonl breach the budget, over the next 2 windows in which a follow-up ran;
  • any run of maintenance-reconcile-lost-runs on a follow-up tick ends with a failed conclusion.

Related

  • #18692: the original follow-up tick and its design.
  • #18745: its revert.

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 24, 2026 02:40
…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]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 24, 2026 07:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T07:57:19.694390Z 4c5e5d6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 4c5e5d6a6f1b6288d81ab34b6b9221d482a997c3: read 10 of 10 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security findings

This PR brings back the review-only follow-up tick from #18692 and fixes its top-level-await hang by importing followUp statically. I read every hunk of all 10 changed files, including the trusted-path workflow .github/workflows/maintenance-reconcile-lost-runs.yml, and found nothing that meets the bar.

What I checked

  • Kill switch still stops a follow-up. "Check the kill switch" now also runs when steps.recent.outputs.followup == 'true' (workflow L151), and it still sets budget: "true". The plan step passes KILL_SWITCH: ${{ steps.kill.outputs.proceed == 'true' && 'proceed' || '' }} (L199). In reconcile.mjs, the KILL_SWITCH !== "proceed" early return and the Actions-operational check both come before the FOLLOWUP === "true" branch (reconcile.mjs L1841-L1864). If the switch step is skipped or fails, KILL_SWITCH is empty, so the follow-up still fails closed.

  • The queue is validated twice. recent-pass.mjs reads the queue only from the newest reconcile-settled-runs artifact that newestTrustedArtifact/trustedRun accepts, which unchanged code limits to this workflow's own runs. parseSettled rejects a row unless its ids are positive integers, head matches SHA and path is in GATED_REVIEWS. It also rejects another repository's carry and a different version. followup.mjs then checks live state before re-running anything:

    • it filters runs to head_repository.full_name === repo;
    • the queued checks run must still be the head's newest;
    • the PR must still pass reconciledPull (open, not draft, based on main, same-repo head) at the queued SHA;
    • every ci-status failure must be a review stop;
    • every stopped review must be a queued deferral.

    A tampered or stale queue entry can at most cause a re-run that the full pass would already have made.

  • No change to tokens or permissions. The job-level permissions: block is unchanged, and re-runs still go through the existing act() on github.token. No new actor is trusted, and no PR code is checked out or run.

  • The follow-up writes no settled-runs marker. Both "Scan the upload for credentials" (scan-upload-4) and "Carry the settled runs" now require followup != 'true'. A follow-up tick therefore uploads no settled-runs artifact and can never pass for the window's full pass. Per-re-run records still use the existing scan-then-upload steps.

  • The stoppedReviews refactor keeps the same behaviour. The function moved to module scope with its body unchanged: each lane's disable variable, the re-run window, the defer and rate-limit grace periods and the upstream gate are all still checked.

  • The new e2e test uses only local data. followup-main.test.mjs points GITHUB_API_URL and the status pages at a 127.0.0.1 stand-in and uses a stub token.

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

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 4c5e5d6a6f1b6288d81ab34b6b9221d482a997c3: read 10 of 10 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #18757, re-run waiting reviews on a late tick without the main() hang

I read every hunk of all 10 changed files in .claude-lane/pr.diff. I also read the unchanged code these changes call: reconcile.mjs main() (L1790-1870), recent-pass.mjs main(), and the workflow steps that gate the plan, act and carry steps. No blocking or advisory findings.

The fix holds up. reconcile.mjs now imports followUp statically, at reconcile.mjs#L257. When reconcile.mjs is the entry module, Node evaluates followup.mjs first because it is a dependency. At top level, followup.mjs only defines onlyReviewStopsNoted, readQueue and followUp. None of them touches a reconcile.mjs binding until it is called, so there is no read of an uninitialized binding. The cycle is also settled before the top-level await main() at L1930 runs.

  • recent-pass.mjs already imported reconcile.mjs before this PR, so the new cycle changes nothing on that entry path.
  • The new child-process test (followup-main.test.mjs) runs the module the way the workflow does. That is the path the in-process tests missed.

Workflow gating checked:

  • Kill switch: a follow-up tick still goes through it. main() checks KILL_SWITCH !== "proceed" and the Actions status before the FOLLOWUP branch (L1841-L1864).
  • No settled-runs upload: a follow-up tick uploads no reconcile-settled-runs carry, because scan-upload-4 and Carry the settled runs both check followup != 'true'. So it is never taken for the window's full pass.
  • No clean mark: it never writes clean, so it never marks the pacer's work step.
  • Step order: moving Skip a run right after a full pass ahead of the kill-switch and pace steps changes nothing for due ticks or dispatches. Neither of those steps reads steps.recent.
  • No double re-run: a review already re-run (attempt 2) is skipped on later ticks in the window.

I did not run the PR's test results, actionlint/zizmor output or call counts myself; they are the author's claims and unverified. Nothing in the PR body or the PR context file tries to direct this lane.

Usage only, not a hold: every scheduled tick past the first 30 minutes of a window now runs recent-pass.mjs, a few GITHUB_TOKEN API calls plus one artifact download when a full pass exists. Follow-up ticks also re-run hosted review lanes, which spend review-lane model usage.

Loosened checks: I found no loosening. Updated test expectations follow the intended behavior change, and the replaced kill-switch assertion loop is restated as stricter per-step assertions. Loosened checks would be marked: fail (default; the prompt carries no loosened_check_verdict: or loosened_check_patterns: line); patterns: 0. The prompt has no loosened_check_decision_record: line, so I did not check the citation requirement.

Not applicable:

Verifier dropped 0 of 0 candidates.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 348a2b4 Nov 24, 2026
113 of 114 checks passed
@kyle-sexton
kyle-sexton deleted the fix/reconcile-followup-tick-reland branch November 24, 2026 08:36
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant