Skip to content

feat(deliver): wait for CI without spending the REST quota - #100

Closed
jtomaszewski wants to merge 2 commits into
mainfrom
fix/deliver-ci-wait-quota
Closed

jtomaszewski wants to merge 2 commits into
mainfrom
fix/deliver-ci-wait-quota

Conversation

@jtomaszewski

@jtomaszewski jtomaszewski commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 CI waits drain the REST quota every agent shares

All agents on a machine share one gh login's 5,000 REST requests an hour. When that runs out, everything that needs REST fails, including posting a review.

In gh 2.90.0, each gh run watch refresh makes at least three REST requests (run, workflow, jobs), plus one annotations request per job still running. A new watch also fetches every job's annotations again. In one 37-minute window that ended with the quota used up, agents spent 57 minutes in total in gh run watch, on a project whose CI runs typically have 39 jobs. That is an estimated 500–1,500 requests. It was not the only cause: two bulk reads used more.

deliver recommended gh run watch for merge and deploy runs. Its "PR notifications are not the wait" rule also steered agents away from subscribe_change_request.

🔧 Three ways to wait, chosen by who waits for what

Waiting for Who How
PR checks persistent top-level Paseo agent, no re-run on this head subscribe_change_request, end the turn, verify the current head on waking
PR checks subagents, unattended runs, other hosts, any wait after a re-run gh pr checks --watch --interval 60 (GraphQL)
Merge, deploy and other non-PR runs anyone one actions/runs/<id> request a minute, for at most 45 minutes
  • gh run watch is banned. A rate-limit error stops the wait, isn't retried, and is never read as a CI result.
  • Logs: download only the failing job's log, with one actions/jobs/<id>/logs request. The watch brief now returns job ids instead of run ids. Unlike gh run view --log-failed, this doesn't need the whole run to have finished.
  • Deploys: the wait now has a limit, so an unfinished run is reported as still running. A later run of the procedure waits for that run and doesn't dispatch the level again.
  • Version 3.0.0 → 3.1.0 (minor: new capability).

🧩 How this fits the existing rules

  • As few wakes as possible. Comments and reviews wake the agent too. If checks are still pending on the same head after one of those, it keeps the subscription and fallback and ends its turn again. Any other wake ends the subscription; if checks are still pending then, the agent finishes with the blocking watch and does not subscribe again for that head. The first version ended the subscription on any wake. In the first live try, a preview bot's comment arrived while checks were still running, which would have sent the agent straight back to polling.
  • Notifications. The old rule's concerns are handled this way:
    • Paseo's check messages name the commit, but the agent still checks the current head itself.
    • If checks have already settled when the agent subscribes, it verifies right away, because no message may follow.
    • After a re-run it uses the watch, because a fast second failure may send no message.
  • Waits that would never end. From Paseo's code, a cancelled check counts as neutral and sends no message, and neither does a stuck run. The agent sets one fallback wake (create_heartbeat, maxRuns: 1) about 45 minutes out. If it can't, it uses the watch.
  • Deliver to a level. Ending the turn to wait is a normal exit: it removes $WT and ends with the Next moves block. On waking, the procedure runs again from step 1, and the owner's click still stands.

🧪 Testing

  • Ran the new run-wait loop in bash and zsh against a fake gh, 4 cases each. It stops when the run completes, stops after one call on a rate limit, recovers from a 502, and gives up after 9 calls.
  • Checked request costs against the gh 2.90.0 source, and subscription behaviour against Paseo's code.
  • Checked that 3.1.0 is above 3.0.0 with .github/scripts/semver_cmp.py; git diff --check is clean.
  • Tried the subscription by hand on another PR: it woke the agent, for a comment. Not tested: a wake for a check result, the fallback wake, or a full deliver run that uses either.

📌 Not in this PR

upstream-pr still runs gh pr checks --watch at its default interval. That uses GraphQL, not REST.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

jtomaszewski and others added 2 commits December 1, 2026 17:01
Persistent top-level Paseo agents wait for PR checks with
subscribe_change_request, with one fallback wake for cancelled or stuck
checks, then verify the current head. Everyone else, and any wait after a
re-run, blocks on `gh pr checks --watch --interval 60` (GraphQL). Merge and
deploy runs cost one bounded request a minute. `gh run watch` is banned, and
only the failing job's log is downloaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A preview bot comments while checks are still running, so ending the
subscription on any first wake sent agents straight back to polling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jtomaszewski

Copy link
Copy Markdown
Contributor Author

Closing without merging: this has happened once so far. We'll look at it again if the quota runs out like this 2-3 times. The branch is kept.

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