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(agentic-ide): keep a pane's own sub-agent fan-out out of the spawn path
Ruben Lütke9955ba30e8ef
diff --git a/jarvis/agentic_ide/intent.py b/jarvis/agentic_ide/intent.pyindex 0058a7b561..1c69b7c217 100644--- a/jarvis/agentic_ide/intent.py+++ b/jarvis/agentic_ide/intent.py@@ -1606,6 +1606,78 @@ def expects_several(user_text: str) -> bool:return bool(_PLURAL_ADDRESS_RE.search(text))+def _spawn_words_describe_pane_work(text: str, candidates: list[str]) -> bool:+ """True when the spawn vocabulary describes what a PANE should do.++ The tie-breaker for the one utterance shape the vehicle stand-down below+ cannot read: telling a coding agent to fan out. "Sub-agent" is not Jarvis+ vocabulary in this workspace — it is what every agentic coding CLI calls its+ own parallel helpers, and asking for them is among the most ordinary things+ a user says to a pane. Live failure 2026-07-27 (voice session 20:00): "let+ Alex and Ellis do a deep dive … and they should spawn swarms of sub-agents"+ named two running panes, was detected as an instruction to both — and was+ then handed to a background mission worker anyway, because the sentence+ contained "sub-agents" and "spawn". Both terminals sat idle.++ The signal is WORD ORDER, and it is the same one a listener uses:++ * "spawn an agent that helps Kai" — the vehicle word OPENS the request, the+ call-sign is what the new agent is for. An order to Jarvis;+ * "Alex should spawn sub-agents" — the call-sign comes first and the vehicle+ word sits inside the work being described. An order to Alex.++ So every vehicle word must stand BEHIND the first named pane. One in front+ is enough to hand the turn back to the spawn path, which keeps the mirror+ bug — a workspace swallowing a genuine delegation request — shut.++ The name has to be CERTAIN (exact, or a spelling folding to the same sound):+ this branch decides against a background mission the user may well have+ wanted, and a merely similar word is not evidence enough to do that.+ """+ if not candidates:+ return False+ from jarvis.brain.spawn_gate import spawn_vehicle_spans++ # Both positions must be measured in the SAME string: canonicalisation+ # rewrites a garbled call-sign ("Elis" → "Ellis") and shifts every offset+ # behind it.+ working = _canonical_text(text, candidates)+ mentions = _mentions(working, candidates, fuzzy=False)+ if not mentions:+ return False+ spans = spawn_vehicle_spans(working)+ if not spans:+ return False+ first_name_at = mentions[0][0]+ return all(start > first_name_at for start, _ in spans)+++def spawn_vehicle_outranks_workspace(+ user_text: str, *, names: list[str] | None = None+) -> bool:+ """True when explicit spawn vocabulary should beat an addressed pane.++ The vehicle stand-down, as ONE function, because it now has two exceptions+ and three callers (``owns_turn`` for both routing gates, and the router's+ Agentic-IDE fast path, which carries its own candidate roster). A caller+ that re-implemented it would strand precisely the exception turns: the spawn+ gate refuses the mission, the fast path refuses to type, and the user is+ left with silence — the failure this whole area exists to end.+ """+ from jarvis.brain.spawn_gate import coding_mode_blocks_spawn, names_spawn_vehicle++ text = (user_text or "").strip()+ if not names_spawn_vehicle(text):+ return False+ if coding_mode_blocks_spawn():+ # No wording reaches a background worker in this mode, so letting the+ # vocabulary win here would only take the turn away from the pane that+ # can still serve it.+ return False+ candidates = _running_names() if names is None else list(names)+ return not _spawn_words_describe_pane_work(text, candidates)++def owns_turn(user_text: str, *, names: list[str] | None = None) -> bool:"""True when the open workspace should handle this turn instead of a spawn.@@ -1619,13 +1691,17 @@ def owns_turn(user_text: str, *, names: list[str] | None = None) -> bool:spawn vehicle ("spawne … Terminals"). The mandatory pane noun is whatmakes claiming it safe, and it holds with no workspace open too — thefeature then opens one, so a background mission would be just as wrong.- 2. Otherwise an utterance that explicitly names the spawn vehicle is NOT+ 2. Coding mode owns every turn it can serve. While the user is IN the+ Agentic IDE, Jarvis does not dispatch its own workers at all+ (``spawn_gate.coding_mode_blocks_spawn``), so an addressed pane must not+ lose the turn to vocabulary that can no longer reach a spawn anyway —+ that would strand the work in the gap between the two gates.+ 3. Otherwise an utterance that explicitly names the spawn vehicle is NOTowned here — asking for a background agent while a workspace happens tobe open is a real request, and stealing it would be the mirror image of- the bug this module fixes.+ the bug this module fixes. The one exception is an utterance whose spawn+ words describe a PANE's work; see ``_spawn_words_describe_pane_work``."""- from jarvis.brain.spawn_gate import names_spawn_vehicle-text = (user_text or "").strip()if not text:return False@@ -1633,7 +1709,7 @@ def owns_turn(user_text: str, *, names: list[str] | None = None) -> bool:return Trueif detect_spawn(text, names=names) is not None:return True- if names_spawn_vehicle(text):+ if spawn_vehicle_outranks_workspace(text, names=names):return Falsereturn detect(text, names=names) is not None@@ -1652,7 +1728,8 @@ __all__ = ["expects_several","owns_turn","references_recent_fleet",- "spawn_instruction","spawn_includes_task",+ "spawn_instruction",+ "spawn_vehicle_outranks_workspace","wants_split",]diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.pyindex 94e7d217fe..c4d586f8a6 100644--- a/jarvis/brain/manager.py+++ b/jarvis/brain/manager.py@@ -5815,11 +5815,15 @@ class BrainManager:# Naming the spawn vehicle outranks the workspace: "spawn an agent that# helps Kai" is a genuine background-worker request even with a- # workspace open. Same test the spawn gate and ``intent.owns_turn`` use,- # so the three cannot drift into disagreeing about one utterance.- from jarvis.brain.spawn_gate import names_spawn_vehicle-- if names_spawn_vehicle(user_text):+ # workspace open. Asked through the shared rule rather than through+ # ``names_spawn_vehicle`` directly, because that stand-down has two+ # exceptions now (coding mode is on; the spawn words describe a PANE's+ # work, "Alex should spawn sub-agents"), and a second hand-written copy+ # of it here would strand exactly those turns: the spawn gate would+ # refuse the mission, this fast path would refuse to type, and the user+ # would get silence. Passed THIS path's roster — it may include a+ # just-closed fleet the global one no longer lists.+ if ide_intent.spawn_vehicle_outranks_workspace(user_text, names=candidates):return Noneout_lang = resolve_output_language(@@ -6539,6 +6543,23 @@ class BrainManager:# _heavy_worker_provider_viable.if not self._heavy_worker_provider_viable():return False+ # Agentic-IDE coding mode forbids an internal worker outright — ahead of+ # the explicit-trigger hoist below, which is negation- AND context-blind+ # and would otherwise read the CLI agent's own fan-out vocabulary+ # ("they should spawn sub-agents") as an order to dispatch a Jarvis+ # mission. Maintainer mandate 2026-07-27; the LLM-chosen path is closed+ # by the same predicate in ``spawn_gate.llm_spawn_allowed``.+ try:+ from jarvis.brain.spawn_gate import coding_mode_blocks_spawn++ if coding_mode_blocks_spawn():+ log.info(+ "force-spawn skipped: Agentic-IDE coding mode is on — "+ "the terminals do this work, no background agent"+ )+ return False+ except Exception as exc: # noqa: BLE001 — optional surface, never fatal+ log.debug("coding-mode spawn check failed, ignoring: %s", exc)# Explicit spawn DECLINE wins over EVERYTHING below, including the# negation-blind explicit-trigger hoist: when the user literally says# "don't spawn a subagent" / "talk to me directly", the trigger worddiff --git a/jarvis/brain/spawn_gate.py b/jarvis/brain/spawn_gate.pyindex ccb54ecfc9..b7f02ee08c 100644--- a/jarvis/brain/spawn_gate.py+++ b/jarvis/brain/spawn_gate.py@@ -185,6 +185,48 @@ def names_spawn_vehicle(user_text: str) -> bool:return bool(_DELEGATION_MARKER_RE.search((user_text or "").strip()))+def spawn_vehicle_spans(user_text: str) -> list[tuple[int, int]]:+ """Character spans of every explicit spawn-vehicle mention, in order.++ The positional view of ``names_spawn_vehicle``, for the one caller that+ needs to know not merely THAT the vehicle was named but WHERE: the+ Agentic-IDE precedence rule has to tell "spawn an agent that helps Kai"+ (an order to Jarvis, vehicle word first) from "Alex should spawn+ sub-agents" (a description of Alex's work, vehicle word behind the+ call-sign). Both share this ONE pattern so the two answers cannot drift.+ """+ return [+ (match.start(), match.end())+ for match in _DELEGATION_MARKER_RE.finditer((user_text or "").strip())+ ]+++def coding_mode_blocks_spawn() -> bool:+ """True while the Agentic IDE is the active mode, which forbids a spawn.++ Maintainer mandate 2026-07-27: inside the coding workspace, "sub-agent" is+ the CLI agent's own fan-out vocabulary — every agentic coding tool has the+ feature and users ask for it constantly. Reading those words as an order to+ dispatch a JARVIS mission worker is a collision the user cannot phrase their+ way out of, so the mode decides instead of the wording: while coding mode is+ on, work goes to the panes on screen and no internal worker is dispatched.++ The mode is deliberately the toggle a user can see (the app-wide coding-mode+ badge), not the mere presence of a workspace: an open workspace with the+ toggle off is "terminals on a screen", and delegation there is a legitimate+ request. Turning the toggle off restores the background agent in full.++ Never raises — the workspace is an optional surface and must never be able+ to break spawn routing; a fault answers "does not block".+ """+ try:+ from jarvis.agentic_ide.session import coding_mode_active # noqa: PLC0415++ return coding_mode_active()+ except Exception: # noqa: BLE001 — optional surface, never fatal to routing+ return False++def _agentic_ide_claims_turn(text: str) -> bool:"""True when an open Agentic-IDE terminal is being addressed instead.@@ -214,6 +256,13 @@ def llm_spawn_allowed(user_text: str) -> bool:text = (user_text or "").strip()if not text:return False+ # Coding mode outranks EVERYTHING below, including explicit delegation+ # vocabulary. See ``coding_mode_blocks_spawn`` — inside the Agentic IDE the+ # word "sub-agent" belongs to the CLI agent in the pane, so no wording may+ # unlock an internal worker while that mode is on.+ if coding_mode_blocks_spawn():+ log.info("spawn gate: Agentic-IDE coding mode is on — no background agent")+ return Falseif _is_decline_or_feature_talk(text):log.info("spawn gate: decline / feature talk — spawn blocked")return False@@ -263,11 +312,43 @@ SPAWN_BLOCKED_MODEL_FEEDBACK: str = ()+# The coding-mode variant. The generic text above would mislead here: it invites+# the model to OFFER a background agent, and in the Agentic IDE that offer is+# exactly the wrong next move — the work belongs in a pane the user is looking+# at. "Sub-agents" in this mode means the CLI agent's own fan-out, which happens+# inside the terminal once the brief arrives there.+SPAWN_BLOCKED_CODING_MODE_FEEDBACK: str = (+ "spawn_worker was not executed: the Agentic-IDE coding mode is ON, and in "+ "that mode Jarvis never starts its own background workers. The coding "+ "agents in the named terminals do this work. Send the user's request to the "+ "right terminal with the agentic-ide-prompt function, in the user's own "+ "words — including any instruction to spawn sub-agents, which is an "+ "instruction for the agent IN that terminal to carry out itself. If no "+ "terminal is addressed, answer inline or ask which one should take it. Do "+ "not offer a background agent."+)+++def spawn_blocked_feedback() -> str:+ """The tool-error text matching WHY the spawn was blocked.++ One function so the classic and realtime paths cannot teach the model two+ different next moves for the same block.+ """+ if coding_mode_blocks_spawn():+ return SPAWN_BLOCKED_CODING_MODE_FEEDBACK+ return SPAWN_BLOCKED_MODEL_FEEDBACK++__all__ = ["OFFER_WINDOW",+ "SPAWN_BLOCKED_CODING_MODE_FEEDBACK","SPAWN_BLOCKED_MODEL_FEEDBACK","SPAWN_VEHICLE_TOOL_NAMES","DelegationOfferWindow",+ "coding_mode_blocks_spawn","llm_spawn_allowed","names_spawn_vehicle",+ "spawn_blocked_feedback",+ "spawn_vehicle_spans",]diff --git a/jarvis/brain/tool_use_loop.py b/jarvis/brain/tool_use_loop.pyindex b9e8072e35..a5512b81db 100644--- a/jarvis/brain/tool_use_loop.py+++ b/jarvis/brain/tool_use_loop.py@@ -26,9 +26,9 @@ from jarvis.brain.cu_gate import (llm_computer_use_allowed,)from jarvis.brain.spawn_gate import (- SPAWN_BLOCKED_MODEL_FEEDBACK,SPAWN_VEHICLE_TOOL_NAMES,llm_spawn_allowed,+ spawn_blocked_feedback,)from jarvis.core.protocols import Brain, BrainMessage, BrainRequest, ImageBlock, Toolfrom jarvis.core.turn_language import resolve_output_language, resolve_turn_language@@ -927,7 +927,7 @@ class ToolUseLoop:tool_result_payload = {"success": False,"output": None,- "error": SPAWN_BLOCKED_MODEL_FEEDBACK,+ "error": spawn_blocked_feedback(),}elif (tool_name in CU_VEHICLE_TOOL_NAMESdiff --git a/jarvis/realtime/tools.py b/jarvis/realtime/tools.pyindex cb322e7bf4..9d41d45249 100644--- a/jarvis/realtime/tools.py+++ b/jarvis/realtime/tools.py@@ -15,9 +15,9 @@ from jarvis.brain.cu_gate import (llm_computer_use_allowed,)from jarvis.brain.spawn_gate import (- SPAWN_BLOCKED_MODEL_FEEDBACK,SPAWN_VEHICLE_TOOL_NAMES,llm_spawn_allowed,+ spawn_blocked_feedback,)from jarvis.brain.tool_use_loop import (_is_instructional_question,@@ -410,7 +410,7 @@ class RealtimeToolBridge:# spoken turn asks for one (or confirms an offer one turn later).# Deterministic — prompt-side discouragement failed repeatedly.# See jarvis/brain/spawn_gate.py.- message = SPAWN_BLOCKED_MODEL_FEEDBACK+ message = spawn_blocked_feedback()elif name in CU_VEHICLE_TOOL_NAMES and not llm_computer_use_allowed(user_text):diff --git a/tests/unit/agentic_ide/test_coding_mode_spawn_gate.py b/tests/unit/agentic_ide/test_coding_mode_spawn_gate.pynew file mode 100644index 0000000000..069e62e04e--- /dev/null+++ b/tests/unit/agentic_ide/test_coding_mode_spawn_gate.py@@ -0,0 +1,216 @@+"""Coding mode forbids an internal worker; a pane's own fan-out stays its work.++Two rules, one collision. "Sub-agent" is the vocabulary every agentic coding CLI+uses for its own parallel helpers, and it is also the word that makes Jarvis+dispatch a background mission worker. While the user is inside the Agentic IDE+those two readings point in opposite directions, and the user cannot phrase+their way out of it — so the MODE decides, not the wording.++Live failure these pin (voice session 2026-07-27 20:00, maintainer mandate the+same day): "let Alex and Ellis do a deep dive … and they should spawn swarms of+sub-agents". Both call-signs named running panes, the addressing was detected+correctly — and the turn went to an invisible background worker anyway because+the sentence contained "sub-agents" and "spawn". Both terminals sat idle while+the assistant reported that the agents had been briefed.++The other direction is guarded just as hard: with coding mode off, asking for a+background agent must still get one. That feature is the reason the vehicle+stand-down exists at all, and breaking it while fixing the above would only swap+which half of the user's intent gets lost.+"""+from __future__ import annotations++from pathlib import Path++import pytest++from jarvis.agentic_ide import session as session_mod+from jarvis.agentic_ide.intent import owns_turn, spawn_vehicle_outranks_workspace+from jarvis.agentic_ide.session import Registry, reset_registry+from jarvis.brain.spawn_gate import (+ OFFER_WINDOW,+ SPAWN_BLOCKED_CODING_MODE_FEEDBACK,+ SPAWN_BLOCKED_MODEL_FEEDBACK,+ coding_mode_blocks_spawn,+ llm_spawn_allowed,+ spawn_blocked_feedback,+)+from tests.fakes.fake_pty_manager import FakePtyManager++# The live utterance, in the spelling the transcript actually produced —+# including "Elis" for the pane called Ellis, which is what made the phonetic+# folding part of this path rather than an incidental detail.+LIVE_TURN = (+ "Kannst du bitte einen Alex und Elis mal einen Deep Dive machen " # i18n-allow: transcript+ "lassen und ich möchte, dass die nach konkreten Fehlern bei " # i18n-allow: transcript+ "unserem Wiki System suchen. Die sollen nur lesen und sie sollen " # i18n-allow: transcript+ "Schwärme von Sub Agents spawnen, um kompletten Kontext für die " # i18n-allow: transcript+ "Codebasis zu erlangen." # i18n-allow: transcript+)++PANES = ["Alex", "Ellis", "Casey"]++# The strongest delegation wording the gate knows, spoken. If THIS reaches a+# mission worker while coding mode is on, nothing said inside the IDE is safe+# from the collision.+EXPLICIT_DELEGATION = "Spawne bitte einen Agenten im Hintergrund" # i18n-allow: input vocab++# The mirror cases: the vehicle word comes FIRST, so these are orders to Jarvis+# even though two of them also name a running pane.+GENUINE_DELEGATIONS = [+ "Spawne einen Agenten, der Alex hilft die Tests zu fixen", # i18n-allow: input vocab+ "spawn an agent that helps Alex fix the failing tests",+ "Delegiere das im Hintergrund an einen Worker", # i18n-allow: input vocab+]++# "Open five more panes" — the pane-noun path, which is decided before any of+# the vehicle logic and must stay exactly as it was.+MORE_TERMINALS = "Öffne bitte fünf neue Claude Code Terminals" # i18n-allow: input vocab++[email protected](autouse=True)+def clean_registry():+ reset_registry()+ OFFER_WINDOW.disarm()+ yield+ reset_registry()+ OFFER_WINDOW.disarm()+++def wired(monkeypatch: pytest.MonkeyPatch) -> Registry:+ registry = Registry(pty_manager=FakePtyManager())+ monkeypatch.setattr(session_mod, "agent_argv", lambda name: (f"/usr/bin/{name}",))+ monkeypatch.setattr(session_mod, "get_registry", lambda: registry)+ return registry+++async def _coding_mode(registry: Registry, folder: Path) -> None:+ await registry.start(str(folder), [{"agent": "claude"}])+ registry.set_focus_mode(True)+++# --------------------------------------------------------------------------- #+# Part A — the mode is the switch #+# --------------------------------------------------------------------------- #+++async def test_coding_mode_blocks_even_an_explicit_spawn_request(+ wired: Registry, tmp_path: Path+) -> None:+ """The clearest possible delegation request still starts no worker.++ Deliberately the strongest wording the gate knows: if THIS reaches a mission+ worker, nothing the user says inside the IDE is safe from the collision.+ """+ await _coding_mode(wired, tmp_path)+ assert coding_mode_blocks_spawn() is True+ assert llm_spawn_allowed(EXPLICIT_DELEGATION) is False+++async def test_workspace_without_the_toggle_still_delegates(+ wired: Registry, tmp_path: Path+) -> None:+ """Terminals on a screen are not the mode — the background agent stays.++ The toggle is what the user can see (the app-wide coding-mode badge), so it+ is what may take a feature away from them.+ """+ await wired.start(str(tmp_path), [{"agent": "claude"}])+ assert coding_mode_blocks_spawn() is False+ assert llm_spawn_allowed(EXPLICIT_DELEGATION) is True+++async def test_leaving_coding_mode_restores_the_background_agent(+ wired: Registry, tmp_path: Path+) -> None:+ """The block is a mode, not a latch — turning it off gives the feature back."""+ await _coding_mode(wired, tmp_path)+ assert llm_spawn_allowed("Spawn a background worker for this") is False+ wired.set_focus_mode(False)+ assert llm_spawn_allowed("Spawn a background worker for this") is True+++def test_no_workspace_leaves_the_gate_untouched() -> None:+ """With no workspace at all, the gate behaves exactly as it always did."""+ assert coding_mode_blocks_spawn() is False+ assert llm_spawn_allowed("Spawn an agent to research this") is True+ assert llm_spawn_allowed("What is the capital of Portugal?") is False+++async def test_blocked_feedback_tells_the_model_to_use_a_terminal(+ wired: Registry, tmp_path: Path+) -> None:+ """A block inside the IDE must not invite an offer of a background agent.++ The generic text asks the model to OFFER delegation on the next turn, which+ is the wrong next move here — the work belongs in a pane on screen.+ """+ assert spawn_blocked_feedback() == SPAWN_BLOCKED_MODEL_FEEDBACK+ await _coding_mode(wired, tmp_path)+ message = spawn_blocked_feedback()+ assert message == SPAWN_BLOCKED_CODING_MODE_FEEDBACK+ assert "agentic-ide-prompt" in message+++# --------------------------------------------------------------------------- #+# Part B — a pane's own fan-out is the pane's work #+# --------------------------------------------------------------------------- #+++def test_live_turn_reaches_the_addressed_panes() -> None:+ """The 2026-07-27 20:00 utterance belongs to Alex and Ellis, not to a worker.++ Asserted with the toggle OFF on purpose: whether coding mode was on during+ the live session cannot be recovered, so the fix may not depend on it.+ """+ assert coding_mode_blocks_spawn() is False+ assert owns_turn(LIVE_TURN, names=PANES) is True+++def test_pane_told_to_fan_out_keeps_the_turn_in_english() -> None:+ """Same shape, plainly worded — the rule is about word order, not locale."""+ text = "Alex should spawn a swarm of sub-agents to map the codebase"+ assert owns_turn(text, names=PANES) is True++[email protected]("text", GENUINE_DELEGATIONS)+def test_genuine_delegation_still_outranks_an_open_workspace(text: str) -> None:+ """The mirror bug stays shut: the vehicle word FIRST is an order to Jarvis.++ "Spawn an agent that helps Alex" names a pane too — as what the new agent is+ FOR. Reading it as an instruction to Alex would swallow a background request+ the user genuinely made, which is the failure the vehicle stand-down exists+ to prevent.+ """+ assert spawn_vehicle_outranks_workspace(text, names=PANES) is True+ assert owns_turn(text, names=PANES) is False+++def test_spawn_vocabulary_without_any_named_pane_is_never_the_workspace() -> None:+ """No call-sign, no claim — the ordinary delegation request is untouched."""+ text = "Spawn a background agent that audits the wiki system"+ assert spawn_vehicle_outranks_workspace(text, names=PANES) is True+ assert owns_turn(text, names=PANES) is False+++async def test_coding_mode_hands_the_turn_to_the_pane(+ wired: Registry, tmp_path: Path+) -> None:+ """In coding mode the stand-down lifts entirely.++ Not cosmetic: with Part A blocking the spawn, a turn the workspace also+ refused would reach nothing at all — the spawn gate would decline the+ mission, the router's fast path would decline to type, and the user would+ get silence. The two gates have to agree in the same direction.+ """+ await _coding_mode(wired, tmp_path)+ pane = wired.session.terminals[0].name+ text = f"{pane} should spawn sub-agents and analyze the wiki system"+ assert spawn_vehicle_outranks_workspace(text, names=[pane]) is False+ assert owns_turn(text, names=[pane]) is True+++def test_asking_for_more_terminals_is_still_the_workspace() -> None:+ """The pane-noun path is untouched — it is checked before any of this."""+ assert owns_turn(MORE_TERMINALS, names=PANES) is True