Repository navigation
ci-gate: wait out an exhausted API budget; keep the ref when there is no verdict - #200
Conversation
… no verdict Every session on the account shares one 5,000-request/hour REST budget. At 0, ci-gate counted each 403 as a failed read: discovery gave up with an exhausted-budget ERROR and the watch hit maxUnreadable, and either way the ci/ ref was deleted while the run still ran (five calls in two days). A 403 or 429 that names the rate limit is now waited out (pace.mjs read): sleep until the later of retry-after and, at 0 remaining, the published reset (a minute when neither is given), plus 5 s; check GET /rate_limit, which is not counted, and sleep again while it still says 0, since the reset moves when the window refills and drains. Each wait prints THROTTLE remaining=<n> until=<ISO>. Discovery, the watch and the failed log's fetch read through it; discovery's 5-minute deadline does not count the wait. After 90 min of continuous exhaustion, ERROR as before. The healthy path makes no extra request and prints nothing new. The ref is removed after GREEN or RED, and when no run appeared. After an ERROR or an interruption while a run exists (or when the budget hid it), it stays, recorded under the clone's git directory; a later ci-gate in that clone deletes recorded refs older than 24 h, compare-and-delete.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9a854d5a8
ℹ️ 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".
| if (until - exhaustedSince > LIMIT_WAIT_MS) { | ||
| throw new BudgetExhausted(`the GitHub API rate limit stayed exhausted for ${LIMIT_WAIT_MS / 60_000} min (resets ${iso(until)})`); |
There was a problem hiding this comment.
Enforce the exhaustion bound using elapsed time
If /rate_limit continues returning zero remaining with an unchanged reset timestamp that is now in the past, this condition never reaches the 90-minute bound: until stays fixed while the loop sleeps another minute indefinitely. With an injected clock and a constant exhausted response, the pacer was still polling after 99 minutes instead of throwing BudgetExhausted. Check elapsed time against exhaustedSince as well as the proposed resume time so an overdue reset cannot leave discovery or the watch hanging forever.
Useful? React with 👍 / 👎.
| const removed = remove(entry); | ||
| rmSync(file, { force: true }); |
There was a problem hiding this comment.
Retain ledger entries when remote deletion fails transiently
When a sweep encounters a network, authentication, or remote-server failure, deleteRef() in cli/git.mjs returns false, just as it does for a moved ref. Unconditionally deleting the ledger entry here permanently forgets the still-existing remote ref, so later calls cannot retry its cleanup; sweepOldRefs() also misleadingly reports that it is gone or moved. Since these automatically kept refs have no other janitor, retain the entry on an unconfirmed deletion failure, or distinguish a confirmed absent/moved ref from a failed removal before forgetting it.
Useful? React with 👍 / 👎.
- The 90-min bound is elapsed time on ci-gate's clock, not the published reset, and each sleep is cut to what the bound has left. A /rate_limit that kept saying 0 with a reset already past never tripped it. - Discovery marks that a run may exist when the budget first hides it, before the wait (pacer.read onLimited), so a Ctrl-C during the hour's wait keeps the pushed ref instead of deleting it under a live run. - The sweep reads each due ref's newest run first (one request, skipped while the budget is low) and leaves the ref while a run on it is queued or going: a rerun keeps the nonce commit, so compare-and-delete alone would delete the branch under it. - A record is dropped only when the delete succeeds or ls-remote shows the ref gone or moved; a failed push is tried again by a later call.
|
Review fixes in 796f336, each with a regression test:
Focused tests: 82/82. ci-gate on 796f336: GREEN (run 42809717282). The sweep made one branch-run read and dropped a backdated probe record. |
…emoved by hand Review kept finding edges in the automatic 24-hour sweep (an active rerun of an older run, a push URL that differs from the fetch URL, a Ctrl-C after the verdict) for a rare event, and a kept ci/ ref is harmless: a branch nobody pushes to starts nothing. The ledger in the git directory, the sweep, latestRunOnBranch and deleteKeptRef go, with their tests. An exit without a verdict while the run exists, or may, keeps the ref and prints one stderr note with its delete command. The SIGINT handler is detached once the call has its result, so a late Ctrl-C cannot follow a verdict with ERROR interrupted.
Why
Every session on the account shares one 5,000-request/hour REST budget. At 0, ci-gate counted each 403 as a failed read. Discovery gave up with an exhausted-budget
ERROR, the watch ran intomaxUnreadable, and either way theci/ref was deleted while the run was still going. That happened five times in two days (friction entryparallel-gh-watchers-exhaust-owner-api-budget).What changes
Waiting out the limit (
cli/pace.mjs,pacer.read):retry-afterand, when 0 remain,x-ratelimit-reset, plus 5 s. If the answer gives neither, it waits a minute (GitHub's documented rule).GET /rate_limit, which is not counted against the budget. If that still says 0, it sleeps again until the new reset: the published reset moves when the window refills and drains again.lib/github.mjs:GitHubErrornow carries the error response'sremaining/reset/retry-after; addsisRateLimitedandrateLimit().Bound: 90 minutes of continuous exhaustion, measured as elapsed time on ci-gate's clock, never from the published reset. Each sleep is cut to what the bound has left. That covers one hourly window plus a reset that moves once. A successful read starts the bound over. Past it, ci-gate ends in
ERROR … the GitHub API rate limit stayed exhausted for 90 min (resets <ISO>).Stdout: each wait prints
THROTTLE remaining=<n> until=<ISO>, the same keyword with a new field. I found no consumer that parsesTHROTTLE: MAWS'sscripts/ci-gate.shis its own bash watcher and never reads ci-kit's output. The healthy path is unchanged: no/rate_limitcall and no new line.The ref (
cli/ci-gate.mjs):GREENorRED, and when no run appeared within the deadline. Such a push has nothing to rerun, and keeping its ref would let a late run start that no one is watching.ERRORor an interruption while a run exists, and as soon as the budget first hides the run from discovery (a run most likely exists, so a Ctrl-C during the wait keeps it too). One stderr note names the ref with its delete command:kept <ref>: … remove it with: git push origin --delete <ref>.ci/*refs, and a kept ref is harmless: a branch nobody pushes to starts nothing. An automatic 24-hour sweep was built in this PR and dropped in review, because each round found another edge in it for a rare event. A server-side sweep is tracked in ci-gate: deferred edge cases (tech debt) #201.ERROR interrupted.Tests
test/pace.test.mjs(new): the healthy pass-through, waiting to the reset,retry-afterbeating the reset, a secondary limit, the 60 s default when the answer gives no time, a moved reset, a failed/rate_limitcheck, the 90-min bound (elapsed time, with each sleep cut to the bound), a reset stuck in the past, a reset far past the bound, the bound starting over after a successful read,onLimitedfiring before the wait, and non-limit errors being thrown at once.test/discover.test.mjs: the old give-up test is replaced by waiting to the reset, the deadline not counting the wait, the bound giving anERROR, andonHiddenfiring at the first 403.test/watch.test.mjs: a rate-limited watch reads pastmaxUnreadableto GREEN; the bound gives anERRORnaming the rate limit.test/github.test.mjs: the error's rate-limit fields,isRateLimited,rateLimit().Verification (ci-gate on ci-kit)
THROTTLE remaining=0 until=2026-11-10T11:22:04Z, sleep, one/rate_limit, thenPASS testandGREEN(run 42806419239). 13 requests; ref removed.PASS test,GREEN(run 42811688111), noTHROTTLEline, ref removed. (The healthy path making no/rate_limitcall was shown withCI_GATE_DEBUG=1at d9a854d, run 42807148591; that path is unchanged since.)ERROR interrupted, exit 130, the keep note printed, ref still on the remote (git ls-remote). The printed command then removed it.