Repository navigation
perf(sessions): reuse reply initialization snapshots - #170171
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 changes before merge. What this changesThis PR reuses lifecycle-planning snapshots during reply initialization and adds bounded session-command timing labels. Example: An operator measures worker requests while chatting in agent:main:main.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this maintainer-authored PR open: the focused optimization remains absent from main, and no definite introduced defect was found; remaining CI failures need attribution. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherReply initialization prepares an admitted turn’s session state; lifecycle workers select bounded rows, and the existing commit owner validates and persists the prepared entry. flowchart TD
A[Admitted chat input] --> B[Reply initialization]
B --> C[Lifecycle planning worker]
C --> D[Selected session rows]
D --> E[Revision check and metadata merge]
E --> F[Guarded session commit]
C --> G[Bounded worker diagnostics]
Technical reviewBest possible solution: Reuse the existing lifecycle planner’s bounded rows while preserving preparation effects, revision checks, metadata merging, and commit authority. Do we have a high-confidence way to reproduce the issue? Current-main source demonstrates the preliminary selected-row read followed by lifecycle planning; the claimed final-candidate latency improvement is not yet measured. Is this the best way to solve the issue? Snapshot reuse fits the existing owner, and the caller retains genuine parent-fork preparation while the transaction preserves authoritative validation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 21f043cf86f5. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +86, Tests +44, Docs +4. Total +134 across 11 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 HistoryReviewed October 12, 2026, 4:47 PM ET / 20:47 UTC (Revision 3). |
|
Entry-write lane coordination: I am measuring repeated |
Reuse the lifecycle planner’s bounded current, related, and stored-parent rows for ordinary reply initialization. Keep preparation snapshots for parent effects and creation authority, durable input acknowledgment, and the existing metadata merge/retry path. Expose finite session-command labels through existing worker request diagnostics. Measured saving: five SQL statements and one worker request per warmed turn; no consistent end-to-end latency improvement. The three native/incognito T1 sites remain owner-cutover follow-up work.
Problem and change
Ordinary reply initialization reads a session snapshot immediately before the lifecycle planner reads the same bounded rows. This PR removes that preliminary worker request and duplicate revision comparison, reusing the planner's current, related, and stored-parent rows for the existing revision check and metadata merge. It also removes the ordinary turn's no-op preparation callback.
Worker diagnostics now expose a finite allowlist of session command names, using the existing broker timing path. Private or unknown command suffixes remain grouped; no SQL, message content, identifiers, or payload bytes are recorded.
Durable input ACK, writer FIFO, live authority at effects, and concurrent metadata preservation retain their existing owners. Parent-fork preparation and creation binding retain their earlier snapshot because they perform effects before lifecycle planning. No configuration, schema, retention, SDK, or update migration changes.
Removed check and accepted edge case: an ordinary reply's preliminary revision check is removed; a changed session is discovered at lifecycle planning and follows the existing retry path. Same-session metadata is merged from that current row.
The pending-input early authority read stays. Removing it changed the real Gateway membership test's session-replacement denial from
INVALID_REQUESTtoUNAVAILABLE; the final source restores the original input-admission path. This is the retained live-authority boundary, not a claimed optimization.Measurement
Base
8f7bac24b5fe6de7a511c6b372669cdf6324cc4d; candidatee37e3c449a4311fcfea6922e71dd69407c91e42f. Exact-source builds on one quiet AWS c7a.2xlarge host, shared perfbase collectors, order M,C,M,C,M,C, 10 warmed turns per fixture (30 per source), all six full fixtures/restarts passed. Pre/post host idle was 99.6–100%. Identical detailed observation on both sources; one-second post-workload idle, no long-idle claim. The shared harness itself was not edited.No measured latency win: the −80 ms p50 target was missed. The repeatable owner saving is five SQL statements and one worker request per warmed turn; the removed fresh-read span averaged 1.91 ms. Reported percentiles below pool individual turns, not per-run percentiles.
Event-loop rows describe distributions of per-turn histograms, not a merged histogram. Mean foreground spans: durable admission 34.420→34.472 ms; reply initialization 30.448→29.061 ms; session-state initialization 18.563→16.885 ms. These spans overlap and must not be summed.
Per-pair warmed p50 was 390.47→392.76, 401.79→406.17, and 405.75→413.28 ms. Both sources drifted upward over the sequence. The one permitted extra diagnostic pair reversed the order to C,M: baseline→candidate p50 419.90→406.75 ms (−13.15), p95 536.17→531.57 ms (−4.60), first delta p50 275.84→269.75 ms (−6.09). Both full fixtures/restarts passed; pre/post host idle was 99.75–100%. Each had one inherited shutdown-only failed
BEGIN IMMEDIATE. The sign reversal supports time/order sensitivity; it does not establish a consistent latency benefit. This extra pair is kept separate from the primary three-pair result.One separate supporting harness-v2 M,C pair (10 warmed turns/source), with causal and legacy-window totals kept separate:
The removed read is
BEGIN+ three boundedSELECTs +COMMIT: exactly −5 statements / −1 request per ordinary turn. Causal means are 215→209.5 statements and 50.2→49.1 requests; the extra −0.5/−0.1 is helper timing, not claimed owner savings. Warm-window background SQL is 935.82→947.27 statements/minute because window duration differs; the shared read-family counts below do not increase. The latency fixtures independently report raw SQL 227 [220–233]→222 [215–228] and requests 56.5 [54–58]→56 [53–57].Shared causal reads per turn: exact-entry facts 5→5; actor hydration 4→4; entry-cache snapshots 0→0; row facts 0→0; watermark 1→1. Their warmed background counts are also unchanged: row facts 3 statements / 1 request per turn, watermark 2 / 2, other three families 0 / 0. No saving is obtained by moving SQL to another thread.
Session command breakdown
The original base grouped these commands as
sqlite_writer:sessions. Named baseline below is the earlier diagnostics-only commit3c545616(10 turns), compared with final candidate (30 turns); these are unpaired diagnostic samples, not the primary latency comparison. Service time is observed worker duration, not additive critical-path latency. All command counts are unchanged and no candidate command errors occurred.session.entry.patch.commitsession.actor.acceptInputsession.actor.appendTranscriptEventsession.actor.readsession.actor.deliverySettledsession.entry.patch.preparesession.actor.completeTurnsession.lifecycle.projectsession.entry.readsession.actor.adoptRunThe primary base's aggregate session writer service was 138.71 ms/turn versus candidate 140.52 ms/turn. This PR does not consolidate those writer commands. The five patch commits and two input admissions remain the larger batching opportunity.
T1 and validation
Touched initialization-owner T1 remains 3→3: the native reply snapshot callback plus lifecycle generation-read/state-delete primitives. They serve process-held incognito storage or maintenance; removing them requires a separate acquisition/owner cutover. This is retained debt under the owner-redesign escape hatch, not a zero-T1 claim. Global ratchet: T1 471→471, compatibility 9→9. Warmed MAIN stays zero.
Final CI tested merge
af1fa7cb(candidatee37e3c44onto main24dec4d6). All production/test type shards, type-aware lint, source contracts, architecture/Madge (zero cycles), T1/dialect ratchets, security, docs, and build passed. All eight tests in the three changed files passed: reply-init selection four cases (4.641 s summed test execution), lifecycle bounded-read case (0.114 s), diagnostics three cases (0.037 s); these durations exclude shard setup. Coverage includes concurrent metadata preservation, replaced stored-parent selection, bounded related reads, and private diagnostic suffixes.Focused final-source
pnpm test <file> --maxWorkers=1on the same remote host: membership-authority product suite passed in 80.73 s (base 74.73 s); ACP completion passed in 72.31 s (base 72.51 s). Final qaRuntime build passed in 94.84 s. Local changed-file formatting/basic lint andgit diff --checkpassed.Knip was not selected by the PR CI plan, so it ran separately. Its 34 production findings exactly match saved main CI and its 22 full-tree findings exactly match the original-base remote scan (100.45 s); all are unrelated UI exports. The prior-head candidate scan is reused because the final input-authority restoration changes no imports, exports, entrypoints, or configuration. This is zero candidate-only findings, not a clean full-tree Knip claim.
Both permitted Codex autoreview rounds returned no actionable P0–P2 finding. The second reviewed the optimization against the pinned base; the final correction restored input-admission production/test files to baseline bytes, so no third routine review was run. No SDK diff or published-driver update cell applies. LOC: +201/−67 across 11 files.
CI exception
The completed run is red: 54 successful jobs, 29 failed jobs (including the aggregate gate), 24 skipped. Landing uses the explicitly authorized relaxed CI exception, not a green-CI claim. All static families and changed tests pass. Of 326 failure reports (duplicates included), 199 match saved main errors; 112 have original-base or unchanged-source attribution, including the profile-catalog pre-dispatch failures introduced by main
930bb545; five exercise unchanged direct admission/abort/read/media-cleanup paths whose underlying causes remain unresolved. Four timeout reports across three Workshop/chat-read tests also remain unresolved and are not labeled proven inherited. The other six reports belong to the three late tests compared below.Late-job focused comparisons use
pnpm test <file> --maxWorkers=1, selecting onlynative=true, thread=root, rejectStop=truefor the Slack file. Both sources reproduce the Slack progress-finalization timeout (base 118.15 s, candidate 126.92 s) and heartbeat captured-creating-reference error (45.05 / 45.60 s). The transcript CLI setup also fails identically withRuntime config is not prepared(26.18 / 26.41 s). Thus all three late failures reproduce on the original baseline and final candidate. These are controlled failure reproductions, not passing reruns.Saved-main evidence includes run 38292584060 and run 38298274614; the last job's 14 media-retention and two fallback-accounting failures all match these. Unresolved failures, exact job links, and source-attribution limits are handed to the red-main owner. No new product regression remains established; the known input-authority regression was fixed before these final checks. The remaining writer-batching and T1 work is recorded as follow-up.