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-07-02 19:59)

Ruben Lütke6232127660a3
diff --git a/jarvis/cu/engine.py b/jarvis/cu/engine.py
index 98dba48f39..2faa960bfc 100644
--- a/jarvis/cu/engine.py
+++ b/jarvis/cu/engine.py
@@ -106,7 +106,9 @@ _SYSTEM_BASE = (
"* FIRST CHECK, before choosing ANY action: is the GOAL's proof already "
"visible in this screenshot? Then reply with the done action IMMEDIATELY "
"— every extra action after success is a failure (it wastes seconds and "
- "can undo the result).\n"
+ "can undo the result). Scrolling around, waiting, or re-checking 'to be "
+ "sure' AFTER the proof is visible is exactly that failure — the user is "
+ "waiting for your confirmation.\n"
"* The screenshot is the ONLY ground truth. Never assume an effect "
"happened; check the fresh screenshot.\n"
"* FIRST verify the effect of your previous action (see PREVIOUS STEPS). "
@@ -461,20 +463,33 @@ async def _judge_done(
monitor: MonitorInfo,
image_cfg: _ImageCfg,
output_language: str | None,
+ *,
+ frame: Frame | None = None,
) -> tuple[bool, str]:
- """Strict completion judge against a FRESH stable frame."""
- try:
- frame = await asyncio.wait_for(
- asyncio.to_thread(
- capture_stable_frame,
- monitor,
- max_dimension=image_cfg.max_dimension,
- blob_dir=image_cfg.blob_dir,
- ),
- timeout=_OBSERVE_TIMEOUT_S,
- )
- except Exception: # noqa: BLE001 — judge is best-effort; reject on no frame
- return (False, "")
+ """Strict completion judge.
+
+ Verifies against ``frame`` when the caller passes one — the perception
+ frame of the CURRENT step, valid when no action executed since it was
+ captured (the model claims "the proof is visible in THIS screenshot",
+ so judging that exact evidence is both faster AND the more faithful
+ check). Without a frame (actions ran in this batch), a FRESH stable
+ capture is taken as before. The recapture cost the completion readback
+ ~0.5–1.5 s per done (live complaint 2026-07-02: "he was done but said
+ nothing for too long").
+ """
+ if frame is None:
+ try:
+ frame = await asyncio.wait_for(
+ asyncio.to_thread(
+ capture_stable_frame,
+ monitor,
+ max_dimension=image_cfg.max_dimension,
+ blob_dir=image_cfg.blob_dir,
+ ),
+ timeout=_OBSERVE_TIMEOUT_S,
+ )
+ except Exception: # noqa: BLE001 — judge is best-effort; reject on no frame
+ return (False, "")
system = _JUDGE_SYSTEM + _proof_language_directive(output_language)
user = (
f"GOAL: {goal}\n\nThe attached screenshot shows the CURRENT screen. "
@@ -491,6 +506,7 @@ async def _judge_done(
build_prompt=lambda provider, brain: (system, user),
images=[image],
max_tokens=_JUDGE_MAX_TOKENS,
+ early_stop_json=True,
)
except Exception: # noqa: BLE001 — an unreachable judge must not crash a
# finished mission; the caller treats it as "not confirmed".
@@ -664,6 +680,7 @@ async def run_cu_loop(
if fruitless_steps >= _STUCK_FRAMES:
done, proof = await _judge_done(
ctx, goal, monitor, image_cfg, output_language,
+ frame=frame, # captured this step; the screen is unchanged
)
if done:
yield _final(
@@ -788,6 +805,7 @@ async def run_cu_loop(
# ---- act + verify ---------------------------------------------------
pointer_used = False
+ batch_acted = False # any executed action invalidates the step frame
for action in actions:
if _is_cancelled(cancel_token):
yield _final(stderr="[cu] cancelled\n", exit_code=_EXIT_CANCEL)
@@ -797,6 +815,10 @@ async def run_cu_loop(
if kind == "done":
done, proof = await _judge_done(
ctx, goal, monitor, image_cfg, output_language,
+ # No action ran since perception -> the screen IS the
+ # frame the model called done on; judge that evidence
+ # directly instead of paying a second stability capture.
+ frame=None if batch_acted else frame,
)
if done:
yield _final(
@@ -1132,6 +1154,7 @@ async def run_cu_loop(
profiler.add("settle", t0, step_idx)
# -- bookkeeping ---------------------------------------------------
+ batch_acted = True
summary = _summarize_action(action)
if ok:
consecutive_failures = 0
diff --git a/jarvis/speech/pipeline.py b/jarvis/speech/pipeline.py
index d8618170a7..4c407f4230 100644
--- a/jarvis/speech/pipeline.py
+++ b/jarvis/speech/pipeline.py
@@ -1802,8 +1802,19 @@ class SpeechPipeline:
# bei ACTIVE-Familie (LISTENING/THINKING/SPEAKING) resumen.
self._maybe_toggle_vision_on_state(new_state)
- async def _set_turn_state(self, new_state: TurnTakingState) -> None:
+ async def _set_turn_state(
+ self,
+ new_state: TurnTakingState,
+ *,
+ only_from: TurnTakingState | None = None,
+ ) -> None:
previous = getattr(self, "_turn_state", TurnTakingState.IDLE)
+ # Conditional transition (``only_from``): apply ONLY when the state is
+ # still the expected origin. Used by callbacks that may race a newer
+ # state (a late VAD false-start endpoint must never yank the machine
+ # out of JARVIS_SPEAKING).
+ if only_from is not None and previous != only_from:
+ return
if previous != new_state:
log.info("turn-state: %s -> %s", previous.value, new_state.value)
# Jarvis just STOPPED speaking → the floor goes back to the user. Stamp it
@@ -1858,12 +1869,20 @@ class SpeechPipeline:
return "SPEAKING"
return "IDLE"
- def _schedule_turn_state(self, state: TurnTakingState) -> None:
+ def _schedule_turn_state(
+ self,
+ state: TurnTakingState,
+ *,
+ only_from: TurnTakingState | None = None,
+ ) -> None:
try:
loop = asyncio.get_running_loop()
except RuntimeError:
return
- loop.create_task(self._set_turn_state(state), name=f"turn-state-{state.value}")
+ loop.create_task(
+ self._set_turn_state(state, only_from=only_from),
+ name=f"turn-state-{state.value}",
+ )
def _on_vad_speech_start(self) -> None:
log.info("voice activity start")
@@ -1905,6 +1924,17 @@ class SpeechPipeline:
self._reset_probe_state()
if reason != "false_start":
self._schedule_turn_state(TurnTakingState.WAITING_FOR_FINAL_TRANSCRIPT)
+ else:
+ # A discarded false start must RELEASE the floor: the VAD start
+ # set USER_SPEAKING, no transcript will ever follow, and without
+ # this transition every completion announcement is deferred
+ # "user holds the floor" until some unrelated event (live
+ # 2026-07-02 19:06: the mission readback sat 31 s behind a 96 ms
+ # VAD blip). Guarded so a racing newer state is never regressed.
+ self._schedule_turn_state(
+ TurnTakingState.LISTENING,
+ only_from=TurnTakingState.USER_SPEAKING,
+ )
def _reset_probe_state(self) -> None:
self._probe_last_text = ""
diff --git a/tests/unit/cu/test_engine_loop.py b/tests/unit/cu/test_engine_loop.py
index 7af53b0652..68a02c80cc 100644
--- a/tests/unit/cu/test_engine_loop.py
+++ b/tests/unit/cu/test_engine_loop.py
@@ -91,6 +91,7 @@ def patched(monkeypatch, tmp_path):
clicks_seen=0,
clickables=[],
focus_hit=None, # verify_click_focus_point verdict
+ capture_calls=0, # capture_stable_frame invocations
)
def fake_select_capture_target(
@@ -99,6 +100,7 @@ def patched(monkeypatch, tmp_path):
return MONITOR
def fake_capture(monitor, *, max_dimension, blob_dir=None, **kw):
+ state.capture_calls += 1
return capture_stable_frame(
monitor,
grab=lambda bbox: _solid(state.screen_shade),
@@ -238,6 +240,40 @@ async def test_second_pointer_action_in_one_batch_is_skipped(patched):
assert any("only one pointer action" in user for (_, user) in brain.calls)
+async def test_done_judge_reuses_the_step_frame_when_no_action_ran(patched):
+ # "Say you are done FAST": when `done` arrives before any action of the
+ # batch executed, the screen is exactly the frame the model saw — the
+ # judge must verify against THAT frame instead of paying a second
+ # stability capture (live complaint 2026-07-02: the completion
+ # confirmation took too long).
+ brain = FakeBrain([
+ '{"action": "done", "reason": "goal visible"}',
+ '{"done": true, "proof": "the channel is open"}',
+ ])
+ executor = FakeExecutor()
+ chunks = await _run(_ctx(brain, executor))
+ assert _final(chunks).exit_code == 0
+ assert patched.capture_calls == 1, (
+ "the done-judge must reuse the perception frame, not recapture"
+ )
+
+
+async def test_done_judge_recaptures_after_batch_actions(patched):
+ # After any executed action the screen may differ from the perception
+ # frame — the judge must then verify against a FRESH capture.
+ brain = FakeBrain([
+ '[{"action":"key","keys":["enter"]},'
+ '{"action":"done","reason":"submitted"}]',
+ '{"done": true, "proof": "the form is submitted"}',
+ ])
+ executor = FakeExecutor()
+ chunks = await _run(_ctx(brain, executor))
+ assert _final(chunks).exit_code == 0
+ assert patched.capture_calls == 2, (
+ "a done after executed actions needs a fresh judge frame"
+ )
+
+
async def test_click_on_already_focused_target_passes_and_type_proceeds(patched):
# Live incident 2026-07-02 19:06 (Chrome guest new-tab): the address bar
# is focused BY DEFAULT, so clicking it changes zero pixels. The pixel
diff --git a/tests/unit/speech/test_announcement_user_speaking_guard.py b/tests/unit/speech/test_announcement_user_speaking_guard.py
index 91ecfe6674..b42e0c15f1 100644
--- a/tests/unit/speech/test_announcement_user_speaking_guard.py
+++ b/tests/unit/speech/test_announcement_user_speaking_guard.py
@@ -246,6 +246,63 @@ async def test_preamble_during_processing_carries_staleness_gate() -> None:
assert pred() is False
+async def _await_turn_state_tasks() -> None:
+ tasks = [
+ t
+ for t in asyncio.all_tasks()
+ if t.get_name().startswith("turn-state-") and not t.done()
+ ]
+ if tasks:
+ await asyncio.gather(*tasks)
+
+
+async def test_discarded_false_start_releases_the_floor() -> None:
+ """Live 2026-07-02 19:06: a 96 ms VAD blip set USER_SPEAKING, the false
+ start was discarded WITHOUT a state transition, and the mission's
+ completion readback sat deferred for 31 s ("user holds the floor") until
+ the hangup forced a transition. A discarded false start must release the
+ floor so deferred announcements flush immediately."""
+ bus = EventBus()
+ tts = FakeTTS()
+ player = FakePlayer()
+ pipeline = _make_pipeline(tts, bus, player)
+ pipeline._turn_state = TurnTakingState.USER_SPEAKING # type: ignore[attr-defined]
+
+ await bus.publish(
+ AnnouncementRequested(
+ text="Erledigt. Das Fenster ist offen.",
+ language="de",
+ priority="normal",
+ kind="completion",
+ )
+ )
+ assert player.plays == 0 # correctly deferred while the floor was held
+
+ pipeline._on_vad_endpoint("false_start")
+ await _await_turn_state_tasks()
+ await _flush_deferred()
+
+ assert pipeline._turn_state == TurnTakingState.LISTENING
+ assert player.plays == 1, (
+ "the completion stayed deferred behind a discarded VAD false start"
+ )
+
+
+async def test_false_start_release_never_regresses_a_newer_state() -> None:
+ """The release is guarded: if the state already moved on (e.g. the answer
+ started voicing), a late false-start endpoint must not yank it back."""
+ bus = EventBus()
+ pipeline = _make_pipeline(FakeTTS(), bus, FakePlayer())
+ pipeline._turn_state = TurnTakingState.JARVIS_SPEAKING # type: ignore[attr-defined]
+
+ pipeline._on_vad_endpoint("false_start")
+ await _await_turn_state_tasks()
+
+ assert pipeline._turn_state == TurnTakingState.JARVIS_SPEAKING
+
+
@pytest.mark.asyncio
async def test_announcement_while_idle_is_unaffected() -> None:
"""Regression guard: the guard only arms while the user holds the floor."""