Repository navigation
fix: keep conversation list reads from blocking the gateway - #149971
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 17, 2026, 3:05 AM ET / 07:05 UTC (Revision 28). ClawSweeper reviewWhat this changesMoves conversation-list database reads into bounded workers, preserves current access checks, transfers reply buffers, and keeps extension validation on shared TypeBox registries. Merge readiness⛔ Blocked before merge - 2 items remain This remains useful work: current main still reads inventories synchronously. No blocking defect remains identified, the earlier TypeBox finding is addressed, and the PR explicitly accepts the measured memory tradeoff. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway builds conversation lists from per-agent SQLite databases and returns filtered metadata to clients. This change moves inventory work off its event loop while retaining final visibility and membership checks. flowchart TD
A[Conversation list request] --> B[Resolve agent databases]
B --> C[Bounded SQLite workers]
C --> D[Metadata cache and ordered assembly]
D --> E[Read selected page]
E --> F[Recheck current access]
F --> G[Filtered conversation response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1193, Tests +1430, Docs +24, Other +3. Total +2650 across 48 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain one metadata-cache owner and bounded worker lifecycle, with current access checks and the accepted memory and cold-start costs clearly documented. Do we have a high-confidence way to reproduce the issue? Yes: current main synchronously scans complete inventories on the Gateway thread, and the recorded six-store workload demonstrates the resulting delays. This review inspected source without rerunning the workload. Is this the best way to solve the issue? Yes: the patch extends the existing SQLite broker and cache owner while preserving ordered results and final access checks; the measured resource tradeoff is explicitly accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 59f709f8f145. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (27 earlier review cycles; latest 8 shown)
|
9c5620b to
e255752
Compare
154940c to
9479917
Compare
Move cold Node session inventory and selected-page reads through the existing SQLite worker broker while preserving current final visibility and membership decisions. Bound idle worker references and reuse metadata without requiring a writable session handle.
Adopt the shared cache revision API and preserve the required worker module export. Synchronize the single-flight regression through loader-entry signals and settle requests before fixture cleanup.
Observe the current worker-store API across shared test module resets, await database resource drainage before durable reopen, and run native consumers in forked owners. Keep projection and target-preparation assertions at their actual owners without weakening physical admission or timeouts.
Prepare one target plan, preload at most four inventories, and assemble through the same ordered reader as synchronous callers. Join started reads before reporting failures and preserve earlier canonicalization and admission errors. The bounded candidate passes 65 focused cases and selected checks; latency and peak memory still require matched qualification.
Combine main 8dd36a0 with the reviewed final-worker output drain from #150511 at 4ba658ce6c34443796e1d61a3f2230ba08de4041 for local integration proof. Preserve the extracted model-source owner with the current reader contract and keep final output drainage before owned reply transfer. The public #149971 branch remains unchanged until its prerequisites land. Validation: 114 focused tests passed; 2 existing Linux-only skips. Full build, resolution formatting, and fresh independent P2 review passed.
Keep the extension loader and external tool-dispatch validator on the same Format and Settings registries. Remove forced TypeBox bundling and the legacy-finalizer exception it required; retain the canonical virtual subpaths used by extensions and sealed builds. The original compiled dispatcher executed custom-format-invalid arguments. The repaired built flow rejects format, shape, and exact-optional failures while preserving valid tool execution. Focused tests, full build, typed lint, and independent review pass. A controlled local comparison preserves cached and concurrent list latency, with additional first-use and reopen cost.
Preserve the reviewed metadata, model-source, and native TypeBox owners. Keep final SQLite diagnostics drained before owned reply transfer and retain current main's storage documentation and test inventory. The full feature review and focused current-input integration tests pass.
|
Merged via squash.
|
…#149971) * fix: keep conversation list reads from blocking the gateway Move cold Node session inventory and selected-page reads through the existing SQLite worker broker while preserving current final visibility and membership decisions. Bound idle worker references and reuse metadata without requiring a writable session handle. * fix: integrate session list workers with current cache ownership Adopt the shared cache revision API and preserve the required worker module export. Synchronize the single-flight regression through loader-entry signals and settle requests before fixture cleanup. * test: align session list consumers with worker ownership Observe the current worker-store API across shared test module resets, await database resource drainage before durable reopen, and run native consumers in forked owners. Keep projection and target-preparation assertions at their actual owners without weakening physical admission or timeouts. * fix: bound session-list observers through page consumption * test: isolate model catalog read budget from background work * perf(sessions): avoid host adapters in metadata workers Keep grouped entry reads with the existing entry cache and membership queries in the sharing kernel. Use the existing Kysely facade directly for node-only queries so read workers avoid importing writable scope and lifecycle setup. Preserve canonical admission, cache, membership, and final page checks. * test(voice-call): await routed bridge connections * perf(build): bundle TypeBox with the shared runtime * test: preserve native TypeBox imports in legacy finalizer * perf: overlap independent session inventory reads Prepare one target plan, preload at most four inventories, and assemble through the same ordered reader as synchronous callers. Join started reads before reporting failures and preserve earlier canonicalization and admission errors. The bounded candidate passes 65 focused cases and selected checks; latency and peak memory still require matched qualification. * perf: transfer serialized SQLite worker replies * fix(build): preserve native TypeBox validation registries Keep the extension loader and external tool-dispatch validator on the same Format and Settings registries. Remove forced TypeBox bundling and the legacy-finalizer exception it required; retain the canonical virtual subpaths used by extensions and sealed builds. The original compiled dispatcher executed custom-format-invalid arguments. The repaired built flow rejects format, shape, and exact-optional failures while preserving valid tool execution. Focused tests, full build, typed lint, and independent review pass. A controlled local comparison preserves cached and concurrent list latency, with additional first-use and reopen cost. * fix: include shared worker bytes in PR wrapper sources
Related: #149118
What Problem This Solves
Conversation-list reads scan and parse complete session inventories on the Gateway event loop, delaying other requests and streaming events. Repeated reads also lose reusable metadata when no writable database handle remains open.
User Impact
Inventory and selected-page reads use the existing SQLite broker, keeping the Gateway responsive while preserving complete ordered results and current access checks. Up to four independent inventories load concurrently. Cached and concurrent reads improve substantially in the qualified workload; first-use, reopen, and memory costs remain explicit below.
Implementation
The existing entry-cache owner retains reusable metadata and fences publication by generation. Admitted requests retain their snapshot through consumption; later callers cannot adopt a stale generation. Physical database identity, membership, caller identity, and configuration are checked again after awaited work. Filtering, sentinel lineage, and inherited-model behavior remain with their existing owners.
All started inventory reads settle before errors propagate, preserving target order and earlier admission-error precedence. Idle resources remain bounded to 64 observers and eight backends, while active reads and borrowed handles retain their claims until consumption and joined retirement finish. Bun retains its native metadata-read path.
Successful SQLite replies transfer their serialized buffers through the shared Git/SQLite owned-byte helper. Partial, shared, pooled, or marked storage is copied to an exact owned buffer first; framing, credits, error replies, and joined cleanup retain their existing contracts.
TypeBox remains native in ordinary Node builds so extension registrations and the external tool-dispatch validator share one Format/Settings registry. All canonical virtual extension subpaths remain supported. The earlier forced TypeBox bundle and the test-build exception it required are removed. Sealed builds retain their existing static-import bundling behavior.
Verification
Integrated public head:
bdf730055946b55e83ee1ff60fdcb42eba1ccc8c.Original concurrency regressions fail on the serial implementation. The concurrent implementation passes reversed completion, target/model order, admission, error precedence, and joining cases.
Reply-transfer proof covers complete Unicode/NUL/large payloads, bounded frames, sender ownership, and native Node/Bun cleanup. The original defect fails all 16 sender-ownership assertions without weakening data assertions.
Main integration passed 114 focused and sibling tests, the full build, selected checks, and fresh P2 review before the additional TypeBox repair.
The TypeBox repair passed 71 tests across six files, typed lint, formatting, the full build, and fresh P2 review. Its dependency-ownership regression fails before the fix. Real compiled extension loading, registered-tool wrapping, and agent-loop dispatch verify three valid controls execute and invalid format, missing-field, and exact-optional inputs are rejected before execution. The pre-fix built dispatcher demonstrably executed invalid custom-format input.
Integration against main
de4cb3de1cad16023ff2d9becb537e3b500239b2passed 157 focused tests across 16 files, with two existing Linux-only skips on macOS, and a fresh P2 review. All production feature files matched the qualified native-TypeBox candidate.Integration against main
3421c79364b44384a11ef441f1f5434c7429cd0epreserves its independent maintenance-age owner and shared 30-minute recheck deadline. The async cache fences remain byte-identical to the previously qualified candidate. It passed 67 focused maintenance, async-read, admission and worker-lifecycle tests, with two existing Linux-only skips on macOS, core type checking, targeted typed lint, formatting, and a fresh P2 review.Final integration against main
c4987966826340590b00b6fa973684172d12300eretains its CPU diagnostics while awaiting inventories outside the synchronous CPU sample. The existing diagnostics test injects unrelated CPU during the asynchronous wait and keeps its original CPU, error, visibility and cache assertions. All 71 focused tests across five files passed, along with core and affected test types, typed lint, formatting, and fresh P2 review. The previously qualified cache, maintenance, TypeBox, concurrency and transport owners are unchanged.Hosted CI exposed a missing shared-byte helper in the native PR wrapper source inventory. The unchanged cold-start tests reproduced both missing-module failures locally. Adding the helper to the canonical inventory passed 23 selected cold-start, materialized-wrapper and source-closure cases, with unchanged assertions and deadlines, plus fresh P2 review. Application runtime files are unchanged. Full CI 35192192827 passed on the reviewed head. Merged as 9ab47386778b, with native source verification and cleanup complete.
Performance and Tradeoffs
Linux comparison 35158442915 compared baseline
9e6026a90e9fdc084c21a9115b9d43775c32385dwith the earlier4eba963b1ee420fc8606a0939d21f8dbcca76e0ccandidate: six stores, 5,000 rich rows each, four fresh processes in ABBA order, and 48 complete responses. It measured cached reads at 534 → 147 ms and four concurrent requests at 503 → 117 ms. Cached maximum timer gaps fell from 448 → 91 ms. First use was 1,214 → 1,298 ms and reopen 538 → 628 ms. These are small-cohort medians, not percentiles, and predate the native TypeBox repair.The repair's separate macOS Node 24.21 comparison used the preserved bundled root runtime and repaired native root runtime with one identical pinned set of current external package outputs. Four fresh ABBA processes returned 32 identical complete responses with verified order, compiled import graphs, and joined cleanup. This isolates the local repair's marginal effect; it is not a preserved complete original build or replacement Linux qualification.
Restoring validation preserves warm responsiveness and adds cold/reopen cost. Response timestamps were validated against each row's snapshot time before normalizing only those exact fields; every other field and row order remained equal. No memory or CPU profiling ran in this comparison.
The earlier Linux candidate used approximately 1.74–1.75 GiB peak Node RSS versus 1.10–1.12 GiB baseline. Diagnostic run 35170787354 independently verified 1,035 artifact hashes, 96 complete responses, 96 heap checkpoints, seven observer smoke cases, and all final closures. The candidate adds three concurrently live broker threads in this fixture. Metadata workers showed natural heap declines and retired at reader release; the shared state worker survived until final lifecycle close. No worker remained after cleanup. The measured working-set cost is accepted alongside the responsiveness gains, but neither a long-term memory plateau, exact native-RSS attribution, nor a leak verdict is established. These historical memory measurements are not new-head memory measurements.
All owned Testboxes were stopped and verified completed. Failed/partial evidence and raw responses remain private; public evidence contains derived metrics and source/run identities. The workload contains metadata without transcript messages. Ordinary page-load acceptance on a deployed candidate remains unverified.