← Back to Pull requests

perf(runtime): batch Recall session reads #5880

Closed
unknown closed this pull request without merging on Oct 03, 2026 20:31 UTC
View on GitHub
unknown unknown commented on Sep 30, 2026 07:55 UTC
Author

Summary

Recall reconstructs each candidate Session before ranking passages. That reconstruction issued 4N + 2 SQL 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.

  • Storage suite: 1,545 passed, 8 skipped; Runtime suite: 3,699 passed, 14 skipped, with NODE_OPTIONS=--disable-warning=ExperimentalWarning.

  • Core Recall and Host Recall coordinator: 66 passed.

  • Regression coverage includes bounded SQL, one decode per durable event, fallback without rereads, complete result/navigation equivalence, active partials, child exclusion, migrated openings, event-identity validation and a concurrent terminal commit during a read. The SQL-count and duplicate-read tests failed before their fixes.

  • Full repository npm run lint, npm run format:check, npm run build and npm run typecheck: passed. npx knip --workspace apps/desktop and npx knip --workspace packages/ui: passed. Checked in a clean checkout of implementation commit 684ec89f9 (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

  • No generative tool made a substantive contribution

  • Generative tooling made a substantive contribution
  • 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

  • Tests cover the change and fail without it

  • Lint, format, typecheck and the affected suites pass locally
  • Does this PR entail a change in behavior?

  • Yes — described under Summary above

  • No
  • Diff: 478 lines (+358 / -120) across 5 files Reviewer: hqhq1025 Review duration: 5076m
    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
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.8% (MEDIUM) · Higher = larger blast radius
    45.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.1% · Safe to merge
    18.1%
    Repository