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(agentic-ide): a recap provider that keeps failing is benched for ten minutes

rubenluetke10-beep0a6e39da46a7
diff --git a/jarvis/agentic_ide/recap_engine.py b/jarvis/agentic_ide/recap_engine.py
index b81dc5826c..8df62af285 100644
--- a/jarvis/agentic_ide/recap_engine.py
+++ b/jarvis/agentic_ide/recap_engine.py
@@ -141,6 +141,19 @@ MAX_PROVIDER_TRIES = 3
FAILURES_BEFORE_QUIET = 3
QUIET_S = 600.0
+#: The same idea per PROVIDER. The pane-level guard above only engages when
+#: EVERY family fails, so a dead first family was paid on every single cycle
+#: as long as a later one still wrote the recap — live (2026-08-23, 12 panes):
+#: two ~14 s CLI turns whose answer never parsed, then two API calls that
+#: 402/429, on every refresh of every pane, for hours, before the subscription
+#: CLI wrote the sentence. A provider that failed this many summaries in a
+#: row is skipped for ``PROVIDER_QUIET_S``; one success clears it, and when
+#: every candidate is cooling the whole chain still runs (the pane-level
+#: guard is the one that decides then). The recap itself is unchanged — it
+#: only stops re-buying the failures.
+PROVIDER_FAILURES_BEFORE_QUIET = 3
+PROVIDER_QUIET_S = 600.0
+
#: This is a DISPLAY budget, not merely a transport cap. In a normal grid the
#: call-sign and pane actions leave room for about 48 characters; a 90-character
#: model instruction merely guaranteed that CSS would hide the distinguishing
@@ -369,6 +382,37 @@ class _PaneState:
_panes: dict[str, _PaneState] = {}
_tasks: set[asyncio.Task[None]] = set()
_inflight = 0
+#: Per-provider circuit breaker (see PROVIDER_FAILURES_BEFORE_QUIET): consecutive
+#: failures and the monotonic time until which the provider is not asked.
+_provider_failures: dict[str, int] = {}
+_provider_quiet_until: dict[str, float] = {}
+
+
+def _provider_label(brain: Any) -> str:
+ """The name a brain is tracked (and logged) under — the model, else the type."""
+ return str(getattr(brain, "model", "") or getattr(brain, "name", "") or type(brain).__name__)
+
+
+def _provider_is_quiet(label: str, now: float) -> bool:
+ return _provider_quiet_until.get(label, 0.0) > now
+
+
+def _note_provider_failure(label: str, now: float) -> None:
+ count = _provider_failures.get(label, 0) + 1
+ _provider_failures[label] = count
+ if count >= PROVIDER_FAILURES_BEFORE_QUIET and not _provider_is_quiet(label, now):
+ _provider_quiet_until[label] = now + PROVIDER_QUIET_S
+ logger.info(
+ "Agentic IDE recap: {} failed {}x in a row — not asked again for {:.0f}s",
+ label,
+ count,
+ PROVIDER_QUIET_S,
+ )
+
+
+def _note_provider_success(label: str) -> None:
+ _provider_failures.pop(label, None)
+ _provider_quiet_until.pop(label, None)
def describe_failure(exc: BaseException) -> str:
@@ -925,8 +969,21 @@ async def summarize_with_model(
brains = await asyncio.to_thread(_resolve_brains)
if not brains:
return None
+ # Skip the families that keep failing (PROVIDER_FAILURES_BEFORE_QUIET). When
+ # every one of them is cooling the chain runs in full anyway: the pane-level
+ # guard — not this one — decides what an install with nothing working does.
+ now = time.monotonic()
+ eligible = [b for b in brains if not _provider_is_quiet(_provider_label(b), now)]
+ if not eligible:
+ eligible = list(brains)
+ elif len(eligible) < len(brains):
+ logger.debug(
+ "Agentic IDE recap: skipping {} cooling provider(s): {}",
+ len(brains) - len(eligible),
+ ", ".join(_provider_label(b) for b in brains if b not in eligible),
+ )
first_failure: Exception | None = None
- for brain in brains:
+ for brain in eligible:
try:
from .prompt_composer import compose_busy
@@ -935,15 +992,20 @@ async def summarize_with_model(
break
except Exception: # noqa: BLE001 - a missed pause never costs the brief
logger.debug("Agentic IDE recap: compose-busy check failed", exc_info=True)
+ label = _provider_label(brain)
try:
- return await _summarize_on(brain, term, rows, folder=folder)
+ answer = await _summarize_on(brain, term, rows, folder=folder)
except Exception as exc: # noqa: BLE001 - the next family is the handling
first_failure = first_failure or exc
+ _note_provider_failure(label, time.monotonic())
logger.info(
"Agentic IDE recap: {} could not write it ({}) — crossing to the next provider",
- getattr(brain, "model", "") or getattr(brain, "name", "") or type(brain).__name__,
+ label,
type(exc).__name__,
)
+ else:
+ _note_provider_success(label)
+ return answer
if first_failure is None:
return None
raise first_failure
@@ -1119,6 +1181,8 @@ def reset_for_tests() -> None:
_panes.clear()
_tasks.clear()
_inflight = 0
+ _provider_failures.clear()
+ _provider_quiet_until.clear()
__all__ = [
@@ -1135,6 +1199,8 @@ __all__ = [
"STABLE_AFTER_LINES",
"UNLABELLED_HEADLINE_CHARS",
"NO_PROVIDER_NOTE",
+ "PROVIDER_FAILURES_BEFORE_QUIET",
+ "PROVIDER_QUIET_S",
"WHY_DISABLED",
"WHY_NOT_STARTED",
"WHY_PINNED",
diff --git a/tests/unit/agentic_ide/test_recap_engine.py b/tests/unit/agentic_ide/test_recap_engine.py
index 40a9a49a9d..701887266e 100644
--- a/tests/unit/agentic_ide/test_recap_engine.py
+++ b/tests/unit/agentic_ide/test_recap_engine.py
@@ -536,6 +536,105 @@ def test_when_every_family_fails_the_first_failure_is_reported(monkeypatch) -> N
asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+# ------------------------------------------------ the per-provider breaker
+
+
+class _CountingBrain:
+ """A protocol fake that counts how often it was asked, failing or writing."""
+
+ def __init__(self, model: str, *, fails: bool) -> None:
+ self.model = model
+ self.fails = fails
+ self.calls = 0
+
+ async def complete(self, request): # noqa: ANN001, ANN202 - protocol fake
+ self.calls += 1
+ if self.fails:
+ raise RuntimeError(f"{self.model} cannot write today")
+ yield SimpleNamespace(
+ content=(
+ "HEADLINE: Pane recaps — provider breaker\n"
+ "DETAIL: The goal is a recap that stops paying for a dead first "
+ "family. The working family wrote this one."
+ )
+ )
+
+
+def test_a_provider_that_keeps_failing_is_skipped_after_three_strikes(monkeypatch) -> None:
+ """Live 2026-08-23: the first family burned two ~14 s CLI turns on EVERY
+ refresh of EVERY pane because a later family always rescued the recap, so
+ the pane-level quiet period never engaged. Three failures in a row now
+ bench that provider; the recap still lands, on the family that writes."""
+ dead = _CountingBrain("dead-first", fails=True)
+ alive = _CountingBrain("alive-second", fails=False)
+ monkeypatch.setattr(recap_engine, "_resolve_brains", lambda: [dead, alive])
+
+ for _ in range(recap_engine.PROVIDER_FAILURES_BEFORE_QUIET):
+ answer = asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ assert answer is not None and answer.writer == "alive-second"
+ assert dead.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET
+
+ answer = asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+
+ assert answer is not None and answer.writer == "alive-second"
+ assert dead.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET # not asked again
+ assert alive.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET + 1
+
+
+def test_a_benched_provider_is_asked_again_once_its_quiet_period_is_over(monkeypatch) -> None:
+ dead = _CountingBrain("dead-first", fails=True)
+ alive = _CountingBrain("alive-second", fails=False)
+ monkeypatch.setattr(recap_engine, "_resolve_brains", lambda: [dead, alive])
+ for _ in range(recap_engine.PROVIDER_FAILURES_BEFORE_QUIET):
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ assert dead.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET
+
+ later = time.monotonic() + recap_engine.PROVIDER_QUIET_S + 1.0
+ monkeypatch.setattr(recap_engine.time, "monotonic", lambda: later)
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+
+ assert dead.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET + 1
+
+
+def test_one_success_clears_a_providers_strikes(monkeypatch) -> None:
+ flaky = _CountingBrain("flaky-first", fails=True)
+ alive = _CountingBrain("alive-second", fails=False)
+ monkeypatch.setattr(recap_engine, "_resolve_brains", lambda: [flaky, alive])
+ for _ in range(recap_engine.PROVIDER_FAILURES_BEFORE_QUIET - 1):
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ flaky.fails = False
+ answer = asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ assert answer is not None and answer.writer == "flaky-first"
+ flaky.fails = True
+
+ for _ in range(recap_engine.PROVIDER_FAILURES_BEFORE_QUIET - 1):
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+
+ # 2 strikes, a success (reset), then 2 more strikes + the third: the
+ # breaker only counts CONSECUTIVE failures, so the flaky family was asked
+ # on every call so far and is benched only now.
+ assert flaky.calls == 2 * recap_engine.PROVIDER_FAILURES_BEFORE_QUIET
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+ assert flaky.calls == 2 * recap_engine.PROVIDER_FAILURES_BEFORE_QUIET
+
+
+def test_when_every_provider_is_cooling_the_chain_still_runs_in_full(monkeypatch) -> None:
+ """An install where nothing writes keeps today's behaviour: every family is
+ tried, the first failure is the one reported, and the PANE-level quiet
+ period is what stops the retries — the breaker never turns a broken
+ install into a silent one."""
+ first = _CountingBrain("first", fails=True)
+ second = _CountingBrain("second", fails=True)
+ monkeypatch.setattr(recap_engine, "_resolve_brains", lambda: [first, second])
+
+ for _ in range(recap_engine.PROVIDER_FAILURES_BEFORE_QUIET + 2):
+ with pytest.raises(RuntimeError, match="first cannot write today"):
+ asyncio.run(recap_engine.summarize_with_model(_pane(), _rows(20)))
+
+ assert first.calls == second.calls == recap_engine.PROVIDER_FAILURES_BEFORE_QUIET + 2
+
+
def test_a_depleted_key_failure_reads_as_a_sentence_not_json() -> None:
"""The screenshot case: the card led with a wall of provider JSON."""
note = recap_engine.describe_failure(