Repository navigation
perf(sessions): share immutable actor snapshot revisions - #169726
Conversation
Reuse frozen actor revisions for reads and callback handoffs while preserving generation, write-token, and live authority checks. Consumers that edit facts explicitly clone their working copy.
|
🦞👀 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 shares immutable session actor snapshots and callback evidence instead of repeatedly cloning them. Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this useful performance PR open, but fix the incognito reconciliation callback before merging: it still mutates the newly frozen commit value. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Gateway’s session actor executor authorizes reads and writes, receives SQLite worker commit evidence, and installs snapshots in its existing bounded replica for callers. flowchart LR
A[Session callers] --> B[Actor executor]
B --> C[Live authority checks]
B --> D[SQLite worker]
D --> E[Native commit evidence]
E --> F[Immutable replica]
F --> A
E --> G[Postcommit reconciliation]
Technical reviewBest possible solution: Keep shared immutable revisions and copy only the value that incognito postcommit reconciliation needs to edit. Do we have a high-confidence way to reproduce the issue? Source tracing shows the frozen commit value reaching an in-place mutation after incognito branch replacement, and an existing integration test supplies the exact scenario; no target code was executed during this read-only review. Is this the best way to solve the issue? Sharing revisions through the existing replica is a focused optimization, but the immutable contract must also reach the existing reconciliation consumer. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5f27b4e9182d. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -3, Tests +20. Total +17 across 6 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
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 Reviewed October 12, 2026, 3:54 AM ET / 07:54 UTC. |
|
Fixed the incognito reconciliation finding in cb382da: the existing callback copies only The original CI failure is independently reproduced on unchanged main f0a14bf: |
|
Landing under the authorized inherited-failure exception on cb382da. The sole originating failure in CI run 38222685831 is Local proof: 47 actor/replica/worker/residency tests and all 6 incognito actor tests pass, changed-file lint/format passes, and fresh independent review is clean. The hosted incognito reconciliation finding is fixed with a value-only copy. The earlier stale-version retry test also reproduces on unchanged main; it was not the originating failure of the final run. The native merge wrapper stopped before submission because this lane has no separate wrapper review worktree. Using the explicitly authorized, exact-head REST fallback. |
…9726) * perf(sessions): share immutable actor snapshot revisions Reuse frozen actor revisions for reads and callback handoffs while preserving generation, write-token, and live authority checks. Consumers that edit facts explicitly clone their working copy. * fix(sessions): copy incognito readiness before editing shared facts
What Problem This Solves
Repeated actor reads and callback handoffs copy the same session snapshot, adding CPU and allocation pressure to agent steps and session reads. This completes the actor snapshot work beyond the prepared-append path in #169651. Related: #169701.
User Impact
Reduces snapshot overhead without changing stored data, schema, configuration, or update behavior. Internal actor facts and receipts are read-only; consumers that need to edit them make an explicit copy. Public mutable entry projections retain their detached-copy behavior.
Why This Change Was Made
The replica already owned a frozen revision but cloned it on each disclosure. SQLite admission facts and native commit receipts were already detached by MessagePort and were cloned again for callbacks. Share those immutable objects through the existing owner and compare installed revisions by identity. Generation, scoped write-token, live authority, stale-read, and unknown-outcome checks remain at their existing boundaries. Failure bookkeeping replaces the frozen result instead of mutating it.
Incognito branch reconciliation copies only its editable result value when reconciliation is required; the durable receipt stays frozen. Both existing branch-replacement regressions caught and now cover this mutable consumer.
Production delta: 26 insertions / 28 deletions, net −2 lines across five production files. No parallel cache or compatibility path is added.
Evidence
Measurement first: isolated Linux rig, Node 26.8.1, baseline
9a1b712a9b80. A task-only driver exercises the real SQLite actor executor and replica with synthetic transport/receipt facts: a 76,154-byte snapshot, one patch plus eight snapshot reads per step. Three interleaved baseline/candidate pairs run 1,000 steps each. This measures the actor boundary, not full Gateway throughput or real worker transport latency. Team was not accessed.Median speedup: 3.20×. Immutable traversal costs more, but replaces substantially more cloning. SELF is exclusive V8 sampled elapsed time, with native clone leaves assigned to their nearest source caller; synthetic transport clones are counted separately and excluded from actor clone counts. Byte counts are input payload estimates, not measured heap allocations. Shared-host timing and this focused workload do not establish a new full-Gateway SELF share; the earlier 900-second discovery profile is motivation only.
Proof:
pnpm test src/config/sessions/session-actor.test.ts src/config/sessions/session-actor-replica.test.ts src/config/sessions/session-actor-entry-residency.test.ts src/config/sessions/session-actor-worker.test.ts --maxWorkers=1: 47 passed, 52.16 s wrapper wall time (47.15 s Vitest, including source transforms).oxfmt --check, repositoryrun-oxlint.mjs, andgit diff --check: passed.pnpm test src/state/openclaw-agent-execution-incognito.session-actor.test.ts --maxWorkers=1: 6 passed, 100.45 s wrapper / 27.81 s Vitest (actual tests about 3.4 s; most wall time is preparation/imports). Both metadata/event reconciliation cases first failed with the read-only-property TypeError and pass after the fix.Inherited CI failure: the existing
attempt-transcript-lifecycle-prepare.test.tscase “uses a stale-version postimage once without replaying a durable append (incognito=false)” deliberately injects an invalid epoch and expects a retry removed by the prepared-append cutover. The same case fails withSessionActorStaleVersionErroron an isolated, unchanged main snapshot atf0a14bf986e6085af1425c00f4d172f45a70ef8d(1 failed / 33 skipped, 147.79 s wrapper wall time). Relevant baseline source files were verified against Git blob IDs. The failing test and append caller are unchanged between the original CI baseline and that main snapshot. No CI rerun was requested.Final-head CI qualification: run 38222685831 tested
cb382da67fdf16242f8ae2fb02d6ac33938f44a5merged with mainccb7b5f7e5de8e0e6c3bd20030c902d2134e9a15. Its sole originating failure istype-suppression-inventory.test.ts: an unchanged cleanup helper contains a nineteenth suppression while the unchanged inventory expects eighteen. Running that test on the exact unchanged main baseline reproduces the same mismatch (1 failed / 3 passed, 5.34 s wrapper / 3.95 s Vitest). Scanner, expectation, and helper blob IDs match the baseline. Security-fast passed; the successful fail-fast monitor cancelled unfinished siblings. Landing uses the authorized inherited-failure exception; no CI rerun or green-chasing push was requested.