Symptom (live test 2026-05-28)
The agent ran run_python 15+ times without converging on a usable reform, never producing a chart. The user sees a long visible stream of "Working…" steps with no terminal result before either Vercel times out or they give up.
Diagnosis
chat_message (backend/routes/chatbot.py:259) has a max_iterations loop but the failure mode for hitting it is silent — the user gets no closure when the agent runs out of budget. The agent can also keep churning if max_iterations is generous.
Fix
- Lower the soft cap. ~10–12 tool iterations per turn is plenty for any sane question; beyond that we're almost certainly looping.
- When the cap is hit, emit a final assistant message summarizing what was tried and what's known so far — don't just cut off mid-stream. Something like:
"I ran into trouble constructing this reform. Here's what I tried and what I learned: [summary of attempts]. Could you (a) rephrase, (b) enable Plan mode for clarifying questions, or (c) provide a more specific scenario?"
- Log iteration count + final-status reason so we can see in metrics how often this fires.
Constraints
- Don't expose the raw tool-call transcript in the fallback message — summarize.
- Plan mode turns may legitimately need fewer iterations (different cap).
- Continue (stop-then-continue) should not reset the iteration counter — the budget is per logical turn, not per stream.
Related
Symptom (live test 2026-05-28)
The agent ran
run_python15+ times without converging on a usable reform, never producing a chart. The user sees a long visible stream of "Working…" steps with no terminal result before either Vercel times out or they give up.Diagnosis
chat_message(backend/routes/chatbot.py:259) has amax_iterationsloop but the failure mode for hitting it is silent — the user gets no closure when the agent runs out of budget. The agent can also keep churning ifmax_iterationsis generous.Fix
Constraints
Related
test_dispatches_compute) — unrelated but in the same neighborhood.