Repository navigation
refactor(sessions): avoid cloning unchanged rollback state - #170484
Conversation
Keep unchanged transcript payloads and rows shared across a private command fork. Detach mutated collections before publication, preserve deep-copy return boundaries, and cover rollback, nested snapshot isolation, and FIFO preimages.
|
🦞👀 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 changes before merge. What this changesThis PR replaces whole-state session rollback clones with shared unchanged rows and copies of collections when first mutated. Example: A session activity command changes updatedAt from 601 to 603.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it provides a focused, maintainer-directed optimization absent from current main, with no actionable correctness or security defect found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe serialized database worker applies session actor commands through existing SQLite transaction kernels and returns committed snapshots and receipts. flowchart TD
A[Session command] --> B[Serialized database worker]
B --> C[Private working state]
C --> D[Existing mutation kernels]
D --> E[SQLite transaction]
E --> F[Install committed state]
E --> G[Discard rejected state]
Technical reviewBest possible solution: Keep rollback isolation within the existing transaction owner while copying mutated collections and preserving detached snapshot and receipt boundaries. Do we have a high-confidence way to reproduce the issue? Current-main source demonstrates complete retained-state cloning before mutations; this read-only review did not measure runtime performance. Is this the best way to solve the issue? The approach fits the existing owner: inspected mutations replace rows or detach collections, mutable scalar shells are copied, and commit and disclosure boundaries remain intact. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ebf0a83c6bb3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +100, Tests +69, Docs +7. Total +176 across 11 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 12, 2026, 10:06 PM ET / October 13, 2026, 02:06 UTC (Revision 3). |
…170484) Replace whole-state session actor rollback clones with first-write collection detachment. Preserve detached returned snapshots, rollback isolation, and FIFO command ordering. Rollback preparation falls from 4.3 to 0.1 sampled intervals per warmed turn across three matched-runtime pairs; actor SQL and request operations remain flat. Latency is unmeasured. Regression coverage preserves the resident preimage after mutation rejection, nested snapshot isolation, and FIFO across rollback. Integrated-head CI passes.
What Problem This Solves
Every durable session actor mutation, resident entry-patch publication, and transcript-rewrite publication deep-cloned all retained state for rollback. The clone traversed unchanged transcript payloads and indexes even for a small metadata command.
User Impact
No command, persistence, or isolation behavior changes. Metadata-only commands avoid walking all retained transcript payloads merely to prepare rollback. No migration or operator action is needed.
Why This Change Was Made
Fork the small mutable object shells and share immutable rows/payloads. Each map or navigation array detaches on its first write. The existing mutation owners replace rows, a rollback discards the working state, and only confirmed commit installs it. Returned snapshots and receipt postimages retain their existing deep-copy boundary. This removes the whole-state clone without changing commands, FIFO scheduling, persistence, SQL, or authority checks; no dependency or new state owner.
Rollback isolation protects real user data, so it is preserved. No authority check was removed, and no new rollback edge case is accepted. The change replaces the expensive isolation mechanism rather than weakening the contract.
Evidence
Measurement
Shared harness v2.1.0, baseline
62f79e969ef02versus candidate8dd786e4ee25: three alternating pairs, ten warmed turns per capture, Node 26.11.1 / SQLite 3.53.4 throughout. Values are median [min–max] of the per-run means. The original first pair crossed a host Node upgrade; it is excluded, and the one permitted extra pair supplies the third matched pair.The removed
cloneSessionActorStoredStateaccounts for 134 sampled intervals across 30 warmed turns; its replacement (forkSessionActorStoredState, map and navigation detachment) accounts for 3. The consolidated entry-publication helper is separate: 1.3 [1.2–2.0] sampled intervals/turn, including entry-boundary clones that existed before this change. V8's 1 ms sampling covers warmed windows plus settling intervals and excludes collector ancestry; zero means below sampling resolution. Weighted rollback intervals are 11.254 [8.392–15.479] → 0.108 [0–0.391] ms/turn, but include possible descheduling and are not latency or scheduler CPU accounting.Per-operation statement medians are unchanged: actor execute 14 → 14; write transaction 9 → 9; phase entry write 8 → 8; append 14 → 14; transaction state 2 → 2. Actor-originating request medians are 8.1 → 8.0. Shared exact-entry reads are 4.1 → 4.0, hydration 1.1 → 1.0, and entry-cache snapshots, row facts, and watermark reads remain zero. No warmed SQL shape, request owner, or shared read family increases. This is a CPU optimization; incidental overall count reductions are not claimed as SQL savings.
First-turn causal statements are 394 [372–403] → 405 [373–418], with requests 81 → 81 and MAIN 33 → 33. Increases are cold runtime/canonical-schema admission and the existing upstream deletion-journal lookup; actor first-turn SQL groups are equal or lower. Background statements/minute are 587.5 → 664.1; timing-dependent background redistribution does not change the SQL-neutral actor result. Shutdown-only audit-prune database-lock refusals occurred on both base and candidate; every primary workload completed.
The shared 32-core host had sampled load 68–93. Latency is unmeasured: the quiet-host attempt ended during source preparation, before any remote workload ran. No latency or total-actor-CPU percentage claim is made.
T1: the durable actor rollback path is worker-owned, 0 → 0. The pre-existing mixed-access inventory in shared storage files remains 27 → 27; this PR changes only their resident-state mutation hooks, not native/incognito or compatibility call routing. No SQL or worker operation is added or removed.
Validation
git diff --checkpasses. Both independent Codex reviews are clean (no P0–P2 findings). The first CI run caught a type-import cycle and a test using a retired entry field; both were corrected. CI on8dd786e4ee25passed in 624 seconds, including types, lint, source/export contracts, Madge, T1/dialect ratchets, builds, and changed-file test shards. The separate Knip export scan found no changed-scope issues and one unrelated unused QA helper; main already removes that helper in582b6dd0041c. The clean main integration includes that fix. Following the updated compute-conservation rule, final integrated-head proof will come from PR CI, without another local Knip or test run.Production delta: +100 net lines (excluding tests and docs), within the increased 500-line budget. The coordinator hold was lifted. Main was merged cleanly in
0852b9c46c7d; the PR-only diff and actor code are unchanged. Integrated-head CI passed in 814 seconds (71 jobs completed, including skipped jobs), including the changed-file tests and static gates. Changed-file formatting, type-aware lint, andgit diff --checkalso pass locally.