Skip to content

perf(pr-pipeline): defer the pr-merge arm run when the token budget is projected to run out - #17660

Merged
kyle-sexton merged 2 commits into
mainfrom
perf/17460-defer-gate
Nov 20, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
perf/17460-defer-gate

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #17460

Summary

check-kill-switch gains a defer gate. On a first run attempt, it stops a job whose work a later run recovers while the GITHUB_TOKEN window is projected to have under defer-project of its limit left when the job would end. The stop carries cause defer and the window's reset. Only pr-merge's PR-scoped arm run defers, and the sweep recovers its work. CI Status and pr-dispatch-feedback never defer.

Fix

  • New deferGate and defer path: no start-gate floor and no wait, a re-run never defers, and 0 turns it off.
  • New inputs defer, defer-job, defer-minutes and resolved-config.
  • Defaults in rate-limits.json: defer-project 0.3, defer-run-minutes 15 and defer-run-minutes-pr-merge 6 (the arm run's p90). Each can be overridden in pr-pipeline.yaml (schema api-pool).
  • The arm gate reads its horizon from the config.
  • A deferral logs ::notice title=defer:: with the reset, and the wake line reads outcome=deferred (cause defer) ... reset at <epoch>.
  • The GATES test gains a defer kind.

Verification

  • check-kill-switch 84/84
  • log-api-budget, resolve-config and pr-merge 2,373/2,373
  • check-convention-yaml 51/51
  • actionlint and the fragment check pass

Related

Phase 1 of the #17460 plan. Deferral for the reviews and Check Intent waits on a separate owner decision.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KeBVgaQE4QB75SPD3ky1jd

kyle-sexton and others added 2 commits November 20, 2026 10:19
…s projected to run out

Add a defer gate to check-kill-switch. With `defer: "true"` on a first run
attempt, its one GET /rate_limit stops the job (cause defer, the window's
reset) while the window's burn rate projected to the job's horizon, or to
the reset when sooner, leaves under github-token's defer-project share of
the limit. It reads no start-gate floor, never waits, and a re-run attempt
never defers. defer-project 0 turns it off.

- deferGate reads defer-project and defer-run-minutes from the resolved
  config's limits.api over rate-limits.json (defaults 0.3 and 15); the
  gate's defer-minutes input sets the job's horizon.
- pr-merge's enable-auto-merge gate defers only a PR-scoped arm run
  (inputs.pr), with a 6-minute horizon (p90 of 29 arm runs); the sweep
  recovers it and keeps switches only. The pr-merge-wake line names the
  deferral and the reset, and the gate logs a defer notice.
- rate-guard.mjs admits both fields; the schema's api-pool admits them.
- The GATES test gains the defer kind and checks that no CI Status or
  pr-dispatch-feedback gate defers.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaQE4QB75SPD3ky1jd
…nfig key

The pr-merge arm gate no longer hardcodes defer-minutes "6". A new
defer-job input names the job's horizon key, github-token's
defer-run-minutes-<job> in limits.api over rate-limits.json, falling back
to defer-run-minutes. defer-run-minutes-pr-merge defaults to 6, the p90 of
29 first-attempt arm runs (327 s), and pr-pipeline.yaml may override it;
the schema's api-pool and rate-guard.mjs admit the key.

Refs: #17460

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KeBVgaQE4QB75SPD3ky1jd
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 20, 2026 15:54
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 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-20T15:56:44.114020Z b95b653 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 b95b65339d91a4fcb56638104ed88f2eea50c48e: read 12 of 12 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #17660 (defer gate for pr-merge's PR-scoped arm run)

No security issues found. I read every hunk of all 12 changed files. These trusted-path files got the full trust-control scrutiny: check-kill-switch/**, rate-guard.mjs, rate-limits.json, pr-merge.yml and pr-pipeline.yaml.

Kill switch (check-kill-switch). The switch still works. The defer path runs only when result.proceed === "true" and the run is not a re-run (check-kill-switch.mjs#L253). So the switch is still read first and fails closed as before, and deferral can only turn a proceed into a stop, never the other way. With share: null, checkBudget skips the start-gate floor (share !== null && budgetStops(...)), and this changes nothing for the existing start gates, which always pass a number. If the defer gate cannot be set up, or the budget read fails, the job proceeds, which is how it behaved before this PR. A refused read defers, so it stops.

Merge holds (pr-merge.yml enable-auto-merge). A defer stop sets proceed=false. Every step that acts in that job is gated on steps.kill.outputs.proceed == 'true' (for example pr-merge.yml#L2549). A deferred run therefore arms nothing, the same as a switch stop.

Deferral applies only when inputs.pr is set. That is the dispatch pr-verify starts on a pass verdict, and it only arms. The runs that disarm on a hold are the event (pull_request_target) runs and the scheduled or hand-started sweep. None of them sets inputs.pr, so none of them defers. No hold is weakened and no merge can happen sooner.

Config input. The new Read the defer override step builds defer-config.json with yq from .base/docs/conventions/pr-pipeline.yaml, which is the base checkout. A pull request's head therefore cannot change defer-project or the run-time horizon. deferGate also checks the share's range, the whole-minute horizon and the defer-job pattern (^[a-z0-9][a-z0-9-]*$).

Shell and output handling. KILL_CAUSE and KILL_RESET reach the wake-outcome step as environment variables and are only expanded inside a quoted assignment, never evaluated. reset is a number the script itself writes, and outputs use the existing delimited writer.

Token scope. No change: the defer read uses the existing BUDGET_TOKEN (github.token) for one GET /rate_limit. No permissions, trusted actors or broker grants change.

Spend. Each PR-scoped pr-merge arm run makes one extra GET /rate_limit call on the GITHUB_TOKEN. It is free and billed nothing, so it is not a hold.

PR text. The description and linked issue context hold no embedded instructions.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

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

CI code review: PR #17660 (head b95b653)

No blocking or advisory findings. I read all 12 changed files in full in the diff. Three files match the trusted-path globs and got extra scrutiny: .github/actions/check-kill-switch/**, rate-guard.mjs / rate-limits.json, and pr-merge.yml / pr-pipeline.yaml.

What I checked:

  • Defer path in check-kill-switch.mjs. deferGate validates defer-project (0 turns deferral off; any other value must be over 0 and at most 1), the defer-job suffix and the whole-minute horizon. If it cannot be set up, it logs a warning, makes no budget read and the job proceeds. checkBudget with share: null skips the start-gate floor (low is false), so only the projection decides. A refused read stops with cause defer and a reset from Math.ceil, so the reset is a whole epoch second. Run attempt !== "1" (empty or unknown included) never defers. The existing start-gate path is unchanged: callers still pass a numeric share, and the default title is start-gate.
  • rate-guard.mjs and rate-limits.json. BUILT_IN_LIMITS and rate-limits.json gain the same three keys. The new keys are added to FIELDS, so readDefaults accepts them. They are kept out of FILE_ONLY_FIELDS, which matches the schema now admitting them under limits.api.
  • pr-merge.yml enable-auto-merge. The job checks out .base fully, so log-api-budget/ and pr-pipeline.yaml are present. The yq step is continue-on-error. If it fails, the redirect leaves an empty file, apiLimits falls back to {}, and the gate uses the shipped defaults. defer is true only for inputs.pr, so schedule, push and pull_request_target runs never defer. Every later step needs steps.kill.outputs.proceed == 'true' or a downstream output, so a deferral ends neutral. The wake line puts the defer branch ahead of the plain kill-switch branch.
  • Tests. In check-kill-switch.test.mjs, the switch kind now also rejects defer inputs. The new defer kind asserts its exact input shape. budgetJobs and falseOnBudget extend the neutral-stop check to defer gates through their own cause. workflow.test.mjs pins the arm gate's inputs.

I have not run any tests. The PR's counts (84/84, 2,373/2,373, 51/51) are the author's claims and unverified.

No Closes issue: the PR says Refs: #17460, so no acceptance criteria apply. I found no embedded instructions in the PR context.

Loosened checks would be marked: fail (default: the prompt carried no loosened_check_verdict: or loosened_check_patterns: line, so no consumer entries); patterns: 0. The decision-record citation requirement was not checked because the prompt has no loosened_check_decision_record: line. No loosening found: every changed assertion accepts the same or less than before.

Spend: each PR-scoped pr-merge arm run makes one more GITHUB_TOKEN GET /rate_limit read. Deferred arm work waits for the next sweep, at most one reset later. This is not a billing change.

Verifier dropped 0 of 0 candidates.

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