Repository navigation
perf(sessions): reduce fresh-session input custody work - #185601
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 SummaryThis 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 stages durable session input using current entry receipts instead of fetching a complete actor snapshot. Example: A fresh session receives “Keep this input in durable custody” after its entry has been published.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR removes redundant input-staging work, fixes the prior benchmark-contract finding, and introduces no actionable correctness defect found in this review. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe session actor sits between input recorders and database workers, turning captured input and lifecycle expectations into durable custody receipts. flowchart LR
A[Input recorder] --> B[Pending input store]
B --> C[Session actor]
C --> D[Entry replica]
C --> E[Writer admission]
E --> F[Database worker]
F --> G[Custody receipt]
Technical reviewBest possible solution: Reuse the existing entry-receipt owner while preserving canonical fallback reads, lifecycle rejection, and final commit authority. Do we have a high-confidence way to reproduce the issue? Current-main source shows the unnecessary full read, and the supplied body reports a base-failing, candidate-passing recorder regression; this read-only review ran no target code. Is this the best way to solve the issue? The change is appropriately narrow: it exposes existing entry facts through the actor fence instead of adding a cache or weakening the worker's lifecycle checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c4d5fddda138. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +13, Tests +53, Docs +10, Other +276. Total +352 across 12 files. Added test files: 0. View PR surface stats
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 HistoryReview history (1 earlier review cycle)
Reviewed October 27, 2026, 3:30 AM ET / 07:30 UTC (Revision 2). |
Avoid a full actor read when current physical-row receipts already supply lifecycle facts. Keep actor lifetime, live authority, and unknown-outcome recovery fences while allowing facts published by another SQLite connection. Add custody work-count, generation/recovery coverage, and a real-owner CPU/allocation measurement script.
8a2b043 to
6f54af4
Compare
|
Fixed the missing The body now records final matched owner measurements, raw memory/worker-lifecycle limits, exact measurement revisions, and the baseline Gateway setup gap. Final CI is running on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
) * perf(sessions): reuse entry receipts for input custody Avoid a full actor read when current physical-row receipts already supply lifecycle facts. Keep actor lifetime, live authority, and unknown-outcome recovery fences while allowing facts published by another SQLite connection. Add custody work-count, generation/recovery coverage, and a real-owner CPU/allocation measurement script. * fix(perf): implement entry snapshots in actor benchmark
What Problem This Solves
Fresh-session input staging fetches a complete actor snapshot even when the actor owner already holds current entry facts, adding worker work while the database writer FIFO is reserved.
User Impact
Reduces the work needed to put a user's input into durable custody. Ordering, lifecycle rejection, recovery after an uncertain write, and live commit authority remain unchanged. No configuration or migration is required.
Why This Change Was Made
Staging needs entry lifecycle facts rather than the full transcript/pending-input snapshot. It now borrows existing entry facts through the actor's authority and reconciliation fence, with physical-database generation and scoped-receipt validation. Missing or fenced facts still use the canonical reader. The native command still hydrates state and checks lifecycle and live authority before committing; writes are not reordered and no cache is added.
Entry receipts belong to the physical database, while complete snapshots retain worker-connection ownership. Keeping that distinction avoids invalidating a current entry merely because another connection published it. The actor's unknown-outcome fence remains authoritative even when another writer publishes fresh facts.
Runtime code grows by 13 lines to preserve that shared authority/recovery boundary. Non-test/non-doc changes total +289 lines: +13 runtime, +274 standalone measurement script, +1 benchmark executor adaptation, +1 tooling entry. Benchmark usage is in its header; the shared perf README is unchanged.
Evidence
Final owner comparison: base
9b7db694b593cd2b498d704611414a8659fe7ffb, candidate runtime8a2b0439c8f8421a5136e753025e41c80d0f4d98. The same measurement script, dependencies, and build artifacts were held fixed while six changed runtime modules were replaced with their exact base/candidate bytes. Source hashes were recorded and verified after restoration. Each fresh process staged 1,000 durable inputs in batches of 32 fresh sessions with 32 KiB skill snapshots. Setup, initial pending-input reads, acquisition, and release are outside measured windows. CPU/GC use an untraced pass; sampled main-thread allocation uses a separate inspector pass. All 4,000 native custody receipts passed.The 12 timing fallbacks completed normally and retain the canonical read path; their individual invalidation causes were not instrumented. These are operation samples from four processes, not 1,000 independent process trials. Earlier runs also reduced main CPU by approximately 41–42% and sampled allocation by 12%, but used an earlier candidate and are not the final-head proof.
Host one-minute load was 88.7→92.1 on base timing, 86.9→74.6 on candidate timing; allocation arms were 93.7→79.3 and 71.7→68.2. Owner latency is context rather than a whole-Gateway speedup claim: p50 24.22→13.45 ms, p95 101.92→46.30 ms, p99 220.31→126.08 ms (1,000 samples per side). GC kind breakdown, promotion, and worker allocation were not collected. No adverse tail claim or A/A rejection is made.
Memory limits
Memory remains inconclusive; no retained-memory improvement is claimed. Fresh, complete direct-worker samples showed:
The allocation candidate finished with its temporary disk-budget worker still alive (42.7 MB heap); the baseline reached that worker's normal 60-second idle retirement. This explains a lifecycle difference, not the entire RSS delta. Timing arms had matching worker counts and a 23.3 MiB RSS increase. No forced GC, maintenance exclusion, or post-hoc pause trimming was used. The earlier unmatched approximately 250 MB RSS gap was retained as preliminary evidence and prompted these matched controls.
Reproduce with
node --import ./scripts/tsx.mjs scripts/perf/session-input-custody-measure.ts --state-dir <new-directory> --iterations 1000 --mode timing, then--mode allocationwith another new directory, using the same script in both revisions.Validation
Final head
6f54af4542cd1766882be48c28d4f1899e54fca8rebases onto7bb0af632123and includes the existing benchmark executor fix. The only manual conflict was an import relocation in the actor test; main’s memory-owner/storage-acquisition refactor remains intact. Independent review of the complete rebased diff is clean. Measurements retain the explicitly identified pre-rebase source pair above and were not repeated after main’s import refactor.The direct source work-count regression failed on base (
actorReads=1, expected zero) after a successful native custody receipt and passed on candidate. The final source reproduction of the complete recorder path stages durable input with zero actor reads. Committed regressions cover entry-only staging, generation retirement, and unknown-outcome recovery after another writer publishes entry facts.Changed-file formatting/lint, export-name collision guard, and script typechecking passed. Independent subagent review (autoreview route unavailable) has no remaining actionable finding, including the final receipt correction and benchmark executor adaptation. The initial focused local run passed 58 of 59 tests; its failing new recorder regression exposed the connection-UUID mistake corrected before this PR's first CI run. Initial PR CI found one missing
snapshotEntrymethod in an existing synthetic benchmark executor; that consumer is now updated and script typechecking passes. Both required import-closure files passed locally (29 tests). Post-rebase focused attempts with the default Bun runtime and the supported Node runtime produced no test results after worker-cache preparation and were stopped; these are local setup gaps, not passing tests. Final CI run 40467121337 passed on6f54af4542cd1766882be48c28d4f1899e54fca8, including changed-code shards, script/production/test types, lint/architecture checks, builds, and all three PostgreSQL conformance shards. No CI rerun was used to chase green. ClawSweeper re-reviewed the final head and reports no actionable findings.The canonical session-start harness was attempted on the built baseline with 10,800 synthetic sessions, 40 configured plugins, 65 clients, four concurrent mock-provider turns, and APFS worktrees. It timed out during
sessions.createwhile the baseline processed sustained maintenance deletions and slow SQLite commits, before producing turn measurements. This is a baseline setup gap, not a candidate performance result. Two isolated build preparations completed, but the final receipt correction was proven through the real source recorder/native custody path rather than a rebuilt Gateway. No session-start, server-handler, sessions.list, or event-loop improvement is claimed. The lane's explicit fast-path scope uses owner work-count/CPU/allocation proof for this read elimination; the separate multi-pair ten-minute Gateway campaign was not run. No production Gateway was load-tested.