Repository navigation
perf(sessions): hydrate only requested entry snapshots - #165181
Conversation
Select saved snapshots in the existing SQL reader without changing canonical admission or lifecycle, membership, and authorization snapshots. Preserve full SDK and mutation/CAS entries, and share ordinary/ordered worker request capture. Release-note context: Reduce metadata read payloads and transaction holds during reply finalization, authorization, and recovery. Load only the saved report or diff baseline needed by usage context and session diff consumers.
|
🦞👀 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, 7:06 PM ET / 23:06 UTC. ClawSweeper reviewWhat this changesThe PR makes session readers load only requested saved snapshots while preserving complete entries for SDK reads and writeback flows. Merge readiness✅ Ready for maintainer review This optimization remains useful on current main. No actionable correctness or security defect was found in the introduced changes. Priority: P2 Review scores
Verification
How this fits togetherSession readers retrieve persisted metadata and saved prompt or diff snapshots from agent SQLite databases. Gateway and agent callers use these entries for reply finalization, authorization, recovery, usage reporting, and checkout diffs. flowchart TD
A[Gateway and agent callers] --> B[Requested snapshot fields]
B --> C[Existing session read worker]
C --> D[SQLite metadata and snapshots]
D --> E[Selected entry fields]
E --> F[Reply and authorization checks]
E --> G[Usage reports and session diffs]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +43, Tests +123, Docs +3. Total +169 across 35 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep selective hydration in the existing SQL reader, with complete entries remaining the default for SDK and mutation flows. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: source confirms unnecessary full snapshot hydration, and the PR supplies before/after synthetic measurements; this review did not execute them. Is this the best way to solve the issue? Yes. Selecting fields through the existing SQL owner avoids a competing hydration cache and preserves complete-entry defaults. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d2167f41b6d3. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Select saved snapshots in the existing SQL reader without changing canonical admission or lifecycle, membership, and authorization snapshots. Preserve full SDK and mutation/CAS entries, and share ordinary/ordered worker request capture. Release-note context: Reduce metadata read payloads and transaction holds during reply finalization, authorization, and recovery. Load only the saved report or diff baseline needed by usage context and session diff consumers.
What Problem This Solves
Exact session reads load and decode saved prompts and diff baselines even when reply finalization, authorization, or ownership checks only need metadata, prolonging the reader's SQLite transaction.
User Impact
Metadata callers stop loading unused saved snapshots. Usage context reads only the system-prompt report; session diff reads only its baseline. No configuration or migration is required. Initialization, creation callbacks, cron reuse, replacement/CAS, and public SDK reads retain complete entries so saved snapshots survive writeback.
Why This Change Was Made
The existing snapshot owner selects requested fields alongside hot entry facts in the same SQL statement. Worker requests carry this choice independently of lifecycle, authorization, and membership selection. Canonical admission, per-key failures, current authority, and the original transaction boundary remain intact.
The change removes duplicate full/metadata prepared-query setup and an unused rowid projection. Ordinary and ordered readers now share one request capture function. No row cache or second hydration owner is added.
Production LOC: +198 / −155, net +43 (excluding tests, test support, and docs). The full-entry SDK and writeback/CAS contracts prevent replacing the default with metadata. Explicit field selection and propagation through the existing worker/Gateway boundaries account for the remaining growth; full reads are retained for those concrete contracts.
Evidence
Synthetic Linux rig, Node 26.8.1 / pnpm 12.5.1; base
0e936b88c4bf72c5114e792c6f3496c8dd43998f, candidate treeeaaed01346023c6fbd37000165a4f0d9ec8227f7. Nine warm samples per request shape. A second run reversed revision order and shuffled request order; both runs showed the metadata savings below. Values shown are medians from the shuffled run.Per entry, hot JSON is 32,936 bytes, saved skills 524,313, prompt report 656,577, and diff baseline 137,199. Metadata reads remove 97.6% of JSON bytes. For the 32-key metadata cohort, JSON parsing falls from 85.488 to 0.640 ms. Initial status recovery has no explicit transaction in this path; its 32-row total time falls from 234.492 to 2.191 ms, alongside the metadata-list reference at 2.180 ms.
Timing includes instrumentation and varies with scheduling/GC. Full-read controls moved in both directions between runs, so no speedup is claimed for retained full reads. Validation/projection is recorded with other residual JavaScript work, not as an isolated timer. These synthetic warm measurements do not establish a new production latency percentile; large-file cold canonical admission is unchanged and was not reproduced.
Validation:
blacksmith-testbox, profileopenclaw-check, final leasetbx_01m44f84y9bjzyfw5zrtmd85xg(runner), following focused runs ontbx_01m44cceyb8a0f6x2bnntp9wxg. The base commit and complete staged Git tree were verified in an isolated checkout before execution.node scripts/run-vitest.mjs <file> --maxWorkers=1, including preparation.node scripts/check-changed.mjs --staged: passed, exit 0, 22m57.63s on final treeef0b3fd7eded0b74323fa09105726a83f3399c6b.AssertionError: expected { …(2) } to deeply equal undefinedbecause an unrequested snapshot is present; it passes on the candidate. Measured single-worker wall times: entry worker 26.36 s (20 tests), prepared reads 16.93 s (4 tests), session diff 23.68 s (47 tests). The additional unchanged Gateway lookup suite passed 32 tests in 76.81 s.The final candidate additionally JSON-serializes the projection in the request cache key, fixing the type-aware lint error caused by implicit array coercion. Its SQL read owner is identical to the measured tree. An earlier rig changed-check caught line-cap growth; consolidating the duplicated request capture fixed it. The superseded rig check was stopped after Testbox became ready, and final gate proof comes from the lease above. The rig was used for synthetic measurements only after the queue exceeded the authorized fallback threshold.
The final lease used the repository source-capsule wrapper after native full sync timed out. The wrapper receipt binds the final tree and exit 0; the runner link can show cancellation after lease cleanup. All task-owned leases and rig worktrees are closed.
GitHub CI run 37242258120 succeeded for head
4b9522008e8ee6c6048df589ac1112138f775d8d; workflow wall time was 581 seconds (9m41s).