Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(agent-chat): drop the one-hour cap on coding-agent turns (#1112)

Ruben Lütke301d26959086
diff --git a/dodaios/agent_chat/runner_cli.py b/dodaios/agent_chat/runner_cli.py
index 05062fbd58..b572556cf0 100644
--- a/dodaios/agent_chat/runner_cli.py
+++ b/dodaios/agent_chat/runner_cli.py
@@ -100,7 +100,14 @@ from dodaios.core.response_style import KEEP_GOING_ON_TOOL_FAILURE
log = logging.getLogger(__name__)
_READLINE_LIMIT: Final[int] = 16 * 1024 * 1024
-_TURN_TIMEOUT_S: Final[float] = 3600.0
+#: A coding-agent turn has no wall-clock limit: a session may run for days.
+#: Stop ends it; a stalled ACP runtime ends through its own watchdog.
+_TURN_TIMEOUT_S: Final[float | None] = None
+#: A CLI that sent its terminal result and then printed nothing for this long
+#: is stuck, not busy (background sub-agents keep printing while they work).
+_EXIT_AFTER_RESULT_S: Final[float] = 600.0
+#: agy's print mode stops itself after 5 min unless told otherwise.
+_AGY_PRINT_TIMEOUT: Final[str] = f"{365 * 24 * 3600}s"
class CliUnavailable(RuntimeError):
@@ -1108,9 +1115,9 @@ def plan_agy(
"stream-json",
"--add-dir",
str(work),
- # agy's own print timeout is 5 min; ours is the long one.
+ # agy's own print timeout is 5 min; a turn here has no limit.
"--print-timeout",
- f"{int(_TURN_TIMEOUT_S // 60)}m",
+ _AGY_PRINT_TIMEOUT,
]
if mode == "plan":
argv += ["--mode", "plan"]
@@ -3718,7 +3725,7 @@ async def resume_hosted_cli_turn(handle: TurnHandle, proc: Any) -> str | None:
placement=None,
tree=None,
bridge=None,
- timeout_s=max(60.0, _TURN_TIMEOUT_S - elapsed),
+ timeout_s=_TURN_TIMEOUT_S,
)
await handle.emit(
make_event(
@@ -4108,7 +4115,7 @@ async def _drive_cli(
placement: Any,
tree: Any,
bridge: Any | None,
- timeout_s: float = _TURN_TIMEOUT_S,
+ timeout_s: float | None = _TURN_TIMEOUT_S,
) -> _Outcome:
"""Read a started CLI to its end: translate, answer, and judge the outcome.
@@ -4588,11 +4595,27 @@ async def _drive_cli(
watcher = asyncio.create_task(_watch_cancel())
provider_watcher = asyncio.create_task(_watch_provider_failure())
stall_watcher = asyncio.create_task(_watch_stall())
+ exit_watcher: asyncio.Task[None] | None = None
+ lingered = [False]
try:
# EOF is not process exit: a CLI may close both pipes and keep
- # running. The deadline must also cover waiting for the process.
+ # running. The deadlines must also cover waiting for the process.
deadline = None if getattr(handle, "goal_turn", False) else timeout_s
- async with asyncio.timeout(deadline):
+ async with asyncio.timeout(deadline) as scope:
+
+ async def _watch_exit_after_result() -> None:
+ # No limit on the work itself, but a CLI that gave its final
+ # answer and then stays alive in silence is stuck, not busy.
+ while True:
+ await asyncio.sleep(_ACP_WATCH_TICK_S)
+ if not getattr(state, "saw_result", False):
+ continue
+ if time.monotonic() - activity[0] > _EXIT_AFTER_RESULT_S:
+ break
+ lingered[0] = True
+ scope.reschedule(asyncio.get_running_loop().time())
+
+ exit_watcher = asyncio.create_task(_watch_exit_after_result())
await asyncio.gather(pump, drain, feeder)
await proc.wait()
except TimeoutError:
@@ -4607,7 +4630,13 @@ async def _drive_cli(
await _acp_cancel()
_kill(proc)
status = "error"
- error_text = f"{runner} did not finish within {int(_TURN_TIMEOUT_S)} s."
+ if lingered[0]:
+ error_text = (
+ f"{runner} did not finish within {int(_EXIT_AFTER_RESULT_S)} s"
+ " of its final answer."
+ )
+ else:
+ error_text = f"{runner} did not finish within {int(timeout_s or 0)} s."
except asyncio.CancelledError:
if hosted and not handle.cancel.is_set():
# The app is going away, nobody pressed Stop: the CLI keeps working
@@ -4623,6 +4652,8 @@ async def _drive_cli(
watcher.cancel()
provider_watcher.cancel()
stall_watcher.cancel()
+ if exit_watcher is not None:
+ exit_watcher.cancel()
for task in (pump, drain, feeder):
if not task.done():
task.cancel()
diff --git a/dodaios/society/team_lead.py b/dodaios/society/team_lead.py
index 3cecf3cf3f..72de063859 100644
--- a/dodaios/society/team_lead.py
+++ b/dodaios/society/team_lead.py
@@ -92,7 +92,6 @@ MAX_WAIT_ATTEMPTS: Final[int] = 120
REVIEW_DELAY_S: Final[float] = 1.5
LEAD_RETRY_S: Final[float] = 10.0
MAX_LEAD_WAIT_ATTEMPTS: Final[int] = 90
-LEAD_TURN_TIMEOUT_S: Final[float] = 30 * 60.0
SWEEP_S: Final[float] = 60.0
#: A task with no sign of life for this long is checked against the scheduler.
STALL_MS: Final[int] = 3 * 60 * 1000
@@ -1199,34 +1198,30 @@ class TeamLeads:
svc = self._rt.chat_service()
ok, final, error = False, "", ""
try:
- try:
- await asyncio.wait_for(svc.wait_turn(session_id), timeout=LEAD_TURN_TIMEOUT_S)
- except TimeoutError: # A turn this long is stopped; the person may resume.
- error = "The lead's turn took too long and was stopped."
- await self._cancel_turn(session_id, turn_id)
- else:
- terminal = None
- for _ in range(6):
- terminal = await asyncio.to_thread(
- svc.store.turn_terminal, session_id, turn_id
- )
- if terminal is not None:
- break
- await asyncio.sleep(0.5)
- payload = (terminal or {}).get("payload", {})
- ok = payload.get("status") in ("ok", "done", "completed")
- if not ok:
- error = str(payload.get("error") or payload.get("status") or "")
- error = error or "The lead's turn did not finish."
- events = await asyncio.to_thread(svc.store.list_events, session_id, tail=200)
- final = next(
- (
- str(e["payload"].get("text") or "")
- for e in reversed(events)
- if e["kind"] == "assistant_text" and e["payload"].get("turn_id") == turn_id
- ),
- "",
+ # A lead's turn may run as long as the work needs; Stop ends it.
+ await svc.wait_turn(session_id)
+ terminal = None
+ for _ in range(6):
+ terminal = await asyncio.to_thread(
+ svc.store.turn_terminal, session_id, turn_id
)
+ if terminal is not None:
+ break
+ await asyncio.sleep(0.5)
+ payload = (terminal or {}).get("payload", {})
+ ok = payload.get("status") in ("ok", "done", "completed")
+ if not ok:
+ error = str(payload.get("error") or payload.get("status") or "")
+ error = error or "The lead's turn did not finish."
+ events = await asyncio.to_thread(svc.store.list_events, session_id, tail=200)
+ final = next(
+ (
+ str(e["payload"].get("text") or "")
+ for e in reversed(events)
+ if e["kind"] == "assistant_text" and e["payload"].get("turn_id") == turn_id
+ ),
+ "",
+ )
except asyncio.CancelledError:
self._release_turn(goal_id, lead_id)
raise
diff --git a/tests/unit/agent_chat/test_agent_chat_ladders.py b/tests/unit/agent_chat/test_agent_chat_ladders.py
index 1845b5257c..09f14e60fe 100644
--- a/tests/unit/agent_chat/test_agent_chat_ladders.py
+++ b/tests/unit/agent_chat/test_agent_chat_ladders.py
@@ -280,7 +280,8 @@ def test_agy_planner_speaks_agy(monkeypatch, tmp_path: Path):
# therefore also skips confirmations so the turn can finish.
assert "--dangerously-skip-permissions" in argv
assert argv[argv.index("--add-dir") + 1] == str(tmp_path)
- assert "--print-timeout" in argv
+ # agy's own 5-minute print limit is lifted: a turn may run for days.
+ assert argv[argv.index("--print-timeout") + 1] == f"{365 * 24 * 3600}s"
# Pro knows only low/high: medium snaps to low, and the pair is sent.
assert argv[argv.index("--model") + 1] == "gemini-3.1-pro"
assert argv[argv.index("--effort") + 1] == "low"
diff --git a/tests/unit/agent_chat/test_cli_lifecycle.py b/tests/unit/agent_chat/test_cli_lifecycle.py
index 33ac698fbf..23e731a25e 100644
--- a/tests/unit/agent_chat/test_cli_lifecycle.py
+++ b/tests/unit/agent_chat/test_cli_lifecycle.py
@@ -121,6 +121,92 @@ async def test_claude_process_completion(tmp_path: Path, result, ending, expecte
store.close()
+def test_a_coding_agent_turn_has_no_wall_clock_limit():
+ """Sessions may run for days, for every coding CLI (no 3600 s cut-off)."""
+ import inspect
+
+ assert runner_cli._TURN_TIMEOUT_S is None
+ default = inspect.signature(runner_cli._drive_cli).parameters["timeout_s"].default
+ assert default is None
+
+
+async def _drive_fake_claude(tmp_path: Path, source: str) -> tuple[object, object]:
+ store = AgentChatStore(":memory:")
+ session = store.create_session(
+ provider="claude-api", model="fake", effort="", cwd=str(tmp_path)
+ )
+
+ async def emit(_event):
+ return None
+
+ async def approve(*_args):
+ pytest.fail("No approval should be requested")
+
+ handle = TurnHandle(session, "turn", emit, approve, asyncio.Event())
+ proc = await asyncio.create_subprocess_exec(
+ sys.executable,
+ "-u",
+ "-c",
+ source,
+ stdin=asyncio.subprocess.PIPE,
+ stdout=asyncio.subprocess.PIPE,
+ stderr=asyncio.subprocess.PIPE,
+ creationflags=NO_WINDOW_CREATIONFLAGS,
+ )
+ try:
+ outcome = await asyncio.wait_for(
+ runner_cli._drive_cli(
+ handle,
+ proc,
+ runner_cli.CliPlan(
+ argv=[],
+ env={},
+ stdin_text="prompt\n",
+ shape="claude",
+ vendor_session=None,
+ keep_stdin=False,
+ ),
+ "claude-cli",
+ cwd=tmp_path,
+ started_at=time.time(),
+ placement=None,
+ tree=None,
+ bridge=None,
+ ),
+ timeout=8.0,
+ )
+ finally:
+ if proc.returncode is None:
+ proc.kill()
+ await asyncio.wait_for(proc.wait(), 3)
+ store.close()
+ return outcome, proc
+
+
+_RESULT_LINE = json.dumps(
+ {"type": "result", "subtype": "success", "is_error": False, "usage": {"output_tokens": 1}}
+)
+
+
+async def test_a_long_silent_turn_is_not_cut_off(tmp_path: Path, monkeypatch):
+ """Silent work before the final answer is never stopped by a clock."""
+ monkeypatch.setattr(runner_cli, "_ACP_WATCH_TICK_S", 0.05)
+ monkeypatch.setattr(runner_cli, "_EXIT_AFTER_RESULT_S", 0.3)
+ source = f"import time\ntime.sleep(1.5)\nprint({_RESULT_LINE!r}, flush=True)\n"
+ outcome, _proc = await _drive_fake_claude(tmp_path, source)
+ assert outcome.status == "done", outcome.error
+
+
+async def test_a_cli_lingering_silently_after_its_answer_is_stopped(tmp_path: Path, monkeypatch):
+ monkeypatch.setattr(runner_cli, "_ACP_WATCH_TICK_S", 0.05)
+ monkeypatch.setattr(runner_cli, "_EXIT_AFTER_RESULT_S", 0.3)
+ source = f"import time\nprint({_RESULT_LINE!r}, flush=True)\ntime.sleep(60)\n"
+ outcome, proc = await _drive_fake_claude(tmp_path, source)
+ assert outcome.status == "error"
+ assert "of its final answer" in outcome.error
+ assert proc.returncode is not None
+
+
@pytest.mark.parametrize("status", ["done", "error", "cancelled"])
async def test_a_turn_publishes_its_terminal_status_only_once(tmp_path, status):
store = AgentChatStore(":memory:")