Skip to content

fix: detect truncated tool_calls when finish_reason is not length - #7693

Closed
tomqiaozc wants to merge 1 commit into
NousResearch:mainfrom
tomqiaozc:user/Tom/fix-finish-reason-validation
Closed

fix: detect truncated tool_calls when finish_reason is not length#7693
tomqiaozc wants to merge 1 commit into
NousResearch:mainfrom
tomqiaozc:user/Tom/fix-finish-reason-validation

Conversation

@tomqiaozc

Copy link
Copy Markdown

Summary

  • When API routers rewrite finish_reason from "length" to "tool_calls", truncated JSON arguments bypassed the length handler and wasted 3 retry attempts in the generic JSON validation loop
  • Now detects truncation patterns in tool call arguments (args that don't end with } or ]) regardless of finish_reason
  • Mirrors the existing truncation detection in the streaming path (_interruptible_streaming_api_call)

Fixes #7680

Test plan

  • Added test with finish_reason="tool_calls" + truncated JSON args — verifies the agent returns partial: True without retrying or executing tools
  • Existing tests for finish_reason="length" path remain passing

🤖 Generated with Claude Code

When API routers rewrite finish_reason from "length" to "tool_calls",
truncated JSON arguments bypassed the length handler and wasted 3
retry attempts in the generic JSON validation loop. Now detects
truncation patterns in tool call arguments regardless of finish_reason.

Fixes NousResearch#7680

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7910. Your commit was cherry-picked onto current main with your authorship preserved in git log. Thanks for catching the truncated tool_calls gap!

@teknium1 teknium1 closed this Apr 11, 2026
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.

Critical: Hermes doesn't validate finish_reason for tool_calls, allowing truncated JSON to be processed

2 participants