Skip to content

[pull] main from danny-avila:main#126

Merged
pull[bot] merged 2 commits into
innFactory:mainfrom
danny-avila:main
Jul 1, 2026
Merged

[pull] main from danny-avila:main#126
pull[bot] merged 2 commits into
innFactory:mainfrom
danny-avila:main

Conversation

@pull

@pull pull Bot commented Jul 1, 2026

Copy link
Copy Markdown

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

* fix: fail fast on tool calls truncated by the output token limit

When a model turn is cut off by the max output token limit while it is still
streaming a tool call, the arguments are necessarily incomplete (the tool-use
block is the last thing the model emits). Providers surface this differently:
Bedrock Converse buries it in response_metadata.messageStop.stopReason,
Anthropic uses stop_reason, OpenAI finish_reason='length', Google
finishReason='MAX_TOKENS'. The partial args parse into a well-formed-but-empty
tool call (e.g. create_file missing its content), so the agent loops on a
malformed request until it hits the recursion limit.

Detect the truncation stop reason across providers and, when the turn carries a
tool call, throw an actionable OutputTruncationError from the single invoke
funnel instead of executing/looping on the incomplete call.

Adds unit coverage for the cross-provider detector and a gated live Bedrock
reproduction (RUN_BEDROCK_TRUNCATION_LIVE=1).

* fix: skip truncation guard for atomic-tool-call providers (Google/Vertex)

Google/Vertex (GenAI) deliver function calls as complete objects sealed on
arrival, not streamed argument deltas, and treat MAX_TOKENS as a final chunk.
A Gemini response with a valid functionCall ending in finishReason MAX_TOKENS
therefore has complete args, so the provider-blind guard wrongly threw on it.

Make assertNotTruncatedToolCall provider-aware: skip providers that deliver
tool calls atomically. Streaming-arg providers (Anthropic, Bedrock, OpenAI)
still fail fast on truncated tool calls.

* fix: detect truncation for Anthropic streaming and OpenAI Responses

Two provider shapes the detector missed:
- Anthropic streaming stores the terminal stop_reason on
  AIMessageChunk.additional_kwargs (response_metadata only gets
  model_provider/context_management), so a streamed Claude tool call cut off at
  max_tokens slipped past the guard.
- OpenAI Responses API signals truncation via response_metadata.status
  'incomplete' + incomplete_details.reason 'max_output_tokens', not a
  stop/finish field.

Read additional_kwargs.stop_reason and incomplete_details.reason in
getTruncationStopReason, and normalize max_output_tokens. Non-token incomplete
reasons (e.g. content_filter) still return null.
@pull pull Bot locked and limited conversation to collaborators Jul 1, 2026
@pull pull Bot added the ⤵️ pull label Jul 1, 2026
@pull
pull Bot merged commit 495568b into innFactory:main Jul 1, 2026
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant