Repository navigation
ci-gate.sh: wait out an exhausted API budget, poll the run cheaply, keep the ref without a verdict - #554
Conversation
…eep the ref without a verdict Every session on the owner's account shares one 5,000-request/hour REST budget. At 0, await_run's `gh run watch` and `gh run view` both failed at once, 20 failures in about 5 min read as a run that cannot be read, and finish deleted the ci/ ref while the run still ran (pr553's landing gate, run 42802241165, 2026-11-10). - scripts/ci-gate-pace.sh: paced_gh. A gh answer naming the rate limit (API rate limit exceeded, or a secondary rate limit, with HTTP 403 or 429) is waited out: read GET /rate_limit (free), sleep to its reset plus 5 s, or 60 s when budget remains (a secondary limit), say so in one line with the reset, read the budget again on waking, retry. A wait that would end past 90 min of continuous exhaustion is not begun: the caller ends as on any failed read. Discovery, the status poll, settle_run's reads, the rerun, the reports' downloads and --log-failed read through it, as ci-kit's ci-gate does (ci-kit d9a854d). - await_run polls the run's status alone with If-None-Match on the last ETag: an unchanged run answers 304, which costs no budget (measured: 8 conditional reads left X-RateLimit-Used unchanged; 8 plain reads moved it 8), where gh run watch read the run, its jobs and each running job's annotations every 30 s. Every 60 s for five polls, then 120 s. - finish keeps the ref when the call ends without a verdict while the run exists (unreadable, interrupted) or the spent budget hid it, and prints the delete command. A verdict, green or red, and a push no run came of still remove it.
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: 5368fbf6b3
ℹ️ 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 ((status == 0)); then | ||
| rm -f "$PACE_MARK" |
There was a problem hiding this comment.
Clear the exhaustion marker after a successful conditional read
When a rate-limited status poll recovers with HTTP 304, gh still exits nonzero, so this condition leaves PACE_MARK intact even though await_run correctly treats that response as a successful read. Subsequent unchanged polls also leave the marker intact. If the shared budget is exhausted again before the run changes, pace_wait measures its 90-minute bound from the previous exhaustion, including the intervening healthy polling period, and can reject the new wait immediately. The gate then exits without a verdict after its failed-read retries instead of waiting out the fresh limit. Clear the exhaustion marker for accepted 304 responses as well as exit-zero responses.
Useful? React with 👍 / 👎.
…included paced_gh cleared PACE_MARK only on exit 0, and gh exits 1 on a 304, so a limit the status poll recovered from with a 304 left the mark set. A later, separate limit then inherited the first one's start, could pass the 90-minute bound at once, and 20 failed polls later the gate ended without a verdict. Any answer that is not the limit, a failure or a 304, now removes the mark. Regression test: limit, recovery by a 304, then a separate limit, which waits under its own bound.
Why
Every session on the owner's account shares one 5,000-request/hour REST budget. It has run out five times in two days. When it did,
await_run'sgh run watchandgh run viewboth failed immediately, and after 20 failures (about 5 min) the script decided the runcannot be read.finish 1then deleted theci/ref while the run was still going. That is what happened to pr553's landing gate (run 42802241165, 2026-11-10 11:02Z).The watcher was also expensive in its own right. Between 11:22 and 11:31Z the budget drained at about 4,200/h with about 15 watchers running, and four of them were this script's
gh run watch --interval 30loops.What changes
scripts/ci-gate-pace.sh,paced_gh(same approach as ci-kit'scli/pace.mjs, ci-gate: wait out an exhausted API budget; keep the ref when there is no verdict ci-kit#200). A failure where gh's stderr saysAPI rate limit exceededorsecondary rate limittogether with HTTP 403 or 429 no longer counts as a failed read. Instead the script:GET /rate_limit, which costs nothing;The wait is bounded. If a wait would end more than 90 min into continuous exhaustion, it is not started, and the caller fails the way it does today. The run discovery after the push, the status poll,
settle_run's reads, the job rerun, the attempt poll, bothrun downloads and--log-failedall go through it. The wait lines go to a descriptor of their own, so they reach the transcript even from a read whose stderr is redirected.await_runpolls cheaply. It reads only the run's status (gh api -i … --jq .status) and sendsIf-None-Matchwith the last ETag. An unchanged run answers 304, which costs no budget (gh exits 1 on a 304 after printing the headers, and the script reads the status line). It polls every 60 s for five polls, then every 120 s. The jobs are still read once, when the run completes, insettle_run. Failed reads are still bounded at 20, 15 s apart.finishkeeps the ref when there is no verdict. That covers three cases: the run can't be read, the call is interrupted while the run exists, and the spent budget hid the run during discovery. In each, the ref is left in place and the script printskept ci/…, as this call ends without the run's verdict; delete it with: git -C … push origin --delete refs/heads/ci/…. A verdict (green or red) still removes the ref, and so does a push that never produced a run.--keepbehaves as before.Request rate per call (measured on run 42811586568, a static gate)
gh run watch --interval 30(before)Before:
GH_DEBUG=api gh run watch 42811586568 --compact --interval 30over 100 s made requests at t = 0–5 s (19), then 3 each at t = 35, 66 and 97 s. After: the script's polls, logged through a gh wrapper, got 200, 200, 304, 304, 200 (completed). Separately, 8 conditional reads leftX-RateLimit-Usedunchanged, while 8 plain reads raised it by 8. Both versions make the same reads once the run completes (attempt, jobs, flaky).Tests
scripts/ci-gate-pace.test.mjs(9 tests, fake gh, and a fake clock that onlysleepmoves). Covers:scripts/ci-gate.test.mjsgets 7 new end-to-end tests:Locally: pace 9/9, preemptions 16/16, hosted 2/2, refusals 22/22, identity and pool-demand 28/28. ci-gate is 32/34: the 2 failures are the spec-import coverage tests, which need TypeScript from
node_modules. They fail the same way on master in a worktree with no dependencies installed. shellcheck is clean apart from the existing SC2329 info onprint_paths.Verified with the script from this branch:
scripts/ci-gate.sh "$PWD" --gates static --label cigate-rl→ run 42811586568 success,removed ci/cigate-rl-5368fbf6.