Repository navigation
perf(agents): reuse retained event routing snapshots - #184085
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 refreshes the existing retained routing snapshot for the same run owner instead of allocating a replacement on every event. Example: The reported benchmark emits 20,000 events across eight runs to 64 subscribers.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this focused, maintainer-directed optimization removes a verified per-event allocation without an identified production regression; required CI remains red with unresolved attribution. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe agent-event owner combines registered run metadata with execution-scoped retained facts, then emits sequenced events to runtime subscribers, including after live context cleanup. flowchart LR
A[Run registration] --> B[Live run context]
B --> C[Retained routing snapshot]
D[Agent stream events] --> E[Event admission and enrichment]
B --> E
C --> E
E --> F[Runtime subscribers]
Technical reviewBest possible solution: Reuse the existing routing snapshot only for the exact same registration while preserving all field refreshes and replacement-owner isolation. Do we have a high-confidence way to reproduce the issue? Current-main source allocates the 13-field snapshot on every accepted event with a live context; the PR supplies a rerunnable owner benchmark, which this read-only review did not execute. Is this the best way to solve the issue? The production change is the smallest complete optimization: it reuses the existing owner and retained storage without adding a cache, alternate dispatcher, or invalidation mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c04f19f3befd. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource 0, Tests +11, Other +124. Total +135 across 3 files. Added test files: 0. View PR surface stats
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 25, 2026, 10:22 PM ET / October 26, 2026, 02:22 UTC. |
|
Baseline attribution for the remaining CI red: the private-child recovery case in The PR body records commands and CI run 40257428681. The routing regression, focused owner tests, typecheck, lint, export and closure guards pass; independent and automated reviews have no findings, and security/dependency reviews pass. Proceeding under the maintainer's standing inherited-failure landing instruction, without rerunning CI or claiming the failed gate is green. |
What Problem This Solves
Streaming agent events allocate a fresh 13-field routing snapshot on every delta, even while the run owner is unchanged.
User Impact
A small allocation reduction during streamed replies, with identical events, progress, cancellation routing, and ownership checks. No configuration or migration changes.
Why This Change Was Made
Reuse the existing retained routing object for the same exact run owner, refreshing all its fields as before. A replacement owner still gets a fresh snapshot. This removes one temporary object per event without adding a cache, invalidation mechanism, or alternate dispatch path. The retained snapshot remains necessary for late settlement after the live context is cleared. Production LOC delta: 0 (15 added / 15 removed).
Progress capture already keeps unchanged retained event objects by identity. Its existing trusted-freeze change (#183914) is present in the evidence build, so remaining progress serialization cost is residual; this PR does not claim to eliminate it or change its wire-size and mutation-isolation contract.
Evidence
Acceptance declared before measurement: identical emitted public frames and ownership/cancellation behavior, one fewer routing allocation per streamed event, and a consistent small allocation or CPU win. Benchmark: eight interleaved synthetic runs, 64 subscribers, 98% assistant deltas and 2% tool start/results; 2,000 warmup events then 20,000 measured events. Five counterbalanced base/candidate pairs against
29ed214d9e2b21895a3b3000a6344046cc59acc6. CPU and sampled allocation use separate processes/passes.CPU pairs (base → candidate, µs/event): 3.4457→3.6063, 3.5411→3.4708, 3.4500→3.5144, 3.4635→3.6352, 3.6193→3.6338. Host load was 56.7–61.3. The baseline had a 159.48 ms wall-time outlier; it is retained in the data, and the lower mean wall time is not claimed as a speedup. All 20 runs produced the same public-event hash and 1,280,000 measured subscriber deliveries.
Run:
The identity regression fails on base because the routing snapshot is replaced. Candidate: 50/50 focused tests pass in
agent-events.test.tsandagent-run-registry.changes.test.ts(7.33 s wrapper wall time; Vitest 4.93 s). Existing tests cover compaction across nested scopes, cancellation, generation handoff, hidden routing, reused run IDs, and stale-owner rejection.This is an owner microbenchmark, not a whole-Gateway load test. Under the scoped fast-path instruction for allocation deletion, no ten-minute stress campaign was run: no scheduling, admission, delivery, or progress semantics change. Whole-Gateway CPU, GC s/min, loop/list p99, and server handler latency remain unmeasured. No production Gateway was loaded and no remote test lease was allocated. PR CI owns broad proof.
Review: independent subagent review (autoreview route unavailable), clean through P2. The helper refused the configured provider route; no operator configuration was changed. Formatting, targeted core/script lint, and the export-name collision guard pass. Author simplification pass retained only same-owner snapshot reuse, its regression, and the rerunnable owner benchmark.
Required closure checks:
eager-import-closure.test.tsandpr-wrapper-source-closure.test.ts, 22/22 passed (50.07 s wrapper wall time). No test files or production exports were added.Targeted infra TypeScript check passed:
node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.infra.json --incremental. Before push, rebased onto7e15500187cd1430cf954ad43e2fd4fb89ac1dd2; relevant event/registry source and tests were unchanged from the measured base, so the patch and proof inputs are unchanged.CI and inherited failure
Exact-head CI run 40257428681 passed 54 jobs and failed only
checks-node-changed-compact-small-20plus its aggregate gate. The failing case isserver.subagent-settle-replay.harness.test.ts→recovers public work once through a sibling and reconciles its private child final:server.subagent-settle-replay-recovery.test-support.ts:459expectsok/completedbut receiveserror/cancelled.Ran the complete failing file, once per revision, through
node scripts/run-vitest.mjs src/gateway/server.subagent-settle-replay.harness.test.ts --maxWorkers=1:2470a2102321aedacaccbfbcb76ce89f0490412e7e15500187cd1430cf954ad43e2fd4fb89ac1dd2CI tested merge
e5a368beagainst mainebbb03b14935796e54e4a6410b90fb7b26f4fa2f; the intervening main changes do not touch the recovery implementation, test, or event-routing owner. This is a reproducible inherited failure, not a passing-retry classification. No CI rerun was requested. The separate dependency-review and security-sensitive-review statuses passed; automated code review completed on the exact head with no findings. Landing uses the standing authorization for attributed inherited failures; CI is not described as green.