Skip to content

perf(sqlite): reuse transferred actor admission snapshots - #169125

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-sqlite-admission-host-receive-clone-20260919
Oct 11, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-sqlite-admission-host-receive-clone-20260919

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Tool-heavy sessions repeatedly copy complete actor snapshots on the Gateway main thread while SQLite workers wait for admission. Snapshot cost grows with transcript anchors, idempotency keys, and model-context membership.

User Impact

Lower host CPU and allocation during session writes, with unchanged authorization, FIFO ordering, refusal/timeout behavior, and committed-state publication. No schema, configuration, stored-data, or update change.

Why This Change Was Made

Actor admission was cloning a snapshot already detached by its private MessagePort three times. Retain that received snapshot for private receipt comparisons and keep one detached copy for the mutable policy callback. No new cache, lifecycle, or fast path is introduced.

The callback copy remains because SessionActorAuthority.authorize accepts mutable state; callback mutations must not rewrite native commit evidence. Production LOC is unchanged (three lines replaced), with two full-snapshot clone operations removed rather than another implementation added.

Evidence

  • Independent isolated Codex review: scoped clean, P0–P2.
  • The actor fixture now crosses the real admission MessagePort. It covers grant/refusal and adds a callback-mutation isolation case; existing admission timeout coverage exercises late/refused grants and rollback.
  • AWS Crabbox cbx_71b4d7afedaa, node scripts/run-vitest.mjs src/config/sessions/session-actor*.test.ts src/infra/sqlite-worker-operation-admission.test.ts src/infra/sqlite-worker-operation-admission.timeout.test.ts --maxWorkers=1: 92 tests passed across seven files, 48.08 s wrapper wall time (50.19 s remote command). The new isolation case took 148 ms.
  • The real actor kernel and MessagePort fixture performed 60 synthetic tool-result appends: 240 admissions (four per append), completing the appends in 1.06 s. At a modeled 60 tool results/minute this is 240 admissions/minute; this is a synthetic rate, not a measurement of a live Gateway.
  • Blacksmith Testbox tbx_01m4ncrmjcf4n115n4cckv653v never acquired a runner; it timed out after 15 minutes and is stopped. All executed validation uses the AWS fallback.
  • node scripts/check-changed.mjs: all preceding checks passed, including core types and all 28 test type graphs; the repository-wide dead-export scan reported unused exports in untouched chat UI and subagent-store files. The identical findings reproduced on unchanged d1618ccd0b276f985711ff297b1b87a77bdad35d in the same hydrated checkout (exit 1); the candidate was restored byte-for-byte afterward. All remaining checks passed separately through the source-owned check plan. No failing scan was skipped or relabeled green.
  • The first timing attempt stopped on a syntax error in its temporary benchmark harness. The corrected harness passed; production source and the reviewed patch were unchanged.
  • node scripts/run-vitest.mjs src/config/sessions/session-actor.test.ts --maxWorkers=1: 12 passed, 29.55 s wall time including worker preparation; the new test took 158 ms (about 0.16 CI seconds).
  • All checks after the dead-export scan passed separately through the same source-owned plan: changed-file lint, native schema version, legacy-store/media/sidecar guards, runtime import cycles, and webhook/pairing guards.

Paired Node 24.19.0 Linux measurements on AWS c7a.8xlarge, comparing baseline d1618ccd0b276f985711ff297b1b87a77bdad35d against this patch in the same process. Each cell is the median of six samples of 1,024 admissions, with one warmup sample discarded and variant order alternated. Main-thread CPU is measured around the real MessagePort receive/service handler and actor admission callback; sender serialization and SQL are outside the interval.

Metadata entries per list JSON snapshot bytes Before ms / 1,000 admissions After ms / 1,000 admissions Speedup
0 499 34.2 14.6 2.33×
128 22,803 761.2 329.9 2.31×
1,024 186,092 5,822.4 2,543.4 2.29×

These are focused host-cost measurements and a synthetic session workload, not a live Gateway CPU or traffic claim. No live deployment or database was accessed.

Remote commands all used AWS lease cbx_71b4d7afedaa after the Testbox timeout: focused tests (run_948a25a99cdd724dfe6ddd6bbc72a0f0, passed); count probe plus node scripts/check-changed.mjs (run_0eb8ae32901bd94e030fb516ff89c56b, count passed, inherited export failure); corrected CPU probe, single-file test, and remaining planned checks (run_d753a34bfa001949492bd26512978ed7, passed); unchanged-base node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts (run_49bbc444c8a3fbf5171491d455dd5496, reproduced the same failure in 93.28 s). An initial separate-worktree baseline attempt could not resolve its UI dependency and was discarded as invalid evidence. Both leases are stopped.

Retain the MessagePort-detached snapshot for private receipt checks while preserving the mutable authorization callback copy. Remove two redundant full-snapshot clone passes per admission without changing grant ordering, live authority checks, or settlement.
@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 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 size: S labels Oct 11, 2026
@steipete
steipete marked this pull request as ready for review October 11, 2026 13:34
@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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses MessagePort-detached admission snapshots for private receipt comparisons while retaining a separate copy for mutable authorization callbacks.

Example: An authorization callback changes sessionId to "policy-mutated" during a patch setting updatedAt to 123.

  • Before: Three host snapshot clones preserve the original sessionId in committed state.
  • After: One host snapshot clone preserves the same original sessionId and committed updatedAt of 123.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The narrow patch is correct on inspection and has meaningful boundary coverage; performance evidence remains confined to a synthetic in-process workload.
Proof confidence 🦐 gold shrimp (3/6) The supplied host facts identify this as maintainer-authored, outside the ordinary contributor proof gate; reported actor-kernel and MessagePort measurements support focused host-cost savings but establish no live Gateway CPU result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Tool-heavy sessions spend avoidable host CPU and allocations copying growing actor metadata during session writes.
Reason: The supplied maintainer direction and focused measurements support removing redundant work while preserving the existing owner and behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it removes redundant snapshot copies from a shared session-write path, preserves callback isolation and live grant checks, and has no identified correctness defect. Current main still performs the extra copies.

Priority: P2
Reviewed head: 5420eda6019eed6d74a1e5be9ce62e162d022e2d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied performance measurements do not exercise a shipped Gateway turn.
Agent review details

How this fits together

Session actors coordinate session mutations through the existing SQLite worker and physical writer queue; worker admission snapshots enter the host authorization handler, and verified committed receipts publish state to the host replica.

flowchart LR
A[Session command] --> B[Existing SQLite writer queue]
B --> C[Actor transaction kernel]
C --> D[Private MessagePort]
D --> E[Host admission handler]
E --> F[Detached policy callback copy]
E --> G[Private receipt comparison]
G --> H[Committed host replica]
Loading

Technical review

Best possible solution:

Land the shared-owner optimization once the normal required checks complete.

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

Current-main source shows three complete snapshot clones per actor admission; the supplied paired measurements support their host-cost impact, but no target code was executed during this review.

Is this the best way to solve the issue?

Reusing the already detached snapshot is a narrow solution at the existing owner, and retaining the mutable callback copy preserves the original isolation contract.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Actor admission snapshot isolation keeps the original intent (d5173cc: Private admission snapshots protect native preimages and committed receipt comparisons from mutable authorization callbacks.)
  • Session actor documentation keeps the original intent (refactor(sessions): route transcript appends through the session actor #168539: Document the existing worker, receipt, authorization, and accepted-write lifecycle used by transcript appends.)

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.ts:213 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.ts)

PR surface

Source 0, Tests +32, Docs +4. Total +36 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 3 0
Tests 1 40 8 +32
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 47 11 +36

Review metrics

Metric Value Why it matters
Production versus test LOC Production +3/-3; tests +40/-8 Production size is unchanged; test growth exercises the real admission port and preserves mutable-callback isolation.
Host snapshot clones per admission 3 → 1 Two complete snapshot copies disappear without adding another cache or execution path.

Labels

Label changes:

  • add P2: A focused performance improvement reduces host work in session writes without changing user-facing contracts.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A focused performance improvement reduces host work in session writes without changing user-facing contracts.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 9:40 AM ET / 13:40 UTC.

@steipete
steipete merged commit d728205 into main Oct 11, 2026
187 checks passed
@steipete
steipete deleted the steipete/perf-micro-sqlite-admission-host-receive-clone-20260919 branch October 11, 2026 13:47
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…69125)

Retain the MessagePort-detached snapshot for private receipt checks while preserving the mutable authorization callback copy. Remove two redundant full-snapshot clone passes per admission without changing grant ordering, live authority checks, or settlement.
scribe-dandelion-cult added a commit to karmaterminal/openclaw that referenced this pull request Oct 20, 2026
First-parent upstream 19fe879..0bc7491 (100 commits, including
openclaw#169090 entry-writer postimages, openclaw#169201 transcript projection facts,
openclaw#169113/openclaw#169107/openclaw#169125 session-actor admission, openclaw#169110 bounded worker
heaps, openclaw#169130 inter-session provenance, openclaw#168931 Solid session UI).

Conflicts:
- session-accessor.sqlite-entry-mutation.ts: openclaw#169090 moved postimage
  publication into writeSessionEntry and replaced the revision-equality
  no-op check with postimages.changed. Took upstream's form; kept our
  recipient-authority advance on visibility narrowing (same transaction,
  after the write, before the no-op return).
- session-accessor.sqlite-entry-store.ts: import union (upstream dropped
  withProjectedParticipants/SessionEntryWindowFacts imports; ours adds the
  recipient-authority advance). Overlay vs upstream is now 2 lines.
- openclaw-tools.types.ts: import union (our RequestCompactionToolOpts,
  upstream's SessionsYieldRuntimeClaim).
- plugin-sdk-surface-report.mts: upstream raised the budgets to 3672/2133;
  ours stays +11/+4 on top (3683/2137).
- worker-access-inventory.md: regenerated on the merged tree.

Auto-merged files that carry continuation overlay (21) keep the overlay
byte-for-byte (interdiff of the +/- lines vs upstream before and after).

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. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant