Repository navigation
fix: reduce Gateway stalls when opening session details - #149858
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. Reviewed September 16, 2026, 4:32 AM ET / 08:32 UTC (Revision 3). ClawSweeper reviewWhat this changesSession detail requests reuse the existing background registry reader, with regression coverage for session replacement and visibility changes during the read. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix absent from current main. No actionable correctness finding remains, and the maintainer’s explicit acceptance resolves the previous review’s worker-cost decision blocker. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway combines stored session metadata with subagent activity to answer session detail requests. Moving cold registry reads to the shared worker leaves more Gateway main-thread capacity for other requests. flowchart TD
A[Session detail request] --> B[Read model metadata]
B --> C[Shared registry cache]
C -->|Cold cache| D[Background database reader]
D --> E[Check current session and visibility]
C -->|Warm cache| E
E --> F[Build session detail response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +10, Tests +107. Total +117 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing registry worker and cache for session descriptions while preserving current visibility checks and unchanged response semantics. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that a cold session-description request on current main reaches synchronous registry loading; the supplied comparison reports the corresponding main-thread CPU cost. This review did not execute that path. Is this the best way to solve the issue? Yes. Reusing the existing asynchronous registry owner avoids a competing cache and preserves post-await session authorization; the disclosed worker-cost tradeoff has been explicitly accepted. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5e27c4e4302e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
2815990 to
9e9d820
Compare
|
Maintainer assessment for The fresh comparison on the row-materialization base shows cold main-thread CPU falling from 22.9–24.9 ms to 4.8–7.7 ms, with the disclosed increase in cold wall time, first-handler startup time and peak process RSS. All 72 focused integration tests pass, all 564 complete benchmark replies match, and independent source review and benchmark audit pass. This is sufficient evidence for this narrow main-thread offload once required exact-head CI passes. Installed-Gateway latency, steady retained memory and direct event-loop delay remain unmeasured; deployment verification is a follow-up, and this PR makes no production latency or total-CPU improvement claim. |
|
Merged via squash.
|
Related: #149466
What Problem This Solves
Opening session details after the subagent registry cache expires parses retained run metadata on the Gateway event loop, delaying unrelated work.
User Impact
Session detail reads leave more main-thread CPU available while preserving the same session, child, swarm, and visibility results. No configuration or migration is required. Cold requests incur worker handoff overhead; the shared worker also has startup and memory costs when it has not already been started.
Why This Change Was Made
Use the existing asynchronous full-registry cache owner already used by
sessions.list, then resolve the current session and permissions after the metadata reads finish. This keeps one cache and lifecycle owner and preserves the full registry projection; it does not change SQL, schemas, cache expiry, or database repair behavior.Evidence
The registered-handler regressions fail on the original implementation because it completes without dispatching the cold read to a worker. They pass after the change and verify replacement and draft visibility while that read is pending, canonical child links, and retained deleted-collector totals.
After incorporating the row-materialization refactor in #149771, all 72 focused Gateway, row-materialization and registry lifecycle tests pass. Fresh formatting and independent P0–P2 review pass. Exact-head CI passes for rebased commit
9e9d820ed629. The original head also passed the full selectedcheck:changedgate, including production and core-test types, typed lint, and database/import guards.A fresh synthetic Node 24.20.0 comparison on base
d0f4dc76b10fused four A/B/B/A processes, 1,564 retained runs including 162 private-parent runs, current-source compiled workers, and 560 measured requests plus four separate first-request observations. Every complete response matched, with independent child/swarm/private-field assertions. Source and compiled inputs remained unchanged and all processes settled naturally. Ranges below are per-call means for each round, not a pooled estimate:The tradeoff is explicit: cold request wall time increased from 23.0–25.0 ms to 27.1–32.0 ms, and whole-process CPU round means were 31.6–48.3 ms before and 31.9–64.1 ms after. Separate first-request observations were 338–339 ms before and 671–686 ms after; peak process RSS was 1,019–1,042 MiB before and 1,214–1,229 MiB after. Those observations include the source-handler fixture and worker startup and are not installed-Gateway memory or latency measurements. The existing worker is reused for the same database and maintenance scope; startup is not paid on each describe or cache miss. This demonstrates moving CPU off the event loop, not reducing total CPU or proving production latency.
The maintainer risk assessment accepts this bounded worker tradeoff and records the remaining deployment-verification gap.