Skip to content

Fail the turn instead of dispatching truncated tool calls - #938

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-7783-stop-reason-truncation
Sep 12, 2026
Merged

Fail the turn instead of dispatching truncated tool calls#938
TheGreatAxios merged 2 commits into
mainfrom
cl-7783-stop-reason-truncation

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Collaborator

Summary

Fixes CL-7783: a truncated Anthropic tool_use (max_tokens cut off mid-JSON) was dispatched as a well-formed call — {"_raw": ...} args or silently dropped params — and reached the reactor as a normal tool call. Now the adapter surfaces stop_reason on the turn and end-of-stream finalization fails the turn with an actionable error instead of dispatching unparseable args.

Changes

  • Adapter (vendor/intx-inference/src/providers/anthropic.ts): parse stop_reason in MessageDelta, plumb through LastUsage/streamState, emit on inference.usage (arktype + static union in vendor/intx-types/src/runtime.ts).
  • Harness (vendor/intx-inference/src/harness.ts): finalizeStreamTurn collects parse failures across all three paths and throws a HarnessError naming the tool and failure kind (truncation vs malformed) instead of dispatching. No _raw fallback remains; the dead _raw consumer in src/plugins/path-escape-plugin.ts is removed.
  • Reactor: truncated tool calls surface as retryable turn failures, never as tool results.
  • Ledgers: local vendor patch recorded as stopgap + promotion candidate in vendor/intx-inference/PATCHES.md and vendor/intx-types/PATCHES.md; docs/VENDORING.md updated. Upstream untouched.

Verification

  • New regression test drives the exact CL-7783 event sequence (content_block_start tool_use Bash, partial input_json_delta, message_delta stop_reason: max_tokens, message_stop) and asserts no tool_call block reaches the reactor: bun test vendor/intx-inference/src/providers/anthropic.test.ts — 7 pass.
  • Targeted suites (inference-harness.test.ts, agent-tool-dispatch.test.ts) green; bun run check green.
  • OpenAI-compatible adapter audited for the same path (see review comment / report).

Fixes CL-7783.

@linear-code

linear-code Bot commented Sep 12, 2026

Copy link
Copy Markdown

CL-7783

@TheGreatAxios
TheGreatAxios force-pushed the cl-7783-stop-reason-truncation branch from 3a38e2c to 0d60d81 Compare September 12, 2026 05:04
@TheGreatAxios
TheGreatAxios force-pushed the cl-7783-stop-reason-truncation branch from 0d60d81 to 980944c Compare September 12, 2026 05:35
@TheGreatAxios
TheGreatAxios merged commit 9334eed into main Sep 12, 2026
8 of 9 checks passed
@TheGreatAxios
TheGreatAxios deleted the cl-7783-stop-reason-truncation branch September 12, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant