Repository navigation
improve(sessions): reduce database work for transcript batch appends - #174817
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 settles transcript recency and projection watermarks once per batch instead of writing them for every event. Example: Append messages one and two, then reject duplicate attempts with timestamps 25 and 40.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored optimization contains useful work absent from current main, and review found no actionable correctness or security defects. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe session transcript storage owner receives events from imports and session mutations, writes canonical events and identities, and maintains active-history and search projections within the caller's transaction. flowchart TD
A[Imports and session mutations] --> B[Transcript batch owner]
B --> C[Event and identity writes]
B --> D[Transaction local cursor]
D --> E[Projection and recency settlement]
C --> F[Caller transaction commit or rollback]
E --> F
Technical reviewBest possible solution: Retain the existing transaction owner and merge the focused batch-settlement optimization when its required CI completes successfully. Do we have a high-confidence way to reproduce the issue? Current-main source directly shows repeated recency and watermark writes inside a synchronous batch; no target code was executed during this read-only review. Is this the best way to solve the issue? The change removes redundant writes at their existing owner, updates every internal appender caller, and preserves standalone settlement without adding another state authority. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8d9c36de833a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +63, Tests +162, Docs +8. Total +233 across 7 files. Added test files: 1. 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 Reviewed October 16, 2026, 7:47 PM ET / 23:47 UTC. |
|
Final post-merge measurement: all three alternating shared-v3 pairs passed. Three alternating shared-v3 pairs completed in order M1,C1,M2,C2,M3,C3 on base
Warm non-regression holds for both causal and raw-window medians. Every arm has causal mean 67.1 SQL / 22.1 requests / 0 MAIN. The standard single-event turn does not exercise the bulk-append savings: its transcript-index/state/store totals remain 100/50/90 SQL per ten warm turns. Raw-window tails include background lease/plugin-index work. Thirteen MAIN lease checks move between first-turn and early warm windows; they appear on both sides and are not turn-caused. The whole-workload MAIN median 206→207 is one extra Shared-family attribution also shows no warm increase: row-facts direct reads are 2 SQL/1 request per turn, with 3 SQL/1 request when counting each full associated request. Captured warm exact-entry, actor hydration, entry-cache snapshot and watermark families are zero on both sides. These are observed-frame counts, not claims that the logical operations never occur. Whole-run row-fact captures vary 132 [131–135]→135 [133–135] statements while associated request medians stay 58; the warm family remains identical. Families overlap and are not summed.
SQLite microbenchmarks use one instrumented run per side and verify persisted event, recency and index state. Offline owner calls do not measure Gateway requests or PostgreSQL network round trips. Every micro fixture was removed. Wall observations below are diagnostic only: the host was busy (load roughly 46–90), so there is no latency/speedup claim.
The 36k-event shape is 300 short sessions ×20 plus one long session receiving 60 successive ×500-event batches. It saves 71,280 append statements (24.6%). Per-operation counts:
Measured head: |
Reduce transcript batch append writes by settling session recency and projection watermarks once per batch. Preserve identity deduplication, rewrite generations, caught partial-iterator settlement, transaction rollback, and actor/non-actor mutation publication. Keep standalone append settlement immediate and retain the existing native SessionManager compatibility contract. No schema or durability change.
What Problem This Solves
Transcript imports and batched appends update session recency and the projection watermark for every event, even though the batch already owns those intermediate facts.
User Impact
Batched transcript writes perform fewer database statements while preserving event bytes, identity deduplication, rewrite generations, recency, and search/index state. There is no schema, configuration, SDK, durability, or transaction-ordering change.
Why This Change Was Made
The append cursor now retains the final attempted recency and flushes it through the existing final mutation write. The index appender retains its watermark and flushes once per batch; standalone appends still settle immediately. Caught iterator failures settle the accepted prefix without advancing the batch mutation fence; escaping failures retain transaction rollback. Rejected identities still affect recency without advancing that fence. Replacement batches also settle their accepted prefix on error.
Removed work and accepted edges:
The two final mutation SQL shapes remain necessary for actor/non-actor publication. Generation ensure already performs no SQL when the actor owns the generation; the offline path retains its ensure because it has no retained generation. Identity lookup remains: immediate payload foreign keys and cold-history/idempotency behavior require separate parity proof before an insert-first redesign.
The touched kernels retain 20 static T1 call sites (state 13, store 1, index 6), unchanged in the exact base/head census. Their released synchronous native SessionManager contract lasts through December 31, 2026, and cannot be removed by moving shared helpers or relabeling them as worker-only. This uses the task's compatibility/owner-redesign escape hatch. Gateway MAIN is measured separately below.
Evidence
Measurements
Three alternating shared-v3 pairs completed in order M1,C1,M2,C2,M3,C3 on base
ece4639ff9306103c9773e6fff1c53b79bdb19ffand candidatee56b2cf677e152f359e2a110479fce4d97a32209. Node 24.22.0 / SQLite 3.54.0; compile cache disabled. Every arm passed workload, source/runtime identity, cleanup, calibration, and causal coverage checks. Independent raw recounts matched the shared analyzer; zero failed native SQL calls. Headline brackets span the three per-arm medians; pooled brackets span all 30 turns per side.Warm non-regression holds for both causal and raw-window medians. Every arm has causal mean 67.1 SQL / 22.1 requests / 0 MAIN. The standard single-event turn does not exercise the bulk-append savings: its transcript-index/state/store totals remain 100/50/90 SQL per ten warm turns.
appendToIndex→appendEventis a function rename, not a −40/+40 SQL change. All captured owner-operation counts are unchanged in the standard workload after combining that rename.Raw-window tails include background lease/plugin-index work. Thirteen MAIN lease checks move between first-turn and early warm windows; they appear on both sides and are not turn-caused. The whole-workload MAIN median 206→207 is one extra
PRAGMA busy_timeoutduring initial boot in C2/C3 (openNativeStateDatabase→setSqliteBusyTimeout, startup preflight). Normalizing the timeout value, all other whole-run MAIN SQL shapes have identical counts across all six arms. The affected boot/state files are unchanged. This is not a warm MAIN increase or a transcript-owned statement. Whole raw SQL/request changes include background phase redistribution; no whole-workload savings claim is made.Shared-family attribution also shows no warm increase: row-facts direct reads are 2 SQL/1 request per turn, with 3 SQL/1 request when counting each full associated request. Captured warm exact-entry, actor hydration, entry-cache snapshot and watermark families are zero on both sides. These are observed-frame counts, not claims that the logical operations never occur. Whole-run row-fact captures vary 132 [131–135]→135 [133–135] statements while associated request medians stay 58; the warm family remains identical. Families overlap and are not summed.
SQLite microbenchmarks use one instrumented run per side and verify persisted event, recency and index state. Offline owner calls do not measure Gateway requests or PostgreSQL network round trips. Every micro fixture was removed. Wall observations below are diagnostic only: the host was busy (load roughly 46–90), so there is no latency/speedup claim.
The 36k-event shape is 300 short sessions ×20 plus one long session receiving 60 successive ×500-event batches. It saves 71,280 append statements (24.6%). Per-operation counts:
Production diff: +141/−78 (net +63), plus tests/docs. The growth provides one explicit batch-settlement lifecycle and preserves the existing partial-iterator contract; no cache, handshake, or new state owner is introduced.