Skip to content

Truncated responses are treated as successful and retried silently (finish_reason never checked) #1836

Description

@revworxai

Related to #1747.

When a model's response is cut off mid-JSON, Agent Zero does not notice. The
envelope never closes, extraction fails, the misformat warning fires, and the
turn is retried — with no indication that the cause was output truncation
rather than a formatting error. On an expensive model each retry is a full
inference on a growing context.

finish_reason appears to be consulted in exactly one place
(helpers/litellm_transport.py, in the tool_calls / function_call check).
There is no branch for length or content_filter.

Two contributing factors make this easier to hit than it looks:

  • No default max_tokens is sent for the Anthropic provider, so the LiteLLM
    default applies. With high reasoning effort, thinking consumes the budget
    before the envelope closes.
  • The limit_output field in model settings is wired only to the rate limiter
    (rl_output) and is never sent to the API, so it looks like a fix but is not.

Suggested fix: detect finish_reason == "length" and surface it distinctly
— either retry with a raised ceiling or emit a warning that names truncation as
the cause, rather than the generic misformat message.

Environment: v2.8 (2026-08-01), Claude Opus 5 high reasoning effort,
Anthropic API via LiteLLM, Docker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions