Skip to content

perf(sessions): coalesce tool-result actor admissions - #169207

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-admissions-per-tool-result-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-admissions-per-tool-result-20260919

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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.appendToolResult transaction. 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:

Resident snapshot Actor grants / result JSON request bytes / grant, before → after Host admission CPU ms / 1,000 results, before → after 60 append wall time, before → after
25,697 bytes 4 → 2 25,722–26,275 → 1,216–1,265 1,160.58 → 41.19 1,408.3 → 796.0 ms
201,987 bytes 4 → 2 202,009–202,565 → 1,219–1,268 8,150.59 → 40.54 5,626.0 → 3,310.2 ms

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:

  • 100 focused tests passed across actor, kernel, replica, diagnostics, incognito actor, and admission/timeout files, via node scripts/run-vitest.mjs … --maxWorkers=1 (35.93 s wrapper wall time). 75 sibling tests and 26 model-context tests also passed.
  • 20 closure tests 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.mts passed. The closure test caught the required shared-helper manifest entry, which is included.
  • Before the later owner extraction, the isolated Linux rig ran rig-staged-check.sh lane770-final-20261011 48f3aa1af0b7c29aa605b14d281c72877c91f3f7, testing the then-reviewed tree fa822fa5ed17a0b7bd6bc2ffede7942192f0afcb. Core types and all 28 core-test type graphs passed; the latter took 3,083.09 s. All preceding checks passed.
  • The sole failed gate is the inherited full-tree unused export loadSubagentMaintenanceCandidatesInDatabase in untouched src/agents/subagents/registry/subagent-registry.store.sqlite.ts. Running node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts on an unchanged checkout of base 48f3aa1af0b7c29aa605b14d281c72877c91f3f7 reproduced the exact finding (exit 1; production and script scans passed). No suppression or skip flag was used.
  • All checks following that scan passed separately through the same source-owned check plan: changed core/script lint, native schema version, legacy-store/media/sidecar guards, import cycles, and webhook/pairing guards. pnpm docs:list passed.
  • Final conflict-rebased tree a58e292400669b067ffb2bb6cdef816b9f15be64 passed 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.
  • Single-file cost before the owner extraction: 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.ts into session-actor-sqlite.ts and 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
Provider / host Lease Command / result
Blacksmith Testbox tbx_01m4nkz22texvx3cx8d5b85h6s Frozen install; original-code regression failed as intended; eight-file focused run passed 100 tests.
Blacksmith Testbox same Temporary session-actor.lane770-benchmark.test.ts, via node 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.
Blacksmith Testbox same Physical execution-owner probe before/after passed; session-manager-model-context-snapshot.test.ts passed 26 tests.
Blacksmith Testbox same Final gate synchronization timed out before execution. Lease stopped.
AWS Crabbox cbx_162b4c04f291 Quota fallback only supplied a 2 GB host. No validation; lease stopped.
Hetzner Crabbox cbx_9aa93d94417c Checkout transfer stalled before validation; lease stopped.
Isolated Linux rig task-owned worktrees Native staged gate, remaining source-owned checks, closure/collision tests, and unchanged-base dead-export reproduction, as recorded above.

The 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.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: S labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: The reported probe observed 420 admission grants.
  • After: The same probe observed 300 grants while retaining full committed snapshots.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused patch with meaningful production-owner harness coverage and reported measurements; shipped-entry-point proof is absent.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; recorded actor/MessagePort and durable-owner measurements support the internal optimization but do not prove live Gateway throughput.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Long, tool-heavy conversations incur avoidable processing overhead as transcript metadata grows.
Reason: The maintainer-authored direction has measured value and removes redundant work within the existing persistence owner.

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
Reviewed head: de3d53c56201cfeca1284000b0db4571a278f3ec

Before merge

  • Complete next step - Resolve the reported conflicts by applying the host changes in session-actor-sqlite.ts, preserve main’s executor and hydration recovery, validate the integrated actor and wrapper paths, and mark this PR ready for review.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Gateway tool-result scenario is supplied; the recorded measurements exercise persistence and admission owners directly.
Agent review details

How this fits together

SessionManager 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
Loading

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d5173cc adds src/config/sessions/session-actor.worker.ts:184 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d5173ccc77b9; files: src/config/sessions/session-actor.worker.ts)

PR surface

Source +43, Tests +75, Docs +4, Other +1. Total +123 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 5 57 14 +43
Tests 1 79 4 +75
Docs 1 7 3 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 8 144 21 +123

Review metrics

Metric Value Why it matters
Production versus test LOC Runtime +57/−14; tests +79/−4. The net runtime growth supplies the narrowed authority contract and receipt comparison; the test growth exercises the admission boundary and rollback.

Labels

Label changes:

  • add P2: A focused performance improvement for tool-heavy sessions, without evidence of an urgent user-facing regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: A focused performance improvement for tool-heavy sessions, without evidence of an urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

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.
@steipete
steipete force-pushed the steipete/perf-micro-admissions-per-tool-result-20260919 branch from de3d53c to adcb7f7 Compare October 11, 2026 16:45
@steipete
steipete marked this pull request as ready for review October 11, 2026 16:46
@steipete
steipete merged commit c400e2a into main Oct 11, 2026
197 of 199 checks passed
@steipete
steipete deleted the steipete/perf-micro-admissions-per-tool-result-20260919 branch October 11, 2026 16:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
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.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 20, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant