Skip to content

perf(sessions): compact append receipts after replica eviction - #199673

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-append-receipt-residual-20261115
Nov 15, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-append-receipt-residual-20261115

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Small transcript appends resend large, unchanged session entries after the bounded replica pool evicts them. Transcript-first eviction helped, but 100 active sessions with large skills snapshots and prompt reports still reproduce the residual on main.

User Impact

Less worker-to-main copying for busy session workloads. Transcript contents, model context, authorization, durable writes, and the existing 128-snapshot / 8 MiB replica budgets (including the existing oversized-single-entry allowance) are unchanged. No migration or configuration change.

Why This Change Was Made

A cold command already receives the full authoritative entry during transaction admission. Keep that existing command-local preimage and its write token through settlement, and use the existing receipt delta protocol against it. This removes compaction's dependency on pool residency without adding a cache or retaining another entry payload: the same entry was already held as previousEntry until settlement. Warm commands continue using their worker-confirmed replica reference. Changed-entry admission facts remain complete, and initialization preserves its full-entry result aliases.

Runtime production delta: +11 lines. Benchmark delta: +74 lines. The requested non-test/non-doc diff totals +87 lines, including the two-line test allocation record. The small production increase is required to carry and retain the admission token; it replaces repeated full-entry transport. Independent review is reserved for the maintainer handoff.

Evidence

Synthetic owner workload on baseline b237d3e5c35329ba6524e773434e5ccbe86ff4ec: 100 simultaneously retained session readers, interleaved SessionManager appends with ~8.5 KB assistant/tool text, Responses-format assistant history and tool results, and ~263 KB entry metadata. Two measured rounds after one warmup round (200 appends per arm). The unchanged pool recorded 486 byte-budget evictions and 0 count-budget evictions in both arms across fixture setup, warmup, and measured rounds, with 13–14 resident entries. This reproduces residual pressure after #199615; its commit is an ancestor of the supplied evidence build.

Metric Base Candidate
Mean committed receipt bytes 276,492 13,597
Main sampled allocation / delivered receipt (3,000 each) 348,023 B 20,685 B
Main CPU / delivered receipt, untraced (5,000 each) 125.82 µs 15.75 µs
Total GC over 5,000 deliveries, untraced 11.706 ms 0.838 ms
GC collections / maximum pause 35 / 0.612 ms 3 / 0.371 ms
Peak accounted replica payload, allocation pass 8,385,644 B 8,385,904 B

The 260-byte pool difference comes from the different synthetic output path lengths; limits and eviction counts are unchanged. Cold receipt field census: skillsSnapshot 242,616 B, systemPromptReport 20,436 B; the remaining entry fields are tiny. Candidate receipts omit the entry and retain a ~253-byte revision reference. Native receipt ranges are 267.6–276.8 KB before and 4.7–13.9 KB after. No reload view or model-prompt projection is transferred.

Allocation and timing were measured separately, in AB then BA order. Untraced host load was 22.68 base / 22.52 candidate; allocation-pass load was 17.50 / 23.05. GC tails have too few collections to serve as percentile gates. All 200 paired model-context hashes match. CPU/allocation numbers cover native receipt delivery on main, not the entire turn or Gateway. The first cold admission still transfers the authoritative entry.

Reproduce using the committed script (base omits --check-compact):

node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-append-receipt-measure.ts \
  --output .local/receipt-candidate --mode allocation --iterations 3000 \
  --sessions 100 --rows 4 --rounds 2 --text-repeats 500 --check-compact
# Repeat separately with --mode timing --iterations 5000.

The script now captures at receipt restoration, which also covers synchronous settlement polling that the former MessagePort event hook missed. Extended existing wire-size regressions fail on main with 278–285 KB receipts against a 16 KiB limit, covering append, tool result, patch, and adoption. Existing tests retain full entry/storage equality, stale-reference rejection, live-policy refusal, lost replies, and incomplete oversized-result transfer.

Local validation: 121 focused tests across six files passed, including all 14 prefix-stability tests, session-manager appends, receipt/replica behavior, native settlement, and rollback. The final five-file run passed 104 tests in 265.5 s including compilation; the separate replica file passed 17 tests. Root script/test typechecks and the matching agents/sessions typecheck passed; changed-file formatting/lint, docs MDX, and git diff --check passed. Exact-head CI passed on 30de6a5876bb2a9fbed906f6f85cae07e39404e7, including PostgreSQL conformance and the PostgreSQL 16 Gateway smoke test. No CI failure or rerun was needed. The four stale-reference wire-size cases fail on the baseline as expected. One intermediate prefix run was invalidated by an edit during compiled test execution; the pinned rerun passed. No Gateway load campaign was run: this is the authorized owner-boundary fast path for removing duplicate transport, with unchanged persistence and authorization semantics. This workload does not execute real provider turns or measure whole-Gateway event-loop/RPC latency.

@clawsweeper

clawsweeper Bot commented Nov 15, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T16:28:50.583534Z 30de6a5 PR opened
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts size: M labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR reuses each command’s authoritative admission entry to compact receipts after replica eviction.

Example: 100 active sessions with approximately 263 KB of entry metadata exceed the replica pool’s byte budget.

  • Before: The supplied benchmark reports mean committed receipts of 276,492 bytes.
  • After: Mean committed receipts fall to 13,597 bytes while all 200 paired model-context hashes match.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused owner-boundary measurements and regression coverage support a correct, useful patch; performance confidence remains scoped to the synthetic workload and receipt delivery.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal transport optimization supplies focused SessionManager/native-worker measurements under synthetic eviction pressure; the evidence supports smaller receipt delivery costs, with whole-Gateway and real-provider performance explicitly unmeasured.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Busy session workloads repeatedly copy large unchanged session metadata after replica eviction.
Reason: The maintainer-authored direction removes measured duplicate work through existing owners while preserving session contents, persistence, authorization, and memory limits.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR addresses a verified residual source of duplicate receipt traffic with a focused change; no actionable correctness or security findings remain, and exact-head CI is pending.

Priority: P2
Reviewed head: 30de6a5876bb2a9fbed906f6f85cae07e39404e7

Before merge

None.

Findings

None.

Agent review details

How this fits together

The SQLite session actor receives session commands, obtains host authorization, commits mutations, and returns receipts that the host restores and publishes to observers and replicas.

flowchart LR
 A[Session command] --> B[Host executor]
 B --> C[SQLite actor worker]
 C --> D[Transaction admission]
 D --> E[Command retained preimage]
 C --> F[Committed delta receipt]
 E --> G[Host receipt restoration]
 F --> G
 G --> H[Observers and replica]
Loading

Technical review

Best possible solution:

Retain the first authoritative admission entry within the existing command lifetime and reuse the existing receipt delta encoder without expanding replica residency.

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

Current main drops receipt compression when the command lacks a matching replica reference, even though its transaction admission transfers the authoritative entry; the supplied benchmark reproduces this path, but no target code was executed during this review.

Is this the best way to solve the issue?

The patch is the smallest complete repair: it carries an already-prepared fact through its existing owner and lifetime, preserves initialization aliases and changed-entry authority facts, and introduces no persistent cache or competing restoration path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

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

PR surface

Source +11, Tests +53, Docs +4, Other +76. Total +144 across 10 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 19 8 +11
Tests 4 61 8 +53
Docs 1 9 5 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 2 187 111 +76
Total 10 276 132 +144

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +19/-8, net +11; tests and support +61/-8, net +53 The production growth carries the admission token through the existing lifetime; test growth extends wire-size and settlement regressions rather than adding another production owner.
Benchmark option One new benchmark-only flag: --sessions, default 2 Allows the committed measurement to reproduce entry-only pool pressure with 100 retained readers; runtime configuration and replica limits are unchanged.

Labels

Label changes:

  • add P2: Removes substantial duplicate transport and allocation under busy session workloads without evidence of an urgent user-facing outage.
  • 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: Removes substantial duplicate transport and allocation under busy session workloads without evidence of an urgent user-facing outage.
  • 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 execution lanes are retired.

Reviewed November 15, 2026, 11:41 AM ET / 16:41 UTC.

@steipete
steipete merged commit 059f958 into main Nov 15, 2026
145 of 147 checks passed
@steipete
steipete deleted the steipete/perf-append-receipt-residual-20261115 branch November 15, 2026 17:02
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
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: M 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