perf(runtime): batch Recall session reads #5880
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 478 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.369
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #5880"
general
weight: 0.35
hqhq1025
Summary
Recall reconstructs each candidate Session before ranking passages. That reconstruction issued
4N + 2SQL reads for N runs and repeatedly decoded the same event payloads. With 20,000 Turns and ten returned passages, the query took 1,603.63 ms and a complete message read issued 80,002 SQL reads / 160,000 JSON parses.Add a storage batch snapshot that reads openings, events, lightweight ordinals and partial presentation in one SQLite read transaction. Reuse decoded opening/terminal events and preserve the existing projection, ordering, legacy-opening and corruption checks. Wire the capability through the production storage facades; stores without it retain the individual-reader path. Resolve corpus-count fallback before reading transcripts so unavailable counts no longer make Recall reread candidates.
Fixes #5877
Refs #5368, #5531 and #4677.
Verification
Benchmark: 20,000 Turns, ten matching passages, seven alternating samples
| Metric | Individual reads | Batch snapshot |
| --- | ---: | ---: |
| Complete Recall query median | 1,603.63 ms | 492.25 ms |
| SQL reads for one complete ReadModel view | 80,002 | 5 |
| JSON.parse calls for that view | 160,000 | 60,000 |
About 3.26× faster on this fixture. A single-Turn check (21 alternating samples) measured 0.23 → 0.18 ms, 6 → 5 SQL reads and 8 → 3 parses.
Measured on macOS 15.7.3 / Apple M4 Pro / Node v24.14.0, using an in-memory SQLite fixture with one opening, user message and terminal per Turn. Each lane is warmed once; every timed query is checked for complete result equality. The comparison disables the batch capability to exercise the existing individual-reader fallback in the same build. Timings cover Core Recall, SQLite and projection, excluding IPC, UI and fixture creation. SQL/JSON counts are collected separately from timing and exclude transaction-control statements, candidate selection and corpus counting.
The benchmark was run as a local diagnostic; its script and report are not included in this PR.
NODE_OPTIONS=--disable-warning=ExperimentalWarning.npm run lint,npm run format:check,npm run buildandnpm run typecheck: passed.npx knip --workspace apps/desktopandnpx knip --workspace packages/ui: passed. Checked in a clean checkout of implementation commit684ec89f9(before removing the benchmark-only artifacts); commit hooks also passed ASF-header, staged formatting and protocol-epoch checks.Candidate Sessions still receive a full projection/scan for the existing ranking contract. This PR does not add a search index or change Host cancellation, and introduces no schema or wire-protocol migration. UI/e2e and the full all-workspace test command were not run.
AI use
Tool(s) and scope: Codex diagnosed and implemented the change, added regression tests, ran the local benchmark and validation, and prepared this issue/PR under @liuxiaocs7's direction. The commit includes
Generated-by: Codex.Checklist
Does this PR entail a change in behavior?