Repository navigation
perf(sessions): retain creation receipts for first-turn reads - #169727
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: needs maintainer review before merge. What this changesThis PR seeds missing session replica cells from complete committed receipts so first-turn entry reads can reuse them. Example: Create agent:main:first-reader with sessionId first-reader-session and label created, then read its entry.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR provides a focused optimization absent from current main, and no actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe bounded session replica consumes committed writer receipts and supplies entry facts to session readers, which retain authority checks and worker fallback. flowchart LR
A[Session creation writer] --> B[Committed entry receipt]
B --> C[Bounded session replica]
C --> D[Session entry reader]
D --> E[Worker read on miss]
F[Later storage writes] --> C
Technical reviewBest possible solution: Retain complete receipts through the existing bounded replica while preserving freshness validation, authority checks, writer ordering, and cold-read fallback. Do we have a high-confidence way to reproduce the issue? Current main's subscriber only updates existing cells, so a complete creation receipt cannot seed an absent cell; no target code was executed during this read-only review. Is this the best way to solve the issue? Reusing the established replica addresses the redundant read without adding another cache, SQL operation, public API, or persistence contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 97775a426a35. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +26, Tests -14. Total +12 across 5 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 (3 earlier review cycles)
Reviewed October 12, 2026, 5:14 AM ET / 09:14 UTC (Revision 4). |
…aw#169727) Seed missing bounded session replica entries from complete committed write receipts. Reuse the creation owner's entry facts while preserving existing update invalidation and effect boundaries. Remove cache-dependent test scaffolding and fix optional-entry assertions in the patch receipt test. The live pair reduces the second-session first turn from 446 statements / 128 requests to 382 / 109; directly attributed entry-read work drops by 13 statements and 13 requests across the workload. Validation: exact-head CI 38227187417 passed all tests and static gates; two Codex review assessments passed.
What Problem This Solves
A new session's first entry reads could go back to SQLite even though creation had just published the complete committed entry. The bounded session actor replica only consumed those receipts for cells that already existed.
User Impact
No user-visible behavior or durability change. New-session readers can reuse the creation owner's committed entry immediately. User-input acceptance and assistant-output commits remain separate; there is no schema, SDK, update, or retention change.
Why This Change Was Made
Seed a missing entry cell from the existing full-entry receipt, using its physical identity, incarnation, and writer token. Existing cells keep their current update/invalidation path. The existing 128-entry / 8 MiB bounds and native-write invalidation still apply. No new cache, worker operation, SQL statement, or synchronous database access is added.
Removed check/read: the first entry-cache miss after a complete creation receipt no longer requires a replacement read. Accepted edge case: eviction or an intervening write can still cause a normal cache miss and worker read. No security or user-data effect-boundary check is removed. The cache-dependent synthetic mid-worker-grant revocation branch is deleted: a private flag flip is not owner revocation, and a retained read need not reach that grant. Real recovery-source validation, late-output authority, and SQL-free grants remain covered. The SDK concurrency test no longer requires two projection worker reads; its retained contract is FIFO and one persisted idempotent message.
Evidence
One isolated live baseline/candidate pair uses a private copy of the shared SQL harness. Both creations are separated from their first turns, the ten warmed turns are unchanged, and the unrelated delegation/cron/compaction suffix is omitted. Synthetic local streaming provider only. Baseline:
9b97574500bea3825579d1c57cfc124870b99b8c; candidate:25bf6c6dcf8e870717079ac5ca368940d902d17c.Candidate warmed averages: 320.7 statements / 101.8 requests / 0 MAIN. First-turn excess over the warmed average falls from 121.4 to 61.3 statements (49.5%). The raw warmed median rises three statements while the average falls 3.9. Under ATTRIBUTION OVER RAW this is scheduling noise: the changed owner adds no SQL or requests, and its entry-read family decreases. A supplementary candidate was interrupted by the coordinator transport restart and is excluded from the measurement. Whole scoped workload falls 7970 → 7760 statements and 1538 → 1481 requests.
The baseline warmed averages are 324.6 statements / 103.1 requests / 0.4 MAIN. The first-turn excess is 121.4 statements / 24.9 requests. These raw turn differences include unchanged memory/projection scheduling and are not all attributable to this cache change. In the first paired second-session turn,
session.entry.readfalls from 21 statements / 7 requests to 18 / 4; the new cell also changes when existing row-projection work settles. Across the complete measured workload,session.entry.readfalls from 218 statements / 70 requests to 205 / 57; during the ten warmed turns it falls from 174 / 54 to 166 / 46. These attributed savings, rather than the larger raw turn delta, are the causal claim. Largest families: domain publication +48.9 statements (including initial metadata append +17, memory source replacement +15.7, embedding cache +7.9), entry patch commits +13, activity summaries +11.4, actor transcript appends +8, history page +8, model context +7. Full actor hydration itself contributes less than one excess statement, so this change reuses the existing entry replica rather than introducing new actor initialization machinery.git diff --check: pass. CI attempt 2 at the measured production head passed all static jobs: types, lint, source contracts, architecture/Madge, Knip/boundaries, and T1/dialect/worker ratchets. The 12-test receipt suite passed in 6.88s (8.21s file wrapper). At67c2f06869258, all behavioral shards and build-artifact smoke passed. Changed-file proof: receipt 12/12 in 9.83s (11.79s wrapper), writer claim 4/4 in 27.28s (62.48s wrapper, including preparation), SDK transcript 13/13 in 16.27s (18.62s wrapper).LOC: production +26 / −0; tests +93 / −107 (net −14), including the new receipt regression and removal of cache-dependent test machinery. Total net +12.
Follow-ups: initial metadata append setup in
session-manager-metadata.worker.ts, initial activity summary scans, and coalescing memory source refreshes. These involve other lifecycle owners and are not folded into this bounded receipt fix.Review disposition: the ClawSweeper P2 about a cache-dependent private revocation trigger is addressed by deleting that obsolete synthetic recheck branch under LESS PARANOID, retaining real recovery-source and late-output authority proof. No replacement timing gate is added. Raw-trace publication and another full measurement are not required under relaxed testing v6; the completed isolated live pair is retained as the behavior evidence.
Inherited CI failure confirmed on pinned main
4fcac11846800494f7b25f795d039be1ed505a62:attempt-transcript-lifecycle-prepare.test.ts→uses a stale-version postimage once without replaying a durable append (incognito=false)throwsSession actor version changed before command admission(30.462s). The test injects a superseded actor epoch and expects retry machinery removed by #169651; this PR changes neither that test nor that command path. The focused main diagnostic was stopped after capturing this matching failure, not reported as a completed suite.Integration: merged main
7c4ff5ae0a4c4ddfa8763ff53d8fae416d22f4bfwithout conflicts. The production diff is unchanged. CI had exposed TS2532 in the main-only #169744 test atsession-entry-patch.authority.test.ts: two assertions dereferenced the fixture's optional entry. They now assert the expected initial/committed objects directly, preserving row presence and fixing the type errors. Final integrated-head CI at1df9c15e64eab02e98de6cb24fa74e032a852a7dis green: run 38227187417, including all tests, types, lint, source contracts, architecture/Madge, Knip/boundaries, and database ratchets. No CI exception is needed. The earlier production-type job was canceled by fail-fast, not a diagnosed production error.Final focused proof: receipt 12/12, 8.54s (10.22s wrapper); writer claim 4/4, 24.59s (59.72s wrapper with preparation); SDK transcript 13/13, 20.22s (22.77s wrapper). Owner attribution:
session-actor-replica.ts:ensureReplicaSubscriptionretains the committed postimage;session-entry-read-writable.ts:readSessionEntryInWorkerconsumes it and eliminates the redundantsession.entry.readrequest on a retained hit.