Skip to content

fix: fail on truncated model tool calls - #457

Open
Geonwoo Jeong (geonwoo-jeong) wants to merge 2 commits into
langchain-ai:mainfrom
geonwoo-jeong:codex/fail-on-truncated-tool-calls
Open

fix: fail on truncated model tool calls#457
Geonwoo Jeong (geonwoo-jeong) wants to merge 2 commits into
langchain-ai:mainfrom
geonwoo-jeong:codex/fail-on-truncated-tool-calls

Conversation

@geonwoo-jeong

@geonwoo-jeong Geonwoo Jeong (geonwoo-jeong) commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #458

Summary

  • Fail the run when a model reaches its output limit before completing a tool call.
  • Correlate the invalid_tool_call and length signals by namespace, node, and model run ID.
  • Preserve existing behavior for valid tool calls, non-length finishes, and unrelated concurrent or subgraph runs.

Reproduction and root cause

During a long Bedrock agent run, stock @langchain/aws@1.4.2 emitted:

  1. content-block-finish with content.type = "invalid_tool_call"
  2. message-finish with reason = "length"

The affected route reported output_tokens = 4096; this PR does not assume that value is a universal Bedrock default.

OpenWiki currently ignores both non-text message events. The incomplete tool call is therefore not executed, but the outer stream can finish without surfacing why the requested file change was missing.

Exact behavior

Stream signals Result
Same message: invalid_tool_call then length Throw an actionable error
invalid_tool_call then another finish reason Preserve existing behavior
length without an invalid tool call Preserve existing behavior
Signals from different runs, namespaces, or nodes Do not combine them

The error is raised inside the existing stream try block, so temporary-plan cleanup and interrupted-run metadata handling remain unchanged. Tool arguments and generated file contents are not included in the error.

Scope

This is a provider-neutral guard at the LangChain v3 protocol boundary. It does not change model defaults, expose a maxTokens setting, patch dependencies, or alter prompts and workflows.

It is also independent of langchain-ai/langchainjs#11231, which addresses replay of unstamped v1 tool-call history rather than truncation of the current streamed response.

Validation

  • Regression tests confirmed RED without the guard and GREEN with it, including namespace/node isolation.
  • An integration regression test exercises the real createDeepAgent(...).streamEvents(..., { version: "v3" }) path and verifies run_id correlation plus message-finish.reason = "length".
  • pnpm install --frozen-lockfile
  • pnpm test — 58 files, 697 tests
  • pnpm run build
  • pnpm run typecheck
  • pnpm run lint:check
  • pnpm run format:check
  • Manual stock-@langchain/aws@1.4.2 stream reproduction confirmed the invalid_tool_calllength sequence.

@geonwoo-jeong
Geonwoo Jeong (geonwoo-jeong) force-pushed the codex/fail-on-truncated-tool-calls branch from 91acb73 to 4ef5ecd Compare July 27, 2026 05:02
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.

[Bug]: Truncated model tool calls can end runs without an error

1 participant