Skip to content

Agent loops indefinitely when tool call output exceeds max_tokens #7527

@angiejones

Description

@angiejones

When a tool call's JSON output exceeds max_tokens, the response is truncated mid-JSON and fails to parse ("EOF while parsing an object"). The agent retries the same call indefinitely because:

  1. no_tools_called is set to false even when the tool call failed to parse (agent.rs ~L1476), so the exit/retry logic is never reached
  2. The system hint ("Try breaking the task into smaller steps") is injected but the model ignores it and attempts the same large write
  3. DEFAULT_MAX_TURNS is 1000, so the loop can burn tokens for a very long time before stopping

Observed in a session where the model tried to write a full HTML dashboard via developer__text_editor. Every attempt hit 8,192 output tokens, failed to parse, and retried — 24 consecutive failures with zero user intervention possible.

Contributing factors:

Fix options (not mutually exclusive):

  • Break after N consecutive tool parse failures (e.g., 3) instead of setting no_tools_called = false
  • Raise default max_output_tokens per model capability
  • Detect repeated identical truncation and suggest a different strategy

Metadata

Metadata

Assignees

Labels

p1Priority 1 - High (supports roadmap)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions