Repository navigation
improve: speed up loading long session histories - #146286
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: needs maintainer review before merge. Reviewed September 12, 2026, 2:55 PM ET / 18:55 UTC (Revision 3). ClawSweeper reviewWhat this changesReduce SQLite query work and repeated child-session decoding when loading long conversations, and add a reusable history benchmark. Merge readiness✅ Ready for maintainer review This remains a useful, supported performance improvement absent from the pinned main and latest release. No actionable introduced defect was found; the maintainer-authored PR should remain open for normal landing. Priority: P2 Review scores
Verification
How this fits togetherGateway chat-history requests read canonical session transcripts through SQLite’s active-branch projection. The reader selects bounded events and supplies ordering and cursor information for the chat response. flowchart TD
A[Chat history request] --> B[Session lookup]
B --> C[SQLite projection snapshot]
C --> D[Indexed bounded history read]
D --> E[Chat display projection]
E --> F[Current session access check]
F --> G[History and session response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +47, Tests +27, Config +1, Other +412. Total +487 across 10 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the canonical reader and snapshot semantics while eliminating redundant queries and decoding, with the benchmark documenting remaining dense-marker costs. Do we have a high-confidence way to reproduce the issue? Yes: current source exposes repeated suffix searches and duplicate child decoding, and the captured benchmarks provide concrete sparse-marker, trailing-marker, and many-child scenarios. No runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? Yes: the patch optimizes the existing owner without introducing another projection store, changing persisted data, or weakening the selected-session access check. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against bbc599d39212. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
* perf(sessions): reduce history loading work * fix(tooling): register and trace session history benchmark
Related: #126914
What Problem This Solves
Loading a long conversation can block the Gateway while SQLite scans unrelated transcript payloads or repeatedly searches beyond the final message. Chat history also decodes child-session metadata twice per request, making session switches more expensive for parents with many children.
Why This Change Was Made
Keep the canonical history reader and its existing SQLite snapshot. Select the existing marker-type index for whole-session reads and the sequence index for reset windows, skip next-message searches beyond the final active message, and carry the generation already read by the snapshot. The post-await authorization check still rereads the selected session and verifies current access and identity; child metadata is loaded once for the response.
The change preserves history ordering, cursors, byte limits, malformed-data guards, and reset behavior. It adds no schema, migration, or persisted state. A reusable synthetic benchmark records SQL plans, statement/row counts, JSON work, and separate first-read and warm timing.
User Impact
Conversations with many markers open substantially faster, ordinary page reads perform less SQL, and parents with many child sessions avoid duplicate decoding.
Evidence
Warm p50 through the real SQLite history reader, requesting 20 events with planner statistics present (Node 26.8.2, Apple M3 Ultra, 15 samples):
Ordinary recent reads execute 5 SQL statements instead of 9; dense marked histories execute 7 instead of 12. Selected-event and total counts match across all 18 comparisons; event JSON parsing remains bounded to the requested page. Dense custom-marker metadata still takes about 30 ms in the 5,000-visible-marker fixture.
A controlled alternating benchmark of the 1,000-child session recheck fell from 5.466 to 0.193 ms. The full registered history handler decodes 1,000 child rows instead of 2,000 and returned every child. Its separate before/after median was 14.61 to 8.54 ms.
Timings use synthetic isolated stores on a shared host. Warm timings exclude tracing; OS caches were not flushed. The benchmark reports first-open and RSS separately, and these results do not claim an RSS reduction.
node scripts/check-changed.mjspassed, including core/test/script types, changed-file lint, and repository guards.