SIGN IN SIGN UP

perf(telemetry): pace background metrics flushes on the sweep's ledger

A backfill's emission volume was uploaded at whatever speed
serialization and the network allowed: the periodic flush drained the
pending backlog in unbounded full-envelope batches on its own thread,
entirely outside the token sweep's duty cycle — the whole-process CPU
spikes observed during backfills, and the RSS high-water mark set by
each cycle's dequeued/parsed/serialized live set.

Periodic flushes now charge each store/upload segment to the same
background-work ledger the sweep charges (one shared duty cycle for
the whole pipeline, worker-side and flush-side), with the pause capped
at 1s and the drain bounded to 16 batches of 250 rows per 3s cycle —
pending rows are durable and resume next tick, and an awaited flush
(the git-ai await barrier) keeps full-envelope unpaced draining.

Sweep batches are additionally time-bounded (150ms) so a slow-disk
batch pauses at duty-cycle cadence instead of only at the byte/entry
bounds.

Measured on a 159k-event pending backlog (worst case, local server):
unpaced this saturates a core for the whole drain; paced it holds a
35% one-second maximum (2 of 562 seconds above 30%) with RSS high-
water down from 74MiB to 52MiB.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
S
Sasha Varlamov committed
95b6a0daddef4af5e4eb378c1469e9df5722e95d
Parent: 1c9d219