Repository navigation
perf(sessions): compact append receipts after replica eviction - #199673
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 changesThis 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.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +11, Tests +53, Docs +4, Other +76. Total +144 across 10 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, 11:41 AM ET / 16:41 UTC. |
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
previousEntryuntil 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.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 --checkpassed. Exact-head CI passed on30de6a5876bb2a9fbed906f6f85cae07e39404e7, 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.