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(brain): Computer-Use goal inherits recent conversation context
Ruben Lütke1920fb5008cb
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.pyindex e1e8e3a18c..6e9f363f75 100644--- a/jarvis/brain/manager.py+++ b/jarvis/brain/manager.py@@ -120,6 +120,15 @@ _TURN_HISTORY_OVERRIDE: ContextVar[tuple[BrainMessage, ...] | None] = ContextVardefault=None,)+#: Bounds for the conversation-context block appended to a Computer-Use goal.+#: The deterministic gate ships the RAW current utterance as the mission goal;+#: a correction / follow-up turn ("that is the wrong server", "do it with+#: Computer-Use") carries no task of its own, so the goal must inherit the+#: recent turns that defined it. Kept small: the CU step prompt repeats the+#: goal on every screenshot cycle.+_CU_CONTEXT_MAX_MESSAGES = 8+_CU_CONTEXT_MAX_MESSAGE_CHARS = 240+#: Hard bound on the per-turn vision capture (Wave-3 latency fix). ``vision.#: current()`` can stall (mss BitBlt hang, paused-state miss, slow disk); without#: a cap it blocks the whole brain turn on the hot path. On timeout the turn@@ -5343,6 +5352,41 @@ class BrainManager:facts=facts,)+ def _cu_goal_with_context(self, goal: str) -> str:+ """Append bounded recent conversation context to a Computer-Use goal.++ The deterministic local-action gate ships the raw current utterance as+ the mission goal. Without the turns that defined the task, a follow-up+ or correction turn hands the loop a vacuous goal and the verifier+ passes against it (live forensic 2026-07-15 07:59: after a failed+ Discord-announcement mission, "Ihr macht es doch mit Computer-Use." # i18n-allow: quoted German speech input from the forensic+ became the whole goal — the loop opened Discord's Friends view and+ announced success). Delegated turns carry their history in+ ``_TURN_HISTORY_OVERRIDE``; classic turns fall back to the live+ ``self._history``. No history → the goal stays bare.+ """+ history = _TURN_HISTORY_OVERRIDE.get()+ if history is None:+ history = tuple(getattr(self, "_history", None) or ())+ lines: list[str] = []+ for message in history[-_CU_CONTEXT_MAX_MESSAGES:]:+ role = "User" if getattr(message, "role", "") == "user" else "Jarvis"+ content = " ".join(str(getattr(message, "content", "") or "").split())+ if not content:+ continue+ if len(content) > _CU_CONTEXT_MAX_MESSAGE_CHARS:+ content = f"{content[:_CU_CONTEXT_MAX_MESSAGE_CHARS]} …"+ lines.append(f"{role}: {content}")+ if not lines:+ return goal+ context = "\n".join(lines)+ return (+ f"{goal}\n\n"+ "CONVERSATION CONTEXT (recent turns, oldest first — the goal above "+ "may refer back to these):\n"+ f"{context}"+ )+async def _run_local_action_fast_path(self,user_text: str,@@ -5516,7 +5560,9 @@ class BrainManager:self._run_computer_use_background(tool=tool,harness_name=harness_name,- prompt=plan.prompt or user_text,+ # A follow-up/correction turn carries no task of its own —+ # the goal inherits the recent turns that defined it.+ prompt=self._cu_goal_with_context(plan.prompt or user_text),timeout_s=timeout_s,user_text=user_text,trace_id=tid,diff --git a/tests/unit/brain/test_computer_use_offload.py b/tests/unit/brain/test_computer_use_offload.pyindex edd6d7f52d..28f10399bb 100644--- a/tests/unit/brain/test_computer_use_offload.py+++ b/tests/unit/brain/test_computer_use_offload.py@@ -415,3 +415,120 @@ async def test_manager_retains_signed_mission_result_for_follow_up() -> None:assert "Jarvis-Agent mission result" in contentassert "019f5ca2-e30f" in contentassert "result_uri" in content+++# ---------------------------------------------------------------------------+# Conversation context in the Computer-Use goal. The deterministic local-action+# gate ships the RAW current utterance as the mission goal. A correction or+# follow-up turn carries no task of its own — without the turns that defined the+# task, the mission verifier passes against a vacuous goal. Live forensic+# 2026-07-15 07:59: after a failed Discord-announcement mission the user said+# "Ihr macht es doch mit Computer-Use."; that bare sentence became the whole # i18n-allow+# goal, the loop opened Discord's Friends view, and the verifier announced+# success. The goal must lead with the latest instruction and carry a bounded+# context block of the recent turns.+# ---------------------------------------------------------------------------+++class _RecordingExecutor:+ """tool_executor stand-in that records the harness dispatch arguments."""++ def __init__(self) -> None:+ self.args: dict | None = None++ async def execute(self, tool, args, *, user_utterance, trace_id): # noqa: ANN001+ self.args = args+ return SimpleNamespace(+ success=True,+ output={+ "harness": "screenshot",+ "exit_code": 0,+ "stdout": "[cu] done at step 1.1 (verified: ok)",+ "stderr": "",+ "cost_usd": 0.0,+ "duration_ms": 10,+ },+ error=None,+ )+++async def test_cu_goal_carries_recent_conversation_context(monkeypatch) -> None:+ """A delegated follow-up turn inherits the task from the turn history."""+ from jarvis.brain.manager import _TURN_HISTORY_OVERRIDE+ from jarvis.core.protocols import BrainMessage++ bus = _FakeBus()+ executor = _RecordingExecutor()+ mgr = _make_manager(executor, bus)+ utterance = "Ihr macht es doch mit Computer-Use." # i18n-allow: German speech-input fixture+ plan = LocalActionPlan(+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt=utterance+ )+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)++ token = _TURN_HISTORY_OVERRIDE.set((+ BrainMessage(+ role="user",+ content=(+ "Öffne meinen Discord-Server Personal Jarvis und kündige an, " # i18n-allow: German speech-input fixture+ "dass übermorgen ein Live-Event stattfindet." # i18n-allow: German speech-input fixture+ ),+ ),+ BrainMessage(role="assistant", content="Alles klar, ich kümmere mich darum."), # i18n-allow: German voice fixture+ ))+ try:+ await mgr._run_local_action_fast_path(utterance)+ finally:+ _TURN_HISTORY_OVERRIDE.reset(token)+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))++ prompt = (executor.args or {}).get("prompt", "")+ assert prompt.startswith(utterance), prompt+ assert "Personal Jarvis" in prompt, (+ f"the goal must inherit the task from the recent turns: {prompt!r}"+ )+ assert "Live-Event" in prompt, prompt+++async def test_cu_goal_without_history_stays_bare(monkeypatch) -> None:+ """A first-turn command has no context to add — the goal stays unchanged."""+ bus = _FakeBus()+ executor = _RecordingExecutor()+ mgr = _make_manager(executor, bus)+ plan = LocalActionPlan(+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt="open chrome"+ )+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)++ await mgr._run_local_action_fast_path("öffne chrome") # i18n-allow+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))++ assert (executor.args or {}).get("prompt") == "open chrome"+++async def test_cu_goal_context_falls_back_to_live_history(monkeypatch) -> None:+ """Classic-pipeline turns (no override) use the manager's own history."""+ from jarvis.core.protocols import BrainMessage++ bus = _FakeBus()+ executor = _RecordingExecutor()+ mgr = _make_manager(executor, bus)+ mgr._history = [+ BrainMessage(role="user", content="Open the Personal Jarvis server."),+ BrainMessage(role="assistant", content="On it."),+ ]+ utterance = "Du bist nicht im richtigen Server." # i18n-allow: German speech-input fixture+ plan = LocalActionPlan(+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt=utterance+ )+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)++ await mgr._run_local_action_fast_path(utterance)+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))++ prompt = (executor.args or {}).get("prompt", "")+ assert prompt.startswith(utterance)+ assert "Personal Jarvis" in prompt, prompt