Skip to content

fix(reconcile): re-run waiting reviews on a late tick once their checks finish - #18692

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

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

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

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) 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, 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

🤖 Generated with Claude Code

kyle-sexton and others added 3 commits November 23, 2026 22:54
…ks finish

A full pass that finds a stopped hosted review on a head whose checks run
is still going only waits, and every later tick of the same token window
skips because a full pass already ran. On 2026-11-24 the reviews of #18671
and #18646, deferred at 03:13Z, waited about an hour for the next window's
pass.

The full pass now queues each such review ({checksRunId, reviewRunId, pr,
head, path}) as waiting_reviews in its reconcile-settled-runs artifact,
leaving out any it selected itself. reset-tick names the window start on
a not-due tick too, and recent-pass, on a scheduled same-window hit,
downloads that artifact by the id its listing gave and writes a non-empty
queue for the follow-up. That tick goes through the existing budget kill
switch into a review-only plan (followup.mjs): one run listing per queued
head, and for a head whose newest checks run finished red only on the
review stop, the full pass's own stoppedReviews (lane switch, re-run
window, defer reset, upstream gate), limited to the queued reviews and to
the DEFER_MAX band. A kill-switch stop needs a MAX_IN_FLIGHT place, which
only a full pass counts, so it waits for that pass. The items go through
recordOutputs, the record uploads and the existing act step on the
workflow GITHUB_TOKEN.

The queue is never rewritten. A review a tick re-ran is at attempt 2 on
the next tick, and the attempt-1 predicate (isUnreviewed) skips it in the
plan and again in act's re-read before the POST. Together with the
workflow concurrency group, that keeps a follow-up from doubling the hub's
forced review re-run. A follow-up uploads no settled runs and never marks
a clean pass, so the full-pass marker and the pacer see only full passes.
Missing or invalid state queues nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…p-tick

# Conflicts:
#	.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs
…ence

Review findings on the follow-up tick:

- The queued checks run must still be the head's newest and be complete.
  A newer checks run on the same head leaves the reviews to the next full
  pass.
- The live pull request must pass the full pass's own filter (open, not a
  draft, into main, from this repository, at the queued head), now shared
  as reconciledPull.
- A head with a CI run the full pass recovers first (a lost CI run, a CI
  re-run in flight, or another CI run's failed first attempt) is left to
  the full pass, through the shared classify.
- The head's whole stopped-review set is judged before the queue filter.
  The follow-up re-runs only when every stopped review is queued and
  deferred and they fit the band; a mixed set goes to a full pass.
- Each follow-up tick writes a "reconcile follow-up tick: N queued, M
  re-run" notice, so a run shows it took this path.

The recent-pass ingestion tests now read fixtures/settled-waiting.json, the
full pass's writer output captured from the reconcile harness, and derive
each malformed variant from it. reconcile.test.mjs pins the writer to that
fixture, so the two cannot drift apart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 24, 2026 04:08
@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-24T04:10:40.157327Z b5e09e5 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 b5e09e58fc1386f02b1db941a9d01682e8bb4dc0: read 9 of 9 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #18692 (reconcile follow-up tick)

I found no security issues. I read every hunk of all 9 changed files. The workflow file and the reconciler scripts are trusted paths, so I also read the code the change depends on.

What I checked

  • Kill switch still stops the new path. The Check the kill switch step now also runs when steps.recent.outputs.followup == 'true' (workflow L149-L157), and it keeps budget: "true".
    • In main, the KILL_SWITCH !== "proceed" early return comes before the new FOLLOWUP === "true" branch (reconcile.mjs L1840-L1864).
    • It fails closed: a kill step that was skipped or failed leaves proceed empty, and nothing is re-run.
    • The Re-run lost runs step uses the same condition as Find lost runs and only acts on the plan file that step wrote. A plan step that fails or is skipped leaves act skipped too.
  • Recent-pass now runs before the kill switch. Its only GitHub calls are reads: a run listing, artifact listings and one archive GET, all on github.token. Its only write is a temp file. Every write still sits behind the kill-switch check.
  • Trust of the carried queue. The carry is downloaded by artifact id only from a run that trustedRun accepts: this workflow's path, a schedule or non-wake workflow_dispatch event, and head_branch === "main" (rotation.mjs L61-L67).
    • The id goes into execFileSync as an argv element, not through a shell (rotation.mjs L131-L151).
    • Each row is shape-checked by waitingReview: positive integer ids, a SHA head, and a GATED_REVIEWS path.
  • What a queue row can trigger. A row only selects which head to look at. The re-run target is taken from the live run listing, using only runs whose head_repository is this repository. stoppedReviews (moved out of plan() without changes) and reconciledPull (the full pass's own filter, now shared) decide what qualifies. act() re-checks attempt 1 and the PR head before the POST.
    • So even a forged row could only re-run a stopped attempt-1 hosted review on an open, ready same-repository PR. A full pass would do the same.
  • Permissions and tokens. The job's permissions: block, its tokens and the act write kinds are unchanged. A follow-up uploads no settled carry and never writes clean.

Spend (not a finding): each late scheduled tick now makes about 3-5 extra GITHUB_TOKEN reads, roughly 240 calls/day by the PR's own estimate. These are free GitHub API rate-limit calls, not a charge.

critical-findings: 0

The register at docs/contracts/instruction-exception-register/README.md was not consulted. This diff deletes or softens no standing instruction, so the instruction-surface lens did not apply.

@github-actions

Copy link
Copy Markdown
Contributor

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

Code review: PR #18692, reconcile follow-up tick

No findings. I read every hunk of all 9 changed files.

What changed. A full reconciler pass now records each hosted review it leaves waiting on a running checks run. It writes that list as waiting_reviews in the reconcile-settled-runs artifact it already uploads. A later scheduled tick in the same token window finds that pass, downloads its artifact by id and passes the list to followup.mjs. That script re-runs a queued review only when all of these hold:

  • the queued checks run is still the head's newest and finished red on the review-stop or rate-hold note;
  • no CI run on the head needs recovery first;
  • the live pull request still passes reconciledPull;
  • the full pass's own stoppedReviews() yields only queued, deferred reviews within DEFER_MAX.

What I checked against unchanged code:

  • Same order as the full pass. I compared ciRecoveryFirst with the full pass's per-head order (reconcile.mjs L1150-1254). classify covers both lost re-runs and attempt-2 runs in flight (inFlight). The attempt-1 failure check covers the flake and infra items, because reconcilerRetries only takes attempt 1 (infra-failure.mjs#L52). A checks run that failed in a non-aggregate job makes onlyAggregateFailed return nothing, so that head goes to the full pass.
  • Kill switch still applies. The follow-up branch in main runs after the KILL_SWITCH !== "proceed" check and the Actions-status check (reconcile.mjs#L1840-L1864). The kill-switch step now also runs when followup == 'true', so the budget gate stops follow-ups too.
  • No double re-runs. A review that was already re-run is at attempt 2. Both isUnreviewed in the plan and lostNow in act skip it.
  • Follow-ups leave the full-pass marker alone. They never write clean and never upload the settled artifact: both scan-upload-4 and "Carry the settled runs" now skip when followup == 'true'. The pacer and recentPass therefore still see only full passes. Skipping the scan only on runs that also skip the upload weakens no check.
  • Calls and imports match their targets. The ghDownloadArtifact call matches its signature (rotation.mjs#L131). Every name followup.mjs imports exists as an export.

Tests. The assertions changed in reset-tick.test.mjs, recent-pass.test.mjs and reconcile.test.mjs pin the new behaviour exactly; none accepts more than before. The author reports 279 + 55 tests passing. I did not run them (author-claimed, unverified).

Closing issue. The PR body says Refs: #17460 and closes no issue, so there are no acceptance criteria to check.

Spend (not a hold, not a finding). Each late scheduled tick now runs recent-pass: 1 run listing, 1-3 artifact listings and 1 archive GET. A follow-up adds about 14 GitHub API calls for one head with two deferred reviews, up to 3 times per window. The PR estimates about 240 extra calls a day on ticks with an empty queue. These draw on the GITHUB_TOKEN rate-limit budget, not on billing. There are no new runners and no cron change.

Loosened checks. I found no loosening: no test skipped, no assertion weakened, no gate made to accept more without a gate in its place.
Loosened checks would be marked: fail (default, no loosened_check_verdict: line); patterns: 0 (no loosened_check_patterns: line). The prompt has no loosened_check_decision_record: line, so I did not check the citation requirement.

Path-scoped rules. No .claude/rules/ glob matches a changed file.

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 7bf2419 Nov 24, 2026
146 of 150 checks passed
@kyle-sexton
kyle-sexton deleted the fix/reconcile-followup-tick branch November 24, 2026 04:38
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 4, survived 3, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 57%; mutation score 57%.

File Killed Survived Timeout No coverage Invalid Not run
.github/scripts/maintenance-reconcile-lost-runs/followup.mjs 1 1 0 0 0 0
.github/scripts/maintenance-reconcile-lost-runs/recent-pass.mjs 1 0 0 0 0 0
.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs 1 2 0 0 0 0
.github/scripts/maintenance-reconcile-lost-runs/reset-tick.mjs 1 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
.github/scripts/maintenance-reconcile-lost-runs/followup.mjs:104 ROR productive input-gap
.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:433 ROR productive input-gap
.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:1690 other productive input-gap

The run's summary has the full report.

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) post-merge: reverted Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant