Repository navigation
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #6990.
Rebuilding the request-history index ran on the serving event loop. One rebuild of a 2.34 GB ledger froze every provider for 487 s. With this change the proxy keeps serving while the index rebuilds, and the SQLite calls that stalled hosted Windows runners for 0.5 to 1.8 s (opening, closing, renaming and checkpointing index files) no longer run on the serving thread.
Large rebuilds run on a worker thread. For a ledger of 1 MiB or more, a Bun Worker (
src/routing/history/rebuild-worker.ts, driven byrebuild-job.ts) does the whole rebuild:Smaller ledgers keep the inline cooperative build (25 ms async slices, 50 ms routing-time sync budget).
Checkpoints and cleanup run on workers. Serving connections use
synchronous = NORMALandwal_autocheckpoint = 0.wal_checkpoint(TRUNCATE)and then makes the first write into the emptied WAL itself, so the WAL restart and its header sync happen on the worker. Tails into that generation wait for the job.routing-history.sqliteare reclaimed by a worker.Routing never waits. The routing-time sync entry never runs worker requests. It hands the refresh to the background and throws
RequestHistoryIndexBusyError, which health scoring reads as unknown evidence (unknownEvidence.health). The health cache is tied to an index epoch.Published generations. A full rebuild publishes under a new name in
<config>/routing-history/. The name is taken at publication and sorts strictly above every generation already published, with zero-padded fields, so a clock that moved back cannot make a new generation sort below an old one. Readers see the previous complete index or the new one.Retryable errors. Busy and closed index errors answer
503withRetry-After: 1at the management boundary, for the list, row, route-decision and analytics routes.Exact resume and specific reasons. Rows,
indexed_offsetandindexed_rowscommit together. The per-refreshquick_checkis gone; a corruption error from any statement schedules a rebuild.last_errorkeeps the reason that fired.Earlier rounds on this branch, carried here: Windows-safe index paths, index-backed routing-health queries, a MEMORY journal and adaptive sub-transactions for the inline build, and publication I/O off the loop for the inline path.
Known limits: ledgers under 1 MiB still rebuild inline on the serving thread (a few short steps). A worker that overruns its 5 s exit bound gets its build-file cleanup when it does exit; test teardown does not wait for that. Nothing new reaches
src/labfromsrc/router.ts,src/server/lifecycle.tsorsrc/server/responses/core.ts.Verification
tests/server/server-history-rebuild-responsiveness.test.ts, bounds unchanged (event-loop lag < 300 ms, every probe < 1 s, at least 5 completed/healthz, dry-run and proxied requests during a 120,000-row cold rebuild). macOS, Bun 1.4.3: worker path max lag 29 to 34 ms, inline path 55 to 57 ms. Hosted Windows 6/9 is the deciding run.New
tests/usage/request-history-rebuild-worker.test.ts(22 tests):Each fix from review rounds 6 to 8 was confirmed to fail with its guard removed.
New
tests/server/server-history-index-unavailable.test.ts: a history read cut off by an index close answers 503 withRetry-After: 1.Focused gate with Bun 1.4.3: 1,330 pass / 0 fail across 72 files (all of
tests/usage, routing analytics, responsiveness, Lab boundary, test layout, structure SSOT, file-size ratchet).Full suite, Bun 1.4.3, at the first worker commit: 45,133 tests. The failures were in three files:
claude-desktop-remote-hubandcodex-runtimefail identically on unmodifieddevon this machine;cli-access-audio-livehits its 20 ms readiness budget under parallel load and passes alone.bun run typecheck,bun run structure:check,bun run privacy:scan: pass.Independent review: GPT-6.1-Sol (high) over 9 rounds through GOAT, plus GPT-6-Luna for round 2 while Sol was at capacity. Every finding was fixed with a regression test. The reviewer accepted one decline: test teardown does not wait indefinitely for a worker stuck in native I/O. Round 9 returned PASS.
Checklist
docs-siterouting reference,structure/dashboard-and-usage.md, devlog dispositions)