Skip to content

perf(pr-pipeline): defer Check Intent on a short token window and recover deferred runs after each reset - #18262

Merged
kyle-sexton merged 6 commits into
mainfrom
perf/17460-token-pacing
Nov 22, 2026
Merged

kyle-sexton merged 6 commits into
mainfrom
perf/17460-token-pacing

Conversation

@kyle-sexton

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

Copy link
Copy Markdown
Member

Closes #17460

Summary

Builds the three items the 2026-11-22 decision left for the lane:

Decision item Where it is met
Review and Check Intent runs defer when the projected token budget runs out Reviews already defer (#18054, pr-review-hosted.yml:108-126, pr-review-security-hosted.yml:113-128). Check Intent now does: pr-verify.yml Check the token budget and Note the deferral
A recovery pass a few minutes after each hourly token reset, with its own cap maintenance-reconcile-lost-runs.yml cron 4,19,34,49, reset-tick.mjs, recent-pass.mjs. Deferred Check Intent runs share the DEFER_MAX band (12) with deferred reviews (reconcile.mjs takeDeferred)
Tests cover the deferral and the cap reconcile.test.mjs (5 new), reset-tick.test.mjs, recent-pass.test.mjs (3 new), check-kill-switch.test.mjs, pr-verify/workflow.test.mjs

The quiet-host re-measure and the before/after calls per hour are host work, per that decision comment.

Fix

Check Intent deferral

  • A second check-kill-switch gate (defer: "true", defer-job: check-intent, resolved-config), plus the step that writes the defer config. This is the same shape pr-review-hosted.yml uses.
  • Placement. The gate runs after the resolver and the trigger gate, not at the first kill-switch step. perf(pr-pipeline): defer hosted reviews on a short token window and recover them after the reset #18054 measured that placement: it would defer about 333 runs a day, about 86% of which the resolver skips anyway, so each would cost a recorded re-run and save nothing. Here only a run that would judge can defer. The owner-decisions row for option B names "pr-verify's Check Intent job" among the deferred jobs.
  • Switch inputs. The second gate passes value: "false" and repo-value: "false". The first gate, at the top of the job, already read both switches and fails the run on either. The second gate decides on the budget alone, so it makes no second switch read.
  • Horizon. Nothing sets defer-run-minutes-check-intent, so the horizon is defer-run-minutes (15). The measured pr-verify durations are p99 5 minutes and max 13 minutes, over the 200 newest successful runs. No new key or threshold.
  • The run on deferral. It ends green with no verdict. Note the deferral prints cause=defer reset=<epoch>. The reconciler's faultHeld reads that step as a hold and waits until a minute past the reset. It then re-runs the run once, recorded, in the DEFER_MAX band. A re-run attempt never defers.
  • Only the key leg defers. The subscription and fallback legs take over a handed-off turn, and those keep switch-only gates (check-kill-switch/README.md).

Recovery pass after each reset

  • Why it cannot wait in its own run. check-trusted-trigger.mjs:1167 trusts a reconciler record only for a re-run that starts within WINDOW_MS (10 minutes, :35) of the reconciler run's run_started_at. That limit is not changed here.
  • Schedule. The reconciler instead ticks at 4,19,34,49. reset-tick.mjs reads GET /rate_limit, which does not count against the REST API rate limit. A tick at most 30 minutes into the window is due, once 90 s in. That is RATE_RESET_GRACE_MS (60 s) plus 30 s of clock slack.
  • One pass per window. recent-pass.mjs skips a due tick when a full pass already started after the window's start (a scheduled pass always waits out the grace before it re-runs anything). It compares run_started_at, so a pass that began before the reset and finished after it does not count. The 30-minute band is two tick periods, so one late or dropped tick does not lose the window's pass.
  • Ticks that are not due stop before the kill switch and read nothing else.
  • A failed reset read runs the pass unless one finished in the last hour, which is today's hourly floor.
  • Pacing is exempt. The post-reset pass is not paced: it spends the fresh window. The pacer now applies only when the reset read fails. Since perf(pr-pipeline): defer hosted reviews on a short token window and recover them after the reset #18054, 4 of 24 scheduled ticks were paced (about 67 calls each). On each of those, deferred runs would have waited another hour.
  • pr-unblock-dispatch.yml keeps 9,39. Its test now checks that each reconciler tick is followed by a dispatcher tick within 30 minutes, which is the done-when of perf(pr-pipeline): dispatch fix-ci when the reconciler's re-run fails, not on the next push to main #9496. It still checks five minutes after :04 and :34. ADR 0071 and the pr-pipeline README now name those ticks.

Known limits and costs

  • Three extra runs an hour. A skipped tick costs one short runner job (free on this public repository) and, UNVERIFIED, no core call: checkout by SHA and setup-pinned-node make none by their own docs. Its job-end api-budget notice will show the count.
  • Reaching the carry. newestTrustedArtifact scans at most 10 trusted runs (rotation.mjs:43). Each pass now steps over about 3 skipped ticks, at one artifact listing each, to reach the last carry. The carry falls out of reach after about 2.5 hours with no full pass, where today it takes about 10. The next pass then reads everything once.
  • DEFER_MAX caps re-runs per pass, not runs in flight. With one pass per window, and deferred runs finishing in minutes (reviews p90 10.4 minutes, Check Intent max 13), the two match. They would not if a failed reset read let a second pass into the same window.
  • Deferred Check Intent runs share the band of 12 with reviews. What does not fit waits for the next pass, which then writes no clean.

Verification

  • node --test: 1583 pass, 0 fail. The run covered pace, the reconciler suite (reconcile, reset-tick, recent-pass, jobs-batch, infra-failure, component-status), check-kill-switch, projection, check-trusted-trigger, pr-unblock workflow-gates, resolve-config callers, and all of .github/scripts/pr-verify/*.test.mjs.
  • bash scripts/ci-rerun-ci-status.test.sh: PASS=325 FAIL=0.
  • actionlint and zizmor --offline are clean on both workflows. check-changelog-fragments.sh --check passes, and markdownlint-cli2 passes on the changed markdown.
  • Mutants:
    • Narrowing the band back to reviews fails the two band tests.
    • Dropping the defer condition from agree fails the neutral-stop test ("Write the prompt and schema runs on a budget stop").
    • The recent-pass window test fails if the comparison uses updated_at.
  • A test pins the longest reset wait (90 s), plus the slowest measured reconciler run (112 s over the 30 newest), under check-trusted-trigger.mjs WINDOW_MS.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 4 commits November 22, 2026 18:04
…er it after the reset

Check Intent's second check-kill-switch gate (defer, after the resolver and
the trigger gate) defers a first attempt while the GITHUB_TOKEN window is
projected to run short; its Note the deferral step prints
cause=defer reset=<epoch>. The lost-run reconciler reads that step as a hold,
waits until a minute past the reset, and re-runs the run in the DEFER_MAX
band beside the hosted reviews.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…token reset

The hourly tick reads GET /rate_limit (not counted against the core pool)
and waits until 90 s past the window's reset (reconcile.mjs's 60 s grace
plus 30 s for the runner's clock), or runs at once when the window began at
most 11 minutes ago, so every pass re-runs deferred reviews and Check Intent
runs at the start of the next window wherever the reset has drifted. Past
11 minutes the next reset is at most 49 minutes ahead, which the job's
65-minute timeout holds with the pass.

The post-reset pass is not paced: it spends the fresh window, and a paced
recovery pass would leave deferred runs waiting another hour. A tick whose
reset read fails runs at once and is paced as before.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fter each token reset

Replaces the in-run wait: check-trusted-trigger trusts a reconciler record
only for a re-run that starts within WINDOW_MS (10 minutes) of the
reconciler run's start (check-trusted-trigger.mjs:35, :1167), so a pass
cannot wait out the reset inside its run.

The schedule ticks at 4,19,34,49. reset-tick.mjs reads GET /rate_limit (not
counted against the core pool): a tick at most 30 minutes into the window is
due, once 90 s in (reconcile.mjs's 60 s grace plus 30 s for the runner's
clock), and names pass-after; recent-pass.mjs skips a due tick when a full
pass already started after pass-after, comparing run_started_at so a pass
that straddled the reset does not count. Any other tick stops before the kill
switch. A failed read runs the pass unless one finished in the last hour.
The 30-minute band, two tick periods, keeps the window's pass when one tick
is late or dropped.

The post-reset pass is not paced: it spends the fresh window, and a paced
recovery pass would leave deferred runs waiting another hour.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 22, 2026 23:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 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-22T23:27:51.253011Z ac36625 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac366259d7

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

Lane run report

Field Value
Activity pr-refine/fix-docs

Run 45083274070, attempt 1

Field Value
Model rung 0
Leg handoff
Run job success
Activity step success
Commits pushed none (read lane)
Run 45083274070

Failed GitHub API calls

No failed call recorded by the run job's scripts.

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 6be8c143eafcc063d57bb83ce03f8151f52655a5: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review (incremental, blocking only): no security issues found

This lane already reviewed an earlier head, so this review was blocking only: it looked for CRITICAL and IMPORTANT findings only. I read every hunk of the 3 files changed since 91411965:

  • .github/scripts/maintenance-reconcile-lost-runs/reset-tick.mjs
  • reset-tick.test.mjs
  • recent-pass.test.mjs

None of them matches a trusted-path glob.

What changed: tickPlan now returns passAfter: reset - WINDOW_SECONDS, which is the window's start. Before, it returned the window's start plus GRACE_SECONDS (reset-tick.mjs#L40). Two kinds of scheduled pass now count as that window's full pass: one that started in the first 90 s of the window and then waited out the grace, and one that started earlier in the grace period. The test fixtures move to match.

What I checked:

  • Kill switch and re-run path. The change only moves the time recent-pass.mjs uses to decide whether a due tick can skip. Here a skip means no re-runs happen. The change cannot cause a re-run, so it adds no route around the kill switch or check-trusted-trigger.
  • Trust checks. recent-pass.mjs and its trustedRun filter are not part of this push, so which runs count as a pass is unchanged.
  • Fallback behaviour. Any event other than schedule, or a failed reset read, still writes due=true with no pass-after, as it did before.
  • Tokens and untrusted text. The change touches no token, secret, permission or untrusted input. pass-after is a number computed from the /rate_limit reset value.
  • Worst case. A tick can now skip in a few more cases, so a deferred run may wait for a later pass. That delays recovery but has no security impact.

Spend: none beyond what the earlier review covered. This push changes no schedules, runners or billing settings.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on ac366259d72d6f1994bf895411310ecda857146f; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 6be8c143eafcc063d57bb83ce03f8151f52655a5: read 3 of 3 changed file(s); 1 finding(s), 0 as inline comments.

Code review: PR #18262 (incremental, blocking only)

This lane already reviewed an earlier head, so this pass reports only blocking findings. I read every hunk of the 3 files in the incremental diff: recent-pass.test.mjs, reset-tick.mjs and reset-tick.test.mjs. I also read the head copy of recent-pass.mjs, the settled threads and my earlier findings.

The earlier blocking finding is fixed at this head. tickPlan now returns passAfter: reset - WINDOW_SECONDS, which is the window start (reset-tick.mjs:40).

  • A scheduled tick that started inside the 90 s grace and waited it out has run_started_at >= passAfter, so recentPass now counts its pass (recent-pass.mjs:23).
  • The new test covers that case: reset 15:03:30Z, start 14:04:00Z, since=30, wait=60, and the start is at or after passAfter.
  • The re-pinned test values match the new start-of-window semantics. In reset-tick.test.mjs these are passAfter: WINDOW_START and pass-after=${WINDOW_START}. In recent-pass.test.mjs, PASS_AFTER is now 14:30:00Z, and the pass that started before the window (14:29:50Z) still gives skip=false.
  • The header comment now matches the code.
  • I found no new blocking problem in this change.

Restated summary finding (loosened check, "Fail a change that loosens a check", item 4: an allowlist entry added). This finding had no line anchor, so it is restated each round. Its line is not in this round's incremental diff, so it has no inline comment.

  • guard-coverage.test.mjs:64 still adds an UNGUARDED allowlist entry for reset-tick.mjs.
  • The closing issue gives no reason for exempting this file from the rate-guard coverage check.
  • The entry's own reason field is PR text, not spec.
  • Fix: route the /rate_limit read through the guard so the entry is not needed, or have the spec record why this file is exempt.

Spend (not a hold, not counted): each hour adds short reconciler ticks, each making one GET /rate_limit, and the post-reset pass is no longer paced.

Loosened checks. The prompt has no loosened-check verdict or patterns lines, so I used fail and no consumer entries. It has no decision-record line, so I did not check the citation requirement.

Loosened checks would be marked: fail (default; no lane settings); patterns: 0

Other criteria: No plugin manifest changed in this round. The settled threads and prior findings contain no instructions aimed at this lane. I ran nothing; any test results in the PR are claimed by the author and I did not verify them.

Verifier dropped 0 of 1 candidates.

kyle-sexton and others added 2 commits November 22, 2026 18:40
…fetches

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… window's pass

pass-after was the window start plus the 90 s grace, so a tick that started
inside the grace and waited it out had run_started_at before pass-after, and
the next tick in the same window ran a second full pass. pass-after is now
the window start: a scheduled pass that starts after it always waits out the
grace before it re-runs anything.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 862e4c3 Nov 22, 2026
79 checks passed
@kyle-sexton
kyle-sexton deleted the perf/17460-token-pacing branch November 22, 2026 23:57
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 6, survived 1, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 86%; mutation score 86%.

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

Surviving mutants

Location Operator Disposition Cause
.github/scripts/maintenance-reconcile-lost-runs/reconcile.mjs:1171 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(ci): pace GITHUB_TOKEN spend so busy hours stop tripping the kill switch

1 participant