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 19:34)

Ruben Lütke638642e24438
diff --git a/.claude/skills/ship-public-release/references/distribution-denylist.txt b/.claude/skills/ship-public-release/references/distribution-denylist.txt
index a841197c96..0eafe9dd7a 100644
--- a/.claude/skills/ship-public-release/references/distribution-denylist.txt
+++ b/.claude/skills/ship-public-release/references/distribution-denylist.txt
@@ -181,3 +181,12 @@ docs/qa/**
# valid snapshot never depends on a last-minute abort. Internal process doc with
# no downstream value; a fork writes its own.
docs/handoffs/**
+
+# --- Voice-session transcripts (2026-06-30) ---------------------------------
+# voice-session-*.{md,txt} are raw transcripts of the maintainer talking to
+# Jarvis (e.g. "was-geht-ab…") — personal speech content with no downstream
+# value, occasionally git-tracked by accident (an auto-save / `git add -A` in a
+# parallel session). Withhold every voice-session transcript, at any depth, so a
+# stray one never reaches public history.
+voice-session-*
+**/voice-session-*
diff --git a/jarvis/missions/init.py b/jarvis/missions/init.py
index a0232b6208..2dd2980a9b 100644
--- a/jarvis/missions/init.py
+++ b/jarvis/missions/init.py
@@ -449,6 +449,64 @@ def _live_subagent_provider(boot_snapshot: str | None) -> str | None:
return boot_snapshot
+def _cross_family_last_resort_worker(task_text: str) -> Any | None:
+ """The key-aware, cross-family LAST-resort heavy worker (open-source AP-22/23).
+
+ The legacy last resort was always ``ClaudeDirectWorker`` — the Claude Max
+ OAuth ``claude`` CLI. A downloader whose only credential is a Gemini /
+ OpenRouter / OpenAI key (and who never switched ``[brain.worker].provider``
+ off the ``claude-api`` default) then bricked every heavy mission: there is no
+ ``claude`` binary on a fresh install and no Anthropic key. This mirrors the
+ Brain's cross-family fallback chain — probe the families the user ACTUALLY
+ has and run on the first reachable one, crossing families instead of
+ dead-ending on Claude.
+
+ Subscription-first ordering (no metered key before a metered key):
+ 1. Claude Max OAuth ``claude`` CLI, when its binary is present — this keeps
+ the maintainer/subscription path unchanged (it is reached first, so a
+ host WITH Claude never diverts to a metered key);
+ 2. ChatGPT subscription via the codex CLI OAuth login (no API key);
+ 3. the in-process ``ApiAgentWorker`` on whatever single API key is
+ configured — ``claude-api``, ``gemini``, ``openrouter``, ``openai``, in
+ the Brain chain's family order.
+
+ Returns ``None`` ONLY when nothing is reachable (the genuine no-credential
+ case); the caller then keeps the honest Claude last resort, which fails
+ legibly rather than silently. Because Claude is probed first, this never
+ silently diverts a working Claude to Gemini — it only rescues a host that
+ has no Claude at all (the §3 single-key downloader).
+ """
+ # 1. Claude Max OAuth CLI — subscription, no metered key, preferred floor.
+ from jarvis.missions.workers.claude_direct_worker import _resolve_claude_binary
+
+ if _resolve_claude_binary() is not None:
+ return ClaudeDirectWorker(
+ mcp_servers=_assemble_worker_mcp_servers(task_text=task_text)
+ )
+ # 2. ChatGPT subscription via the codex CLI OAuth login (no API key).
+ from jarvis.codex_auth_state import codex_needs_reauth
+ from jarvis.missions.workers.codex_direct_worker import _codex_oauth_available
+
+ if _codex_oauth_available() and not codex_needs_reauth():
+ return CodexDirectWorker()
+ # 3. In-process API worker on whatever single key the user has, crossing
+ # families — the same cross-family set the Brain fallback chain uses.
+ from jarvis.core.config import get_provider_secret
+ from jarvis.missions.workers.api_agent_worker import supports_api_agent_worker
+
+ for prov in ("claude-api", "gemini", "openrouter", "openai"):
+ if supports_api_agent_worker(prov) and get_provider_secret(prov):
+ logger.warning(
+ "Mission worker -> ApiAgentWorker(%r): no Claude CLI / Codex login "
+ "reachable, crossing to the configured API-key family so the heavy "
+ "mission runs instead of failing on the absent `claude` binary "
+ "(open-source AP-22/AP-23, single-key downloader).",
+ prov,
+ )
+ return ApiAgentWorker(prov)
+ return None
+
+
async def bootstrap_missions(
*,
db_path: Path,
@@ -817,6 +875,15 @@ async def bootstrap_missions(
"window resets (avoids a wasted Claude probe per mission)."
)
return CodexDirectWorker()
+ # Open-source AP-22/AP-23: before the honest Claude last resort, try
+ # the user's ACTUAL provider family. A fresh install whose only key is
+ # gemini/openrouter/openai (and who never moved off the claude-api
+ # default) has neither the `claude` binary nor an Anthropic key, so a
+ # bare ClaudeDirectWorker here would brick the mission. The helper
+ # probes Claude FIRST, so a host WITH Claude is unchanged.
+ cross = _cross_family_last_resort_worker(getattr(step, "prompt", "") or "")
+ if cross is not None:
+ return cross
# Give the delegated worker the connected marketplace plugins as a
# claude-cli MCP config so it can issue the plugin tool calls (AD-OE4).
return ClaudeDirectWorker(
@@ -882,11 +949,14 @@ async def bootstrap_missions(
)
return ApiAgentWorker(provider)
logger.warning(
- "Mission worker -> ClaudeDirectWorker: subagent provider %r has no "
- "API key configured, so it cannot run — completing on Claude Max "
- "instead of failing the mission.",
+ "Mission worker: subagent provider %r has no API key configured, "
+ "so it cannot run — trying the user's other provider families "
+ "before the Claude last resort (open-source AP-22/AP-23).",
provider,
)
+ cross = _cross_family_last_resort_worker(getattr(step, "prompt", "") or "")
+ if cross is not None:
+ return cross
return ClaudeDirectWorker(
mcp_servers=_assemble_worker_mcp_servers(
task_text=getattr(step, "prompt", "") or ""
@@ -920,7 +990,12 @@ async def bootstrap_missions(
# The legacy ``"subjarvis"`` kind (openclaw-claude / unknown provider /
# unset default) routed to the OpenClaw subprocess worker, which was
# removed (it caused the ~92% nested-claude hang; see docs/BUGS.md).
- # All of those cases now fall back to the proven direct Opus worker.
+ # Open-source AP-22/AP-23: try the user's ACTUAL provider family before
+ # the Claude last resort, so an openrouter/gemini/openai-only downloader
+ # is not dead-ended on the absent `claude` binary.
+ cross = _cross_family_last_resort_worker(getattr(step, "prompt", "") or "")
+ if cross is not None:
+ return cross
return ClaudeDirectWorker(
mcp_servers=_assemble_worker_mcp_servers(
task_text=getattr(step, "prompt", "") or ""
diff --git a/tests/missions/test_worker_cross_family_fallback.py b/tests/missions/test_worker_cross_family_fallback.py
new file mode 100644
index 0000000000..43be948c6e
--- /dev/null
+++ b/tests/missions/test_worker_cross_family_fallback.py
@@ -0,0 +1,113 @@
+"""Open-source AP-22/AP-23: the heavy-mission Worker LAST resort must be
+key-aware and cross-family — never a dead-end on the Claude Max ``claude`` CLI.
+
+Forensic shape of the bug (provider-agnostic feature parity audit, pre-public
+release): a downloader whose ONLY credential is a Gemini / OpenRouter / OpenAI
+key — and who never switched ``[brain.worker].provider`` off the ``claude-api``
+default — could chat fine (the Brain has a cross-family fallback chain) but the
+first heavy mission bricked: the worker factory fell through to
+``ClaudeDirectWorker``, which needs either the ``claude`` CLI binary (absent on
+a fresh install) or an Anthropic key (absent). The fix mirrors the Brain's
+cross-family chain in ``_cross_family_last_resort_worker``.
+"""
+from __future__ import annotations
+
+import pytest
+
+from jarvis.missions import init as mi
+from jarvis.missions.workers.api_agent_worker import ApiAgentWorker
+from jarvis.missions.workers.claude_direct_worker import ClaudeDirectWorker
+from jarvis.missions.workers.codex_direct_worker import CodexDirectWorker
+
+
+def _patch_env(
+ monkeypatch: pytest.MonkeyPatch,
+ *,
+ claude_binary: str | None = None,
+ codex_oauth: bool = False,
+ codex_reauth: bool = False,
+ keys: tuple[str, ...] = (),
+) -> None:
+ """Pin every probe the last-resort helper consults to a known world."""
+ monkeypatch.setattr(
+ "jarvis.missions.workers.claude_direct_worker._resolve_claude_binary",
+ lambda: claude_binary,
+ )
+ monkeypatch.setattr(
+ "jarvis.missions.workers.codex_direct_worker._codex_oauth_available",
+ lambda: codex_oauth,
+ )
+ monkeypatch.setattr(
+ "jarvis.codex_auth_state.codex_needs_reauth", lambda: codex_reauth
+ )
+ keyset = {k.strip().lower() for k in keys}
+ monkeypatch.setattr(
+ "jarvis.core.config.get_provider_secret",
+ lambda p: "KEY" if (p or "").strip().lower() in keyset else None,
+ )
+ # The claude-binary branch assembles MCP servers; keep that cheap + offline.
+ monkeypatch.setattr(mi, "_assemble_worker_mcp_servers", lambda **_k: ())
+
+
+# --- The brick scenario: a single non-Claude key must run, not dead-end -------
+
+
+ "key,provider",
+ [("gemini", "gemini"), ("openrouter", "openrouter"), ("openai", "openai")],
+)
+def test_single_nonclaude_key_runs_on_that_family(
+ monkeypatch: pytest.MonkeyPatch, key: str, provider: str
+) -> None:
+ """No claude binary, no codex login, ONE non-Claude API key → the in-process
+ ApiAgentWorker on THAT family — never None, never a Claude dead-end."""
+ _patch_env(monkeypatch, keys=(key,))
+ worker = mi._cross_family_last_resort_worker("do the task")
+ assert isinstance(worker, ApiAgentWorker)
+ assert worker.provider == provider
+
+
+def test_claude_api_key_only_runs_in_process(monkeypatch: pytest.MonkeyPatch) -> None:
+ """An Anthropic-API-key-only user with no `claude` binary runs in-process."""
+ _patch_env(monkeypatch, keys=("claude-api",))
+ worker = mi._cross_family_last_resort_worker("t")
+ assert isinstance(worker, ApiAgentWorker)
+ assert worker.provider == "claude-api"
+
+
+# --- Subscription-first ordering (no metered key before a metered key) --------
+
+
+def test_claude_cli_binary_wins_subscription_first(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """When the Claude Max OAuth `claude` binary IS present, it is the floor —
+ the maintainer path is unchanged (no regression to a metered API key)."""
+ _patch_env(monkeypatch, claude_binary="/usr/bin/claude", keys=("gemini",))
+ worker = mi._cross_family_last_resort_worker("t")
+ assert isinstance(worker, ClaudeDirectWorker)
+
+
+def test_codex_oauth_beats_api_keys(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A live ChatGPT (codex) login is a subscription floor before metered keys."""
+ _patch_env(monkeypatch, codex_oauth=True, keys=("openai",))
+ worker = mi._cross_family_last_resort_worker("t")
+ assert isinstance(worker, CodexDirectWorker)
+
+
+def test_codex_needing_reauth_is_skipped(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A dead codex login is skipped — it must not shadow a usable API key."""
+ _patch_env(monkeypatch, codex_oauth=True, codex_reauth=True, keys=("gemini",))
+ worker = mi._cross_family_last_resort_worker("t")
+ assert isinstance(worker, ApiAgentWorker)
+ assert worker.provider == "gemini"
+
+
+# --- The genuine no-credential case still degrades honestly -------------------
+
+
+def test_nothing_reachable_returns_none(monkeypatch: pytest.MonkeyPatch) -> None:
+ """No binary, no codex, no key → None, so the caller keeps the honest Claude
+ last resort (which fails legibly rather than silently)."""
+ _patch_env(monkeypatch)
+ assert mi._cross_family_last_resort_worker("t") is None