Repository navigation
perf(gateway): reuse prepared facts across control-plane reads - #133477
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 6:51 PM ET / 22:51 UTC. ClawSweeper reviewWhat this changesThe PR reduces repeated Gateway control-plane work by reusing prepared configuration, model, session, and static-file facts, while making all measured control-request budgets enforceable in the concurrency benchmark. Merge readinessNo blocking correctness or security defect was found in the exact-head refactor. This remains open for normal maintainer review because it is maintainer-authored, carries the protected Priority: P2 Review scores
Verification
How this fits togetherGateway control requests read prepared configuration and model data, session state, and Control UI assets before returning chat metadata, session projections, or HTTP responses. This refactor keeps those reads at their existing owners while avoiding redundant discovery on the request path. flowchart LR
A[Gateway control requests] --> B[Prepared configuration and model facts]
D[Session state and UI files] --> C[Gateway request handlers]
B --> C
C --> E[Chat metadata and session projections]
C --> F[Control UI HTTP responses]
E --> G[Control UI clients]
F --> G
Before merge
Agent review detailsSecurityNone. PR surfaceSource -57, Tests +452, Other +3. Total +398 across 31 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep the owner-boundary refactor and land it only after a maintainer reviews the exact head with completed required checks. Do we have a high-confidence way to reproduce the issue? Not applicable as a conventional issue reproduction; the supplied exact-head benchmark and built-Gateway browser run exercise the changed control-plane paths. Is this the best way to solve the issue? Yes. The patch reuses already-prepared facts at the configuration, metadata, session, and static-file owners instead of adding a cache or changing public configuration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ee0d376e0fe9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
d1a5b28 to
b1776b9
Compare
|
@clawsweeper re-review The scope expanded after the prior review. Current head b1776b9 consolidates settings preparation, HTML serving, prepared metadata, previews and lightweight rows; production is net -62 lines. The body now includes final owner/gate proof, before/after browser evidence and all retained latency failures. Three final unprofiled runs and the final browser run passed the unchanged budgets, but the final CPU-profiled history maximum was 2904 ms. No claim that all stalls are resolved; no merge requested. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…law#133477) * fix(gateway): avoid redundant work during concurrent turns * refactor(gateway): reduce repeated control-plane work
What Problem This Solves
Reduces avoidable work that delays Gateway control requests and the Control UI during concurrent turns. This extends #133429; it does not claim that every observed multi-second tail has a single established cause or is now eliminated.
Why This Change Was Made
The control plane shares an event loop with agent startup and session projection. The fix carries prepared facts to their consumers and removes duplicate work at the owning boundaries:
The benchmark now enforces all measured load-control budgets, saves violations in JSON, and exits nonzero after retaining evidence. Setup subscriptions and warmup remain excluded; handshakes retain their separate budget.
User Impact
Less repeated discovery, copying and projection during concurrent use. No new cache, dependency, configuration, schema, wire protocol, persistent-store, locking or credential-resolution policy. No production Gateway was exercised. Production: 181 added / 243 removed, net -62; benchmark tooling: net +3; tests: +588 / -131, net +457.
Evidence
Built and exercised exact head
b1776b9e294b962acec4182138b3441b7c3fa089, rebased on main7acb95c3ae6bf28aeec76c86987fef8f4e78a6f6.node scripts/check-changed.mjspassed: formatting, type checks, changed lint, dead exports, runtime cycles and ownership/storage guards. Runtime and Control UI builds passed.The earlier CI failure in the descriptor test was reproduced and repaired without changing the production close path. An intermediate format gate and a file-length lint failure were also fixed; the final full local gate passed. Exact-head CI completed successfully on b1776b9. A fresh landing Codex P0 review also found no actionable P0 finding. The latest ClawSweeper review had no correctness/security finding; its remaining Rank-up move to finish exact-head CI is satisfied. The remaining profiled history failure above remains an open follow-up, not a claim of complete stall resolution.
Owner regressions were observed failing before repair: static requests performed six workspace identity reads; ready/history reads rendered discarded metadata; preview materialized a whole store; five lightweight rows resolved historical models they never consumed. Selected-model/thinking output and the corresponding security/lifecycle contracts remain asserted. The earlier prepared-config, pinned-read and stale-ACP regressions remain covered.
Final CPU evidence agrees with the owner regressions: discarded public model rendering beneath history/startup fell from 139 samples / 171.2 weighted ms to zero; historical-model resolution beneath ordinary list rows and history/startup also had zero final samples. The remaining eight historical-model samples were all within the intended transcript-usage fallback. Baseline and final runs issued 950 and 1205 history requests respectively. Zero samples alone do not prove zero calls; the regressions independently check invocations. Unequal workloads do not establish an overall speedup percentage.
Within the final shared history/startup handler, synchronous timeline emission accounts for 5.120 seconds of weighted inclusive samples, including 3.363 seconds at native
writeBuffer. These are sampled intervals, not exact syscall durations. The timeline owner still appends each enabled event synchronously. There is no common V8/harness clock anchor, so this cost is not causally assigned to the worst history request.Observed maxima in milliseconds; runs from this refactor pass are retained, including failures. “Pre-refactor” is
8e2b93ee(latest-main rebase plus the earlier patch); “intermediate” is before the final lightweight-row change. Same workload and limits throughout; browser and CPU instrumentation are identified separately.All listed operation-failure counters were zero; a failed latency gate still counts as a failure. The adjacent old/new runs used exact runtime source and the same workload, but the earlier old-source baseline itself moved from about 10 seconds to 43 seconds per turn batch. Variation remains unexplained; it is not attributed to host noise or declared a product defect. Event-loop saturation remains; no memory leak has been established.
Reproduction (fresh HOME/state/config, mock provider and loopback ports; task proof also directs logging to its owned artifacts):
Two test-fixture repairs are included: descriptor closure is observed at the real native close instead of probing a reusable numeric descriptor after an await; the abort/idempotency smoke uses the shared prepared-runtime RPC fixture with its unchanged 2000 ms response budget. The latter failed twice in full-file order and in isolation, then passed in isolation and in the full file. These test repairs are not offered as production stall causes.
Named follow-up: batch diagnostics timeline writes without losing trace completeness. The retained synchronous timeline sink accounts for substantial native I/O in the profile. First correlate emission with an over-budget request using a common clock. A batching design also needs explicit emission visibility, bounded overflow, immediate-exit/graceful-flush contracts and a benchmark artifact boundary after owned shutdown. This PR does not disable the timeline, weaken its evidence, or change those contracts.
Browser proof
Real built Gateway and Control UI, a synthetic streaming provider, fresh HOME/state/config, loopback only. The before run failed the latency gate while still rendering the reply; the final run passed. Screenshots show the reply while the turn is still busy; the final recording continues through completion. This is a responsiveness check, not a visual redesign or a controlled overall speedup claim. Captures were inspected for secrets and unrelated data.
Before this refactor (
8e2b93ee):After (
b1776b9e):Final browser recording:
gateway-refactor-after.webm