Repository navigation
perf(server): reaper sweep decodes only live provider bindings - #229
Merged
tusharbhardwaj-bk merged 2 commits intoSep 27, 2026
Merged
Conversation
Every 5 minutes the session reaper called listBindings(), which decodes every provider_session_runtime row (two Schema passes plus a provider-kind decode per row), then skipped every stopped one. In prod that is 1,352 of 1,355 rows; the bindings phase took ~2 s at p90 and up to 5 s on the shared event loop. A fork helper now selects the ids of non-stopped rows and decodes only those through the directory (same binding shape); on a query failure it falls back to the full list. On a copy of the prod database: 1,355 -> 3 rows decoded, 37-67 ms -> 1-4 ms per sweep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Problem
ProviderSessionReapersweeps every 5 minutes. Its bindings phase calleddirectory.listBindings(), which decodes everyprovider_session_runtimerow (two Schema passes plus a provider-kind decode per row,concurrency: "unbounded"), thencontinued past everystoppedone.In prod, 1,351 of 1,355 rows are stopped. The subagent's journal analysis over 575 sweeps in 48 h:
bindingsMs;Fix
provider/liveProviderBindings.expbkt3.ts. It runsSELECT thread_id FROM provider_session_runtime WHERE status <> 'stopped'(a small table, no JSON), thendirectory.getBinding(id)for just those ids. The bindings keep exactly the shapelistBindingsreturns. On an SQL failure it falls back tolistBindings().The decode-everything loop is upstream code, so the cleaner long-term fix is an upstream
listBindings({ excludeStopped }). Noted as an upstreaming candidate.Evidence
Lab benchmark on a
VACUUM INTOcopy of prod (1,355 rows, 1,352 stopped), 5 calls each:listBindings(before)listLiveProviderBindings(after)The idle lab is far faster than prod under contention (p90 1.86 s), but the ratio holds.
Tests:
liveProviderBindings.expbkt3.test.ts: 300 stopped rows, plus one running and one starting; the result is exactlylistBindings().filter(status !== "stopped").ProviderSessionReaper.test.ts: all pass (20 total).vp run typecheckinapps/serveris clean, and the fork-marker check passes.Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code