Repository navigation
Description
Summary
Every dispatcher run and every cloud session draws on one GitHub REST budget: sydevs-bot's 5,000 calls an hour. On 2026-11-20 a batch of member mentions from 22:16Z grew into 486 dispatcher runs in one hour, and the budget ran out at 23:00Z. Every dispatcher run from then until the 23:10Z reset failed, because a 403 is never retried. One of them stranded the lease on sydevs/WeMeditateWeb#326. This ticket makes a rate-limited run wait for the reset, makes each run spend less, and moves the dispatcher onto a GitHub App with a budget of its own.
Approach
- Wait out a rate limit.
installRetry(dispatcher/retry.mjs:33) already wraps every call the dispatcher makes, butretriable(retry.mjs:13) answers every 4xx at once. Add a rate-limit branch:- A 403 or 429 with
x-ratelimit-remaining: 0waits untilx-ratelimit-reset. - A 403 or 429 with
retry-after(a secondary limit) waits that many seconds. - Each waits only up to a new
dispatch.githubRetry.rateLimitMaxWaitSeconds(900). A longer wait, or a 403 with neither header (a permission refusal), is thrown as today. - Raise
timeout-minutesonresolveandact(.github/workflows/dispatcher.yml:54,:86) above that wait. - On 2026-11-20 the budget reset 10 minutes after it ran out, so every failed run, Fri — 0 dispatches · 0 failed · 0 anomalies #326's unlock among them, would have finished.
- A 403 or 429 with
- Measure what a run spends. In the same request hook, count REST and GraphQL requests, and log
api: <n> REST, <m> GraphQLat the end of eachresolverun and eachactleg. - Cut the biggest cost, and shed load under pressure.
- Each event run also adds up to
dispatch.reconcileMaxPerEvent(10) drift targets (dispatcher/resolve.mjs:63-70), each a fullgather(dispatcher/gather.mjs:218) in its ownactleg, and in a burst many runs in one repo pick the same drifted items. Use step 2's counts to cut the largest cost first. - Whatever the measurement shows:
resolvereadsGET /rate_limit, which does not count against the limit. When RESTremainingis under a newdispatch.rateLimitFloor(1,000), an event run returns only its own targets and logs that it shed the rest. The cron's full pass covers them.
- Each event run also adds up to
- Give the dispatcher its own budget through a GitHub App.
- sydevs is on the Free plan with 5 repos, so an App installation gets 5,000 an hour: no more than the PAT, but separate from it. Cloud sessions cannot act as an App (
docs/routine-setup.md§0b). They stay sydevs-bot and keep its 5,000 to themselves. - Token. Each
dispatcher.ymljob that readssecrets.SYDEVS_BOT_PAT(lines 74, 133, 160, 204, 239, 260, 275, 405) mints an installation token withactions/create-github-app-tokenwhen the org variableSYDEVS_APP_IDand the org secretSYDEVS_APP_PRIVATE_KEYare set. When they are not, it uses the PAT. So this merges before the App exists, and the switch is a settings change either way. - Identity. The dispatcher's writes then come from
<app-slug>[bot]. Addidentity.dispatcherLoginstoloop-config.json(both logins), and read it wherever the dispatcher finds its own writes:loadRecord(dispatcher/record.mjs:74),commentOncemarkers, the own-unlock check, andisBot/fullTreatment(dispatcher/decide.mjs:69,:98) for a contract-sync PR the App opens.identity.expectedLoginstays the sessions' login. - Settle by experiment on one PR before switching on. Any call the App cannot make keeps the PAT, so that job holds both tokens:
- whether an App's approving review satisfies the ruleset's required approval (
mergePolicy.proxyApprove); - whether the App can edit a status comment sydevs-bot wrote;
- whether it can write the org issue fields (Priority, Hold Until) and the board's Status;
- whether it can push a relay branch that touches
.github/workflows/; - whether any ruleset lists
sydevs-botas a bypass actor.
- whether an App's approving review satisfies the ruleset's required approval (
- Setup, by a person, after the code merges. Create the App in the sydevs org with Issues, Pull requests, Contents and Workflows (read and write), org Projects (read and write) and Metadata (read). Install it on the five repos, and store
SYDEVS_APP_IDandSYDEVS_APP_PRIVATE_KEYwith visibilityall. Document it besideSYDEVS_BOT_PATindocs/routine-setup.md:286.
- sydevs is on the Free plan with 5 repos, so an App installation gets 5,000 an hour: no more than the PAT, but separate from it. Cloud sessions cannot act as an App (
- Docs. Add
docs/why.mdsections on why a rate-limited call waits for the reset, and why the dispatcher has its own App: the budget split, and sessions cannot use one.
Acceptance criteria
- A call answered 403 or 429 with
x-ratelimit-remaining: 0waits untilx-ratelimit-resetand retries, when that is withinrateLimitMaxWaitSeconds. Beyond it, the error is thrown as today. - A 403 or 429 carrying
retry-afterwaits that long, within the cap, and retries. - A 403 with neither header is thrown at once, as today.
-
resolveandacttime out later than the longest wait. - Every
resolverun andactleg logs its REST and GraphQL request counts. - An event run whose REST budget is under
dispatch.rateLimitFloorreturns only its own targets, and logs that it shed the drift targets. Schedule andworkflow_dispatchruns are unchanged. - The largest per-leg cost step 2 measures is cut, and the PR states the counts before and after.
- With
SYDEVS_APP_IDunset, every job usesSYDEVS_BOT_PATexactly as today. With it set, every job that used the PAT uses the App token, except a call the experiment showed the App cannot make. - The dispatcher reads its own status comments, markers and PRs under either login in
identity.dispatcherLogins, so an item written before the switch keeps its record. -
docs/routine-setup.mdnames the App, its permissions and both settings, anddocs/why.mdrecords why.
Verification checklist
-
node --test dispatcher/test/*.test.mjspasses. -
retry.test.mjscases with a fake sleep:- 403 with
x-ratelimit-remaining: 0and a reset 30 s ahead → one wait of about 30 s, then success. - The same with a reset 2 h ahead → thrown with no wait.
- 429 with
retry-after: 5→ one 5 s wait. - 403 with no rate-limit headers → thrown at once.
- 403 with
- A
resolve.test.mjscase: an event run with/rate_limitreporting 500 remaining yields only the event's own targets, and with 4,000 it adds drift targets as today. - A
record.test.mjscase:loadRecordfinds a status comment written by either dispatcher login, and ignores one written by a member. - On a test item, a dispatcher run with
SYDEVS_APP_IDunset logs the PAT as its token source. After the App is set up, the next run logs the App, and the item's status comment, labels and board Status update. -
claude plugin validate .passes.
Notes
Measured on 2026-11-20, from workflow-state.yml runs in all five repos:
| Window | Dispatcher runs | Failed |
|---|---|---|
| 12:00–21:59Z | 0–32 an hour | 0 |
| 22:00–22:59Z | 486 | 0 |
| 23:00–23:10Z | — | 35, all before the 23:10:28Z reset |
| 23:11Z onward | — | 0 |
- The three failed runs read all say
API rate limit exceeded for user ID 322523691(sydevs-bot),x-ratelimit-resource: core. - One was refactor(server): a folder per route, under server/routes WeMeditateWeb#326's
pull_request_target.unlabeledrun (23:01:35Z), which leftrefs/sydevs-lease/326until a manual sweep at 23:56Z. fix(dispatcher): reclaim dead sessions without waiting on the cron #288 now covers reading such a missed unlock on the item's next event. This ticket stops the run from failing at all. - Budgets, from docs.github.com ("Rate limits for the REST API"):
- A PAT gets 5,000 an hour.
- An App installation gets 5,000, plus 50 per repo beyond 20 repos and 50 per user beyond 20 users, up to 12,500 (15,000 on Enterprise Cloud).
- Requests an App makes on a user's behalf share that user's limit. Cloud sessions act as sydevs-bot through the Claude account's GitHub connection, so they most likely draw on the same 5,000 as the PAT.
- Secondary limits apply on top: 80 content-creating requests a minute, 500 an hour.
- sydevs is on GitHub's Free plan, with 2 seats.
Related: #288.
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Priority
High
Hold Until
None yet
Projects
- StatusShow more project fieldsDone
Activity
Ardnived commentedon Nov 21, 2026
@sydevs-bot implement
sydevs-bot commentedon Nov 21, 2026
🤖 no session running
approved by Ardnived
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.