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.

fix(wiki): let the curator tier extend the CLI brains' internal timeout

Personal Jarvis Maintainer42df4ed37268
diff --git a/jarvis/memory/wiki/consolidator.py b/jarvis/memory/wiki/consolidator.py
index 4e01e8cc20..20ff8e134a 100644
--- a/jarvis/memory/wiki/consolidator.py
+++ b/jarvis/memory/wiki/consolidator.py
@@ -1451,7 +1451,12 @@ class Consolidator:
# Thinking disabled for Gemini non-pro: the judge must spend its
# token budget on page bodies, not on internal reasoning (see
# instantiate_curator_brain).
- self._brain = instantiate_curator_brain(self._registry, provider, model)
+ self._brain = instantiate_curator_brain(
+ self._registry,
+ provider,
+ model,
+ cli_timeout_s=float(self._curator_cfg.timeout_s),
+ )
self._resolved_provider = provider
except Exception as exc: # noqa: BLE001
log.warning(
diff --git a/jarvis/memory/wiki/curator_llm.py b/jarvis/memory/wiki/curator_llm.py
index 813a5b2f83..31d280260e 100644
--- a/jarvis/memory/wiki/curator_llm.py
+++ b/jarvis/memory/wiki/curator_llm.py
@@ -25,6 +25,7 @@ config, timeout-via-wait_for, error-tolerant shape).
from __future__ import annotations
import asyncio
+import functools
import json
import logging
import time
@@ -151,7 +152,11 @@ def _resolve_provider_and_model(
def instantiate_curator_brain(
- registry: Any, provider: str, model: str | None,
+ registry: Any,
+ provider: str,
+ model: str | None,
+ *,
+ cli_timeout_s: float | None = None,
) -> Any:
"""Instantiate a curator-tier brain with extended thinking DISABLED.
@@ -173,7 +178,19 @@ def instantiate_curator_brain(
# curator tier's JSON contract. Providers whose constructor accepts
# ``structured_prompts`` forward the contract verbatim instead; the probe
# is signature acceptance (capability, never a provider name — AP-21).
- for attempt in ({**kwargs, "structured_prompts": True}, kwargs):
+ # ``cli_timeout_s`` rides the same probe: CLI brains cap each turn with an
+ # internal voice-tier deadline, which must not kill a slow background call
+ # the caller is still willing to wait for (live 2026-07-21: the Stage-2
+ # judge died on every codex run at the internal 90 s cap while the wiki
+ # tier's 180 s budget was half unused).
+ structured: dict[str, Any] = {**kwargs, "structured_prompts": True}
+ if cli_timeout_s is not None and cli_timeout_s > 0:
+ structured["cli_timeout_s"] = float(cli_timeout_s)
+ attempts: list[dict[str, Any]] = [structured]
+ if "cli_timeout_s" in structured:
+ attempts.append({**kwargs, "structured_prompts": True})
+ attempts.append(kwargs)
+ for attempt in attempts:
try:
return registry.instantiate(provider, **attempt)
except TypeError:
@@ -639,7 +656,13 @@ class WikiCuratorLLM:
# background JSON work must not burn the token budget on
# internal reasoning (see instantiate_curator_brain).
brain = await asyncio.to_thread(
- instantiate_curator_brain, self._registry, provider, model,
+ functools.partial(
+ instantiate_curator_brain,
+ self._registry,
+ provider,
+ model,
+ cli_timeout_s=float(self._cfg.timeout_s),
+ ),
)
except Exception as exc: # noqa: BLE001
logger.warning(
diff --git a/jarvis/memory/wiki/extractor.py b/jarvis/memory/wiki/extractor.py
index 2bba9e0474..ca644bbdba 100644
--- a/jarvis/memory/wiki/extractor.py
+++ b/jarvis/memory/wiki/extractor.py
@@ -1298,7 +1298,12 @@ class ConversationFactExtractor:
try:
# Thinking disabled for Gemini non-pro: extraction is small,
# deterministic JSON output (see instantiate_curator_brain).
- self._brain = instantiate_curator_brain(self._registry, provider, model)
+ self._brain = instantiate_curator_brain(
+ self._registry,
+ provider,
+ model,
+ cli_timeout_s=float(self._cfg.timeout_s),
+ )
self._resolved_provider = provider
self._resolved_model = model
except Exception as exc: # noqa: BLE001
diff --git a/jarvis/memory/wiki/provider_chain.py b/jarvis/memory/wiki/provider_chain.py
index 204c3fa499..ad49689625 100644
--- a/jarvis/memory/wiki/provider_chain.py
+++ b/jarvis/memory/wiki/provider_chain.py
@@ -24,6 +24,7 @@ from __future__ import annotations
import asyncio
import logging
+import re
import time
from collections.abc import Callable
from typing import Any
@@ -91,6 +92,21 @@ def _order_by_cooldown(
return healthy + cooled, [provider for provider, _model in cooled]
+# Known-safe, content-free failure diagnoses that may ride along with the
+# exception class name in logs and the health surface. Fail-closed allowlist:
+# anything the regex does not recognise stays a bare class name, so raw SDK
+# text (URLs with keys, personal paths, response bodies) can never leak into
+# a persisted record. Added 2026-07-21: the status bar said "codex
+# RuntimeError" while the actual story was "did not answer within 90s".
+_SAFE_DIAGNOSIS_RE = re.compile(
+ r"did not answer within [0-9.]+\s*s|timed? ?out|"
+ r"not (?:installed|logged in|found)|no answer|empty answer|"
+ r"returned no answer|could not be launched|unavailable|"
+ r"rate.?limit(?:ed)?|quota|insufficient credit",
+ re.IGNORECASE,
+)
+
+
def _exception_summary(exc: Exception) -> str:
"""Return diagnostic class/status metadata without persisting raw SDK text."""
status = getattr(exc, "status_code", None)
@@ -101,7 +117,9 @@ def _exception_summary(exc: Exception) -> str:
code = int(status) if status is not None else None
except (TypeError, ValueError):
code = None
- return f"{name} HTTP {code}" if code is not None else name
+ summary = f"{name} HTTP {code}" if code is not None else name
+ diagnosis = _SAFE_DIAGNOSIS_RE.search(str(exc))
+ return f"{summary} ({diagnosis.group(0)})" if diagnosis else summary
def _cli_login_ready(provider: str) -> bool | None:
"""Login-readiness of a subscription-CLI provider; ``None`` = not CLI-backed.
@@ -250,7 +268,9 @@ async def complete_with_fallback(
for index, (provider, model) in enumerate(ordered):
try:
- brain = instantiate_curator_brain(registry, provider, model)
+ brain = instantiate_curator_brain(
+ registry, provider, model, cli_timeout_s=timeout_s,
+ )
except Exception as exc: # noqa: BLE001 — a bad provider must not abort the chain
detail = _exception_summary(exc)
log.warning(
diff --git a/jarvis/plugins/brain/antigravity.py b/jarvis/plugins/brain/antigravity.py
index 7bf1acdbf5..c89052043d 100644
--- a/jarvis/plugins/brain/antigravity.py
+++ b/jarvis/plugins/brain/antigravity.py
@@ -169,7 +169,10 @@ class AntigravityBrain:
supports_vision: bool = False
def __init__(
- self, model: str | None = None, structured_prompts: bool = False,
+ self,
+ model: str | None = None,
+ structured_prompts: bool = False,
+ cli_timeout_s: float | None = None,
) -> None:
self._model = model or DEFAULT_MODEL
# Background/structured callers (the wiki curator tier) set this so
@@ -178,6 +181,14 @@ class AntigravityBrain:
# made structured output impossible by instruction (live 2026-07-18:
# every wiki extraction died with "no JSON array found in response").
self._structured_prompts = bool(structured_prompts)
+ # Slow background callers (wiki Stage-2 judge) pass their own per-call
+ # budget so the internal cap cannot kill a turn the caller is still
+ # willing to wait for; the voice-tier default stays the tight cap.
+ try:
+ budget = float(cli_timeout_s) if cli_timeout_s is not None else 0.0
+ except (TypeError, ValueError):
+ budget = 0.0
+ self._cli_timeout_s = budget if budget > 0 else _CLI_TIMEOUT_S
def can_call_tools(self) -> bool:
"""Runtime tool-calling capability (NOT the static ``supports_tools``).
@@ -249,7 +260,7 @@ class AntigravityBrain:
fut = loop.run_in_executor(
None,
lambda: run_cli_over_pty(
- tuple(argv), timeout_s=_CLI_TIMEOUT_S, cwd=workdir, env=env
+ tuple(argv), timeout_s=self._cli_timeout_s, cwd=workdir, env=env
),
)
try:
@@ -271,9 +282,13 @@ class AntigravityBrain:
f"Antigravity (Google login) is unavailable: {result.error}"
)
if result.timed_out:
- log.warning("AntigravityBrain(agy/PTY): no answer within %.0fs", _CLI_TIMEOUT_S)
+ log.warning(
+ "AntigravityBrain(agy/PTY): no answer within %.0fs",
+ self._cli_timeout_s,
+ )
raise RuntimeError(
- f"Antigravity (Google login) did not answer within {_CLI_TIMEOUT_S:.0f}s."
+ "Antigravity (Google login) did not answer within "
+ f"{self._cli_timeout_s:.0f}s."
)
if not result.text:
log.warning(
@@ -325,7 +340,7 @@ class AntigravityBrain:
proc.stdin.close()
comm_task = asyncio.create_task(proc.communicate())
- deadline = t0 + _CLI_TIMEOUT_S
+ deadline = t0 + self._cli_timeout_s
stdout_bytes = b""
stderr_bytes = b""
@@ -367,9 +382,13 @@ class AntigravityBrain:
raise
except TimeoutError as exc:
await _kill()
- log.warning("AntigravityBrain: no answer within %.0fs (killed)", _CLI_TIMEOUT_S)
+ log.warning(
+ "AntigravityBrain: no answer within %.0fs (killed)",
+ self._cli_timeout_s,
+ )
raise RuntimeError(
- f"Antigravity (Google login) did not answer within {_CLI_TIMEOUT_S:.0f}s."
+ "Antigravity (Google login) did not answer within "
+ f"{self._cli_timeout_s:.0f}s."
) from exc
finally:
with suppress(OSError):
diff --git a/jarvis/plugins/brain/codex.py b/jarvis/plugins/brain/codex.py
index d2d1589146..6a85a31624 100644
--- a/jarvis/plugins/brain/codex.py
+++ b/jarvis/plugins/brain/codex.py
@@ -141,7 +141,10 @@ class CodexBrain:
supports_vision: bool = False
def __init__(
- self, model: str | None = None, structured_prompts: bool = False,
+ self,
+ model: str | None = None,
+ structured_prompts: bool = False,
+ cli_timeout_s: float | None = None,
) -> None:
self._model = model or DEFAULT_MODEL
self._client: Any = None
@@ -150,6 +153,16 @@ class CodexBrain:
# conversational "answer in 1-3 plain-text sentences" wrapper — which
# made structured output impossible by instruction.
self._structured_prompts = bool(structured_prompts)
+ # Slow background callers (the wiki Stage-2 judge sends ~16k-char
+ # body-aware prompts) pass their own per-call budget; the voice-tier
+ # default stays the tight cap. Live 2026-07-21: the judge died on
+ # every run because the fixed 90 s cap killed codex before the wiki
+ # tier's 180 s budget was half used.
+ try:
+ budget = float(cli_timeout_s) if cli_timeout_s is not None else 0.0
+ except (TypeError, ValueError):
+ budget = 0.0
+ self._cli_timeout_s = budget if budget > 0 else _CLI_TIMEOUT_S
# Only the API-key path can see images (see the supports_vision note).
self.supports_vision = bool(self._api_key())
@@ -255,7 +268,7 @@ class CodexBrain:
pass
comm_task = asyncio.create_task(proc.communicate())
- deadline = t0 + _CLI_TIMEOUT_S
+ deadline = t0 + self._cli_timeout_s
stdout_bytes = b""
stderr_bytes = b""
@@ -302,10 +315,12 @@ class CodexBrain:
except TimeoutError as exc:
await _kill_cli_process()
log.warning(
- "CodexBrain CLI: no answer within %.0fs (killed)", _CLI_TIMEOUT_S
+ "CodexBrain CLI: no answer within %.0fs (killed)",
+ self._cli_timeout_s,
)
raise RuntimeError(
- f"Codex (ChatGPT login) did not answer within {_CLI_TIMEOUT_S:.0f}s."
+ "Codex (ChatGPT login) did not answer within "
+ f"{self._cli_timeout_s:.0f}s."
) from exc
finally:
with suppress(OSError):
diff --git a/tests/unit/memory/wiki/test_provider_chain.py b/tests/unit/memory/wiki/test_provider_chain.py
index fc3e6f53ed..7024acf6f1 100644
--- a/tests/unit/memory/wiki/test_provider_chain.py
+++ b/tests/unit/memory/wiki/test_provider_chain.py
@@ -611,3 +611,84 @@ async def test_provider_failures_never_expose_raw_exception_secrets(
assert secret not in detail
assert "C:/Users/private" not in detail
assert secret not in caplog.text
+
+
+async def test_chain_passes_its_timeout_budget_to_cli_capable_brains() -> None:
+ """The wiki tier's per-call budget reaches the brain constructor.
+
+ Live 2026-07-21: CodexBrain's internal 90 s voice-tier cap killed every
+ Stage-2 judge run although the wiki tier waited 180 s — the chain must
+ hand its own budget down so a CLI brain never times out earlier than
+ the caller ('Chain failure: codex RuntimeError').
+ """
+
+ class _KwargRecordingRegistry:
+ def __init__(self) -> None:
+ self.kwargs_seen: list[dict[str, Any]] = []
+
+ def available(self) -> set[str]:
+ return {"openrouter"}
+
+ def instantiate(self, name: str, **kwargs: Any) -> Any:
+ self.kwargs_seen.append(dict(kwargs))
+ return _FakeBrain(fail=False)
+
+ reg = _KwargRecordingRegistry()
+ result = await complete_with_fallback(
+ registry=reg,
+ chain=[("openrouter", None)],
+ request=object(),
+ timeout_s=180.0,
+ label="test",
+ aggregate=_aggregate,
+ )
+
+ assert result is not None
+ assert reg.kwargs_seen[0].get("cli_timeout_s") == 180.0
+
+
+async def test_cli_timeout_kwarg_degrades_for_older_provider_signatures() -> None:
+ """A constructor that rejects cli_timeout_s still gets instantiated."""
+
+ class _LegacyRegistry:
+ def __init__(self) -> None:
+ self.kwargs_seen: list[dict[str, Any]] = []
+
+ def available(self) -> set[str]:
+ return {"openrouter"}
+
+ def instantiate(self, name: str, **kwargs: Any) -> Any:
+ if "cli_timeout_s" in kwargs:
+ raise TypeError("unexpected keyword argument 'cli_timeout_s'")
+ self.kwargs_seen.append(dict(kwargs))
+ return _FakeBrain(fail=False)
+
+ reg = _LegacyRegistry()
+ result = await complete_with_fallback(
+ registry=reg,
+ chain=[("openrouter", None)],
+ request=object(),
+ timeout_s=180.0,
+ label="test",
+ aggregate=_aggregate,
+ )
+
+ assert result is not None
+ assert reg.kwargs_seen # instantiated without the unsupported kwarg
+
+
+def test_exception_summary_carries_known_safe_diagnosis_only() -> None:
+ """Recognised content-free diagnoses ride along; raw text never does."""
+ from jarvis.memory.wiki import provider_chain as pc
+
+ safe = pc._exception_summary(
+ RuntimeError("Codex (ChatGPT login) did not answer within 90s.")
+ )
+ assert safe == "RuntimeError (did not answer within 90s)"
+
+ raw = pc._exception_summary(
+ RuntimeError("request failed ?key=sk-proj-XYZ at C:/Users/private")
+ )
+ assert raw == "RuntimeError"
diff --git a/tests/unit/plugins/brain/test_antigravity_brain.py b/tests/unit/plugins/brain/test_antigravity_brain.py
index 5d63ad5672..9d18c80cab 100644
--- a/tests/unit/plugins/brain/test_antigravity_brain.py
+++ b/tests/unit/plugins/brain/test_antigravity_brain.py
@@ -473,3 +473,15 @@ async def test_complete_agy_pty_unavailable_raises(monkeypatch):
with pytest.raises(RuntimeError):
async for _ in brain.complete(_req()):
pass
+
+
+def test_cli_timeout_accepts_a_caller_budget() -> None:
+ """Background callers may extend the internal CLI cap (wiki judge tier)."""
+ from jarvis.plugins.brain import antigravity as antigravity_module
+ from jarvis.plugins.brain.antigravity import AntigravityBrain
+
+ assert AntigravityBrain(cli_timeout_s=180.0)._cli_timeout_s == 180.0
+ assert (
+ AntigravityBrain()._cli_timeout_s
+ == antigravity_module._CLI_TIMEOUT_S
+ )
diff --git a/tests/unit/plugins/brain/test_codex_brain.py b/tests/unit/plugins/brain/test_codex_brain.py
index 01fd4de102..6355b68f96 100644
--- a/tests/unit/plugins/brain/test_codex_brain.py
+++ b/tests/unit/plugins/brain/test_codex_brain.py
@@ -161,3 +161,23 @@ async def test_no_oauth_means_the_account_error_is_surfaced(
with pytest.raises(_StatusError):
await _collect(brain.complete(_wiki_request()))
assert calls == []
+
+
+def test_cli_timeout_defaults_to_the_voice_tier_cap() -> None:
+ assert CodexBrain()._cli_timeout_s == codex_module._CLI_TIMEOUT_S
+
+
+def test_cli_timeout_accepts_a_caller_budget() -> None:
+ """Slow background callers (wiki Stage-2 judge) extend the internal cap.
+
+ Live 2026-07-21: the fixed 90 s cap killed every consolidator run while
+ the wiki tier's 180 s budget was half unused — 'Chain failure: codex
+ RuntimeError' with a growing journal backlog.
+ """
+ assert CodexBrain(cli_timeout_s=180.0)._cli_timeout_s == 180.0
+ # Garbage/zero budgets fall back to the voice-tier default.
+ assert CodexBrain(cli_timeout_s=0)._cli_timeout_s == codex_module._CLI_TIMEOUT_S
+ assert (
+ CodexBrain(cli_timeout_s="nope")._cli_timeout_s
+ == codex_module._CLI_TIMEOUT_S
+ )