Skip to content

fix(ai): truncated Anthropic streams error; proxies exempt from message_stop contract - #120030

Merged
steipete merged 2 commits into
mainfrom
steipete/anthropic-proxy-message-stop
Aug 7, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/anthropic-proxy-message-stop

Conversation

@steipete

@steipete steipete commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an inverted guard in the Anthropic SSE transport. The "stream ended before message_stop" check only fired when a refusal buffer happened to be non-empty — so a genuinely truncated first-party Anthropic stream (dropped connection mid-response) passed silently as a complete message, while Anthropic-compatible proxy providers that legitimately end their stream without a message_stop event could fail on refusal-ish content. Both directions were wrong: silent truncation on the strict contract, spurious errors on the lenient one.

Why This Change Was Made

The invariant belongs to the transport contract owner. Anthropic's first-party API completes every SSE response with message_stop (per their streaming docs), so direct Anthropic models now always enforce it. Compatible proxies aren't held to that first-party framing contract, so isDirectAnthropicModel gates the check instead of the incidental refusal-buffer state.

User Impact

Truncated Anthropic streams surface as errors instead of silently delivering partial replies; proxy-routed Anthropic-compatible models stop hitting spurious message_stop failures.

Evidence

  • node scripts/run-vitest.mjs packages/ai/src/transports/anthropic-transport-stream.test.ts — passes, with new regression tests: direct model + truncated stream throws (with and without refusal content); proxy model + no message_stop succeeds.
  • Codex autoreview (gpt-5.6-sol, high) over the change bundle: clean, no actionable findings.

@steipete
steipete marked this pull request as ready for review August 6, 2026 19:00
@steipete steipete closed this Aug 6, 2026
@steipete steipete reopened this Aug 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 6, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 6, 2026
@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 7, 2026, 3:36 AM ET / 07:36 UTC.

ClawSweeper review

What this changes

The PR requires terminal message_stop events for direct Anthropic SSE streams and exempts compatible proxy streams, with regression coverage for both outcomes.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: the direct-Anthropic guard is the right owner-boundary fix, but it silently turns an existing proxy-commentary test fixture into an error path while its assertions still pass.

Priority: P1
Reviewed head: e24d1c4042eb6c30dd5bcc2a94330cebd4ae9a1a

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The contract repair is well scoped, but the changed guard invalidates an existing proxy test's success semantics until the fixture is corrected.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-labelled PR has focused test and CI evidence; the external-contributor real-behavior-proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-labelled PR has focused test and CI evidence; the external-contributor real-behavior-proof gate does not apply.
Evidence reviewed 6 items Current-main root cause: The current transport validates a missing terminal event only when a refusal buffer exists, allowing ordinary direct streams outside that model-specific path to finalize incomplete output.
Owner-boundary predicate: Directness already combines the Anthropic provider identity with the default or first-party endpoint classification, so it naturally leaves custom endpoints and proxy providers outside the terminal-event contract.
Test regression introduced by the guard: The existing test labelled as a proxy case uses the default direct Anthropic model and omits message_stop; after the proposed guard it reaches failure handling, but its content-only assertions still pass because failure handling preserves non-buffered output.
Findings 1 actionable finding [P2] Keep the proxy tool-turn test on its successful path
Security None None.

How this fits together

The managed Anthropic transport converts provider SSE events into normalized agent output. It must reject incomplete first-party responses without applying that framing requirement to compatible proxy endpoints.

flowchart LR
A[Agent model request] --> B[Managed Anthropic transport]
B --> C[Provider SSE events]
C --> D{Direct Anthropic endpoint?}
D -->|Yes| E[Require message stop]
D -->|No| F[Accept proxy framing]
E --> G[Normalized result or error]
F --> G
Loading

Before merge

  • Keep the proxy tool-turn test on its successful path (P2) - This new guard makes the existing proxy-labelled tool-turn fixture fail because it still uses the default direct Anthropic model and omits message_stop. Its content assertions continue to pass because failure handling retains non-buffered output, so the test no longer proves proxy commentary behavior; use a proxy model identity/custom endpoint and assert a non-error terminal result.

Findings

  • [P2] Keep the proxy tool-turn test on its successful path — packages/ai/src/transports/anthropic-transport-stream.ts:1691-1693
Agent review details

Security

None.

PR surface

Source +2, Tests +83. Total +85 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 1 85 2 +83
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 88 3 +85

Review metrics

Metric Value Why it matters
Production versus test LOC production +2 net; tests +83 net The small production increase is justified by a first-party transport-contract boundary, while the test growth should preserve both direct and proxy outcomes.

Technical review

Best possible solution:

Keep the direct-service terminal-event guard, but make the proxy tool-turn test use an actual proxy identity and assert a successful terminal result before exact-head re-review.

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

Yes—source establishes that the existing proxy-labelled fixture becomes an error after this guard while its assertions remain green because failure handling retains its output.

Is this the best way to solve the issue?

No—the guard is the best fix for the stream contract, but the PR must also preserve the existing proxy tool-turn test as a successful proxy case rather than silently changing its outcome.

Full review comments:

  • [P2] Keep the proxy tool-turn test on its successful path — packages/ai/src/transports/anthropic-transport-stream.ts:1691-1693
    This new guard makes the existing proxy-labelled tool-turn fixture fail because it still uses the default direct Anthropic model and omits message_stop. Its content assertions continue to pass because failure handling retains non-buffered output, so the test no longer proves proxy commentary behavior; use a proxy model identity/custom endpoint and assert a non-error terminal result.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against ea4466e5dce5.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-labelled PR has focused test and CI evidence; the external-contributor real-behavior-proof gate does not apply.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The change addresses silent delivery of truncated direct-provider responses on an agent's normal model stream.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-labelled PR has focused test and CI evidence; the external-contributor real-behavior-proof gate does not apply.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs packages/ai/src/transports/anthropic-transport-stream.test.ts.

What I checked:

Likely related people:

  • steipete: Current-line blame attributes both the terminal-event condition and the affected proxy-commentary fixture to this authored transport introduction; the same person authored the proposed repair. (role: current transport and test author; confidence: high; commits: 48ea08918e3f, e24d1c4042eb; files: packages/ai/src/transports/anthropic-transport-stream.ts, packages/ai/src/transports/anthropic-transport-stream.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Model the existing tool-turn fixture as a proxy and assert its successful result.
  • Request one exact-head ClawSweeper re-review after the focused test repair.

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-06T23:32:54.324Z sha a578ca6 :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Aug 7, 2026
The Anthropic SSE transport threw 'stream ended before message_stop' only when
a refusal buffer happened to be non-empty, so a truncated first-party stream
could pass silently while compatible proxy providers that legitimately omit
message_stop failed intermittently. The invariant now keys off the transport
contract owner: direct Anthropic models always require message_stop; proxy
providers are exempt.
ClawSweeper P1: the proxy exemption had no focused test, so the lenient
branch could regress silently. A non-anthropic provider through a custom
endpoint now proves stopReason=stop with no error when the stream ends
without message_stop.
@steipete
steipete force-pushed the steipete/anthropic-proxy-message-stop branch from e24d1c4 to 273ab83 Compare August 7, 2026 08:25
@steipete
steipete merged commit 74500f3 into main Aug 7, 2026
310 of 313 checks passed
@steipete
steipete deleted the steipete/anthropic-proxy-message-stop branch August 7, 2026 08:49
@steipete

steipete commented Aug 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 Aug 8, 2026
…ge_stop contract (openclaw#120030)

* fix(ai): enforce message_stop only for direct Anthropic models

The Anthropic SSE transport threw 'stream ended before message_stop' only when
a refusal buffer happened to be non-empty, so a truncated first-party stream
could pass silently while compatible proxy providers that legitimately omit
message_stop failed intermittently. The invariant now keys off the transport
contract owner: direct Anthropic models always require message_stop; proxy
providers are exempt.

* test(ai): cover proxy streams ending without message_stop

ClawSweeper P1: the proxy exemption had no focused test, so the lenient
branch could regress silently. A non-anthropic provider through a custom
endpoint now proves stopReason=stop with no error when the stream ends
without message_stop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant