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(agents): let a routine due at startup wait for the agent brain
rubenluetke10-beepf4a31d9c6205
diff --git a/jarvis/tasks/runner.py b/jarvis/tasks/runner.pyindex e350735293..79215da089 100644--- a/jarvis/tasks/runner.py+++ b/jarvis/tasks/runner.py@@ -135,6 +135,7 @@ class TaskRunner:| None = None,workflow_services: Any = None,owned_action_guard: Callable[[tuple[str, ...]], Awaitable[None]] | None = None,+ agent_brain_wait_s: float = 120.0,) -> None:self._store = storeself._bus = bus@@ -143,6 +144,8 @@ class TaskRunner:self._executor = tool_executorself._tools = tool_registryself._brain = agent_brain+ #: How long an agent run waits for a brain wired after boot.+ self._agent_brain_wait_s = agent_brain_wait_sself._approver = auto_approver#: ``(tags, text, status)`` after an agent action — where a tagged#: task's result also goes (a society agent's routine reports into its@@ -550,6 +553,19 @@ class TaskRunner:TaskStepRecorded(task_id=task_id, seq=seq, kind="log", source_layer="tasks.runner"))+ async def _await_agent_brain(self, cancel_token: CancelToken | None) -> None:+ """Give the agent brain time to arrive when a run starts before it.++ The brain is wired after the deferred boot build, while the scheduler+ is already firing the runs it missed: a routine due at startup died+ with "Agent brain not configured" seconds before the brain existed+ (live 2026-09-27 18:28:30). It waits, cancellable, instead.+ """+ deadline = time.monotonic() + self._agent_brain_wait_s+ while self._brain is None and time.monotonic() < deadline:+ self._check_cancel(cancel_token)+ await asyncio.sleep(0.5)+async def _run_agent(self,task_id: str,@@ -626,6 +642,8 @@ class TaskRunner:task_id=task_id, seq=seq, kind="log", source_layer="tasks.runner"))+ if self._brain is None and owned_result is None and owned_failed is None:+ await self._await_agent_brain(cancel_token)if self._brain is None and owned_result is None:if owned_failed is not None:raise RuntimeError(_seat_then_no_path(owned_failed)) from owned_faileddiff --git a/tests/unit/tasks/test_runner_agent_result.py b/tests/unit/tasks/test_runner_agent_result.pyindex 381231c1f5..47a3fce04a 100644--- a/tests/unit/tasks/test_runner_agent_result.py+++ b/tests/unit/tasks/test_runner_agent_result.py@@ -375,3 +375,41 @@ async def test_a_failed_agent_routine_reports_to_its_chat_and_never_speaks(]row = await store.get(task_id)assert row is not None and row["last_error"].startswith("RuntimeError: ")+++async def test_an_agent_run_waits_for_a_brain_wired_after_boot(store: TaskStore) -> None:+ """A routine due at startup fired before the deferred brain build and died+ with "Agent brain not configured". It now waits for the brain."""+ runner = TaskRunner(store, EventBus(), agent_brain=None, agent_brain_wait_s=5.0)+ spec = TaskSpec(+ title="[agent:Mailbox] Inbox sweep",+ trigger=TriggerAfterDelay(delay_seconds=0.01),+ action=AgentAction(prompt="Sort the inbox."),+ )+ task_id = await store.insert(spec)+ brain = FakeAgentBrain()++ async def wire_later() -> None:+ await asyncio.sleep(0.3)+ runner._brain = brain++ await asyncio.gather(+ asyncio.wait_for(runner.run(task_id, CancelToken()), timeout=5.0), wire_later()+ )+ row = await store.get(task_id)+ assert row is not None and row["state"] == "completed"+ assert brain.prompts+++async def test_an_agent_run_still_fails_when_no_brain_ever_arrives(store: TaskStore) -> None:+ runner = TaskRunner(store, EventBus(), agent_brain=None, agent_brain_wait_s=0.2)+ spec = TaskSpec(+ title="plain",+ trigger=TriggerAfterDelay(delay_seconds=0.01),+ action=AgentAction(prompt="Say hi."),+ )+ task_id = await store.insert(spec)+ await asyncio.wait_for(runner.run(task_id, CancelToken()), timeout=5.0)+ row = await store.get(task_id)+ assert row is not None and row["state"] == "failed"+ assert "Agent brain not configured" in row["last_error"]