#5169

fix(tools): reject truncated JSON args and circuit-break retry loops

OpenLB623wants to merge intofrom

Summary

  • Reject truncated/invalid JSON object strings in ToolRegistry.prepare_call (e.g. '{"recap": "') before execute
  • Track consecutive tool failures and circuit-break after max_consecutive_tool_failures (default 3) to stop model retry loops
  • Clear the counter on success

Fixes #4864

Problem

complete_goal / update_goal with malformed string args (truncated JSON) produced soft errors; the model retried indefinitely and burned tokens (Telegram/OpenRouter reports).

Test plan

  • tests/agent/tools/test_registry_circuit_break.py (truncated reject + circuit-break + valid execute)
  • CI suite on this PR

Residual risk

  • Registry stops tool spam; agent loop should honor the circuit-break message (no further same-arg retries).