Repository navigation
perf(sessions): preserve compact append receipts under transcript pressure - #199615
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThe 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSessionManager 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +16, Tests +3, Docs +3, Other +367. Total +389 across 6 files. Added test files: 0. View PR surface stats
Preflight sourceSource 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
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 15, 2026, 8:37 AM ET / 13:37 UTC. |
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.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 withgit show <base>:src/config/sessions/session-actor-replica.tsand pass--owner-file <saved-file>. Repeat with--mode allocation. Candidate--check-compactpasses; 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 --checkpass, matching session test typecheck and alltsgo:test:rootleaves 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 requiredopenclaw/ci-gatechecks are successful. No CI retries were used.