Skip to content

The agent that grows with you

fix(goal): resume after max-iterations summary Closes #102213

finn763a3013c009064
diff --git a/tui_gateway/prompt_turn.py b/tui_gateway/prompt_turn.py
index 2f2eea78507..39497c941e7 100644
--- a/tui_gateway/prompt_turn.py
+++ b/tui_gateway/prompt_turn.py
@@ -47,11 +47,25 @@ def _hook_failure(what: str, exc: BaseException) -> None:
def _is_successful_goal_turn(result: Any, status: str, raw: Any) -> bool:
- """Whether a turn produced a real response the goal judge can use."""
- return bool(
- status == "complete" and isinstance(raw, str) and raw.strip()
- and not (isinstance(result, dict) and result.get("failed"))
- and not (isinstance(result, dict) and result.get("completed") is False))
+ """Whether a turn produced a real response the goal judge can use.
+
+ A non-failed ``max_iterations_reached(...)`` handoff is a resumable
+ turn boundary, not a failure: the summary must reach the goal judge
+ so an active goal can continue (#102213). Failed, interrupted, and
+ other ``completed is False`` turns still stay out (cf. #63180).
+ """
+ if status != "complete" or not isinstance(raw, str) or not raw.strip():
+ return False
+ if not isinstance(result, dict):
+ return True
+ if result.get("failed") or result.get("interrupted"):
+ return False
+ if result.get("completed") is False:
+ reason = result.get("turn_exit_reason") or ""
+ return isinstance(reason, str) and reason.startswith(
+ "max_iterations_reached"
+ )
+ return True
def _active_goal_manager(session: dict):