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(agents): announce a failed routine as a sentence, not an exception line

rubenluetke10-beepe1f2aac9baa8
diff --git a/jarvis/tasks/runner.py b/jarvis/tasks/runner.py
index 4d355b1b47..00082b82ac 100644
--- a/jarvis/tasks/runner.py
+++ b/jarvis/tasks/runner.py
@@ -245,7 +245,10 @@ class TaskRunner:
if template:
await self._announce(template, fail_ctx)
elif "society" in tags:
- await self._announce(error_msg, fail_ctx)
+ # The template path formats ``{…}``; an error text is not a
+ # template, so its braces are escaped before it goes through.
+ spoken = spoken_routine_failure(str(getattr(spec, "title", "") or ""), error_msg)
+ await self._announce(spoken.replace("{", "{{").replace("}", "}}"), fail_ctx)
return
duration_ms = int((time.perf_counter() - start) * 1000)
@@ -872,6 +875,29 @@ def _event_context(trigger_event: dict[str, Any] | None) -> dict[str, Any]:
return {k: v for k, v in trigger_event.items() if k not in drop}
+_EXCEPTION_PREFIX_RE = re.compile(r"^(?:[A-Za-z_][\w.]*(?:Error|Exception)):\s*")
+_EXCEPTION_NAME_RE = re.compile(r"[A-Za-z_][\w.]*(?:Error|Exception)")
+_AGENT_TITLE_TAG_RE = re.compile(r"^\s*\[agent:[^\]]*\]\s*")
+_ROUTINE_WRAPPER_RE = re.compile(r"^The routine chat failed:\s*", re.IGNORECASE)
+
+
+def spoken_routine_failure(title: str, error: str) -> str:
+ """The sentence an agent routine's failure is announced with.
+
+ ``last_error`` keeps the precise ``Type: message`` line for the Runs tab;
+ read aloud (and turned into a conversation title) that line was
+ "RuntimeError: The routine chat failed: …". A person hears which routine
+ failed and why, without the exception class or the wrapper phrase.
+ """
+ reason = _EXCEPTION_PREFIX_RE.sub("", error.strip())
+ reason = _ROUTINE_WRAPPER_RE.sub("", reason).strip().rstrip(".")
+ if _EXCEPTION_NAME_RE.fullmatch(reason):
+ reason = "" # a bare class name tells a listener nothing
+ name = _AGENT_TITLE_TAG_RE.sub("", title).strip()
+ head = f'The routine "{name}" failed' if name else "A routine failed"
+ return f"{head}: {reason}." if reason else f"{head}."
+
+
def _safe_format(template: str, ctx: dict[str, Any]) -> str:
"""Interpolate ``{field}`` placeholders from ``ctx``; never raise.
diff --git a/tests/unit/tasks/test_runner_agent_result.py b/tests/unit/tasks/test_runner_agent_result.py
index 15204bbc88..dd7f1b6e10 100644
--- a/tests/unit/tasks/test_runner_agent_result.py
+++ b/tests/unit/tasks/test_runner_agent_result.py
@@ -331,3 +331,30 @@ async def test_no_brain_after_seat_failure_says_there_was_no_other_path(
assert row is not None and row["state"] == "failed"
assert row["last_error"] is not None
assert "not rerouted" in row["last_error"]
+
+
+class FailingAgentBrain(FakeAgentBrain):
+ async def run_task(self, **kwargs: Any):
+ raise RuntimeError("The routine chat failed: Individual quota reached {see plan}")
+
+
+async def test_a_failed_agent_routine_is_announced_as_a_sentence(store: TaskStore) -> None:
+ """Read aloud, the raw ``last_error`` was "RuntimeError: The routine chat
+ failed: …" — and it became a conversation title. The announcement names
+ the routine and the reason; the stored error keeps the precise line."""
+ bus = EventBus()
+ spoken = _collect(bus, AnnouncementRequested)
+ runner = TaskRunner(store, bus, agent_brain=FailingAgentBrain())
+ spec = TaskSpec(
+ title="[agent:Mailbox] Inbox sweep",
+ trigger=TriggerAfterDelay(delay_seconds=0.01),
+ action=AgentAction(prompt="Sort the inbox."),
+ tags=("society", "agent:mailbox"),
+ )
+ task_id = await store.insert(spec)
+ await asyncio.wait_for(runner.run(task_id, CancelToken()), timeout=2.0)
+ assert [e.text for e in spoken] == [
+ 'The routine "Inbox sweep" failed: Individual quota reached {see plan}.'
+ ]
+ row = await store.get(task_id)
+ assert row is not None and row["last_error"].startswith("RuntimeError: ")