Receipts, not claims

We run a lot of agents in parallel. Each works in its own GitSpace workspace and opens pull requests that are tested, explained and reviewed before a person looks at them. That part works. What broke was CI.

Every agent PR then went through the full suite again on CI: typecheck, lint, golden files and six test jobs, a median of 46 billed job-minutes per push. The agent had usually run the same checks minutes earlier, on the same commit. In the week before we changed anything, 83% of our CI spend was pull-request checks, and most of that was CI repeating work that had already passed.

This note covers what we did about it. CI no longer redoes the work. It checks receipts.

A claim is not a receipt

"Tests pass" in a PR description is a claim. CI exists because claims are cheap. But a full re-run isn't the only way to check one.

A receipt is a stored result for one task (one package's typecheck, one test shard) whose cache key covers every input to that task: source files, lockfile, toolchain versions, the operating system, the time zone, the environment variables tests read, and the exact arguments the task runs with. A receipt only counts if a machine we trust wrote it.

So when a PR is ready, CI asks one question for each of its roughly 170 tasks: is there a trusted result for exactly these inputs? If there is, the work was done, and done on this code. If there isn't, CI says so.

We built it on Nx's task cache. Nx Cloud would have hosted it, but it prices by CI pipeline run. With the number of runs agents create, we estimated that at about $500 a month on top of the runner bill. Nx 24 supports a self-hosted remote cache, so ours is a small Cloudflare Worker in front of R2.

Who may write a receipt

A receipt is only as good as whoever wrote it. The rules:

  • Develop CI writes with a GitHub OIDC token for refs/heads/develop.
  • Our machines write after signing in with GitHub; the account must have push access to the repository.
  • Ordinary pull-request runs only read. A push to a PR can't add an entry someone else will trust. The one exception came later (#1520): a ci label run on a PR from this repository writes, but only after the cache confirms the token came from that labelled run and that the author, the labeller and anyone re-running it can push. Forks and outside contributors stay read-only.
  • First writer wins. An entry is never replaced, so nobody can overwrite a good result later.
  • A nightly full suite runs without reading the cache, and the staging build runs the full suite uncached. If a bad receipt ever got in, those two would catch it.

Each receipt records who wrote it. The PR shows receipts: All 171 tasks proven by machine:<host>, or which tasks are still missing.

The hard part: agreeing on "the same inputs"

The idea is simple. The work was making a shared development machine and CI compute the same hash for the same work, and never the same hash for different work. Our rule: a wrong input should cause a miss, never a stale hit. Getting there meant finding every place the two environments quietly disagreed:

  • Bun versions drifted. verify now refuses to run under a Bun CI doesn't use. Later (#1431), machines also stopped picking up whichever bun came first on PATH; on our Linux machine that was a bootstrap Bun 1.4.0 instead of the 1.4.4 CI runs. Each machine now exposes its own pinned Bun 1.4.4.
  • The time zone. Tests depend on it, so it's a task input. Shell quoting once froze that input to a fixed value. And Bun doesn't pass a TZ set at runtime to the processes it starts, so the cache client now passes its environment to them explicitly.
  • Nx resolved npm dependencies differently under Bun than under Node. Receipts are hashed under Node, as the Nx CLI does.
  • A stale project graph. Nx's task runner read a cached graph that didn't know about a new package yet. verify now starts from a freshly built graph.
  • Styling output regenerated mid-run. Some test suites rebuild Panda CSS output their own way, which changed the inputs of the tiers after them. verify now regenerates install-time output before each tier.
  • Git LFS. One side had pointer files, the other the real media. Media is now hashed by its pointer.
  • A submodule that only exists locally. CI doesn't check it out, so it's no longer part of any input.
  • Arguments after --. They're part of a task's hash, so verify invokes every task exactly as CI does, shard flags and reporters included.
  • Wrappers that compounded. On our Linux machine each nested tool call (Bun starting Node starting Bun) prepended the same library paths again. Our compiler plugin keys its cache on those paths, so it rebuilt itself in the middle of a run, and one test timed out only inside verify. The wrappers now add a path only if it's missing (#1431).

Three near-misses were worse, because they would have passed:

  • A lint script that reads dependency cycles parsed colored output under Nx, found zero cycles, and would have rewritten its own baseline.
  • Some tests read files they don't import, so a change to those files didn't change their hash. Those files are now declared inputs.
  • macOS resolves imports case-insensitively and Linux doesn't. Rather than hash the operating system into every typecheck, a lint rule now checks import casing.

Buttons, and pending instead of red

The first version gated every ready PR on receipts and failed when any were missing. That was the wrong signal. On one PR, marked ready before anyone ran verify, a red quick checks sat at the top of the page even after full CI had proven everything. A missing receipt doesn't mean broken code. It means not proven yet.

So we changed the PR flow to work like this:

  1. Drafts run nothing. No checks, no tests, no preview unless someone adds the preview label.
  2. A ready push runs one small job, quick checks: formatting, the changeset check, and Rust when Rust inputs changed. It fails only on those.
  3. receipts is a commit status, not a job. It's pending until every task is proven, and every new push sets it back to pending. Pending is yellow, not red.
  4. Two buttons prove a commit. Run bun run verify on a machine and add the verify label; CI checks the receipts in about a minute. Or add the ci label and CI runs the full suite itself. Either way, the run removes the label when it starts (#1426), so a later push needs a button pressed again. A forgotten ci label no longer reruns full CI on every push.
  5. Success names who proved it: machine:<host>, or CI (run <id>).
  6. A ci run leaves receipts behind (#1520). On a PR from someone with write access, it writes its results to the cache as ci:pr-<number>#<run>, under the same first-writer-wins rule. A later verify, or CI after a small push, replays them instead of doing the work again. Forks and outside contributors stay read-only.

On a machine that has already proven a source, verify is cheap: on our Linux machine a repeat run took 19 seconds, with all 171 tasks replayed from receipts. Only tasks whose inputs changed run again.

What it did to the bill

We measured every Actions run from October 26 to November 14: each job's start and end from the GitHub API, rounded up to whole minutes, at Blacksmith's list rate for its runner. The changes landed in four steps, so the table has five periods. It stops when #1520 changed the ci label again; the two days since are too few to read.

PeriodSpanPR CI per dayAll CI per dayMedian ready-PR runPR CI per merged PR
Before (full CI on every PR push, drafts included)7.7 days$23.52$28.3046 job-min, $0.73$7.82
Drafts run nothing (#1319)4.4 days$37.44$46.1636 job-min, $0.56$4.72
Receipts (#1377)14.5 h$40.54$48.0712 job-min, $0.15$2.72
One quick-checks job (#1409)13.6 h$9.80$14.3712 job-min, $0.18$0.79
ci is a button, receipts pending (#1426)5.8 days$9.05$14.171 job-min, $0.004$1.82

Spend per day went up after drafts stopped running CI. Mostly that's because we were merging more: about 3 PRs a day before, almost 8 after, and around 15 a day while receipts were new. Per merged PR, every step cut the cost. Over the full week after #1426, CI per merged PR was 77% lower than before we started, and all CI per day was half.

Drafts alone account for a lot of runs. From November 2 to 8, 222 Check Build runs started on draft PRs. 174 of them ran no job at all, 40 were previews someone asked for with the label, and 8 were one-minute jobs cancelling superseded runs. None ran a check or a test. 38 of the 57 PRs opened in those days started as drafts.

The first 18 hours after #1426 looked like the finished picture: five verify runs, each about a minute of CI, no ci label at all, and $0.10 of PR CI per merged PR. The rest of the week didn't hold that. The ci label was pressed 80 times, against 23 verify runs. A median ci run is 30 job-minutes, 40 cents and 9 minutes, and those runs were 59% of that week's PR CI spend. Most proofs came from CI doing the work, not from a receipt.

The caveats

  • The fallback became the default. Receipts only save money when a machine has already done the work. Ours mostly came from one shared Linux machine. When a fresh machine proof wasn't at hand, agents pressed ci and paid full price, and we haven't yet separated how often that was the machine being unavailable and how often it was habit. A large toolchain change (#1499) also landed mid-week and changed every task's inputs.
  • Until #1520, a ci run's results were thrown away. PR runs had read-only cache tokens, so after a small push the next proof started from scratch. Trusted ci runs now write receipts, which should make the second proof of a PR cheap whichever way the first one came. We haven't measured that yet.
  • Receipts don't block merging yet. The status is advisory until we make it a required check.
  • Previews are now the biggest cost per PR. A labelled preview build is 15 to 18 job-minutes. That's next.

What changed, really

CI went from doing the work to auditing it. The checks still have to pass on exactly this code, but they can pass anywhere we trust, and CI's job is to confirm that they did. Local compute stopped being a convenience and became a resource agents spend deliberately: run verify once, at the end, then press the button.

If you run agents, or just a busy monorepo, against CI you pay for by the minute:

  • Find out how much of your bill is re-checking work that already passed somewhere else.
  • Make drafts free. Only finished work should cost CI minutes.
  • If you cache task results across machines, make a wrong input a miss, never a stale hit, and record who wrote each entry.
  • Report "not proven yet" as pending, not as a failure. People learn to ignore red.