Repository navigation
perf(agents): share stable stream observers - #184797
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 consolidates Responses and model-diagnostic stream observation into one shared iterator and extends the performance probe. Example: Observing 240 Responses events containing text, reasoning, and tool-call updates.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored PR open: the shared observer has a measured allocation benefit, and source review found no actionable correctness or security defect. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherProvider streams enter the observation layer, which records transport and model-call diagnostics before forwarding events to existing stream consumers. flowchart TD
A[Responses transport] --> C[Shared iterator observer]
B[Model diagnostic adapter] --> C
C --> D[Diagnostic callbacks]
C --> E[Stream consumers]
B --> F[Bounded cleanup and shared result]
Technical reviewBest possible solution: Retain the shared iterator with caller-owned cleanup policies and complete the existing merge gates before the requesting maintainer chooses to land it. Do we have a high-confidence way to reproduce the issue? The base Responses observer visibly forwards through an async generator, and the committed probe exercises that production owner; the PR reports before/after promise counts, but no target code was executed during this review. Is this the best way to solve the issue? The consolidation removes the competing diagnostics queue, preserves caller-specific policies, and supports the measured Responses benefit without adding a fallback or cache. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 99f7a303e3ff. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +123, Tests +509, Docs +99, Other +421. Total +1152 across 11 files. Added test files: 3. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (1 earlier review cycle)
Reviewed October 26, 2026, 1:38 PM ET / 17:38 UTC (Revision 2). |
19db3bb to
b1431d9
Compare
|
Consolidated both observers into one shared @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
b1431d9 to
0af1741
Compare
* perf(agents): reduce Responses stream observation allocations * perf(agents): share stable stream observation lifecycle * test(agents): check recorded stream fixture entries
What Problem This Solves
Responses transport diagnostics add a forwarding generator to every raw event. This change uses one shared stable-continuation observer in
llm-coreand ports both Responses observation and the model-call diagnostic iterator introduced in #184369 onto it. The remaining-layer inventory extends #184742 with real installers and promise accounting.The helper owns FIFO
next()/return()/throw()scheduling, active-context resumption, source versus observer errors, and exactly-once finalization. Callers retain their policies: Responses logs lazily and closes like its generator; model diagnostics retain bounded cleanup, shared return promises, final-result ownership, and their existing unopened-return behavior. The two private FIFO implementations are removed. No package dependency edge or user configuration is added.Runtime delta against main is +123 lines, not a net deletion: shared helper +191, existing diagnostics owner −74, Responses owner +5, export +1. This is 27 fewer runtime lines than the original proposal while also migrating the second owner. The remaining growth preserves the explicitly requested FIFO/context/error contracts and diagnostic eager-return exception. Tests compare the helper with the language generator and test the diagnostic caller against unchanged main.
Evidence
Five-pair owner measurements
Acceptance: preserve delivered bytes and lifecycle contracts; retain one added promise per ordinary event; report both owners independently and all five counterbalanced pairs. These are local owner measurements, not whole-Gateway claims. The explicit fast-path exception applies; no Team access, Testbox lease, or ten-minute Gateway stress campaign was used.
Both comparisons use 5 alternating AB/BA pairs, 60,000 delivered events per arm/pass (3,000 events ×20 turns), plus 15,000 warmup events. CPU uses an uninstrumented pass; allocation uses a separate 512-byte sampling pass. No subscriber sinks; model diagnostics uses real lifecycle/context and 1,000 history entries/40 tools. Baseline owner files are byte-identical between rebased main eaaa6f1 and captured main 2cb5b0c.
The Responses allocation win remains clear. Diagnostics already had a stable continuation, so this is a consolidation: its apparent +41.30 B/event allocation and +30.13 ns/event CPU costs are reported rather than claimed as another optimization. No A/A-based adverse classification or whole-Gateway inference is made from these small owner deltas. Timing and allocation passes are separate; traced CPU is not used for the timing comparison.
Added promises/event: Responses 4 → 1; diagnostics 1 → 1. Total source/consumer-inclusive slopes are 6 → 3 and 3 → 3, respectively (32 versus 240 events).
Byte-identical 240-event replay SHA-256, base and candidate:
31f1b4c7c61d8dba562b7659241ff192682841e311747ecaadae6fb419f31a99.7c738c9fe4e7ca90f1e7a98aa34db303cb83cc4642e8a117f7ecbd8dae39f802.Rerun either
responses-observerormodel-diagnostics:node --expose-gc --import ./scripts/tsx.mjs scripts/perf/agent-stream-update-measure.ts --layer responses-observer --mode timing --events 3000 --turns 20 --warmup 5 # Repeat with --mode allocation, alternating AB/BA for five pairs. node --import ./scripts/tsx.mjs scripts/perf/agent-stream-update-measure.ts --layer responses-observer --mode promises --events 240 --turns 1 --warmup 1 node --import ./scripts/tsx.mjs scripts/perf/agent-stream-update-measure.ts --layer responses-observer --mode verify --events 240 --turns 1 --warmup 1Proof and review
Exact-head PR CI supplies broad validation. Leave this PR unmerged for the requesting maintainer.