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-07 16:22)

Ruben Lütke81b73f6a5a8f
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index de770e1d67..ccb522d676 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -281,6 +281,14 @@
"running": "fährt",
"completed": "ankunft",
"failed": "störung"
+ },
+ "health_degraded": "Subagent-Anbieter beeinträchtigt",
+ "health_error": "Kein Subagent-Anbieter erreichbar",
+ "error_class": {
+ "provider_auth": "Anbieter-Anmeldung ungültig oder abgelaufen — in der API-Keys-Ansicht neu verbinden.",
+ "provider_quota": "Anbieter-Kontingent erschöpft — Missionen weichen auf einen anderen Anbieter aus.",
+ "provider_unreachable": "Anbieter vorübergehend nicht erreichbar.",
+ "worker_timeout": "Der Worker hat das Zeitlimit überschritten."
}
},
"tasks_view": {
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index f32155514d..9aea0051a0 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -281,6 +281,14 @@
"running": "running",
"completed": "arrived",
"failed": "failed"
+ },
+ "health_degraded": "Subagent provider degraded",
+ "health_error": "No subagent provider reachable",
+ "error_class": {
+ "provider_auth": "Provider sign-in invalid or expired — reconnect it in the API-Keys view.",
+ "provider_quota": "Provider quota exhausted — missions retry on another provider.",
+ "provider_unreachable": "Provider temporarily unreachable.",
+ "worker_timeout": "The worker hit its time limit."
}
},
"tasks_view": {
diff --git a/jarvis/ui/web/frontend/src/views/JarvisAgentsView.tsx b/jarvis/ui/web/frontend/src/views/JarvisAgentsView.tsx
index c858bd4f91..4eac733a37 100644
--- a/jarvis/ui/web/frontend/src/views/JarvisAgentsView.tsx
+++ b/jarvis/ui/web/frontend/src/views/JarvisAgentsView.tsx
@@ -16,9 +16,11 @@ import { selectTaskRows } from "./sub-agents/rows";
import { useMissionWebSocket } from "@/components/missions/useMissionWebSocket";
import { useMissionsStore } from "@/components/missions/store";
import { useT } from "@/i18n";
+import { useSectionHealth } from "@/hooks/useProviders";
export function JarvisAgentsView() {
const t = useT();
+ const { health } = useSectionHealth();
const subAgents = useSubAgentStore((s) => s.subAgents);
const sweepExpired = useSubAgentStore((s) => s.sweepExpired);
const hydrateSnapshot = useSubAgentStore((s) => s.hydrateSnapshot);
@@ -108,7 +110,11 @@ export function JarvisAgentsView() {
</header>
<div className="flex-1 relative overflow-hidden">
- <DepartureBoard agents={nodesList} snapshotError={snapshotError} />
+ <DepartureBoard
+ agents={nodesList}
+ snapshotError={snapshotError}
+ health={health["subagents"] ?? null}
+ />
</div>
</div>
);
diff --git a/jarvis/ui/web/frontend/src/views/sub-agents/DepartureBoard.tsx b/jarvis/ui/web/frontend/src/views/sub-agents/DepartureBoard.tsx
index 982fc3532d..020bc25965 100644
--- a/jarvis/ui/web/frontend/src/views/sub-agents/DepartureBoard.tsx
+++ b/jarvis/ui/web/frontend/src/views/sub-agents/DepartureBoard.tsx
@@ -276,11 +276,13 @@ function AgentRow({
nowMs,
expanded,
onToggle,
+ t,
}: {
agent: SubAgentNode;
nowMs: number;
expanded: boolean;
onToggle: () => void;
+ t: (key: string) => string;
}) {
const hasDrilldown = agent.tool_calls.length > 0 || agent.error || agent.prompts.length > 0;
@@ -317,8 +319,8 @@ function AgentRow({
</span>
<span className="text-zinc-400">{agent.tool_calls.length}</span>
<span className="text-zinc-400">{runtimeLabel(agent, nowMs)}</span>
- <span className="truncate text-zinc-400" title={resultLabel(agent)}>
- {resultLabel(agent)}
+ <span className="truncate text-zinc-400" title={resultLabel(agent, t)}>
+ {resultLabel(agent, t)}
</span>
</button>
@@ -356,7 +358,9 @@ function AgentRow({
))}
</div>
)}
- {agent.error && <div className="text-destructive">{agent.error}</div>}
+ {failureLabel(agent, t) && (
+ <div className="text-destructive">{failureLabel(agent, t)}</div>
+ )}
<div className="text-[10px] uppercase tracking-[0.16em] text-zinc-700">
trace {agent.trace_id.slice(0, 10)}
</div>
diff --git a/tests/missions/test_worker_cross_family_fallback.py b/tests/missions/test_worker_cross_family_fallback.py
index d930506979..1a90158056 100644
--- a/tests/missions/test_worker_cross_family_fallback.py
+++ b/tests/missions/test_worker_cross_family_fallback.py
@@ -27,6 +27,7 @@ def _patch_env(
claude_auth_viable: bool = True,
codex_oauth: bool = False,
codex_reauth: bool = False,
+ codex_quota_capped: bool = False,
keys: tuple[str, ...] = (),
) -> None:
"""Pin every probe the last-resort helper consults to a known world."""
@@ -42,6 +43,10 @@ def _patch_env(
monkeypatch.setattr(
"jarvis.codex_auth_state.codex_needs_reauth", lambda: codex_reauth
)
+ monkeypatch.setattr(
+ "jarvis.codex_quota_state.codex_in_quota_cooldown",
+ lambda **_k: codex_quota_capped,
+ )
keyset = {k.strip().lower() for k in keys}
monkeypatch.setattr(
"jarvis.core.config.get_provider_secret",
@@ -105,6 +110,27 @@ def test_codex_needing_reauth_is_skipped(monkeypatch: pytest.MonkeyPatch) -> Non
assert worker.provider == "gemini"
+def test_usage_capped_codex_crosses_to_api_key(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """The 2026-07-07 incident shape: the codex ChatGPT plan is usage-capped
+ ("try again at Jul 31st") while `codex status` still says connected, AND the
+ claude binary's auth is dead. The factory must skip BOTH subscription
+ families and run on the healthy API key instead of the codex->claude
+ guaranteed-fail loop."""
+ _patch_env(
+ monkeypatch,
+ claude_binary="/usr/bin/claude",
+ claude_auth_viable=False,
+ codex_oauth=True,
+ codex_quota_capped=True,
+ keys=("openrouter",),
+ )
+ worker = mi._cross_family_last_resort_worker("t")
+ assert isinstance(worker, ApiAgentWorker)
+ assert worker.provider == "openrouter"
+
+
# --- 2026-07-06: a PRESENT `claude` binary with DEAD auth must not dead-end ---
diff --git a/tests/missions/workers/test_codex_auth_fallback.py b/tests/missions/workers/test_codex_auth_fallback.py
index 640a5f9518..a4f30d9c8d 100644
--- a/tests/missions/workers/test_codex_auth_fallback.py
+++ b/tests/missions/workers/test_codex_auth_fallback.py
@@ -261,6 +261,151 @@ async def test_codex_auth_expired_falls_back_to_claude(
assert calls["claude_argv"] and calls["claude_argv"][0] == "claude"
+# --- 2026-07-07 incident: usage-capped codex + dead Claude looped forever -----
+#
+# Forensic ground truth (jarvis_desktop.log 15:50-15:52, mission_019f3cd8-1dd4):
+# the ChatGPT plan was usage-capped until Jul 31, `codex status` still said
+# connected=True, and the Claude Max OAuth login was dead. Every iteration then
+# spawned codex (~28 s to the cap error), fell back HARDCODED to Claude ("Not
+# logged in"), failed, and retried the identical pair — three times per mission,
+# every mission, while a healthy OpenRouter key sat unused (AP-22).
+
+_USAGE_CAP_STDOUT = (
+ b'{"type":"error","message":"You\'ve hit your usage limit. Upgrade to Plus '
+ b'to continue using Codex (https://chatgpt.com/explore/plus), or try again '
+ b'at Jul 31st, 2026 6:06 PM."}\n'
+)
+
+
[email protected]("_viable_claude_fallback")
+async def test_codex_usage_cap_arms_cooldown_and_falls_back_to_claude(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A usage-capped codex must arm the quota cooldown (so the worker factory
+ skips codex until it self-expires) AND still complete the mission on a
+ VIABLE Claude fallback."""
+ from jarvis.codex_quota_state import codex_in_quota_cooldown
+
+ claude_result_line = (
+ b'{"type":"result","subtype":"success","is_error":false,'
+ b'"result":"OK","session_id":"s1"}\n'
+ )
+ calls: dict[str, Any] = {"n": 0}
+
+ async def _fake_exec(*_a: Any, **_k: Any) -> _FakeProc:
+ calls["n"] += 1
+ if calls["n"] == 1:
+ return _FakeProc(_USAGE_CAP_STDOUT, returncode=1)
+ return _FakeProc(b"", returncode=0, streaming=claude_result_line)
+
+ monkeypatch.setattr(cdw.asyncio, "create_subprocess_exec", _fake_exec)
+ monkeypatch.setattr(
+ cdw_claude, "_resolve_provider_chain",
+ lambda *a, **k: (_FallbackStep("claude-api", "claude-opus-4-8"),),
+ )
+ monkeypatch.setattr(cdw_claude, "_resolve_claude_argv_prefix", lambda: ["claude"])
+
+ events = await _drive(CodexDirectWorker(), tmp_path)
+
+ final = events[-1]
+ assert getattr(final, "is_error", None) is False
+ assert calls["n"] == 2
+ # The proactive complement: the factory now knows codex is capped.
+ assert codex_in_quota_cooldown() is True
+
+
+async def test_codex_usage_cap_with_dead_claude_surfaces_error_honestly(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """THE 2026-07-07 loop killer: when Claude auth is NOT viable, the usage-cap
+ fallback must NOT spawn the guaranteed-401 Claude worker. It surfaces the
+ honest usage-limit error (transient => the orchestrator retries and the
+ factory — seeing the armed cooldown — crosses to an API-key family)."""
+ from jarvis.codex_quota_state import codex_in_quota_cooldown
+ from jarvis.missions import init as mi
+
+ calls: dict[str, Any] = {"n": 0}
+
+ async def _fake_exec(*_a: Any, **_k: Any) -> _FakeProc:
+ calls["n"] += 1
+ return _FakeProc(_USAGE_CAP_STDOUT, returncode=1)
+
+ monkeypatch.setattr(cdw.asyncio, "create_subprocess_exec", _fake_exec)
+ monkeypatch.setattr(cdw_claude, "_resolve_claude_binary", lambda: "claude")
+ monkeypatch.setattr(mi, "_claude_cli_auth_viable", lambda: False)
+
+ events = await _drive(CodexDirectWorker(), tmp_path)
+
+ final = events[-1]
+ assert getattr(final, "is_error", None) is True
+ assert "usage limit" in final.result.lower()
+ assert calls["n"] == 1, "must NOT spawn the known-dead Claude fallback"
+ assert codex_in_quota_cooldown() is True
+
+
+async def test_codex_auth_dead_with_dead_claude_surfaces_error_honestly(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """Same gate on the auth-dead path: dead codex login + dead Claude must not
+ ping-pong into a guaranteed-401 nested spawn."""
+ from jarvis.codex_auth_state import codex_needs_reauth
+ from jarvis.missions import init as mi
+
+ stdout = (
+ b'{"type":"error","message":{"message":"Failed to refresh token. '
+ b'Please log in again."}}\n'
+ )
+ calls: dict[str, Any] = {"n": 0}
+
+ async def _fake_exec(*_a: Any, **_k: Any) -> _FakeProc:
+ calls["n"] += 1
+ return _FakeProc(stdout, returncode=1)
+
+ monkeypatch.setattr(cdw.asyncio, "create_subprocess_exec", _fake_exec)
+ monkeypatch.setattr(cdw_claude, "_resolve_claude_binary", lambda: "claude")
+ monkeypatch.setattr(mi, "_claude_cli_auth_viable", lambda: False)
+
+ events = await _drive(CodexDirectWorker(), tmp_path)
+
+ final = events[-1]
+ assert getattr(final, "is_error", None) is True
+ assert calls["n"] == 1, "must NOT spawn the known-dead Claude fallback"
+ # The dead login is still flagged so the factory skips codex this session.
+ assert codex_needs_reauth() is True
+
+
+async def test_codex_success_clears_quota_cooldown(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """A codex success proves the cap reset — the cooldown must clear so the
+ subscription-first ordering returns to codex immediately."""
+ from jarvis.codex_quota_state import (
+ codex_in_quota_cooldown,
+ mark_codex_quota_cooldown,
+ )
+
+ mark_codex_quota_cooldown()
+ stdout = (
+ b'{"type":"item.completed","item":{"type":"agent_message","text":"done"}}\n'
+ b'{"type":"turn.completed","usage":{"input_tokens":10,"output_tokens":5}}\n'
+ )
+
+ async def _fake_exec(*_a: Any, **_k: Any) -> _FakeProc:
+ return _FakeProc(stdout, returncode=0)
+
+ monkeypatch.setattr(cdw.asyncio, "create_subprocess_exec", _fake_exec)
+
+ events = await _drive(CodexDirectWorker(), tmp_path)
+
+ final = events[-1]
+ assert getattr(final, "is_error", None) is False
+ assert codex_in_quota_cooldown() is False
+
+
@pytest.mark.asyncio
async def test_codex_hardcap_timeout_preserves_work_and_flags_timed_out(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch