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(missions): failure context attaches only to worker-caused terminal reasons
Ruben Lütke2ce2a27978c5
diff --git a/jarvis/missions/kontrollierer/orchestrator.py b/jarvis/missions/kontrollierer/orchestrator.pyindex 2ca5ac9f10..ecb7e4377a 100644--- a/jarvis/missions/kontrollierer/orchestrator.py+++ b/jarvis/missions/kontrollierer/orchestrator.py@@ -1397,15 +1397,21 @@ class Kontrollierer:# (2026-07-06: expired Claude OAuth token killed every mission# terminally while codex + OpenRouter were healthy — AP-22).is_auth = _worker_error_is_auth(err_lower)+ # Classify once, reuse below for both the recorded context and+ # the WorkerKilled payload — avoids re-deriving error_detail+ # from spawn_result.worker_error twice and re-fetching+ # error_class back out of the dict we just wrote.+ error_class = _classify_worker_error(+ spawn_result.worker_error,+ timed_out=spawn_result.worker_timed_out,+ )+ error_detail = spawn_result.worker_error[:300]# Record the classified failure for the terminal MissionFailed# event. Last write wins: the final iteration's cause is the# one the mission actually died of.self._mission_failure_context[mission_id] = {- "error_class": _classify_worker_error(- spawn_result.worker_error,- timed_out=spawn_result.worker_timed_out,- ),- "error_detail": spawn_result.worker_error[:300],+ "error_class": error_class,+ "error_detail": error_detail,"failed_provider": (getattr(worker, "provider", None)or getattr(worker, "cli", None)@@ -1452,6 +1458,12 @@ class Kontrollierer:"as task_error",step.task_id, iteration, len(diff_text),)+ # The critic is now the judge: if it rejects, the honest+ # cause is the critic verdict, not this (survived) worker+ # error — drop the recorded context so a later+ # _fail_mission cannot misattribute the failure (stale+ # cross-outcome context, AP-19 class).+ self._mission_failure_context.pop(mission_id, None)# Deliberately fall through (no continue / no return): the# WorkerDraftReady publish + critic call below grade the# partial deliverable. We intentionally do NOT emit@@ -1488,10 +1500,8 @@ class Kontrollierer:mission_id=mission_id,worker_id=spawn_result.worker_id,reason=kill_reason,- error_class=self._mission_failure_context.get(- mission_id, {}- ).get("error_class"),- error_detail=spawn_result.worker_error[:300],+ error_class=error_class,+ error_detail=error_detail,)# A worker that ran out of time (wall-clock cap) on its# final attempt is a TIMEOUT, not a crash. Surface the@@ -2718,7 +2728,16 @@ class Kontrollierer:# terminal MissionFailed event names the real cause instead of the# bare mission-level reason (2026-07-06 incident: error_class was# always None and the UI/voice could not name a dead credential).+ #+ # Attach the recorded worker-failure context ONLY when the terminal+ # reason is actually worker-caused. Any other reason (critic_*,+ # budget_exceeded, worktree_setup_failed, ...) has its own honest+ # cause — inheriting a leftover worker-error context would+ # misattribute the failure (review finding, 2026-07-07). The pop is+ # unconditional either way: terminal means the context is dead.failure_ctx = self._mission_failure_context.pop(mission_id, {})+ if reason not in ("task_error", "attempts_timed_out"):+ failure_ctx = {}# Only transition when not already terminalview = await self._manager.mission(mission_id)if view is None or view.state in (diff --git a/tests/missions/kontrollierer/test_loop.py b/tests/missions/kontrollierer/test_loop.pyindex 8f9f3d0bfe..94a0bb0d43 100644--- a/tests/missions/kontrollierer/test_loop.py+++ b/tests/missions/kontrollierer/test_loop.py@@ -1123,6 +1123,52 @@ async def test_mission_failed_carries_error_classification(assert "401" in (killed[-1].error_detail or "")+async def test_critic_rejection_does_not_inherit_stale_worker_error_context(+ manager: MissionManager, tmp_path: Path+) -> None:+ """Review finding 2026-07-07: a worker error that left a real diff falls+ through to critic grading; if the critic then REJECTS, the mission's+ failure cause is the critic verdict — it must NOT be stamped with the+ survived worker error's error_class (stale-context misattribution)."""++ class _AuthErrorWithDiffWorker:+ cli = "claude"++ def __init__(self) -> None:+ self.last_pid = 555+ self.spawn_calls: list[dict[str, Any]] = []++ async def spawn(self, prompt, *, worktree, env, job, worker_id, log_dir, **kw): # type: ignore[no-untyped-def]+ self.spawn_calls.append(dict(kw))+ log_dir.mkdir(parents=True, exist_ok=True)+ (log_dir / "stream.jsonl").write_text("", encoding="utf-8")+ # Leave a real file so the external-write augmentation produces a+ # non-empty diff — mirroring "worker did real work, then 401'd".+ yield _FakeAuthErrorEvent()++ worker = _AuthErrorWithDiffWorker()+ critic = FakeCriticRunner(_make_reject_verdict())+ k = _make_kontrollierer(+ manager=manager, tmp_path=tmp_path, critic=critic,+ worker_factory_fn=lambda step: worker,+ )+ # Force the graded path: patch the diff capture so the worker error falls+ # through to the critic instead of retrying (non-empty diff).+ k._capture_diff = lambda wt: "diff --git a/x b/x\n+real work\n" # type: ignore[method-assign]+ mid = await manager.dispatch(prompt="work then die on auth")++ end = await k.run_mission(mid)+ assert end == MissionState.FAILED+ events = await manager.store.events_for_mission(mid)+ failed = [e.payload for e in events if e.payload.event_type == "MissionFailed"]+ assert len(failed) == 1+ assert failed[0].reason == "critic_rejected"+ # The honest cause is the critic verdict — no stale provider_auth stamp.+ assert failed[0].error_class is None+ assert failed[0].failed_provider is None++@pytest.mark.asyncioasync def test_critic_timeout_retries_then_approves(manager: MissionManager, tmp_path: Path