Skip to content

perf(github): writes are paced by a budget - #281

Merged
sweepies merged 2 commits into
mainfrom
perf/write-budget
Nov 12, 2026
Merged

sweepies merged 2 commits into
mainfrom
perf/write-budget

Conversation

@sweepies

@sweepies sweepies commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Consult 7, PR 6. Every GitHub write waited a second after the previous one returned, so every run that writes had a floor of about ten seconds. Writes are now paced by a budget.

  • The content governor is a token bucket: capacity burst, one token a second, one token per write counted from the write's start. Still one write in flight at a time, and still at most 500 writes an hour.
  • Operator setting github.writeBurst, default 12, range 1–19 (PatchulaSettings.pkl, reference/settings.mdx), honoured by server and CLI runs alike. Any minute allows at most writeBurst + 60 writes: 72 by default, at most 79, under GitHub's documented 80. One new pull request (six writes) or two (eleven) pay no pause; a large run settles at one a second.
  • Safety valve: any secondary-rate-limit answer caps the bucket at one token for the next hour, which is today's pacing, and logs it.

Behaviour change: the first dozen writes of a run go out without the one-second pause (internals/github-client.md, "Writes").

Proof:

  • Paused-clock governor tests: a 12-token burst then one-second intervals; refill capped at the burst after idle; at most 72 writes in any minute over randomised arrival times; and the one-hour fallback after a secondary-limit answer, then back to the burst.
  • a_token_run_honours_the_write_burst: the CLI's token path uses the operator's burst.
  • offline.rs's serial-cooldown test pins write_burst: 1 so its one-second assertion still means something.
  • No transcript changes.

Also fixed: cli_run_reopens_disk_receipts… intermittently lost its write receipts saved/restored log lines. tracing caches each callsite's interest process-wide, and a parallel test that first hit the same receipts callsites without a subscriber cached never. The test now installs a global subscriber (try_init).

Benchmark (VM, release, M0 harness, full write with 100 historical pull requests): 9,998 ms → 2,991 ms.

View guided diff Turn on auto-fix

The one-hour fallback lives in memory, like the governor's other limits, so a restart restores the burst.

* perf(github): writes are paced by a budget

Writes used to pay a fixed one-second pause after each one, so a run's
first dozen writes cost twelve seconds of dead time. The content
governor now keeps a token bucket instead: `write_burst` tokens (12 by
default, the new `github.writeBurst` setting, 1 to 20) refilling one a
second, one token taken when a write starts. The first burst goes out
without a pause — no minute can hold more than burst + 60 writes, 72 by
default, inside GitHub's documented 80 — and the 500-an-hour queue is
unchanged. Writes still run one at a time across all client clones:
the permit is the bucket lock held for the request.

A secondary-rate-limit answer cuts the budget's capacity to one token
for the next hour — the one write a second GitHub asks for — and logs a
warning; the existing secondary cooldown is unchanged.

M0 full-write at N=100: wall_ms 9998 → 2991 on boat.dev.

The receipt-log CLI test's subscriber is now global rather than a
scoped default: a callsite first registered on a thread with no
dispatcher caches Interest::never, and other tests exercise the same
write path in parallel, so its events could silently never reach the
scoped subscriber.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula adbf820 Commit Preview URL

Branch Preview URL
Nov 12 2026, 07:02 PM

The CLI's token path rebuilt its GitHub options from the defaults and
dropped the operator's burst. A burst of 20 allowed exactly GitHub's
documented 80 writes a minute; the cap is now 19, so writeBurst + 60
stays under it.
@sweepies
sweepies merged commit 0114c8e into main Nov 12, 2026
13 checks passed
@sweepies
sweepies deleted the perf/write-budget branch November 12, 2026 19:09
@sweepies-ops sweepies-ops Bot mentioned this pull request Nov 12, 2026
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