Repository navigation
perf(sessions): coalesce tool-result actor admissions - #169207
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs changes before merge. What this changesThis PR reduces tool-result append admissions and transfers only the session facts needed for authorization. Example: Persist 60 synthetic tool results through the durable execution owner.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this maintainer-authored PR provides a distinct, measured optimization, with no discrete introduced bug found. The draft head has confirmed conflicts with main’s actor extraction. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherSessionManager sends prepared transcript appends to the existing session actor and SQLite worker; host callbacks authorize writes, and native receipts publish committed state before acknowledgement. flowchart LR
A[Tool result] --> B[SessionManager]
B --> C[Session actor]
C --> D[SQLite worker]
D --> E[Host authorization]
E --> D
D --> F[Agent database]
F --> G[Committed receipt]
G --> C
Technical reviewBest possible solution: Carry the optimization into main’s existing SQLite actor executor while preserving its shared lifecycle, hydration recovery, custody checks, and complete receipts. Do we have a high-confidence way to reproduce the issue? Source confirms the redundant admission path, and reported paired synthetic measurements support reduced overhead; live Gateway throughput is not established. Is this the best way to solve the issue? Sharing the existing transaction and final grant directly addresses the overhead, and inspected callers use the retained entry and identity facts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a45edbfa69ea. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +43, Tests +75, Docs +4, Other +1. Total +123 across 8 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 11, 2026, 12:21 PM ET / 16:21 UTC. |
Reuse the actor transaction and final commit grant for transcript appends, and carry only entry and identity facts through host admission. Preserve current custody checks, native receipts, FIFO, and refusal semantics.
de3d53c to
adcb7f7
Compare
Reuse the actor transaction and final commit grant for transcript appends, and carry only entry and identity facts through host admission. Preserve current custody checks, native receipts, FIFO, and refusal semantics.
First-parent upstream 0bc7491..408a1f3 (53 commits, including openclaw#169164 cold session/memory SQL off the Gateway main thread, openclaw#169173 per-turn SQLite bookkeeping, openclaw#169207 coalesced tool-result actor admissions, openclaw#169238 inter-session envelope bytes, openclaw#168989 ACP replies). Conflict: - plugin-sdk-surface-report.mts: upstream budgets 3673/2134; ours stays +11/+4 on top (3684/2138). Drag removed against upstream: - plugin-sdk-surface-report.mts: dropped the "+1: createSessionHeaderLink" budget comments; upstream added them in openclaw#158742 and retired them in openclaw#165334, and no such export exists any more. - normalize-reply.ts: restored upstream's blank line before bindNormalizeReplyTransformOwner (formatting-only overlay noise). Auto-merged files that carry continuation overlay (normalize-reply, sqlite-entry-store, user-turn-transcript, baselines, vitest paths) keep the overlay byte-for-byte. Worker access inventory regenerated. Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Tool-heavy sessions repeatedly send resident transcript metadata to the Gateway just to authorize one SQLite append. Related: #169125.
User Impact
Lower host CPU and allocation during tool-result persistence. Acknowledgement still follows native commit; FIFO, current authority, rollback, refusal, timeout, and unknown-outcome handling remain intact. No configuration, schema, stored-data, retention, or update change.
Why This Change Was Made
The four snapshot-bearing grants were one actor preimage grant, the nested append's transaction and commit grants, and the final actor commit grant—all within one
session.actor.appendToolResulttransaction. The append now shares the actor's transaction and final grant. Explicit fresh-message, pending-input, and CLI-writer checks retain their effect boundaries; final admission uses current message custody facts.Host policy consumes session entry and physical/version identity. Admission now projects those facts, excluding anchors, idempotency lists, model-context membership, and other resident indexes. Reads and native committed receipts retain complete snapshots. Callback copies and receipt matching preserve isolation.
Production delta: +43 runtime lines, plus one wrapper-manifest entry. The explicit smaller authority type, shared projection, and projected receipt comparison preserve the existing full-result and callback-isolation contracts. Two redundant grants and intermediate full-state projections are removed; no cache, competing fast path, or compatibility layer is added.
Evidence
Final rebased measurements on the isolated Linux rig (Node 26.8.1, pnpm 12.9.0), using synthetic state:
CPU medians replay actual captured admission frames through the real host actor and MessagePort handler: five samples of 1,024 logical results, excluding sender serialization and SQL. Byte counts are UTF-8 JSON request sizes, matching the earlier snapshot-size convention. Before/after use the same seeded state and return identical full snapshot sizes. Wall measurements separately execute real actor transaction kernels. The same seeds now produce slightly larger snapshots after main added actor facts; the measured improvement remains meaningful, so the original 23–186 KB sizing estimate is not treated as a gate.
The final real durable execution-owner probe counts every grant: 420 → 300 per 60 results (7 → 5/result). The additional two prepare grants and one identity-only transaction grant are unchanged and carry no actor snapshot. Across three matched 60-result batches with growing transcripts, median total host-thread CPU fell 11,955 → 7,233 ms/1,000 results (39.5% lower). Full worker-flow wall time was effectively unchanged at the median (2,109.7 → 2,118.7 ms/60 results) and varied substantially between samples; this does not establish a full Gateway throughput gain. The table isolates the admission cost and synchronous kernel benefit.
The regression fails on unchanged
89564fa3a101b437a485fbe501dd99281c9402ba, observing transaction/transaction/commit/commit instead of transaction/commit. It passes on the candidate and proves a fresh-message refusal leaves transcript state unchanged. Independent isolated review of the final rebased scope is clean through P2; the two earlier reviews were also clean.Validation:
node scripts/run-vitest.mjs … --maxWorkers=1(35.93 s wrapper wall time). 75 sibling tests and 26 model-context tests also passed.node scripts/run-vitest.mjs test/scripts/eager-import-closure.test.ts test/scripts/pr-wrapper-source-closure.test.ts --maxWorkers=1(57.44 s).node --import ./scripts/tsx.mjs scripts/check-export-name-collisions.mtspassed. The closure test caught the required shared-helper manifest entry, which is included.rig-staged-check.sh lane770-final-20261011 48f3aa1af0b7c29aa605b14d281c72877c91f3f7, testing the then-reviewed treefa822fa5ed17a0b7bd6bc2ffede7942192f0afcb. Core types and all 28 core-test type graphs passed; the latter took 3,083.09 s. All preceding checks passed.loadSubagentMaintenanceCandidatesInDatabasein untouchedsrc/agents/subagents/registry/subagent-registry.store.sqlite.ts. Runningnode --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mtson an unchanged checkout of base48f3aa1af0b7c29aa605b14d281c72877c91f3f7reproduced the exact finding (exit 1; production and script scans passed). No suppression or skip flag was used.pnpm docs:listpassed.a58e292400669b067ffb2bb6cdef816b9f15be64passed 138 focused tests, including all actor/memory backend siblings and admission/timeout tests (229.43 s wrapper time), core types, 20 closure tests, export-name collisions, import cycles, changed-file lint, and both line-cap ratchets. Exact-head CI run 38156886381 passed: 44 successful / 23 intentionally skipped jobs, including the required CI gate; the separate security-review gate also passed.pnpm test src/config/sessions/session-actor.test.ts --maxWorkers=1: 13 passed, 67.699 s wall time on the rig (66.69 s wrapper time). The new case took 105 ms in the original focused run (about 0.105 incremental CI seconds); no new test file or worker boot was added.The first conflict-free rebase incorporated main's existing fix for unrelated Solid panel type errors. A subsequent main change extracted SQLite ownership from
session-actor.tsintosession-actor-sqlite.tsand introduced an inactive memory backend. The conflict resolution moves this lane's admission changes to that SQLite owner, preserving the shared executor and memory backend. Fresh review, focused/memory tests, and measurements cover that final layout. No upstream fix was copied or cherry-picked; the branch contains one lane commit.These are synthetic persistence/admission measurements, not a live Gateway throughput claim. No production host or database was accessed. Observed process RSS after the small/large benchmark cells was 455/909 MB before and 448/705 MB after, including test runtime and prior allocations; this is not retained-heap evidence.
Remote execution and infrastructure gaps
tbx_01m4nkz22texvx3cx8d5b85h6ssession-actor.lane770-benchmark.test.ts, vianode scripts/run-vitest.mjs … -t 'lane770 batches' --maxWorkers=1: paired host benchmarks passed; six sibling files passed 75 tests; collision guard passed; closure failure identified and repaired.session-manager-model-context-snapshot.test.tspassed 26 tests.cbx_162b4c04f291cbx_9aa93d94417cThe first sibling command named a nonexistent
session-turn.test.ts; the corrected command used the existing planning/source-custody files. An initial per-grant CPU probe was discarded because timer granularity produced zero-valued samples; the reported batched method resolves that limitation.