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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agent-runtimes): keep a local model's silent prefill from tripping the stall watchdog (#1015)
Ruben Lütke2edfdd20828a
diff --git a/dodaios/agent_chat/runner_cli.py b/dodaios/agent_chat/runner_cli.pyindex 66c1b75c46..dd4e463d7c 100644--- a/dodaios/agent_chat/runner_cli.py+++ b/dodaios/agent_chat/runner_cli.py@@ -1528,8 +1528,10 @@ _ACP_CANCEL_GRACE_S: Final[float] = 5.0#: * the runtime must open its session within the handshake limit — generous,#: since a runtime may finish its own setup first (Hermes after an update);#: * afterwards, the model must say something within the idle limit. The-#: counter resets on every frame, and pauses while a tool runs or the-#: person has an approval card open (both take as long as they take).+#: counter resets on every frame, and pauses while a tool runs, the person+#: has an approval card open, or Jarvis' gateway is still serving the+#: runtime's model call (a local model reading a long prompt or thinking+#: sends nothing for minutes; the gateway's own read timeout bounds it)._ACP_HANDSHAKE_TIMEOUT_S: Final[float] = 420.0_ACP_IDLE_TIMEOUT_S: Final[float] = 300.0_ACP_WATCH_TICK_S: Final[float] = 2.0@@ -4196,13 +4198,19 @@ async def _drive_cli(acp = plan.acpif acp is None or hosted:return+ from dodaios.agent_runtimes import gateway+started = time.monotonic()reason = ""while not acp.saw_result and proc.returncode is None:await asyncio.sleep(_ACP_WATCH_TICK_S)now = time.monotonic()- if approval_pending[0] or acp.tool_running():- activity[0] = now # a person or a tool sets this pace+ if (+ approval_pending[0]+ or acp.tool_running()+ or gateway.model_call_open(plan.provider_failure)+ ):+ activity[0] = now # a person, a tool or the model sets this pacecontinueif not acp.handshaken:if now - started > _ACP_HANDSHAKE_TIMEOUT_S:diff --git a/dodaios/agent_runtimes/gateway.py b/dodaios/agent_runtimes/gateway.pyindex 85e4efadf4..8e9c87057f 100644--- a/dodaios/agent_runtimes/gateway.py+++ b/dodaios/agent_runtimes/gateway.py@@ -113,6 +113,11 @@ _FAILURES: dict[Grant, Future[str]] = {}#: answer, the runner reports this instead of a silent empty turn._LAST_FAILURES: weakref.WeakKeyDictionary[Future[str], str] = weakref.WeakKeyDictionary()_TURN_EFFORTS: dict[Grant, str] = {}+#: Model calls the gateway is still serving, per watched turn. A local model+#: may read a long prompt or think for minutes without one byte reaching the+#: runtime; the runner's stall watchdog asks here before it calls that a hang+#: (issue #978). The gateway's own read timeout still ends a dead model call.+_OPEN_CALLS: weakref.WeakKeyDictionary[Future[str], int] = weakref.WeakKeyDictionary()#: Per (provider, account, model): until when calls are refused, why#: (``rate_limited`` / ``usage_limit``) and whether the provider named that#: time (a usage limit's reset is only told when it did).@@ -498,6 +503,25 @@ def _turn_effort(grant: Grant) -> str:return _TURN_EFFORTS.get(grant, "")+def model_call_open(signal: Future[str] | None) -> bool:+ """Whether the gateway is still serving a model call for this turn."""+ if signal is None:+ return False+ with _LOCK:+ return _OPEN_CALLS.get(signal, 0) > 0+++def _track_call(signal: Future[str] | None, step: int) -> None:+ if signal is None:+ return+ with _LOCK:+ count = _OPEN_CALLS.get(signal, 0) + step+ if count > 0:+ _OPEN_CALLS[signal] = count+ else:+ _OPEN_CALLS.pop(signal, None)++def capture_turn(grant: Grant) -> Future[str] | None:"""Bind inference to its ingress turn, before body/setup awaits can yield."""signal = _watch_for(grant)@@ -1350,6 +1374,7 @@ async def _deltas(await queue.put(exc)task = asyncio.get_running_loop().create_task(pump())+ _track_call(signal, 1)try:while True:item = await queue.get()@@ -1359,6 +1384,7 @@ async def _deltas(raise itemyield itemfinally:+ _track_call(signal, -1)task.cancel()with contextlib.suppress(asyncio.CancelledError, Exception):await taskdiff --git a/tests/unit/agent_runtimes/test_acp_runner.py b/tests/unit/agent_runtimes/test_acp_runner.pyindex 367d84c186..8d89f74063 100644--- a/tests/unit/agent_runtimes/test_acp_runner.py+++ b/tests/unit/agent_runtimes/test_acp_runner.py@@ -513,6 +513,19 @@ def test_a_long_tool_call_is_not_a_stall(monkeypatch, tmp_path):assert _finished(events)["status"] == "cancelled"+def test_a_model_call_still_open_at_the_gateway_is_not_a_stall(monkeypatch, tmp_path):+ # A local model reading a long prompt or thinking sends nothing for+ # minutes while the gateway still serves its call (#978).+ from dodaios.agent_runtimes import gateway++ monkeypatch.setattr(rc, "_ACP_IDLE_TIMEOUT_S", 0.5)+ monkeypatch.setattr(rc, "_ACP_WATCH_TICK_S", 0.1)+ monkeypatch.setattr(gateway, "model_call_open", lambda signal: True)+ events, _ = _run_live(monkeypatch, tmp_path, "SLOW", cancel_after=2.5)+ # Ended by the person after 2.5 s, not by the 0.5 s watchdog.+ assert _finished(events)["status"] == "cancelled"++def test_an_open_approval_card_is_not_a_stall(monkeypatch, tmp_path):monkeypatch.setattr(rc, "_ACP_IDLE_TIMEOUT_S", 0.5)monkeypatch.setattr(rc, "_ACP_WATCH_TICK_S", 0.1)diff --git a/tests/unit/agent_runtimes/test_gateway_brains.py b/tests/unit/agent_runtimes/test_gateway_brains.pyindex bc9c3b8ef5..4bd75d1ace 100644--- a/tests/unit/agent_runtimes/test_gateway_brains.py+++ b/tests/unit/agent_runtimes/test_gateway_brains.py@@ -256,3 +256,26 @@ def test_the_subscription_client_waits_for_long_thinking() -> None:assert client._pool._timeout_s == gateway._HOSTED_READ_TIMEOUT_Sfinally:gateway.reset()+++async def test_an_open_model_call_is_visible_to_the_stall_watchdog(plugins) -> None:+ # The runner's watchdog asks the gateway before it calls a silent+ # runtime hung: the model may still be reading or thinking (#978).+ grant = gateway.Grant("agent-1", "openai", scope="s1")+ token = gateway.grant_token("agent-1", "openai", scope="s1")+ signal = gateway.watch_failure(token)+ seen: list[bool] = []++ class _Thinking(_Brain):+ async def complete(self, request: BrainRequest) -> AsyncIterator[BrainDelta]:+ seen.append(gateway.model_call_open(signal))+ yield BrainDelta(content="ok", finish_reason="stop")++ import dodaios.agent_chat.runner_api as runner_api++ runner_api.build_brain = _Thinking # restored by the fixture's monkeypatch+ assert not gateway.model_call_open(signal)+ await _call(grant)+ assert seen == [True]+ assert not gateway.model_call_open(signal)+ gateway.unwatch_failure(token, signal)