Repository navigation
perf(sessions): stream SQLite transcript hydration - #174890
Conversation
Use one native SQLite cursor for cron history metadata while preserving bounded PostgreSQL batches, SQL payload projections, exact totals and page visibility. Baseline regression records two candidate reads for a 520-row history; the new boundary requires one. Codex autoreview found no actionable issues. Scale measurements and focused candidate proof are pending.
Restore native row iteration under the existing hydration snapshot while retaining bounded PostgreSQL pages. Preserve SQL byte slices, frame acknowledgments, resume bounds and compressed-event decoding. The baseline cancellation regression decodes unread corruption before the first acknowledgment. Codex autoreview found no actionable issues; scale measurements and focused candidate proof are pending.
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs changes before merge. What this changesThis PR streams SQLite transcript rows through a native iterator while retaining PostgreSQL’s bounded batches. Example: A hydration contains 128 small events followed by a corrupt compressed event, and the consumer cancels at the first acknowledgement.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it is an owner-directed optimization with distinct value, and current main still eagerly reads SQLite pages; no actionable patch defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe transcript history worker reads a fenced database snapshot and sends bounded byte frames to the host, which assembles events and publishes a full snapshot only after successful completion. flowchart LR
A[Transcript reader] --> B[History worker]
B --> C[Read snapshot]
C --> D[SQLite iterator]
C --> E[PostgreSQL batches]
D --> F[Byte frames and acknowledgements]
E --> F
F --> G[Host transcript assembly]
Technical reviewBest possible solution: Keep SQLite streaming within the existing snapshot owner and preserve PostgreSQL’s bounded buffering and the established framing contract. Do we have a high-confidence way to reproduce the issue? The base eagerly materializes 256 rows before sending its first 128-frame chunk, so the supplied corrupt row at sequence 128 reaches decoding before cancellation; this follows from source and the focused fixture, but no tests were run during this read-only review. Is this the best way to solve the issue? The patch addresses eager buffering at the existing reader owner, reuses established iterator cleanup, and preserves the reason PostgreSQL needs bounded pages. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7034ca42b491. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +13, Tests +2, Docs +2. Total +17 across 3 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 16, 2026, 8:51 PM ET / October 17, 2026, 00:51 UTC. |
Resolve the obsolete cron test fixture conflict to the already landed main version. The measured and reviewed hydration worker and tests remain byte-identical; the main-relative change is only the three hydration files.
Replace SQLite keyset batches with native iteration under the existing read snapshot; retain bounded PostgreSQL batches. Preserve chunk limits, acknowledgement backpressure, cancellation, resume bounds and cleanup. At 60,000 transcript messages, source SELECTs fall from 235 to 1 per usage timeseries/log request, with unchanged source-row volume. Three alternating shared-harness pairs preserve causal warmed medians of 67 SQL / 22 worker requests / 0 MAIN. Touched-owner T1 remains zero. Regression coverage includes exact bytes, snapshot isolation, cancellation without decoding unread rows, host errors and cursor cleanup. No schema, protocol or authorization changes.
What Problem This Solves
Full transcript hydration executes a SQLite query for every 256 rows and eagerly decodes that batch before the first consumer acknowledgement. Use native SQLite iteration under the existing snapshot; retain PostgreSQL's sixteen-row batches to bound buffered transfers.
The worker preserves 64 KiB slices, 128-frame/1 MiB chunks, acknowledgements, resume bounds, once-per-event decompression and cleanup. Large-value projection remains in SQL. No schema, protocol, public API or caller-authorization changes.
Evidence
The selected transcript has 60,000 messages at both population scales. Counts are causal SQL/worker requests/MAIN; “first” and “repeat” describe ordered workload calls, not independently cold caches.
The exact owner saving is 235 → 1 transcript-source SELECTs per call at both scales. Other total-count/request differences are cache/lifecycle work outside this patch. Source rows remain 60,001 per call and input remains approximately 36 MB. The five-character-longer candidate fixture path adds five header bytes per call. This reduces repeated query execution and eager batch decoding, not full-history transfer/parsing. Loaded-host wall observations establish no latency improvement.
The SQLite keyset loop is deleted. The existing snapshot already spans acknowledgements, so iteration does not extend its lifetime. Accepted edge: corrupt later rows can reject after earlier private chunks were acknowledged; the public operation still rejects without publishing a partial snapshot. Cancellation need not decode unread rows. No live-authority check is removed.
Both baseline cancellation/host-error regressions fail by decoding unread corruption before the first acknowledgement. All four candidate hydration tests pass, including exact bytes, concurrent-update snapshot isolation and cursor cleanup; forty cron/Gateway sibling tests also pass. One isolated Codex review completed without actionable findings. Touched-owner T1 is 0 → 0. Required CI, types, typed lint, contracts/export collisions, Madge, ratchets, changed tests and PostgreSQL conformance passed on the frozen head; canonical Knip's production/full-tree/scripts scans each passed with zero entries. The final integrated head is
cf8e1e722043643779221c0b6ce7965cb4a48274; its hydration worker and test are byte-identical to the measured/reviewed candidate. On that head, selected Node tests, production/test types, typed lint, source contracts/export collisions, Madge, security and dependency gates passed. The T1 ratchet stays 182 → 182 and the dialect ratchet stays zero. Local changed-file formatting, typed lint and diff checks also passed. Final canonical Knip failed with 20 production/13 full-tree/0 script findings: every diagnostic tuple occurs in the completed main scan at8fc3509a66ad89028e1bd15c027a5426373cd977; none concerns a changed file. The baseline-ratchets job failed only on the identical main mock-export diagnostic atsrc/process/exec-scope-settlement.test.ts:35(main run 39015139934). These are inherited-static exceptions, not passing scans.Final PostgreSQL infrastructure passed. PostgreSQL integrations failed three memory-tool cases; the aggregate CI gate is therefore not green. Scheduled main run 39013936147 has the exact snippet failure at line 359 and the same vector test failing earlier at line 313 rather than candidate line 324. The body/path replacement failure at line 250 has no exact-main reproduction. This uses the authorized relaxed job-level landing exception because the same integrations job fails on main; it does not claim all assertions are proven inherited or that final PostgreSQL CI passed. The PostgreSQL hydration branch retains its existing sixteen-row paging; these memory-tool sources are unchanged by this PR. The unmatched failure and assertion distinction have been reported to the main-repair owner. Current-head Codex review completed without findings. SDK/update-cell checks do not apply. Scope: three files, +82/−65. The separate cron prerequisite landed as #174889; this PR now targets main and contains only the three hydration files.
The broader four-arm synthetic census records every RPC, including one candidate 10× usage-page assertion failure: the protocol returned an empty partial result. All four overview/page-two calls at that scale included partial metadata near the unchanged 15-second budget; the recorded metadata lacks the values needed to quote the wire reason. These are incomplete usage-view results, not savings. All 88 RPCs were observed in each arm; the other three arms passed 88/88 and candidate 10× passed 87/88. All observed RPC MAIN counts are zero, no observer-recorded native execution errors occurred, and all four Gateways exited cleanly. An earlier two-600k-session attempt failed with worker heap exhaustion; the final matched fixtures use two/twenty 60k-message sessions and prove population scaling, not 600k-session support.
Three alternating shared-harness pairs completed in M,C,M,C,M,C order on frozen baseline
a1bb732d30bc377dcc89f679822db7420d034357and cumulative candidate76b1ddeed66dd28e4708134290fb12ce073d30bc. Every arm passed fourteen turns, compaction, restart and clean shutdown, with zero observer-recorded native errors. Counts below are median [min–max].Causal warm count arrays match exactly. The +0.5 raw run-median SQL difference is background work, not an increase in the changed owners. Background MAIN reaches nine in a warm window; causal warm MAIN stays zero. Standard cron-history totals vary with one versus two
cron.runspolls: baseline 7 [4–7] SQL / 3 [2–3] requests, candidate 2 [2–3] / 2 [2–3]. No request saving is attributed to that variable polling. Small-fixture hydration remains 8 SQL / 2 requests in every arm. The controlled scaled RPCs above provide the owner-specific saving evidence.All six arms use the unchanged shared harness's supported zero-idle option, retaining normal settling, compaction and restart. Whole totals are descriptive, not default-idle or equal-call-count saving claims. No warmed-chat or latency improvement is claimed.