Skip to content

perf(sessions): preserve compact append receipts under transcript pressure - #199615

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

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

Conversation

@steipete

@steipete steipete commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Long concurrent session contexts evict the actor entry reference along with cached transcript bodies, making small appends resend roughly 264 KB of session metadata in their committed receipts.

User Impact

Reduces worker-to-main receipt traffic and allocation during session appends under transcript-cache pressure. Transcript contents, anchors, parents, idempotency, model context, persistence, schema, and live authority checks are unchanged.

Why This Change Was Made

The existing replica owner now releases reloadable transcript bodies before discarding the entry reference, when that satisfies its existing shared byte budget. The 8 MiB / 128-entry limits, single-oversized-cell allowance, revision checks, and invalidation stay intact. No new cache or wire contract is introduced.

Runtime production delta: +16 lines. The growth is the separate release/accounting step required to preserve compact receipts without increasing the budget or removing load-bearing full eviction. The unchanged size estimator moves into the existing replica bookkeeping module to keep the owner below its file-size limit. Benchmark code is separate; regression test growth is +3 lines with an exact allocation record.

This addresses a reproduced residual after #193326, which is already an ancestor of the reported production evidence build. It does not claim that all production receipt traffic has this cause. Individually oversized contexts still follow full eviction: a larger supplementary probe improved receipt bytes only 30% (2,675,840 → 1,869,232 bytes), with all 12 model-context hashes unchanged.

Evidence

Acceptance declared in the benchmark header: identical model-context bytes, smaller receipts and main-thread CPU/allocation, no material timing/GC regression. Baseline owner is from 81ca4f4d712a67c012c7dc0311e0fa37ac576490; all other source/dependencies are held constant. Two actual SessionManagers use 512-entry bounded histories with user messages, tool calls/results, and assistant replies. Each history independently fits the replica budget; their combined retained contexts exceed it. One warmup round precedes six measured rounds (12 appends), followed by 2,000 native receipt deliveries from a separate worker per arm. Timing and allocation use separate counterbalanced passes, two runs per side.

Owner metric Before After
Mean request bytes / append 5,898.5 6,038
Mean receipt bytes / append 141,039.8 9,124.5 (−93.5%)
Main-thread CPU / delivered receipt 20.58 µs 12.15 µs (−40.9%)
Sampled allocation / delivered receipt 147,488 B 15,644 B (−89.4%)
Minor GC / 2,000 deliveries 2.010 ms, 7 collections 0.295 ms, 1 collection
Instrumented append mean, 24 samples / side 5.177 ms 5.430 ms

The append timing includes census capture and is context only: paired changes are +0.671 / −0.165 ms, mean +0.253 ms. There are too few append samples for tail claims. Timing-pair max GC pauses are 0.446→0.297 ms and 0.518→0.292 ms; no major collections. Host one-minute load was 8.64→10.03 and 8.84→9.78. Post-replay RSS was 1,511.6/1,508.4 MB before versus 1,409.2/1,463.3 MB after; heap was 179.45/179.46 versus 147.68/148.26 MB. These include fixture/module residency, not a steady-state Gateway footprint. The first timing pair was excluded and replaced because a harness cleanup edit occurred during its baseline.

Field census: six of twelve baseline receipts contain a 264,150-byte postimage.entry; the candidate contains none. Reload and model-prompt-projection fields are absent throughout. Appended-event bodies and authority facts remain in the receipt. The extra ~140 request bytes are retained-entry references. Admission snapshots are not included in this native-receipt metric. All 96 model-context hashes across accepted timing/allocation arms match by append position. The dominant sampled allocation bucket is (V8 API): 295.35 MB → 29.09 MB over 2,000 native deliveries in the first allocation pair.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/session-append-receipt-measure.ts --output <new-directory> --mode timing --rounds 6 --iterations 2000; save the baseline replica owner with git show <base>:src/config/sessions/session-actor-replica.ts and pass --owner-file <saved-file>. Repeat with --mode allocation. Candidate --check-compact passes; the same check fails on base at the 64 KiB receipt bound.

Proof: the extended existing replica regression fails on base because eviction loses the entry reference, then passes with the fix. Four focused files pass (80 tests): session-actor-replica, session-actor-receipt, session-manager-model-context-snapshot, and agent-tools.prefix-stability. The focused command took 95.67 seconds including compilation; the changed replica/receipt files together took 5.1 seconds of test execution. Both closure guards pass (24 tests), export collision guard passes, changed-file lint/format and git diff --check pass, matching session test typecheck and all tsgo:test:root leaves pass.

Scope/gaps: actual SessionManager/native-worker owner proof, not full model turns or a whole-Gateway load test. No Team access, Testbox lease, or production load. Independent review and merging are delegated to the maintainer's review workflow; this PR is ready for that review. Exact-head CI run 43718307846 passed on c5e8441115ed9f5c0fc59f169e571f6bd94b5082, including PostgreSQL conformance; all required openclaw/ci-gate checks are successful. No CI retries were used.

@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-15T13:20:36.521156Z c5e8441 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

The replica releases cached transcript bodies before evicting entry references needed to keep append receipts compact.

Example: Two sessions with 512-entry histories exceed the shared transcript replica budget.

  • Before: The supplied benchmark reports mean append receipts of 141,039.8 bytes, including repeated 264,150-byte entry payloads.
  • After: Mean receipts fall to 9,124.5 bytes, with matching model-context hashes.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch appears correct; supplied production-owner measurements support the receipt improvement, with confidence limited to the measured workload.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal optimization supplies actual SessionManager/native-worker owner measurements and matching context hashes; it makes no whole-Gateway latency claim and requires no separate shipped-entry-point proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Long concurrent conversations cause small appends to retransmit large unchanged session metadata and allocate unnecessary main-thread objects.
Reason: The maintainer-authored direction targets measured waste with a small change to the existing owner and explicitly preserves the bounded-cache tradeoff.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR provides a useful transcript-pressure optimization absent from fetched main, with no actionable correctness or security finding identified.

Priority: P2
Reviewed head: c5e8441115ed9f5c0fc59f169e571f6bd94b5082

Before merge

None.

Findings

None.

Agent review details

How this fits together

SessionManager appends run through the database worker, whose committed receipts update the main-thread actor replica; retained entry references let the existing receipt compressor omit unchanged metadata.

flowchart LR
  A[SessionManager] --> B[Main actor replica]
  B --> C[Database worker]
  C --> D[Committed receipt]
  D --> B
  B --> E[Entry reference]
  B --> F[Reloadable transcript bodies]
Loading

Technical review

Best possible solution:

Keep the staged release inside the existing replica owner, preserving full eviction, canonical transcript fallback, and exact-revision receipt compression.

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

Base source discards entry references with transcript bodies under byte pressure, forcing full metadata receipts; the supplied benchmark and regression report the corresponding base failure, but no target code was executed during this review.

Is this the best way to solve the issue?

This is a focused owner-level fix: it reuses existing transcript charges and receipt references without adding a cache, changing the wire format, or weakening invalidation.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Replica eviction changes intended behavior with a stated reason (d5173cc: Bound retained actor payloads; the later fix(sessions): keep reads working above 128 active sessions #175046 preserves resident-payload counting and the oversized-cell allowance.)
  • Transcript residency charges keeps the original intent (4821920: Record each transcript's existing charge to avoid traversing replaced contents again; the new release step consumes and resets that same charge.)
  • Heap estimation and memoization keeps the original intent (0a9f690: Preserve the structural heap estimate and bounded immutable-row memoization while avoiding reducer allocations; relocation leaves its arithmetic unchanged.)
  • Bounded transcript facts documentation keeps the original intent (0aadd89: Reuse bounded transcript facts without restoring full-history indexes to compact receipts; the documentation retains the shared budget and revision lifecycle.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Bounded eviction remains intact: The introduced branch subtracts the recorded transcript charge while retaining entry or snapshot facts; full eviction still handles count pressure and insufficient byte recovery, and the single-oversized-cell condition remains unchanged. (src/config/sessions/session-actor-replica.ts:384, c5e8441115ed)
  • Transcript misses retain canonical fallback: A missing retained context returns undefined, after which the hydration owner reads the canonical transcript through its existing worker; missing bounded anchor facts likewise remain unknown. (src/config/sessions/session-transcript-hydration.ts:284, c5e8441115ed)
  • Focused regression and owner measurements: The existing budget regression now checks that transcript eviction preserves the command entry preimage. The complete PR body reports base-failing/head-passing coverage and actual SessionManager/native-worker measurements, while explicitly excluding whole-Gateway performance claims. (src/config/sessions/session-actor-replica.test.ts:316, c5e8441115ed)
  • Distinct follow-up to existing compact receipts: perf(sessions): retain unchanged transcript windows and compact entry receipts #193326 already supplies full entry-only preimages to the receipt compressor; this PR addresses losing those facts under transcript byte pressure. Fetched main retains full-cell eviction without the new release step. (src/config/sessions/session-actor-replica.ts:420, 52fd3d802952)
  • Reviewed head and current gates: The PR remains open, non-draft and mergeable at the reviewed head. Aggregate CI is pending on PostgreSQL conformance; dependency and security-sensitive review statuses pass, with no observed failing required check. (c5e8441115ed)
  • Policy, history and checkout limits: Root, docs and scripts AGENTS.md files were read and applied; no maintainer-notes directory exists. Feature history identifies the actor, accounting and receipt contributors. Some older blobs were unavailable during follow/stat reads, but relevant scoped history and blame succeeded; the checkout remained clean. (AGENTS.md, c5e8441115ed)

Likely related people:

  • Peter Steinberger: Raw commit a494b7f adds src/config/sessions/session-actor-replica.ts:383 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a494b7f1e39b; files: src/config/sessions/session-actor-replica.ts)
  • Josh Avant: Raw commit 4821920 adds src/config/sessions/session-actor-replica.test.ts:185 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4821920804c9; files: src/config/sessions/session-actor-replica.test.ts)

PR surface

Source +16, Tests +3, Docs +3, Other +367. Total +389 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 53 37 +16
Tests 1 5 2 +3
Docs 1 4 1 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 2 367 0 +367
Total 6 429 40 +389

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 LOC Production +16 net; tests +3 net The production growth implements separate transcript release and accounting; the unchanged estimator moves between existing modules, and regression coverage extends the existing budget test.

Labels

Label changes:

  • add P2: Measured receipt traffic and allocation improve under concurrent transcript pressure, without evidence of an urgent functional 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: Measured receipt traffic and allocation improve under concurrent transcript pressure, without evidence of an urgent functional 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, 8:37 AM ET / 13:37 UTC.

@steipete
steipete merged commit ceac637 into main Nov 15, 2026
151 of 153 checks passed
@steipete
steipete deleted the steipete/perf-append-receipt-payload-20261115 branch November 15, 2026 13:51
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