Anthropic stream: EOF before message_stop still returns complete tool arguments
At current main commit 3e3a6665c9d2a53e69d0259172e335f4b60f2e60, the Anthropic streaming provider can return argumentsComplete: true when the HTTP stream ends after a closed tool block but before the message's final message_stop. It also does so when EOF arrives before both message-level terminal events.
I wanted to check whether that is an intentional gateway-compatibility policy or an incomplete native Anthropic message being treated as a completed tool call.
Runnable reproduction
Native-first reproduction, pinned source, lockfile and outputs.
Download its files into an empty directory, then with Node 22.19+, npm and Git:
npm ci --ignore-scripts --engine-strict --no-audit --no-fund
npm run source:prepare
npm run upstream:checks
npm run native
The native run uses unchanged upstream Anthropic provider, SSE parser and ToolRuntime/registry, with authored SSE and a harmless memory-counter handler. It installs only eventsource-parser, p-limit and Zod. The actual complete agent loop, approval flow and built-in tools are outside the trial; the harness applies the agent loop's model-visibility and invalid-input preflight before calling ToolRuntime. No API key, model request or file mutation is involved.
Observed counter results:
| Stream | argumentsComplete |
Native effects |
|---|---|---|
Closed block + tool_use metadata + message_stop |
true | 1 |
Same stream, EOF before message_stop |
true | 1 |
| Closed block, EOF before both message terminal events | true | 1 |
Complete JSON + explicit max_tokens + message_stop |
false | 0 |
The eight existing tests in provider-anthropic.test.js and tool-runtime.test.js pass unchanged. The token-limit control already withholds the call natively; the remaining question is missing positive message completion, not JSON syntax or that token-limit case. These authored fixtures do not establish production frequency.
Source boundary
buildFinalStreamResult uses tc.closed === true && !isCompletionTruncated(finishReason). The streaming loop records stop metadata and block closure, but does not retain message_stop; a missing finish reason is not classified as truncated. ToolRuntime.beginModelResponse refuses explicit argumentsComplete: false, so the returned true value passes that boundary.
The native Anthropic streaming sequence ends with message_stop. If native message completion is intended here, tracking that event plus a positive stop reason would support two additional EOF regression cases. Gateways deliberately using a different terminal contract may need an explicit compatibility policy.
I maintain prefix-safe-json; the reproduction also contains an optional strict caller-boundary comparison using published 0.5.4. It tees the same original response before projection, consumes authority once, and passes its raw value into the same ToolRuntime. Results for the four rows are 1 / 0 / 0 / 0. The native reproduction and an in-tree correction can be used independently. If reusing that strict boundary fits Codemini, I can prepare an opt-in project-local integration and help validate it at the actual dispatch boundary.
Thanks for the detailed report and reproduction! This was a bug, rather than an intentional gateway-compatibility policy.
The fix is already in the dev-20261020 development branch, but hasn’t been released yet. Streaming tool calls now require a closed tool block, a message_stop event, and a non-empty, non-truncated stop reason before their arguments are marked complete.
Regression tests cover both EOF cases you reported, along with missing stop reasons and token-limit termination. The focused Anthropic provider and ToolRuntime tests pass (19/19).
Thanks also for offering the integration. We’ve addressed this directly in the provider without adding a dependency. I’ll keep this issue open until the fix is released.
This is included in v0.10.0. Closing as completed — thanks again for the report and reproduction.