Repository navigation
perf(sessions): avoid cloning rebuilt actor projections - #170377
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. What this changesThis PR selectively clones retained session facts and rebuilds derived projections without copying transcript navigation. Example: Project a session containing events named user and assistant.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes redundant projection copying that current main still performs, with no actionable correctness or security finding. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe session database worker turns retained actor state into snapshots for command receipts and session readers. flowchart LR
A[Session command] --> B[Database worker]
B --> C[Retained actor state]
C --> D[Hot state projection]
D --> E[Detached receipt]
E --> F[Session readers]
Technical reviewBest possible solution: Keep selective cloning at the existing projection owner while preserving rollback and committed-receipt isolation. Do we have a high-confidence way to reproduce the issue? Source confirms that current main copies collections immediately replaced during projection; no target code was executed during this read-only review. Is this the best way to solve the issue? The patch removes redundant work at its existing owner, preserves nested output isolation, and adds no competing cache or state authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e4f463159d0a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +19, Tests +33. Total +52 across 2 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 12, 2026, 7:50 PM ET / 23:50 UTC (Revision 2). |
) Build session actor hot projections from detached retained facts and fresh derived collections, and scan actor-owned navigation without a redundant copy. Preserve rollback and receipt isolation, with a production-path caller-mutation regression. Three alternating profile pairs reduced projection samples from 9.67 to 5.29 ms per warmed turn; aggregate service remained too noisy to claim a speedup. The shared SQL pair showed no statement or request increase, and warmed MAIN statements remained zero.
Problem and change
Session actor commands deep-cloned the previous hot projection and transcript navigation, then immediately rebuilt the derived collections. Construct the projection from detached retained facts and fresh derived collections, and scan the actor-owned navigation directly.
The returned snapshot stays isolated from caller mutation. Rollback snapshots and committed-receipt copies remain. No SQL, command batching, cache, routing, schema, or authority contract changes.
Measurements
Base
0975d2455659f8715e47d483b63d871b4bc86ce5; measured production candidateae98aca55e675f6d0fee85d73e4aa3a10688c8e0. Final head5bd718f2c6b78987a0c5ae66164ebfa7a7062556differs only by test typing. Three alternating same-host profile pairs, ten warmed turns each, under the local CPU gate. One separate unchanged shared-v2 SQL pair, ten warmed turns each, supplies causal counts.Projection samples: 9.670 [7.862–22.349] → 5.293 [5.126–5.863] ms/turn (−4.377 ms, about 45%). The ranges do not overlap. This is a modest per-command optimization; the requested −80 ms summed-service target was not achieved.
Worker service and V8 sampling intervals are elapsed time, not scheduler CPU accounting. The 32-core macOS host started profile runs at 1-minute loads of roughly 93–132; the proof queue was fully occupied before admission, with observed load around 159. Admission waits, descheduling, native SQL, GC and profiler overhead inflate the totals. Aggregate latency/service regressions below are not evidence of a demonstrated CPU regression, and no end-to-end speedup is claimed. Direct projection samples are the primary signal. Native SQL is inside handler time, not additive.
SQL and requests
Legacy warmed-window statements: 236.5 → 220.3; window requests: 63.3 → 58.2; MAIN: 0 → 0. Whole workload: 7,166 → 6,854 statements, 1,383 → 1,271 requests, and 849 → 848 MAIN statements (startup/one-shot work included). Causal coverage is complete. Every exact SQL shape’s warmed causal execution count stayed equal or fell; none increased. These observed reductions are not credited to the SQL-neutral patch.
Actor execute envelopes were 9.3 → 9.4/turn (one extra envelope in ten turns, with no increased SQL shape); transcript tasks 7.3 → 6.4; ordered entry reads 4.2 → 4.1; patch commit 4 → 4 and prepare 3 → 3; state-worker executes 6 → 6. Counts are disclosed as workload variation, not command batching or query savings.
T1 in the touched owner: 0 → 0. The implementation stays inside the existing database worker.
Profiled elapsed service and latency
Per-run mean service: 2,189.897 [1,426.663–8,107.257] → 3,717.561 [3,470.182–4,224.213] ms/turn. The broad overlap and unrelated-worker inflation make this unsuitable for attributing CPU cost. No aggregate-service saving is claimed.
Worker, command, stage and top-10 flame summaries
Worker service (ms per warmed turn)
Command service (ms per warmed turn)
Writer stages (ms per warmed turn; decode includes admission preparation)
Top 10 active self-time functions: sqlite-store.worker.js (sampled ms per warmed turn)
Top 10 active self-time functions: session-transcript.worker.js (sampled ms per warmed turn)
Top 10 active self-time functions: openclaw-state-read.worker.js (sampled ms per warmed turn)
Top 10 active self-time functions: memory-search.worker.js (sampled ms per warmed turn)
Top 10 active self-time functions: memory-index.worker.js (sampled ms per warmed turn)
Removed work and boundaries
Verification
pnpm test src/config/sessions/session-actor-kernel.test.ts --maxWorkers=1(291.11 s Vitest; 393.82 s wrapper; 4.483 s test bodies). First-use worker compilation dominates.pnpm deadcode:exports, 447.4 s).git diff --checkpassed. SDK diff and update cell are not applicable to this scope.LOC: +24/−5 production; +33 tests. No changelog edit: release-note context is this PR.