Skip to content

Raise the Strands runner's recursion limit to allow 1,000 tool turns - #209

Merged
aarora79 merged 2 commits into
mainfrom
fix/strands-recursion-limit
Oct 5, 2026
Merged

aarora79 merged 2 commits into
mainfrom
fix/strands-recursion-limit

Conversation

@aarora79

@aarora79 aarora79 commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Strands' event loop calls itself after every round of tool calls (_handle_tool_execution -> recurse_event_loop -> event_loop_cycle) and adds 3 Python frames per turn. With Python's default recursion limit of 1,000 frames, a Strands task crashes after about 320 tool turns. A Claude Haiku 4.5 task in #206 failed with RecursionError: maximum recursion depth exceeded.

This PR raises the limit in benchmarks/scripts/strands_agent_runner.py to RECURSION_LIMIT = 3,500 frames before the agent starts. That is MAX_TOOL_TURNS (1,000) x FRAMES_PER_TOOL_TURN (3) plus 500 frames of headroom. The runner never lowers a higher limit, and a task that runs past 1,000 turns still stops with RecursionError. Only --agent strands runs this file.

Evidence

A fake model that answers every call with one no-op tool call, on Strands 1.57.1, with no network or real model:

Limit Tool turns Result
1,000 (default) 2,000 requested RecursionError after 319 turns
3,500 1,000 finished in 234 s
3,500 1,200 requested RecursionError after 1,153 turns

Stack depth grew from 29 frames at the first model call to 329 at the 101st, 3 frames per turn. Our longest finished Strands task took 222 turns. The first attempt at consistent-csrf-across-toggle-endpoints in the minicpm5-2b run (#204) looped for 316 turns, just under the old ceiling of about 320.

Changes

  • strands_agent_runner.py: MAX_TOOL_TURNS, FRAMES_PER_TOOL_TURN, RECURSION_HEADROOM and RECURSION_LIMIT constants, and _raise_recursion_limit(), called from main().
  • docs/strands-setup.md: a sixth row in the table of places the runner departs from Strands as it ships.
  • docs/harness-strands-swe3.md: the note on Haiku's failed task points to this fix.

Testing

  • New unit tests: a low limit is raised, a higher one is never lowered, and the default limit covers the turn budget.
  • uv run python -m unittest discover -s tests passes in benchmarks/. Ruff, mypy and Bandit are clean, and the security-check gate passed.
  • An end-to-end hello-world run through run-e2e-benchmark.sh --agent strands on vLLM scored 6/6 artifacts in 74 turns.

Closes #208

Strands' event loop calls itself after every round of tool calls and adds 3
frames per turn, so Python's default limit of 1,000 frames ends a task after
about 320 turns. A Claude Haiku 4.5 task in #206 crashed this way.

The runner now raises the limit to 3,500 frames before it starts the agent:
MAX_TOOL_TURNS (1,000) x FRAMES_PER_TOOL_TURN (3) plus 500 frames of headroom.
It never lowers a higher limit. A task that runs past the budget still stops
with RecursionError.

Closes #208
@aarora79
aarora79 merged commit cfd5c48 into main Oct 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strands harness: the event loop recurses per tool turn, so tasks past about 320 turns crash with RecursionError

1 participant