Skip to content

fix(ai): prevent truncated Anthropic streamed replies - #140820

Merged
steipete merged 1 commit into
mainfrom
codex/qa2-12-anthropic-seeded-blocks-20260907
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa2-12-anthropic-seeded-blocks-20260907

Conversation

@steipete

@steipete steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor
Additional instructions

Keep Allow edits from maintainers enabled so maintainers can help update the branch.

What Problem This Solves

Fixes an issue where developers consuming Anthropic streams through the standalone adapter received truncated or empty replies when the response included text or thinking in its initial stream events. A response starting with Hello and continuing with world returned only world.

Why This Change Was Made

Both Anthropic adapters now preserve initial content through their shared stream reducer. They also share the completed-signature accumulation path: an initial signature survives when no replacement arrives, and streamed signature data replaces that initial value. Production code shrinks by four lines.

User Impact

Standalone Anthropic consumers retain the complete streamed reply and thinking content, matching the managed adapter and native SDK. The usual empty-start sequence continues to work.

Evidence

The two seeded regression cases failed before production changes; the empty-start control passed. After repair, both adapters matched the pinned Anthropic SDK 0.120.0 across three event sequences and nine real local HTTP requests. All 278 related tests passed, followed by a final 18-test parity run. The full package test typecheck, full-file lint, formatting, max-lines ratchet, and independent P2 review passed. Regression tests add 70 lines, and the corrected snapshot adds 10 net lines.

The HTTP proof uses synthetic local SSE responses. Current first-party frequency of nonempty block starts was not measured: request parameters cannot force whether Anthropic places content in a start event or a later delta, so a live smoke would not reliably exercise this case. The regression compares the actual native SDK parser and both adapters against seeded, seed-only, and empty-start sequences.

Preserve text, thinking, and signatures supplied in Anthropic block-start events through the canonical stream reducer. Reuse the completed-signature path so streamed signatures replace initial seeds. SDK-oracle regressions and local HTTP proof cover seeded, seed-only, and empty-start sequences.
@clawsweeper

clawsweeper Bot commented Sep 7, 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 size: S maintainer Maintainer-authored PR labels Sep 7, 2026
@steipete
steipete marked this pull request as ready for review September 7, 2026 05:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 7, 2026, 1:06 AM ET / 05:06 UTC.

ClawSweeper review

What this changes

Preserves initial Anthropic text, thinking, and completed signatures in standalone streamed replies, with SDK comparison tests covering seeded and empty starts.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main still discards seeded content for standalone Anthropic consumers. No actionable introduced defect was found, and the maintainer-protected PR should remain open for normal landing.

Priority: P2
Reviewed head: 843ea40892f2f4b6f22275c49734a8b450fb5cea

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful SDK-oracle regressions and no blocking findings; reported execution was not independently rerun.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its body reports both production adapters matching SDK results over local HTTP for three synthetic SSE scenarios; the committed tests use injected responses, and raw HTTP traces were not supplied.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its body reports both production adapters matching SDK results over local HTTP for three synthetic SSE scenarios; the committed tests use injected responses, and raw HTTP traces were not supplied.
Evidence reviewed 8 items Current main still needs the repair: The fetched main reducer still conditions initial text, thinking, and signatures on the managed transport profile. The standalone caller explicitly selects the provider profile, so seeded text is discarded before subsequent deltas are appended.
Canonical repair and signature lifecycle: The complete reducer preserves initial content, emits it through existing delta events, accumulates replacement signatures privately, and commits them at content_block_stop. Existing tool, refusal, cancellation, and terminal handling remain intact.
Behavioral regression coverage: The added table checks seeded starts with deltas, seed-only blocks, and empty starts against the actual Anthropic SDK parser and both production adapters. Assertions cover completed content and end events; existing transport tests additionally cover split and interrupted signatures. Tests were inspected, not executed.
Findings None None.
Security None None.

How this fits together

OpenClaw’s AI package converts Anthropic streaming responses into assistant events and completed messages. Its shared reducer serves both standalone consumers and OpenClaw’s managed transport.

flowchart TD
 A[Anthropic response events] --> B[Standalone adapter]
 A --> C[Managed transport]
 B --> D[Shared stream reducer]
 C --> D
 D --> E[Preserve initial content and append deltas]
 E --> F[Publish completed signatures]
 F --> G[Assistant events and final reply]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +80. Total +76 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 8 -4
Tests 2 84 4 +80
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 88 12 +76

Review metrics

None.

Technical review

Best possible solution:

Keep initial-content handling in the shared reducer so both adapters preserve complete replies and publish replacement signatures only when their blocks finish.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: send a text block starting with Hello followed by a world delta through the standalone adapter; current main drops the initial text. This review did not execute the scenario.

Is this the best way to solve the issue?

Yes. Removing the profile restriction repairs the shared owner, and reusing its completed-signature path avoids a second implementation while retaining existing interrupted-stream safeguards.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fd5c985d50a3.

Labels

Label changes:

  • add P2: Repairs source-proven reply truncation for standalone Anthropic consumers without evidence of a widespread urgent production regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its body reports both production adapters matching SDK results over local HTTP for three synthetic SSE scenarios; the committed tests use injected responses, and raw HTTP traces were not supplied.

Label justifications:

  • P2: Repairs source-proven reply truncation for standalone Anthropic consumers without evidence of a widespread urgent production regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. Its body reports both production adapters matching SDK results over local HTTP for three synthetic SSE scenarios; the committed tests use injected responses, and raw HTTP traces were not supplied.

Evidence

What I checked:

  • Current main still needs the repair: The fetched main reducer still conditions initial text, thinking, and signatures on the managed transport profile. The standalone caller explicitly selects the provider profile, so seeded text is discarded before subsequent deltas are appended. (packages/ai/src/transports/anthropic-stream-reducer.ts:312, fd5c985d50a3)
  • Canonical repair and signature lifecycle: The complete reducer preserves initial content, emits it through existing delta events, accumulates replacement signatures privately, and commits them at content_block_stop. Existing tool, refusal, cancellation, and terminal handling remain intact. (packages/ai/src/transports/anthropic-stream-reducer.ts:309, 843ea40892f2)
  • Behavioral regression coverage: The added table checks seeded starts with deltas, seed-only blocks, and empty starts against the actual Anthropic SDK parser and both production adapters. Assertions cover completed content and end events; existing transport tests additionally cover split and interrupted signatures. Tests were inspected, not executed. (packages/ai/src/provider-transport-parity.test.ts:421, 843ea40892f2)
  • Independent SDK contract corroboration: The inspected upstream MessageStream implementation copies content_block_start content, appends text and thinking deltas, and replaces the signature for signature_delta. This corroborates the tested single-signature scenarios. The exact 0.120.0 source could not be retrieved; this is upstream-main corroboration, not pinned-version verification. Source: Anthropic MessageStream. (src/lib/MessageStream.ts)
  • Dependency and implementation boundary: The test directly imports @anthropic-ai/sdk and the package pins version 0.120.0, establishing the relevant dependency contract. Both production adapters call OpenClaw’s own reducer; no changed behavior depends on the Codex harness. (packages/ai/src/provider-transport-parity.test.ts:2, 843ea40892f2)
  • Reported validation and proof scope: The fully supplied PR body reports before-fix failures for both seeded cases, an unchanged passing empty-start control, nine local HTTP requests across the SDK and adapters, and passing related tests and checks. It explicitly identifies synthetic SSE responses and does not claim measured first-party occurrence. These are contributor-reported observations; no raw HTTP trace was supplied. (843ea40892f2)

Likely related people:

  • Peter Steinberger: Raw commit 2dfd3c3 adds packages/ai/src/transports/anthropic-stream-reducer.ts:315 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2dfd3c3daba9; files: packages/ai/src/transports/anthropic-stream-reducer.ts)

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 f02c729 into main Sep 7, 2026
181 checks passed
@steipete
steipete deleted the codex/qa2-12-anthropic-seeded-blocks-20260907 branch September 7, 2026 05:38
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
Preserve text, thinking, and signatures supplied in Anthropic block-start events through the canonical stream reducer. Reuse the completed-signature path so streamed signatures replace initial seeds. SDK-oracle regressions and local HTTP proof cover seeded, seed-only, and empty-start sequences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. 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