fix: fail on truncated model tool calls - #457
Open
Geonwoo Jeong (geonwoo-jeong) wants to merge 2 commits into
Open
fix: fail on truncated model tool calls#457Geonwoo Jeong (geonwoo-jeong) wants to merge 2 commits into
Geonwoo Jeong (geonwoo-jeong) wants to merge 2 commits into
Conversation
Geonwoo Jeong (geonwoo-jeong)
marked this pull request as ready for review
July 24, 2026 11:55
This was referenced Jul 24, 2026
Geonwoo Jeong (geonwoo-jeong)
force-pushed
the
codex/fail-on-truncated-tool-calls
branch
from
July 27, 2026 05:02
91acb73 to
4ef5ecd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #458
Summary
invalid_tool_callandlengthsignals by namespace, node, and model run ID.Reproduction and root cause
During a long Bedrock agent run, stock
@langchain/aws@1.4.2emitted:content-block-finishwithcontent.type = "invalid_tool_call"message-finishwithreason = "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
invalid_tool_callthenlengthinvalid_tool_callthen another finish reasonlengthwithout an invalid tool callThe error is raised inside the existing stream
tryblock, 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
maxTokenssetting, 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
createDeepAgent(...).streamEvents(..., { version: "v3" })path and verifiesrun_idcorrelation plusmessage-finish.reason = "length".pnpm install --frozen-lockfilepnpm test— 58 files, 697 testspnpm run buildpnpm run typecheckpnpm run lint:checkpnpm run format:check@langchain/aws@1.4.2stream reproduction confirmed theinvalid_tool_call→lengthsequence.