Skip to content

fix(agents): keep streamed chunks consistent with diagnostics - #150682

Merged
steipete merged 1 commit into
mainfrom
codex/team-model-stream-value-once-20260917
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/team-model-stream-value-once-20260917

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

When a provider implements IteratorResult.value as 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.value separately 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.

Arm Wall ms Process CPU ms Main-thread CPU ms RSS before/after MiB
1 baseline 31.675 50.576 31.323 312.453 / 331.125
2 candidate 118.223 49.397 28.229 312.453 / 330.688
3 candidate 28.043 45.885 27.822 311.062 / 329.453
4 baseline 35.549 76.489 34.906 323.312 / 332.922

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.

@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 06:33
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 2:41 AM ET / 06:41 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: c6e06afd7d8604f6f506907a454637c05ea77900

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with a meaningful regression and bounded runtime evidence; no actionable defect was found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.
Evidence reviewed 6 items Introduced change and regression coverage: The complete pinned introduction delta changes only the diagnostic wrapper and its test. The wrapper captures value after checking done; the regression supplies different successive getter values and checks delivered content, one getter invocation, and diagnostic byte accounting. The complete affected production module and test were read.
Current main still contains the defect: The inspected fetched-main implementation passes next.value to observation and separately yields next.value. A getter returning different values therefore produces inconsistent observation and delivery; the proposed fix remains necessary on this revision.
Production entrypoint and plugin boundary: attempt-stream.ts installs this wrapper around session.agent.streamFn. The observation owner measures the captured chunk, while plugin-instance-value-views.ts retains getter admission and wraps returned callable values. This patch changes neither that authority owner nor plugin API contracts and supplies no affirmative dependency on the separate Codex implementation.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +1, Tests +78. Total +79 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 2 +1
Tests 1 79 1 +78
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 82 3 +79

Review metrics

Metric Value Why it matters
Getter reads Reported 2,000 → 1,000 per 1,000 chunks The controlled comparison supports eliminating duplicate accessor work without establishing broader latency or memory improvements.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs a concrete stream-consistency edge case with a narrow implementation and no demonstrated urgent outage.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.

Label justifications:

  • P2: This repairs a concrete stream-consistency edge case with a narrow implementation and no demonstrated urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the real diagnostic wrapper consuming an active registry-owned plugin stream on macOS: getter reads halved while output, diagnostic accounting, and cleanup matched. This supports the changed accessor behavior; the separate test and Testbox claims are supplemental.

Evidence

What I checked:

  • Introduced change and regression coverage: The complete pinned introduction delta changes only the diagnostic wrapper and its test. The wrapper captures value after checking done; the regression supplies different successive getter values and checks delivered content, one getter invocation, and diagnostic byte accounting. The complete affected production module and test were read. (src/agents/embedded-agent-runner/run/attempt.model-diagnostic-events.ts:111, c6e06afd7d86)
  • Current main still contains the defect: The inspected fetched-main implementation passes next.value to observation and separately yields next.value. A getter returning different values therefore produces inconsistent observation and delivery; the proposed fix remains necessary on this revision. (src/agents/embedded-agent-runner/run/attempt.model-diagnostic-events.ts:111, a3bea6a8e386)
  • Production entrypoint and plugin boundary: attempt-stream.ts installs this wrapper around session.agent.streamFn. The observation owner measures the captured chunk, while plugin-instance-value-views.ts retains getter admission and wraps returned callable values. This patch changes neither that authority owner nor plugin API contracts and supplies no affirmative dependency on the separate Codex implementation. (src/agents/embedded-agent-runner/run/attempt-stream.ts:401, c6e06afd7d86)
  • Reported production-path comparison: The fully supplied PR body, captured under sourceRevision 4a1e1aa4930b6df508f61f21b777ca2b2214d3df1e1279120dd87aea8664ed13, reports a macOS baseline/candidate/candidate/baseline comparison using the real wrapper and an active registry-owned plugin stream. Each 1,000-chunk request required 2,000 getter reads before and 1,000 afterward, with matching output and normalized diagnostics, byte accounting, request/result counts, and cleanup. The body explicitly retains adverse timing observations and limits its performance claim. (c6e06afd7d86)
  • Validation distinction: The body reports 44 focused tests passing and a successful command in Blacksmith Testbox. GitHub identifies the linked workflow run as cancelled, so its overall status is not independent confirmation of those command results. No tests were executed during this read-only review.
  • Area history and inspection limits: Current-main file history identifies recent work by SunnyShu and repeated related work by Peter Steinberger. Exact line-introduction attribution could not be established because deeper blame required unavailable objects. The latest-release source object was also unavailable, so no shipped-fix claim is made. The canonical PR search endpoint was denied; no replacement relationship was established. (src/agents/embedded-agent-runner/run/attempt.model-diagnostic-events.ts, a3bea6a8e386)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • SunnyShu: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 67ecde7 into main Sep 17, 2026
281 checks passed
@steipete
steipete deleted the codex/team-model-stream-value-once-20260917 branch September 17, 2026 07:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant