Repository navigation
perf(sessions): bound transcript source reads - #165221
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 October 4, 2026, 8:47 PM ET / October 5, 2026, 00:47 UTC. ClawSweeper reviewWhat this changesThe PR pages transcript source reads and incrementally consumes them for attachment cleanup and context reports while preserving callers that require complete results. Merge readiness✅ Ready for maintainer review This remains useful: current main still materializes complete source transcripts. The pinned patch has no actionable correctness findings, and the supplied measurements support its performance benefit. Priority: P2 Review scores
Verification
How this fits togetherTranscript readers turn stored SQLite events and retained archive files into session messages. Gateway history, context reports, and attachment cleanup consume those messages. flowchart TD
A[SQLite transcript events] --> C[Bounded source reader]
B[Retained archive files] --> D[Incremental archive index]
D --> C
C --> E[Snapshot and byte checks]
E --> F[Context reports and attachment cleanup]
E --> G[Complete-result collector]
G --> H[History and existing array consumers]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +455, Tests +340, Docs +22, Other 0. Total +817 across 30 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use one bounded source-page owner with snapshot fencing, incremental consumers, and explicit collection for existing complete-result contracts. Do we have a high-confidence way to reproduce the issue? Yes, source inspection establishes the eager whole-transcript selection on current main, and the supplied 50,000-event runs quantify its cost. The reviewer did not execute a reproduction. Is this the best way to solve the issue? Yes, the patch replaces the eager owner and migrates its consumers while preserving reset, branch, archive, and complete-result contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 869657375d2d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Bound source worker reads to 128 physical events and 8 MiB, fence the captured indexed history, and stream attachment cleanup and context reports. Prepare archive navigation incrementally while preserving reset, retained-branch, and full-result caller contracts.
Migrate remaining archive fixtures to bounded source and recent readers, preserve generation-change race coverage on file-window reads, keep fixture types concrete, and remove the retired full-reader type export.
Bind the history reader to its owner, construct the fixed-shape source cursor explicitly, and keep the archive index guard outside the bounded loop. Complete import, wire-key, and deferred-fixture lint cleanup.
Keep source-page contracts with the existing reader types and migrate every type consumer. Include the runtime postbuild helper in declaration fixtures to repair the missing fixture dependency exposed by Windows CI after the upstream build change.
3b78476 to
8d45f39
Compare
Integrate the landed declaration-fixture dependency fix in #165221 without rebasing. Scoped integration proof passed 75 tests. The review's Talk-policy concern was rejected after source inspection and two real worker-authority probes confirmed current-policy revocation and fail-closed missing targets; no additional production change was needed.
* perf(sessions): page transcript source reads Bound source worker reads to 128 physical events and 8 MiB, fence the captured indexed history, and stream attachment cleanup and context reports. Prepare archive navigation incrementally while preserving reset, retained-branch, and full-result caller contracts. * fix(sessions): complete paged reader cutover Migrate remaining archive fixtures to bounded source and recent readers, preserve generation-change race coverage on file-window reads, keep fixture types concrete, and remove the retired full-reader type export. * fix(sessions): preserve reader binding and explicit page state Bind the history reader to its owner, construct the fixed-shape source cursor explicitly, and keep the archive index guard outside the bounded loop. Complete import, wire-key, and deferred-fixture lint cleanup. * fix(sessions): keep source page contracts acyclic Keep source-page contracts with the existing reader types and migrate every type consumer. Include the runtime postbuild helper in declaration fixtures to repair the missing fixture dependency exposed by Windows CI after the upstream build change.
What Problem This Solves
Large
sessions.history.source-messagesreads decoded the complete transcript in one SQLite transaction and copied a 100+ MB result into the Gateway, delaying other work on the reader worker and causing heap spikes.User Impact
Attachment cleanup and context reports consume bounded pages without retaining complete message arrays. Each source call admits at most 128 physical events and 8 MiB of stored payload. Oversized individual records fail explicitly; cleanup never treats an incomplete scan as proof that an attachment is unused.
The public
before_resethook, legacy model-context estimation, and unlimited HTTP history still require complete results and collect these same pages. Their total-result memory cost remains. Transcript bytes, schemas, retention, configuration, and update behavior are unchanged.Why This Change Was Made
One source-page reader replaces the eager active-path/off-path readers. It walks indexed physical positions, preserving reset-kept messages, visible markers, and retained branches. The captured indexed sequence, generation, physical active tail (including hidden controls), and reset window exclude later appends and reject incompatible history changes. Shared exact-payload and coordinate readers also serve existing history/tail operations; the SQLite main-thread call-count ratchet remains flat.
Cold archives incrementally prepare the existing identity/LRU navigation index before returning bounded payload pages. The cache retains navigation metadata, not message payloads, and file identity invalidates partial and completed preparation. Ordinary exact archive reads retain oversized-image recovery. Context classification carries only its cross-page lookback counter.
Production delta is +455 lines (792 additions, 337 deletions, excluding
*.test.ts, test-support, and docs). Growth is required to preserve the existing reset/branch/archive fidelity and whole-array consumer contracts while releasing each transaction: the cursor, snapshot fence, byte admission, and resumable archive preparation replace eager operations. The old whole-source readers, redundant recent branch, and test-only array methods are removed; there is no competing eager fast path. Legacy model-context estimation cannot simply sum page estimates because it plans tool-result truncation across the whole context.Evidence
Pre-publication builds, test suites, and static gates ran on Blacksmith Testbox, profile
openclaw-check; no local suites, typechecks, or builds. Final fixture and focused-test lease:tbx_01m44enevryb0s7dcqme0ke4y6, Node v24.19.0. Baselinea2697c13548d1a5cac96af77508e54b6dc496b8cand candidate ran sequentially on the same lease in disposable copies with source hashes checked. Each fixture verifies all 50,000 ordered IDs through the public source-reader facade.Full scans trade some throughput for bounded requests and worker availability. Observed caller peak heap growth during an entire paged scan was 82–85 MB across garbage-collection cycles; the per-request delta is the smaller figure above. SQLite scans used 391 requests; cold archive scans used 391 preparation continuations plus 391 payload requests. Worker-hold diagnostics lowered only the logging threshold in disposable copies and verified
isMainThread=false; production instrumentation is unchanged. The benchmark command wasnode --expose-gc --import ./scripts/tsx.mjs <inline 50k fixture>; eight baseline/candidate runs completed successfully in 171.25 seconds.365 distinct tests across 24 files passed on Testbox, comprising the 322-test history/session/attachment/context run, 40 additional archive tests, and three managed-image end-to-end cases.
node scripts/run-vitest.mjs <21 focused history/session/attachment/context files>: 322 tests passed, five shards, 244.74 seconds. Coverage includes byte limits, ordered pages, append exclusion, reset/branch/marker fidelity, archive preparation/cache behavior, bounded-tail readers, incognito/history siblings, and incremental consumers. On earlier Testboxtbx_01m448g4p9bm9w194s3khtggsd, the source-page regressions fail on the original eager implementation (260 messages instead of 128; three 3 MiB records instead of two). A separate pinned negative control proved the earlier visible-anchor fence deleted one retained attachment after an in-place hidden-tail branch change; the current physical-tail fence rejects the scan and preserves it. Both negative/positive runs completed as expected in 63.85 seconds.Single-worker cost, command
pnpm test <file> --maxWorkers=1on the same CI-class lease:src/)agents/compaction-real-conversation.test.tsauto-reply/reply/commands-context-report.test.tsgateway/managed-image-attachments.branch-retention.test.tsgateway/managed-image-attachments.sqlite-visibility.test.tsgateway/session-history.subagent-visibility.test.tsgateway/session-transcript-index.fs.test.tsgateway/session-transcript-readers.test.tsgateway/managed-image-actions.e2e.test.tsgateway/session-utils.fs.test.tsgateway/session-utils.fs.display-position.test.tsFinal test cutover on Testbox
tbx_01m44h8bjafdyjh46pa2pt31y5: five focused files passed 81 tests in 39.83 seconds, including the two archive suites; their exact input hashes matched the applied test migration. The archive suites also passed individually with the explicit byte limit shown in the cost table.Independent Codex reviews completed with no actionable P0–P2 findings for the production change and the final test cutover. Static checks also identified and removed two unused imports and a retired type re-export, required an explicit byte limit matching the existing default in one test fixture, and tightened method binding and fixed-shape cursor construction.
Managed-image E2E passed all three cases; its long command cost above is dominated by the fresh runtime build. Rebased onto
42ebb9d73483with no production or test changes from the rebase; the only conflict combined independent documentation additions.Final Testbox
tbx_01m44n807vqf0jvk4gmpvv5x0f:node scripts/check-changed.mjs --base 42ebb9d73483b2d0d55178709b960af363cdd07dand the eight affected history/archive/attachment files (126 tests) both passed in one uninterrupted run (gate_result=0,test_result=0, total command 1,528.80 seconds; runtime tests 149.91 seconds). This includes all 27 core test-typecheck partitions, production types, structural guards, all three dead-export scans, core/script lint, and schema/storage/cycle/webhook/pairing guards. Source hashes verified the complete candidate before execution.Measurements precede mechanical import/type-export/lint cleanup and test-only corrections; the paging bounds and selection behavior are unchanged. No production Gateway or real customer state was used. Final independent review of the lint-driven corrections also completed with no actionable P0–P2 findings.
CI follow-up: the first GitHub run found a type-only cycle between the reader contracts and page iterator, which the runtime-value cycle check does not cover. The source-page contracts now live with the existing reader types, and all consumers import them there. It also exposed an inherited declaration-fixture omission after
76922aba447e: the fixture copiedscripts/libbut omitted its new root-levelruntime-postbuild-shared.mjsdependency. The fixture now copies that existing helper; no assertion was weakened. The branch was rebased ontoc5012333049ewithout changing lane-owned runtime source.Testbox
tbx_01m44s8k6z1pbavnn5x6f07m35verified the CI repairs:pnpm check:architecture(including both cycle scanners, Kysely checks, and storage guards), production and gateway-test types, affected core/root-test lint, and 25 reader/archive tests passed. The exact failing declaration case,pnpm test test/scripts/write-unified-entry-dts.test.ts --maxWorkers=1 -t 'reuses unaffected canonical groups while rebuilding runtime after input edits', passed unchanged (11.31 s test time, 13.09 s command wall). A remaining test-only type import was migrated to the new contract owner and its gateway typecheck/lint passed separately. Independent review of the CI repair completed with no actionable P0–P2 findings. The final test-only import migration was typechecked and linted, then formatted into canonical import order.Final GitHub CI passed on
8d45f399a8104e0868adda20581097643b2fb18d, includingopenclaw/ci-gate. The PR merged as12785be2ff02a11e6587399ea3a0ac6ea2a4be36. The final CI plan skipped its Windows matrix; the declaration-fixture regression was verified on Linux Testbox as recorded above.