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.

chore: auto-save WIP via Claude stop-hook safety net (2026-06-30 18:09)

Ruben Lütke1a197fddfe20
diff --git a/jarvis/brain/manager.py b/jarvis/brain/manager.py
index 8341432570..a3b03e5663 100644
--- a/jarvis/brain/manager.py
+++ b/jarvis/brain/manager.py
@@ -4963,6 +4963,17 @@ class BrainManager:
canned=lambda: action_phrase("cu_crashed", lang),
latency_budget_ms=2000,
)
+ # Ground the finished outcome in the LIVE conversation history so the
+ # model's NEXT turn knows the on-screen action ran and how it ended.
+ # The outcome is offloaded fire-and-forget and only ever rode the
+ # announcement bus (spoken, then gone) — it never re-entered _history,
+ # so the model believed the screen action SUCCEEDED (it saw only the
+ # optimistic ACK) and answered a follow-up "why didn't it work?" against
+ # a stale unrelated error (live forensic 2026-06-30: a failed Spotify
+ # screen action was explained with an old Google-Calendar auth error).
+ self._append_cu_outcome_to_history(
+ user_request=user_text, outcome_text=text, diagnostic=diag,
+ )
# AD-OE6 zero silent drops: ALWAYS speak the outcome at the next turn
# boundary (announcement -> scrub_for_voice -> TTS).
try:
@@ -4978,6 +4989,50 @@ class BrainManager:
except Exception: # noqa: BLE001
log.debug("CU-background completion announce failed", exc_info=True)
+ def _append_cu_outcome_to_history(
+ self,
+ *,
+ user_request: str,
+ outcome_text: str,
+ diagnostic: str | None,
+ ) -> None:
+ """Ground a finished background Computer-Use outcome in the live history.
+
+ A desktop action is offloaded fire-and-forget, so its outcome lands AFTER
+ the optimistic ACK ("On it, I'll do that on screen") was already appended
+ as the turn's assistant message. Without this, ``_history`` shows only the
+ ACK and the model never learns whether the screen action actually
+ succeeded — so a later "why didn't it work?" is answered against whatever
+ OTHER failure is still in context (live forensic 2026-06-30: a failed
+ Spotify screen action was explained with a stale Google-Calendar auth
+ error). Append an honest assistant note carrying the spoken outcome PLUS
+ the real technical reason — which the humanized spoken readback hides — so
+ the next turn is grounded in what actually happened. Pure in-memory
+ append, no LLM, no IO (off the hot path anyway). ``user_request`` is
+ accepted for call-site symmetry/debuggability; the ACK already names the
+ request in history, so the note stays compact.
+ """
+ history = getattr(self, "_history", None)
+ if history is None:
+ return
+ spoken = (outcome_text or "").strip()
+ diag = (diagnostic or "").strip()
+ if not spoken and not diag:
+ return
+ note = spoken
+ if diag:
+ # The spoken readback is humanized to "didn't work on screen"; the
+ # model needs the REAL cause to answer a follow-up honestly. Mark it
+ # clearly as a non-spoken background detail so the model treats it as
+ # context, not as something it already said aloud.
+ note = (
+ f"{note}\n\n(Background on-screen-action detail, not spoken aloud "
+ f"— for your context on a follow-up: {diag})"
+ ).strip()
+ history.append(BrainMessage(role="assistant", content=note))
+ if len(history) > self._HISTORY_MAX:
+ self._history = history[-self._HISTORY_MAX:]
+
async def _record_response_side_effects(
self,
*,
diff --git a/tests/unit/brain/test_computer_use_offload.py b/tests/unit/brain/test_computer_use_offload.py
index 958b5ce484..b750772ebf 100644
--- a/tests/unit/brain/test_computer_use_offload.py
+++ b/tests/unit/brain/test_computer_use_offload.py
@@ -211,3 +211,116 @@ async def test_three_parallel_cancels_speak_nothing(monkeypatch) -> None:
assert not completions, (
f"three hangup-cancelled missions must speak nothing; got {len(completions)}"
)
+
+
+# ---------------------------------------------------------------------------
+# Conversation continuity: a finished background CU outcome must be written back
+# into the LIVE history (BrainManager._history — the model's next-turn context).
+#
+# Live forensic 2026-06-30: the user asked to open Spotify on screen; the action
+# failed (exit 2, vision-provider chain exhausted). The spoken failure readback
+# rode AnnouncementRequested(kind="completion") and was NEVER recorded in
+# _history. So the model's only "problem" in context was a stale Google-Calendar
+# auth error from an earlier turn — and a follow-up "why don't you get one?" was
+# answered against the CALENDAR, the wrong subsystem. Grounding the outcome (and
+# its real technical reason) in history fixes the subsystem confusion at the root.
+# ---------------------------------------------------------------------------
+
+
+async def test_cu_failure_outcome_is_written_back_to_history(monkeypatch) -> None:
+ bus = _FakeBus()
+ # exit 2 here = the vision-provider chain was exhausted (the real 2026-06-30
+ # cause); the harness writes the technical reason into stderr.
+ output = {
+ "harness": "screenshot",
+ "exit_code": 2,
+ "stdout": "",
+ "stderr": (
+ "[cu] giving up after 3 model failures (last: ComputerUseLoop "
+ "provider chain failed: no vision-capable provider reachable)"
+ ),
+ "cost_usd": 0.0,
+ "duration_ms": 9700,
+ }
+ executor = _SlowHarnessExecutor(
+ output=output, success=False, error="exit 2", delay=0.05
+ )
+ mgr = _make_manager(executor, bus)
+ plan = LocalActionPlan(
+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt="open spotify"
+ )
+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)
+
+ await mgr._run_local_action_fast_path("öffne mein spotify und spiel das lied")
+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))
+
+ # The failed screen action must be grounded in the live history so the model
+ # knows it failed (no stale-error confusion on the next turn).
+ assert mgr._history, "the failed CU outcome must be recorded in the live history"
+ last = mgr._history[-1]
+ assert last.role == "assistant", f"unexpected role: {last.role!r}"
+ content = str(last.content).lower()
+ # carries BOTH the fact it was an on-screen action AND the real technical
+ # reason the humanized spoken readback hid.
+ assert "screen" in content or "bildschirm" in content, content
+ assert "provider chain" in content or "vision" in content, (
+ f"the real technical reason must be grounded for a faithful follow-up: {content!r}"
+ )
+
+
+async def test_cu_success_outcome_is_written_back_to_history(monkeypatch) -> None:
+ bus = _FakeBus()
+ output = {
+ "harness": "screenshot",
+ "exit_code": 0,
+ "stdout": "[cu] done at step 2.1 (verified: Spotify is open and the song is playing)",
+ "stderr": "",
+ "cost_usd": 0.0,
+ "duration_ms": 4200,
+ }
+ executor = _SlowHarnessExecutor(output=output, success=True, delay=0.05)
+ mgr = _make_manager(executor, bus)
+ plan = LocalActionPlan(
+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt="open spotify"
+ )
+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)
+
+ await mgr._run_local_action_fast_path("öffne spotify und spiel das lied")
+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))
+
+ assert mgr._history, "a successful CU outcome must also be recorded in history"
+ last = mgr._history[-1]
+ assert last.role == "assistant"
+ assert "spotify" in str(last.content).lower(), str(last.content)
+
+
+async def test_cu_user_cancel_writes_nothing_to_history(monkeypatch) -> None:
+ """A user-initiated cancel (exit 130 / "auflegen") speaks nothing AND must
+ not pollute the history — there is no outcome the user is waiting on."""
+ bus = _FakeBus()
+ output = {
+ "harness": "screenshot",
+ "exit_code": 130,
+ "stdout": "",
+ "stderr": "[cu] cancelled mid-batch\n",
+ "cost_usd": 0.0,
+ "duration_ms": 6200,
+ }
+ executor = _SlowHarnessExecutor(
+ output=output, success=False, error="exit 130", delay=0.05
+ )
+ mgr = _make_manager(executor, bus)
+ plan = LocalActionPlan(
+ mode=LocalActionMode.COMPUTER_USE, harness="computer-use", prompt="do it"
+ )
+ monkeypatch.setattr("jarvis.brain.manager.match_local_action", lambda _t: plan)
+
+ await mgr._run_local_action_fast_path("mach einen screenshot")
+ await asyncio.gather(*getattr(mgr, "_cu_background_tasks", set()))
+
+ assert mgr._history == [], (
+ f"a silent user cancel must not write to history; got {mgr._history!r}"
+ )