Repository navigation
fix(agents): keep streamed chunks consistent with diagnostics - #150682
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 17, 2026, 2:41 AM ET / 06:41 UTC. ClawSweeper reviewWhat this changesThe PR reads each streamed model chunk once so consumers receive the same value that diagnostics measure, with a regression test for getter-backed streams. Merge readiness✅ Ready for maintainer review This remains a useful, focused fix: inspected current main still reads the iterator value twice. No actionable correctness or security finding was identified, and the protected maintainer label precludes cleanup closure. Priority: P2 Review scores
Verification
How this fits togetherThe embedded agent runner wraps provider streams to record model-call diagnostics before forwarding chunks to the agent. This wrapper also coordinates final-result observation and iterator cleanup. flowchart LR
A[Provider stream] --> B[Read next iterator result]
B --> C{Stream complete?}
C -->|No| D[Capture chunk once]
D --> E[Measure diagnostics]
E --> F[Deliver captured chunk]
C -->|Yes| G[Observe final result and cleanup]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +1, Tests +78. Total +79 across 2 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the existing diagnostic and lifecycle owners, using one captured iterator value for both measurement and delivery. Do we have a high-confidence way to reproduce the issue? Yes, from source: a nonterminal iterator result whose value getter changes between reads makes current main measure one chunk and deliver another. The added regression exercises this trigger; it was not executed during this review. Is this the best way to solve the issue? Yes. Capturing the value after the existing completion check repairs the inconsistency directly without introducing another wrapper, configuration option, or lifecycle policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a3bea6a8e386. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
What Problem This Solves
When a provider implements
IteratorResult.valueas a getter, the diagnostic wrapper can measure one chunk and deliver another.User Impact
Consumers receive the same chunk that the diagnostic wrapper measures, with one value read per chunk.
Why This Change Was Made
The diagnostic wrapper read
IteratorResult.valueseparately for observation and delivery. Accessors can return different values, and managed plugin reads also repeat admission and execution-scope work. Capture the value once after the existing completion check and reuse it without changing iterator cleanup or plugin authority checks.Evidence
The new regression failed on the original source because the consumer received the accessor's second value. All 44 focused diagnostic stream, plugin iterable, and invocation-isolation tests pass with the fix, including terminal/error/early-return/final-result coverage. Independent P2 review found no actionable issues.
Selected repository checks passed on Linux x64 / Node 24.19.0 through Blacksmith Testbox: command exit 0 and one-shot lease completed.
A fixed macOS arm64 / Node 26.8.2 baseline/candidate/candidate/baseline control used the real diagnostic wrapper around an active, registry-owned plugin stream. Each process consumed one 1,000-chunk request. Getter reads fell from 2,000 to 1,000; output and normalized diagnostic hashes, request/result counts, byte accounting and cleanup matched. Imports/setup and final serialization/disposal were outside the measured interval.
These are two samples per arm on a busy 16-CPU host; one-minute load was 16.766 before and 51.218 afterward. The adverse candidate wall observation and RSS variation are retained, without assigning their cause. This establishes the exact getter reduction, not stable latency, memory or production-wide savings. An initial baseline attempt stopped because the harness counted the TypeScript loader's local Unix-socket probe as network activity. The corrected control still blocked that exact socket, counted it separately before measurement, and recorded zero other connection attempts. No extra workloads or warmups were added.