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(brain): an unattended turn recovers from an unknown tool instead of ending on the missing-tool phrase (BUG-212)

rubenluetke10-beepe05265776ada
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index 8fed84d1b2..e668749aaa 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -13227,11 +13227,14 @@ class BrainManager:
brain = self._get_brain(name, model)
dispatcher = self._build_dispatcher(
brain, tools_override=tools,
- tool_context={"delivery": "written"},
+ # ``unattended``: the tool-use loop feeds an unknown tool
+ # name back and continues instead of ending the turn on
+ # the spoken "missing tool" phrase (BUG-212).
+ tool_context={"delivery": "written", "unattended": True},
)
agg = await dispatcher.dispatch(
prompt, history=[], intent_level=intent, trace_id=trace_id,
- turn_context=turn_context,
+ turn_context=_scheduled_turn_context(turn_context, tools),
)
return agg.text or ""
except Exception as exc:
@@ -13287,6 +13290,27 @@ _TASK_FALLBACK_ORDER: tuple[str, ...] = (
)
+def _scheduled_turn_context(turn_context: str, tools: dict[str, Any]) -> str:
+ """The per-turn context of an unattended scheduled turn.
+
+ The cached system prompt advertises skills, CLIs and the full tool
+ surface of a live conversation; a scheduled turn sees only its allowlist
+ and has nobody to ask. Say so ON the turn (never in the cached prefix),
+ naming the tools that exist, so the model neither reaches for ``run-skill``
+ nor ends with a question (BUG-212: the briefing tried the morning-routine
+ skill the prompt had advertised and died on "missing tool").
+ """
+ names = ", ".join(sorted(tools)) or "none"
+ block = (
+ "[Scheduled run — unattended] This turn runs on a schedule with no one "
+ f"listening. The only tools that exist in this turn are: {names}. Skills, "
+ "CLIs and any other tool the instructions mention are NOT available here — "
+ "do not call them. Do not ask questions or request permission; work with "
+ "the tools listed and answer with the finished result."
+ )
+ return f"{turn_context}\n\n{block}" if turn_context else block
+
+
def _short_provider_error(exc: Exception) -> str:
"""One readable line for ``last_error`` / the fallback summary — the
exception class and the first 160 characters of its message."""
diff --git a/jarvis/brain/tool_use_loop.py b/jarvis/brain/tool_use_loop.py
index dd8872b1d6..2fabc8c3ed 100644
--- a/jarvis/brain/tool_use_loop.py
+++ b/jarvis/brain/tool_use_loop.py
@@ -604,6 +604,9 @@ class ToolUseLoop:
# Caller-supplied keys for every tool's ``ExecutionContext.config``
# (see BrainDispatcher.tool_context). Per-turn keys set below win.
self._tool_context = dict(tool_context or {})
+ # A scheduled/background turn (BUG-212): an unknown tool name is fed
+ # back and the loop continues — no listener to keep from silence.
+ self._unattended = bool(self._tool_context.get("unattended"))
# Canonical form → registered name, for hyphen/underscore-tolerant
# lookup. A canonical collision (two registered tools differing only in
# separator/case) maps to None: an inexact name must never guess
@@ -1107,7 +1110,18 @@ class ToolUseLoop:
"(model-invented or gated off this turn)",
tid,
)
- tool_result_payload = {"error": f"Tool '{tool_name}' not available"}
+ # Name what IS available: a scheduled turn whose system
+ # prompt advertises skills/CLIs it was not granted recovers
+ # from "run-skill is not here" only if it learns what is
+ # (BUG-212 — the briefing ended on the fallback phrase).
+ available = ", ".join(sorted(self._tools)) or "none"
+ tool_result_payload = {
+ "error": (
+ f"Tool '{tool_name}' is not available in this turn. "
+ f"Available tools: {available}. Continue with those "
+ "and answer from what they return."
+ ),
+ }
unknown_tool_requested = True
elif (
tool_name == "spawn_worker"
@@ -1450,10 +1464,15 @@ class ToolUseLoop:
# overwrite successful evidence from another call with the generic
# "missing tool" phrase. Feed both results back to the model so it
# can report the partial outcome honestly.
+ # An unattended turn (a scheduled task or routine, BUG-212) has no
+ # listener to protect from silence and nobody to re-ask: the error
+ # is already in the history, so let the model take another round
+ # with the tools it does have instead of ending on the phrase.
if (
unknown_tool_requested
and suppress_output is None
and not final_agg.executed_tool_names
+ and not self._unattended
):
suppress_output = _anti_silence_phrase(
user_utterance, reply_language
diff --git a/tests/unit/brain/test_tool_use_loop.py b/tests/unit/brain/test_tool_use_loop.py
index 98bad8ebf4..b5a05c3e23 100644
--- a/tests/unit/brain/test_tool_use_loop.py
+++ b/tests/unit/brain/test_tool_use_loop.py
@@ -643,6 +643,76 @@ async def test_unknown_tool_cannot_overwrite_successful_call() -> None:
assert len(brain.requests) == 2
+class _SkillThenSearchBrain:
+ """Round 1 reaches for ``run-skill`` (advertised by the system prompt, not
+ granted to the turn); round 2 uses the granted tool; round 3 answers."""
+
+ def __init__(self) -> None:
+ self.requests: list[BrainRequest] = []
+
+ async def complete(self, req: BrainRequest) -> AsyncIterator[BrainDelta]:
+ self.requests.append(req)
+ if len(self.requests) == 1:
+ yield BrainDelta(tool_call={"id": "s", "name": "run-skill",
+ "input": {"skill_name": "morning-routine"}})
+ yield BrainDelta(finish_reason="tool_use")
+ return
+ if len(self.requests) == 2:
+ yield BrainDelta(tool_call={"id": "w", "name": "search_web",
+ "input": {"query": "headlines"}})
+ yield BrainDelta(finish_reason="tool_use")
+ return
+ yield BrainDelta(content="Good morning. Two headlines matter today.")
+ yield BrainDelta(finish_reason="stop")
+
+
+class _SearchTool:
+ name = "search_web"
+ schema: dict[str, Any] = {}
+
+
+async def test_unattended_turn_recovers_from_an_unknown_tool() -> None:
+ """BUG-212: the scheduled Morning Briefing tried ``run-skill`` and the
+ turn ended on the spoken "missing tool" phrase. Unattended, the loop
+ feeds the error back — naming what IS available — and keeps going."""
+ brain = _SkillThenSearchBrain()
+ executor = _ExecWithDeniedLog()
+ loop = ToolUseLoop(
+ brain,
+ {"search_web": _SearchTool()},
+ executor, # type: ignore[arg-type]
+ tool_context={"delivery": "written", "unattended": True},
+ )
+
+ result = await loop.run([], user_utterance="compile the morning briefing")
+
+ assert executor.denied and executor.denied[0][0] == "run-skill"
+ assert executor.calls and executor.calls[0][0].name == "search_web"
+ assert "Two headlines" in result.text
+ assert "missing" not in result.text.lower()
+ assert len(brain.requests) == 3
+ # The model learned what it may use from the error it was handed.
+ fed_back = str(brain.requests[1].messages[-1].content)
+ assert "search_web" in fed_back and "not available" in fed_back
+
+
+async def test_attended_turn_keeps_the_spoken_missing_tool_phrase() -> None:
+ """A live voice turn must still never end in silence."""
+ brain = _AliasCallingBrain("totally_made_up_tool")
+ executor = _ExecWithDeniedLog()
+ loop = ToolUseLoop(
+ brain,
+ {"run_shell": _RunShellTool()},
+ executor, # type: ignore[arg-type]
+ )
+
+ result = await loop.run([], user_utterance="show me the last commit")
+
+ assert "missing the right tool" in result.text
+
+
@pytest.mark.asyncio
async def test_howto_guard_publishes_guard_denied_event() -> None:
brain = _Brain()