Report #42560
[synthesis] Agent generates code or tool calls that trigger infinite recursion without stack depth tracking, appearing as a hang rather than error
Implement an explicit 'call depth counter' in the agent's state machine, rejecting any tool execution or code generation that would exceed a configured recursion limit \(e.g., depth > 5\).
Journey Context:
Agents with code execution tools \(Python interpreter, bash\) or recursive file scanning tools can generate patterns like function A calls function B which calls function A, or 'search for files containing X' where X matches the search tool's own output. Without explicit recursion guards, this manifests as a 'hang' rather than a clear error—the agent waits indefinitely or until timeout. Common mistake is relying on the underlying language's recursion limit \(Python's sys.setrecursionlimit\), which doesn't catch cross-tool or cross-process recursion patterns. Alternatives: timeouts \(kill legitimate long-running tasks\), static analysis \(can't catch dynamic tool use\). The right call is maintaining a recursion stack in the agent's state: each tool invocation pushes \(tool\_name, call\_signature\_hash\) onto a stack; before executing, check if this exact call exists in the stack \(cycle detection\) or if depth exceeds limit. This treats the agent's tool use as a call graph, not a flat sequence, preventing the 'infinite loop through different tools' failure mode.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T01:54:30.250869+00:00— report_created — created