Skip to content

perf(sessions): reduce fresh-session input custody work - #185601

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-actor-queue-20260919
Oct 27, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-session-actor-queue-20260919

Conversation

@steipete

@steipete steipete commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fresh-session input staging fetches a complete actor snapshot even when the actor owner already holds current entry facts, adding worker work while the database writer FIFO is reserved.

User Impact

Reduces the work needed to put a user's input into durable custody. Ordering, lifecycle rejection, recovery after an uncertain write, and live commit authority remain unchanged. No configuration or migration is required.

Why This Change Was Made

Staging needs entry lifecycle facts rather than the full transcript/pending-input snapshot. It now borrows existing entry facts through the actor's authority and reconciliation fence, with physical-database generation and scoped-receipt validation. Missing or fenced facts still use the canonical reader. The native command still hydrates state and checks lifecycle and live authority before committing; writes are not reordered and no cache is added.

Entry receipts belong to the physical database, while complete snapshots retain worker-connection ownership. Keeping that distinction avoids invalidating a current entry merely because another connection published it. The actor's unknown-outcome fence remains authoritative even when another writer publishes fresh facts.

Runtime code grows by 13 lines to preserve that shared authority/recovery boundary. Non-test/non-doc changes total +289 lines: +13 runtime, +274 standalone measurement script, +1 benchmark executor adaptation, +1 tooling entry. Benchmark usage is in its header; the shared perf README is unchanged.

Evidence

Final owner comparison: base 9b7db694b593cd2b498d704611414a8659fe7ffb, candidate runtime 8a2b0439c8f8421a5136e753025e41c80d0f4d98. The same measurement script, dependencies, and build artifacts were held fixed while six changed runtime modules were replaced with their exact base/candidate bytes. Source hashes were recorded and verified after restoration. Each fresh process staged 1,000 durable inputs in batches of 32 fresh sessions with 32 KiB skill snapshots. Setup, initial pending-input reads, acquisition, and release are outside measured windows. CPU/GC use an untraced pass; sampled main-thread allocation uses a separate inspector pass. All 4,000 native custody receipts passed.

Per 1,000 inputs Base Candidate
Full actor reads, timing pass 1,000 12 (988 eliminated)
Full actor reads, allocation pass 1,000 0
Accepted inputs, each pass 1,000 1,000
Main-thread CPU 4,656 ms 3,001 ms (−35.5%)
Total process CPU 11,781 ms 8,712 ms (−26.1%)
Sampled main-thread allocation 548.0 MB 462.3 MB (−15.6%)
Main-thread GC total 180.3 ms 70.4 ms
GC collections / maximum pause 42 / 15.31 ms 18 / 22.45 ms

The 12 timing fallbacks completed normally and retain the canonical read path; their individual invalidation causes were not instrumented. These are operation samples from four processes, not 1,000 independent process trials. Earlier runs also reduced main CPU by approximately 41–42% and sampled allocation by 12%, but used an earlier candidate and are not the final-head proof.

Host one-minute load was 88.7→92.1 on base timing, 86.9→74.6 on candidate timing; allocation arms were 93.7→79.3 and 71.7→68.2. Owner latency is context rather than a whole-Gateway speedup claim: p50 24.22→13.45 ms, p95 101.92→46.30 ms, p99 220.31→126.08 ms (1,000 samples per side). GC kind breakdown, promotion, and worker allocation were not collected. No adverse tail claim or A/A rejection is made.

Memory limits

Memory remains inconclusive; no retained-memory improvement is claimed. Fresh, complete direct-worker samples showed:

Checkpoint (MiB) Base Candidate
Timing RSS before close 758.8 782.2
Timing main heap used / worker heap used 182.0 / 196.1 187.6 / 207.1
Timing RSS after close / live workers 733.3 / 0 759.2 / 0
Allocation RSS before close / live workers 726.2 / 1 905.2 / 2
Allocation main heap used / worker heap used 123.7 / 178.2 122.7 / 226.4
Allocation RSS after close / live workers 586.8 / 0 879.9 / 1

The allocation candidate finished with its temporary disk-budget worker still alive (42.7 MB heap); the baseline reached that worker's normal 60-second idle retirement. This explains a lifecycle difference, not the entire RSS delta. Timing arms had matching worker counts and a 23.3 MiB RSS increase. No forced GC, maintenance exclusion, or post-hoc pause trimming was used. The earlier unmatched approximately 250 MB RSS gap was retained as preliminary evidence and prompted these matched controls.

Reproduce with node --import ./scripts/tsx.mjs scripts/perf/session-input-custody-measure.ts --state-dir <new-directory> --iterations 1000 --mode timing, then --mode allocation with another new directory, using the same script in both revisions.

Validation

Final head 6f54af4542cd1766882be48c28d4f1899e54fca8 rebases onto 7bb0af632123 and includes the existing benchmark executor fix. The only manual conflict was an import relocation in the actor test; main’s memory-owner/storage-acquisition refactor remains intact. Independent review of the complete rebased diff is clean. Measurements retain the explicitly identified pre-rebase source pair above and were not repeated after main’s import refactor.

The direct source work-count regression failed on base (actorReads=1, expected zero) after a successful native custody receipt and passed on candidate. The final source reproduction of the complete recorder path stages durable input with zero actor reads. Committed regressions cover entry-only staging, generation retirement, and unknown-outcome recovery after another writer publishes entry facts.

Changed-file formatting/lint, export-name collision guard, and script typechecking passed. Independent subagent review (autoreview route unavailable) has no remaining actionable finding, including the final receipt correction and benchmark executor adaptation. The initial focused local run passed 58 of 59 tests; its failing new recorder regression exposed the connection-UUID mistake corrected before this PR's first CI run. Initial PR CI found one missing snapshotEntry method in an existing synthetic benchmark executor; that consumer is now updated and script typechecking passes. Both required import-closure files passed locally (29 tests). Post-rebase focused attempts with the default Bun runtime and the supported Node runtime produced no test results after worker-cache preparation and were stopped; these are local setup gaps, not passing tests. Final CI run 40467121337 passed on 6f54af4542cd1766882be48c28d4f1899e54fca8, including changed-code shards, script/production/test types, lint/architecture checks, builds, and all three PostgreSQL conformance shards. No CI rerun was used to chase green. ClawSweeper re-reviewed the final head and reports no actionable findings.

The canonical session-start harness was attempted on the built baseline with 10,800 synthetic sessions, 40 configured plugins, 65 clients, four concurrent mock-provider turns, and APFS worktrees. It timed out during sessions.create while the baseline processed sustained maintenance deletions and slow SQLite commits, before producing turn measurements. This is a baseline setup gap, not a candidate performance result. Two isolated build preparations completed, but the final receipt correction was proven through the real source recorder/native custody path rather than a rebuilt Gateway. No session-start, server-handler, sessions.list, or event-loop improvement is claimed. The lane's explicit fast-path scope uses owner work-count/CPU/allocation proof for this read elimination; the separate multi-pair ten-minute Gateway campaign was not run. No production Gateway was load-tested.

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: M labels Oct 27, 2026
@steipete
steipete marked this pull request as ready for review October 27, 2026 06:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T07:28:18.785163Z 6f54af4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR stages durable session input using current entry receipts instead of fetching a complete actor snapshot.

Example: A fresh session receives “Keep this input in durable custody” after its entry has been published.

  • Before: Staging requests a complete actor snapshot before accepting the input.
  • After: Staging borrows current entry facts and commits custody through the existing worker command.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-consistent optimization with production-owner measurements and useful regressions; evidence remains narrower than a completed shipped Gateway flow.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor-proof gate; supplied evidence exercises the production pending-input owner and real database worker, with claims limited to custody work reduction.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Fresh input performs unnecessary worker reads while holding the database writer queue.
Reason: The area owner's direction and reported work-count reduction justify the small runtime change without changing configuration or intended behavior.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR removes redundant input-staging work, fixes the prior benchmark-contract finding, and introduces no actionable correctness defect found in this review.

Priority: P2
Reviewed head: 6f54af4542cd1766882be48c28d4f1899e54fca8

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The baseline Gateway attempt did not complete, so whole-Gateway latency and retained-memory effects remain unproven.
Agent review details

How this fits together

The session actor sits between input recorders and database workers, turning captured input and lifecycle expectations into durable custody receipts.

flowchart LR
  A[Input recorder] --> B[Pending input store]
  B --> C[Session actor]
  C --> D[Entry replica]
  C --> E[Writer admission]
  E --> F[Database worker]
  F --> G[Custody receipt]
Loading

Technical review

Best possible solution:

Reuse the existing entry-receipt owner while preserving canonical fallback reads, lifecycle rejection, and final commit authority.

Do we have a high-confidence way to reproduce the issue?

Current-main source shows the unnecessary full read, and the supplied body reports a base-failing, candidate-passing recorder regression; this read-only review ran no target code.

Is this the best way to solve the issue?

The change is appropriately narrow: it exposes existing entry facts through the actor fence instead of adding a cache or weakening the worker's lifecycle checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c4d5fddda138.

Provenance checked

  • Pending-input lifecycle selection keeps the original intent (f8ea55f: Select lifecycle expectations inside writer admission and retain them across a single version retry.)
  • Actor replica and scoped receipts keeps the original intent (d5173cc: Keep actor state and phase commands under the existing physical writer, scoped receipts, and accepted-work lifetime.)
  • Snapshot borrowing keeps the original intent (230ea68: Share immutable actor snapshot revisions rather than repeatedly copying installed state.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +13, Tests +53, Docs +10, Other +276. Total +352 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 28 15 +13
Tests 2 60 7 +53
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 3 276 0 +276
Total 12 374 22 +352

Review metrics

Metric Value Why it matters
Runtime versus regression code Runtime +28/-15 lines; tests +60/-7 lines The runtime growth supplies one shared entry-snapshot contract; the tests protect staging work, worker retirement, and reconciliation after uncertain writes.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a focused performance improvement to durable input staging with unchanged intended user behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-27T07:12:28.035Z sha 8a2b043 :: needs changes before merge. :: [P2] Update the existing benchmark executor for snapshotEntry

Reviewed October 27, 2026, 3:30 AM ET / 07:30 UTC (Revision 2).

Avoid a full actor read when current physical-row receipts already supply lifecycle facts. Keep actor lifetime, live authority, and unknown-outcome recovery fences while allowing facts published by another SQLite connection. Add custody work-count, generation/recovery coverage, and a real-owner CPU/allocation measurement script.
@steipete
steipete force-pushed the steipete/perf-micro-session-actor-queue-20260919 branch from 8a2b043 to 6f54af4 Compare October 27, 2026 07:26
@steipete

Copy link
Copy Markdown
Contributor Author

Fixed the missing snapshotEntry implementation in the existing synthetic append benchmark executor. Script typechecking, changed-file lint/format, and the two import-closure test files pass (29 tests). Rebased onto current main; the only manual conflict was the actor test's storage-acquisition import. Independent review of the complete rebased diff is clean.

The body now records final matched owner measurements, raw memory/worker-lifecycle limits, exact measurement revisions, and the baseline Gateway setup gap. Final CI is running on 6f54af4542cd1766882be48c28d4f1899e54fca8.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@steipete
steipete merged commit 8b5268c into main Oct 27, 2026
150 of 153 checks passed
@steipete
steipete deleted the steipete/perf-micro-session-actor-queue-20260919 branch October 27, 2026 07:53
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
)

* perf(sessions): reuse entry receipts for input custody

Avoid a full actor read when current physical-row receipts already supply lifecycle facts. Keep actor lifetime, live authority, and unknown-outcome recovery fences while allowing facts published by another SQLite connection. Add custody work-count, generation/recovery coverage, and a real-owner CPU/allocation measurement script.

* fix(perf): implement entry snapshots in actor benchmark
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: M 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