Repository navigation
perf(sessions): reduce database reads during session creation - #183156
Conversation
Use complete owner-published entry facts for unlabeled canonical creation and include participants in the existing row-metadata aggregate. Keep cold, labeled, alias-sensitive, source-custody, and replacement-conflict paths. The synthetic second-session flow attributes six redundant SQL statements and one worker request to these reads. Add regressions for known absence, post-write visibility, and participant snapshot consistency.
|
🦞👀 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 reuses retained session-creation facts and includes participant identities in the existing row-metadata query. Example: Create agent:main:target after discovery has retained its complete entry or confirmed absence.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it is a useful, maintainer-directed optimization, and source review found no concrete introduced correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe session accessor prepares creation context from worker-owned database facts, invokes the creation callback, and commits through the existing replacement and publication owners. flowchart TD
A[Session creation request] --> B[Session accessor]
B --> C[Retained actor facts]
B --> D[History worker fallback]
C --> E[Creation callback]
D --> E
E --> F[Replacement and commit guards]
F --> G[Database and published facts]
Technical reviewBest possible solution: Reuse complete facts through the existing creation owner and participant query while preserving the established fallback and commit checks. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the unconditional creation-snapshot request and separate participant acquisition; the PR reports matching base-failing work-count regressions, but this read-only review ran no target code. Is this the best way to solve the issue? The patch follows the smallest complete approach: consume the existing receipt-maintained facts and aggregate owner rather than introduce another cache, worker, or state representation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ec74daef033b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +26, Tests +76. Total +102 across 4 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 Reviewed October 24, 2026, 10:47 PM ET / October 25, 2026, 02:47 UTC. |
…w#183156) Reuse complete owner-published entry facts for unlabeled canonical creation and include participants in the existing row-metadata query. Keep cold, alias and labeled fallback, physical source custody, replacement CAS and final authority. Four regression cases fail on the unchanged base; all 36 touched tests pass. No schema or transaction change.
What Problem This Solves
Creating a second session and its native child repeats a full creation read immediately after target discovery. The row-metadata reader also fetches participants separately despite already having an aggregate-capable entry query. The standard synthetic workload attributes six statements and one worker request per spawn to those two classes.
User Impact
Session creation and initial transcript reads perform less database work with the same stored result, permissions, and restart behavior. No user action is required.
Why This Change Was Made
Reuse the existing owner-published full entry facts for eligible unlabeled canonical creation, including known absence. Preserve separate existing/target entries, opaque alias resolution, labeled/cold fallback, physical source custody, replacement CAS, and final authority. Include participants in the existing aggregate when reading row transcript metadata. The
jsonOrderedArraycall and ordering are unchanged. No schema, new cache, generation, or cross-store transaction changes.Acceptance rule (registered before candidate A/B)
Flow: real isolated Gateway, loopback transport and mock provider, frozen v3.1.5 standard synthetic workload including native child, compaction, shutdown and restart. All data is synthetic.
Three alternating same-platform baseline/candidate pairs on base
b406c2b9c1aa310f933c66c3ff0867750af80c54and this head. Count statements, worker requests and MAIN operations; report phase 04.second-session per-owner and execution/causal medians [min–max], plus cold and warm phases separately. Removed owner classes must strictly decrease; other touched-owner work must hold or improve. Runtime MAIN must not increase. Any adverse metric move of 20% stops for attribution. Profile all Gateway threads. No local latency claim on a loaded host; timing comparisons require the campaign timing lock, load <24, and at least five samples per arm with median/p95/spread.Registered expected owner reduction: creation −3 SQL/−1 request; row-facts −3 SQL/0 requests; total −6 SQL/−1 request/0 MAIN per phase04.
Evidence
git diff --checkpasses.The production diff adds 26 net lines to consume existing facts while keeping the required cold/labeled path. Tests add 76 net lines for the two distinct removed read classes. This is a SQL/request reduction, not a net-negative-code claim. Registry recovery, Team leases and spawn admission are unchanged. Historical
subagents.runsJSON scans did not reproduce in three attribution runs and are excluded; pending-input and payload-owner work belong to separate lanes.Shared open-PR index overlap check: #183114 at
c82c9413df6177cae1e4d2ed10f853ded83730f1is clean against both base and candidate; #177242 retains the same 17 inherited conflict messages and unchanged conflict hunks; #146847 retains the same 25 inherited conflict messages and unchanged conflict hunks. This patch adds zero conflicts. Compared committed headd7492aebd58against all three indexed heads withgit merge-tree.Post-merge measurement disposition
The retained pair confirms the intended owner reduction. Creation/exact-entry requests fell from 26 to 23 SQL and 10 to 9 worker requests; row-facts requests fell from 12 to 9 SQL with 3 requests in both arms. That is six fewer statements and one fewer request in these read classes.
Other work offsets the target reduction: the full second-session phase measured 498→496 SQL with 119 requests in both arms. Entry-patch work increased by three statements and one request; activity-summary work increased by one statement. The whole workload measured 2976→2975 SQL, 796→797 requests and 94→94 total MAIN operations; runtime MAIN remained zero. These are single-pair observations, not median/p95 estimates.
The ≥20% stop cells remain disclosed. Idle-settle requests measured 14→17 (+21.4%). Restart-first-turn measured 146→180 SQL (+23.3%) and 49→61 requests (+24.5%); its turn-owned portion was identical at 127 SQL/38 requests with the exact same SQL-shape multiset. Startup and maintenance work moved from connect/boot into that window. The entire restart measured 532→535 SQL with 191 requests in both arms. Additional plugin-state reads, passive checkpoints and idle request residuals remain unresolved; the broader performance claim is unproven.
Gateway-thread profiles were captured, but helper-process profiles are incomplete (five missing on baseline, one on candidate). No CPU or latency comparison is claimed. Two of six planned arms completed; the other four were explicitly closed without running after the sustained load wait. The landed owner-read improvement and its regression proof stand; this is not a claim that every whole-workload metric improved.