How a GC sweep wrote 1.38 billion rows in a day
This is a cost incident, not a feature announcement. Between September 11 and October 11, our staging account wrote 2.01 billion Durable Object rows. 1.38 billion of them happened on October 10. No customer repository or production data was involved. The line item was $561, all from one pathology: a garbage-collection sweep that rebuilt an O(repository) reference set on every alarm tick, for days, on repositories that were otherwise idle.
The useful part is not the number. It is how the number hid, how it moved when we thought it was fixed, and the invariants the eventual fix had to preserve.
The number that found it#
Our local scale runs recorded about 2.7 million rows across every bench result. The bill was three orders of magnitude larger.
The local numbers were not wrong; they were local. They measured individual
operations, not the cost of a Durable Object's alarm loop staying alive for
days. The account-level GraphQL series
(durableObjectsPeriodicGroups with rowsWritten) is what settled it:
- Sep 11-Oct 11: 2,013,934,786 rows written.
- The RepositoryHub namespace: 2,011,144,323 (99.86%); every other namespace combined was about 2.6 million.
- Oct 9: 605M. Oct 10: 1.38B. Oct 11 by 07:35Z: 20M and still climbing.
Mapping object ids to repositories took a short session against the object API while firing one cheap request per bench repository, because the ids are not invertible and the API exposes ids without names.
What the loop was doing#
The live tail showed alarm invocations every ~10 seconds, each burning the full alarm budget, and the only thing they wrote was the GC sweep's reference scratch:
[gc-ref] {"totalWritten":225000}
On a 75k-entry repository, the sweep wrote 225,000 scratch rows per tick.
gc.ts said so in its own comment: the scratch tables were rebuilt from
scratch on every invocation. Everything merge-shaped was empty - no merge
state, no repository jobs, no outbox, no locks. The merge repositories were victims
only because they were the largest repositories whose sweep completion never
latched. Any repository that reached that state looped the same way.
The entry condition was a hot gc_due_now / pending sweep cursor. With no
sockets attached, the heavy-work check was trivially true, so every wake ran
the full path.
The fix that wasn't the whole fix#
The first alarm-path fix was narrow and correct: a purging Durable Object now
takes the light path as soon as purge_started is latched, not only after
purged. That stopped the alarm burn.
It did not stop the bill. An independent review falsified our "0 rows in 60 seconds" reading, and the checks confirmed it:
- The GraphQL series lags. It froze at the same value across four queries while the daily total nearly doubled. A 60-90 second delta cannot distinguish "stopped" from "burning"; short GraphQL deltas are not a burn check.
- The scratch rebuild had moved into the purge request path. Permanent
purge phase B calls
deleteOrphanedBlocks, which calls the same sweep. With the purge driver running, every call rebuilt 172,500-300,000 rows, returneddone:false, and re-armed: about 102,000 rows/s (~$370/hour) in one measured window. - The burn had also escalated earlier, to 444,454 rows/s across five objects (~$1,600/hour), simply because those DOs started purging.
The lesson is uncomfortable but concrete: fixing the alarm path did not fix the sweep. The sweep had two callers, and we had measured only one.
The real fix#
The actual invariant is simple to state: a partial reference set must never drive deletion. The old code rebuilt the set every invocation because a stale set is dangerous; the rebuild was the safety mechanism. The fix keeps the safety and removes the repeated cost:
- Generation-stamped reference sets. The built set carries the data generation it was built from. A cursor-resumed pass on an unchanged generation can skip the rebuild - but only when the set is provably complete for that generation. A partial set still never deletes.
- No-progress backoff and park. A sweep that resumes K times without
reclaiming anything sets
gc_retry_atand parks, mirroring the merge retry policy. Re-entering a stuck sweep at alarm cadence is not progress; it is a bill. - A prefix sweep for permanent purge. A permanent purge deletes everything under the repository's own block prefix, so that caller needs no reference set at all. An O(scoped) prefix sweep is both simpler and correct, and it sidesteps the rebuild on the biggest repositories.
- A per-object write budget breaker and an account-level cost canary. The breaker pauses GC sweeps, the reaper and the planner when an object crosses its rows-written budget; the canary runs every four hours. These are backstops, not the fix, but they turn a silent runaway into a page.
Fix 2 landed on 2026-10-11 with review hardening. The burn stopped when both the alarm and purge callers were covered.
What we would do differently#
- Never trust a short metric delta for a stop. Use the live event stream (the object log) for the signature, and the account series for the magnitude. A lagging series is a lower bound, not a verdict.
- A Durable Object runs the worker version it booted with. Deploying a fix does nothing for a looping specimen until it is restarted or purged. We restarted the burning objects; a deploy alone would have been theater.
- Measure the caller matrix, not the function. The same sweep was called by the alarm and by purge. Fixing the first caller moved the burn; it did not remove it.
- Local benchmarks are not cost models. They answered "does this operation write the right rows?", not "what does this operation cost if it runs forever?" Those are different tests.
The shape we kept#
The incident did not make us stop rebuilding reference sets, and it did not make us relax the deletion guard. It made the rebuild conditional on a generation that proves it is safe to skip, and it made a non-progressing sweep park instead of spin. The guard that a partial set cannot drive deletion is still the rule; the fix is how we avoid paying for a complete set on every tick.
The longer write-up, with the queries, the tail signatures and the purge
arithmetic, is in the repository's ops record:
docs/ops/do-write-burn-2026-10-11.md.