Skip to content

fix(pr-pipeline): wait out a short rate-limit reset in the shared rate guard, hold past it when the step opts in - #12944

Merged
kyle-sexton merged 9 commits into
mainfrom
fix/12292-rate-guard-hold
Nov 3, 2026
Merged

kyle-sexton merged 9 commits into
mainfrom
fix/12292-rate-guard-hold

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #12292

Summary

Problem: a short GitHub rate limit ended lane steps red even when the reset was seconds away. Intent: "waits out a short reset and holds instead of failing the step".

This PR delivers the shared rate-guard part of #12292: criteria 1 and 2 of the 2026-11-03 decision, plus the audit's "shared 2" api-budget.bash row. The rate guard now waits out a reset within the existing 60 s budget (SERVER_RETRY_BUDGET_MS) and then sends the call. check-trusted-trigger gets the same wait through the latch. Past the budget, the call is still refused. A step that opts in with API_BUDGET_HOLD=1 reports that refusal as a notice instead of ::error. No workflow opts in yet.

Fix

  • rate-guard.mjs: the latch waits out a stop that fits the 60 s budget, then sends the call. createGitHub resends a read refused for a rate limit within its 3 attempts, and that refusal fails nothing. Past the budget the call is refused: ::error and a failed step by default, or a notice under the hold, which leaves the exit to the caller.
  • check-trusted-trigger.mjs: passes its sleep into latch.guard and resends a limited read, so it waits instead of refusing within the budget.
  • api-budget.bash, plus its two verbatim copies in pr-require-checks.yml: a notice instead of ::error under the hold. Every refused call still returns 1, so a gate that does not hold still fails.
  • The hold is opt-in because some gates let the run through when a read fails (check-wip-cap.mjs starts the run on a failed read). A blanket hold could therefore let a refusal pass. Tests confirm that a trust check refused under the hold returns proceed=false.
  • docs/outage-posture-audit.md: Remaining narrows to the open rows. The lane rows and citations now match the code, including the shared client's 3 attempts with full jitter.

Verification

  • node --test passed 934 of 934 on the changed suites: rate-guard, log-api-budget, check-trusted-trigger, callers and resolve-pr. The run had merged origin/main.
  • A fresh-context phase verifier passed all 8 acceptance criteria on d6a587a, including the safety test "a trust check whose read a holding rate latch refuses stops the lane, never proceeds".
  • scripts/check-changelog-fragments.sh --check reported all 39 fragments valid. markdownlint-cli2 on the audit doc reported 0 issues.
  • Left out: a live rate-limit run in CI, since no workflow sets the hold yet.

Remaining

  • Opt lane steps into API_BUDGET_HOLD=1 one step at a time. Never set it at job or workflow level, where check-trusted-trigger, check-wip-cap or ci-status runs.
  • pr-refine element 1: budgetedFetch in request-budget.mjs waits out a short rate limit and resends, but its client does not set resendLimited. The guard still fails the step.
  • work-resolve-issue, elements 2 and 4:
    • report-outcome.mjs --find-prior holds on a failed read.
    • A failed labeler read no longer holds the PR.
    • stop-routes.json retry-spent no longer fails the issue when every retry was a fault.
  • intake-triage, element 2: apply-verdict.mjs holds green with a notice on an admission or read error.
  • work-unblock, elements 2, 3 and 6: label-unblocked.mjs holds on a failed listing without losing the closes it missed, drops the stored breaker-trip records, and sends etag on the sweep.
  • pr-refine, elements 1 to 4:
    • handoff-evidence.sh uses capped backoff with full jitter and a green hold on a failed read.
    • fix-docs-dispatch.mjs no longer counts a red outage run as done.
    • report-check-run decide.mjs no longer posts failure on no verdict.
  • pr-review, pr-review-security and pr-verify, elements 3 and 5: reconcile.mjs drops the status-page gate and the one-time re-run record.
  • pr-verify, elements 2 and 6: resolve-pr.mjs completeness throws hold instead of going red, and check-trusted-trigger.mjs sends etag on the re-run record poll.
  • pr-unblock, elements 3 and 4: limit-stop.mjs's per-head cap stops acting as a stored breaker, and escalation-routes.json files no fail route on a job fault.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz

kyle-sexton and others added 8 commits November 3, 2026 15:11
…ep holds

The rate latch now waits out a stop whose reset fits the 60 s budget
(SERVER_RETRY_BUDGET_MS, moved into rate-guard.mjs) and sends the call,
instead of refusing it. createGitHub resends a read a rate limit refused
once the reset passes, inside its 3 attempts. Past the budget the call is
still refused; under API_BUDGET_HOLD=1 the refusal logs a notice and leaves
the exit to the caller instead of failing the step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
…s caller holds

api-budget.bash prints its rate-limit lines as ::notice:: under
API_BUDGET_HOLD=1 and keeps returning 1, so a caller that does not hold,
such as ci-status, still fails closed. The two verbatim copies in
pr-require-checks.yml follow. The outage-posture audit narrows the three
shared rows to the workflow opt-in, and a changelog fragment records it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
The guard failed the step on the first refusal even when createGitHub
then waited out the reset and the resend succeeded. retryServerErrors now
marks each attempt it would resend (RESEND), and the guard logs a notice
and skips the failure for such a refusal, with the same predicate
(refusedForLimit, moved into rate-guard.mjs, plus the latch's waits). A
refused mutation, the last attempt and a reset past the budget still fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
…e wait budget

The rate guard now waits out a reset within 60 s before failing, so a
retry-after of 60 made this test wait a real minute. A reset of 120 s is past
the budget and is refused at once.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
…re audit

The lane rows and the shared-code paragraph now say the rate guard waits out a
reset within 60 s and refuses past it (a notice under API_BUDGET_HOLD=1), cite
the current lines, and give the shared client's 3 attempts with full jitter.
The Remaining table gains a row for budgetedFetch, whose client sets no
resendLimited, so the guard fails the step on a refusal it waits out and resends.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 3, 2026 20:42
@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T20:44:38.441388Z 95bc909 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: 95bc909638

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

…starts

retryServerErrors started each attempt's AbortSignal.timeout and its
clock before calling the guarded fetch, so the latch's wait for a
rate-limit reset ran inside the attempt: a wait past attemptTimeoutMs
sent the resent read on an aborted signal, and the wait counted toward
the 60 s server-retry budget when that attempt failed.

The latch now exposes waitOut, and retryServerErrors calls it with its
own sleep before it starts the timeout and the clock. The guard's own
wait then finds nothing left. Refusal past the budget, the hold notice,
RESEND and refusedForLimit are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_015te8Cr8u7uFJG4tdeUACLz
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Security review: PR #12944, incremental since 95bc909

No security issues found. I read every hunk of the 3 files changed since the last review. Two of them are on trusted paths, so I read their whole change and what it gates: .github/actions/check-trusted-trigger/check-trusted-trigger.mjs and .github/actions/log-api-budget/rate-guard.mjs. The third file holds tests only.

Trust controls checked

  • Trusted-trigger check: no widening. retryServerErrors now calls latch.waitOut(url, method, sleep) at the top of each attempt, before the attempt timeout and its clock start (check-trusted-trigger.mjs#L223). The change only moves where the wait happens.
    • waitOut returns at once when waits(url) is false, meaning no stop is recorded or the stop does not fit the budget (rate-guard.mjs#L580-L588).
    • The request still goes through latch.guard, which still runs check(url, method) before sending (rate-guard.mjs#L672-L683). A stop past the budget is therefore still refused with RateLimitStop.
    • The latch-wide waited total keeps the combined wait across both call sites within SERVER_RETRY_BUDGET_MS.
    • Nothing turns a refusal into a successful answer.
    • A latch without waitOut would throw a TypeError, which fails closed. budgetLatch spreads the latch, so it carries waitOut.
  • rate-guard.mjs: the change only exposes the existing waitOut on the latch object. No stop, hold or fail() path changes.
  • Unchanged: the kill switch, the lane token scope, the token broker and the merge holds. No token, secret or untrusted text reaches anything new. The notice log line carries only the method, URL and reset time.

Other notes

  • Prior findings: the earlier summary comment had 0 findings, so nothing carries over.
  • Settled thread: the earlier correctness note on rate-guard.mjs (wait started after the attempt timeout) is what this push addresses. It was never a security finding.
  • Spend: a step can still sleep up to about 60 s per latch to wait out a rate-limit reset. That uses runner minutes, not a new billing setting, so it is not a hold.
  • Not consulted: the instruction-exception register. This diff deletes no instruction surface, so it was not needed.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Code review (incremental): PR #12944, 95bc909 → 35c0274

I read every hunk of the 3 files in the incremental scope:

  • check-trusted-trigger.mjs
  • check-trusted-trigger.test.mjs
  • rate-guard.mjs

I also read the head versions of retryServerErrors/createGitHub and of createRateLimitLatch's waitOut/guard/budgetLatch. I did not run any tests. The 936/936 run and the "both fail without the fix" claim in the owner's thread reply are the author's claims, not something I checked.

Prior finding: resolved

The blocking finding from the last round was that the latch wait ran inside the attempt's timeout and counted against the 5xx budget (earlier comment). This push fixes it:

  • Wait moved before the timers. retryServerErrors now calls latch.waitOut(url, method, sleep) at the top of each attempt, before AbortSignal.timeout and started are set (check-trusted-trigger.mjs#L223).
  • The latch exposes waitOut (rate-guard.mjs#L666).
  • The second wait is a no-op. guarded still calls waitOut, but after the outer sleep of reset + 1000 the stop has passed, so it waits nothing. It still catches a stop that another request set in between.
  • budgetLatch carries waitOut too, because it spreads the latch.
  • No caller is left without waitOut. The only other caller of retryServerErrors, request-budget.mjs:45, gets a real latch. The stub latches in job-log.test.mjs only reach latch.guard and never reach retryServerErrors.

I traced both new tests by hand against the head code, and they test what they say:

  • Live signal test: a 1 s limit, then an 80 ms real sleep against a 30 ms timeout. The timeout now starts after the wait, so both sends see a live signal.
  • Budget test: a 55 s limit, then the latch sleeps 56 000 ms, then a 500 that takes 5 s, then a 200. spent counts only the 5 s, so the call stays within the 60 s budget, and the sleeps are [56000, 0].

Settled threads

The only settled thread is on rate-guard.mjs:675. It is marked lines changed since resolution: no and is consistent with the head. Nothing is re-raised.

Other checks

Spend

The latch can still sleep up to about 61 s per process before a call. That uses runner time, which is subscription or prepaid usage, so it is not a hold.

No new findings.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit ab3b3a2 Nov 3, 2026
65 checks passed
@kyle-sexton
kyle-sexton deleted the fix/12292-rate-guard-hold branch November 3, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant