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): stop the sticky red 'Chain failure' banner masquerading as a broken Obsidian link

Ruben Lütke65fddb8e144d
diff --git a/jarvis/memory/wiki/extractor.py b/jarvis/memory/wiki/extractor.py
index eca6d8bfcb..148e7b2df2 100644
--- a/jarvis/memory/wiki/extractor.py
+++ b/jarvis/memory/wiki/extractor.py
@@ -847,7 +847,21 @@ class ConversationFactExtractor:
label="ConversationFactExtractor",
aggregate=aggregate,
validate=_validate_response,
- allow_last_rejection=lambda reason: (
+ # Both reasons are CONTENT verdicts ("this turn holds nothing
+ # storable"), not provider damage. Two independent families
+ # agreeing ends the chain quietly; without this, an ordinary
+ # no-fact turn burned EVERY provider (incl. dead rungs and their
+ # timeouts) and recorded a scary chain failure the Wiki tab
+ # rendered as a red "not connected" state (live 2026-07-18).
+ allow_last_rejection=lambda reason: reason in (
+ "empty-needs-second-opinion",
+ "candidate array has no grounded usable fact",
+ ),
+ # But a LONE ungrounded array (no second opinion available) stays
+ # a retryable failure: one weak provider must never be terminal
+ # proof that the transcript held no facts. A lone valid EMPTY
+ # answer remains acceptable as before.
+ allow_lone_rejection=lambda reason: (
reason == "empty-needs-second-opinion"
),
)
diff --git a/jarvis/memory/wiki/health.py b/jarvis/memory/wiki/health.py
index f5938b67a5..78d44d4384 100644
--- a/jarvis/memory/wiki/health.py
+++ b/jarvis/memory/wiki/health.py
@@ -52,6 +52,18 @@ class WikiHealth:
"detail": safe_preview(detail, max_chars=800),
}
+ def record_chain_success(self) -> None:
+ """A completed provider-chain run clears the failure record.
+
+ Without this, ONE bad moment (a single call exhausting every
+ provider) painted the Wiki tab red forever — users read the sticky
+ banner as "Obsidian is not connected" while writes were flowing
+ (live report 2026-07-18). The surface must say "currently broken",
+ never "was ever broken".
+ """
+ with self._lock:
+ self._last_chain_failure = None
+
def record_index(
self,
ok: bool,
diff --git a/jarvis/memory/wiki/provider_chain.py b/jarvis/memory/wiki/provider_chain.py
index 515a13fe08..584d4174ea 100644
--- a/jarvis/memory/wiki/provider_chain.py
+++ b/jarvis/memory/wiki/provider_chain.py
@@ -66,6 +66,16 @@ def reset_provider_failure_memory() -> None:
_provider_failures.clear()
+def _record_chain_recovery(label: str) -> None:
+ """Clear the sticky health chain-failure record on any usable outcome."""
+ try:
+ from jarvis.memory.wiki.health import health
+
+ health.record_chain_success()
+ except Exception: # noqa: BLE001 — health recording must never break the pipeline
+ log.debug("%s: health record_chain_success failed", label, exc_info=True)
+
+
def _order_by_cooldown(
chain: list[tuple[str, str | None]],
) -> tuple[list[tuple[str, str | None]], list[str]]:
@@ -171,6 +181,7 @@ async def complete_with_fallback(
aggregate: Callable[[Any], Any],
validate: Callable[[Any], str | None] | None = None,
allow_last_rejection: Callable[[str], bool] | None = None,
+ allow_lone_rejection: Callable[[str], bool] | None = None,
) -> tuple[Any, str] | None:
"""Try each ``(provider, model)`` until one returns an aggregated response.
@@ -178,6 +189,14 @@ async def complete_with_fallback(
when the whole chain fails. ``validate`` can reject a transport-successful
response with a short reason; the next provider is then tried before the
caller gives up on malformed or truncated structured output.
+
+ ``allow_last_rejection`` marks CONTENT-verdict rejections ("nothing
+ usable in this turn") that may end the chain: two agreeing providers are
+ consensus and stop immediately. ``allow_lone_rejection`` (default: same
+ set) additionally decides whether a SINGLE such verdict — with no second
+ opinion available — is accepted as final; a reason outside it stays a
+ retryable failure, so one weak provider can never be terminal proof that
+ a transcript held no facts.
"""
from jarvis.memory.wiki.curator_llm import instantiate_curator_brain
@@ -235,12 +254,13 @@ async def complete_with_fallback(
)
last_in_chain = index == len(ordered) - 1
if allowed:
- # Keep a semantically safe fallback (currently the
- # extractor's valid empty array) while still asking the
+ # An allowed rejection is a CONTENT verdict ("this
+ # turn holds nothing usable"), not provider damage:
+ # it never cools the provider down. Keep a
+ # semantically safe fallback while asking the
# remaining providers for one *valid structured*
- # second opinion. Transport/malformed failures do not
- # count, but a second allowed answer is agreement and
- # ends the chain immediately.
+ # second opinion; a second allowed answer is
+ # agreement and ends the chain.
if allowed_rejection_fallback is not None:
log.info(
"%s: accepting provider %s output after a "
@@ -249,19 +269,44 @@ async def complete_with_fallback(
provider,
safe_rejection,
)
+ _record_chain_recovery(label)
return agg, provider
# If every later provider fails, their failure must not
# erase this valid bounded answer.
allowed_rejection_fallback = (agg, provider, rejection)
- if last_in_chain and allowed:
+ if last_in_chain:
+ lone_ok = (
+ allow_lone_rejection is None
+ or allow_lone_rejection(rejection)
+ )
+ if lone_ok:
+ log.info(
+ "%s: accepting final provider %s output "
+ "after bounded second-opinion attempts "
+ "(%s)",
+ label,
+ provider,
+ safe_rejection,
+ )
+ _record_chain_recovery(label)
+ return agg, provider
+ # A lone verdict this caller does not trust as
+ # final stays a retryable failure — one weak
+ # provider must never be terminal proof.
+ failure_summaries.append(
+ f"{provider} unusable output: {safe_rejection}"
+ )
+ allowed_rejection_fallback = None
+ continue
log.info(
- "%s: accepting final provider %s output after "
- "bounded second-opinion attempts (%s)",
+ "%s: provider %s returned a valid but empty/"
+ "ungrounded result (%s) - asking one more "
+ "provider for a second opinion",
label,
provider,
safe_rejection,
)
- return agg, provider
+ continue
log.warning(
"%s: provider %s returned unusable output (%s) - "
"trying next provider",
@@ -282,6 +327,7 @@ async def complete_with_fallback(
exc_info=True,
)
continue
+ _record_chain_recovery(label)
return agg, provider
except TimeoutError:
log.warning(
@@ -307,14 +353,20 @@ async def complete_with_fallback(
if allowed_rejection_fallback is not None:
agg, provider, rejection = allowed_rejection_fallback
- log.info(
- "%s: accepting provider %s output after later second-opinion "
- "attempts failed (%s)",
- label,
- provider,
- safe_preview(rejection, max_chars=240),
- )
- return agg, provider
+ safe_rejection = safe_preview(rejection, max_chars=240)
+ if allow_lone_rejection is None or allow_lone_rejection(rejection):
+ log.info(
+ "%s: accepting provider %s output after later second-opinion "
+ "attempts failed (%s)",
+ label,
+ provider,
+ safe_rejection,
+ )
+ _record_chain_recovery(label)
+ return agg, provider
+ # A lone content verdict this caller does not trust as final: the
+ # chain ends as a retryable failure instead of terminal proof.
+ failure_summaries.append(f"{provider} unusable output: {safe_rejection}")
log.error(
"%s: ALL %d wiki provider(s) failed or returned unusable output — "
diff --git a/tests/unit/memory/wiki/test_extractor.py b/tests/unit/memory/wiki/test_extractor.py
index 8016bd4e1d..d9650824af 100644
--- a/tests/unit/memory/wiki/test_extractor.py
+++ b/tests/unit/memory/wiki/test_extractor.py
@@ -205,6 +205,56 @@ async def test_malformed_json_yields_nothing(journal: CandidateJournal) -> None:
assert journal.backlog_count() == 0
+async def test_ungrounded_consensus_ends_the_chain_without_a_chain_failure(
+ journal: CandidateJournal,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """Two families agreeing "nothing groundable in this turn" is a quiet
+ no-op, never a chain failure. Live 2026-07-18: an ordinary no-fact turn
+ burned all 8 providers (incl. dead rungs and a 30s timeout) and left a
+ sticky red 'Chain failure' banner users read as 'Obsidian not connected'."""
+ from jarvis.memory.wiki import health as health_module
+ from jarvis.memory.wiki.health import WikiHealth
+
+ isolated_health = WikiHealth()
+ monkeypatch.setattr(health_module, "health", isolated_health)
+
+ ungrounded = json.dumps(
+ [
+ {
+ "fact": "The assistant guessed something about the user.",
+ "kind": "asset",
+ "evidence_turn_id": "assistant-turn",
+ }
+ ]
+ )
+ registry = ScriptedRegistry(
+ {
+ # Chain order: primary gemini, then the rest alphabetically —
+ # nvidia is the second opinion, openrouter the never-asked third.
+ "gemini": ungrounded,
+ "nvidia": ungrounded,
+ "openrouter": _ok_facts_json(),
+ }
+ )
+ extractor = ConversationFactExtractor(
+ config=_config(), journal=journal, registry=registry,
+ )
+
+ count = await extractor.extract_and_journal(
+ "Hmm, interesting.",
+ "Indeed.",
+ source_label="voice-fact:consensus",
+ turn_hash="h-consensus",
+ )
+
+ assert count == 0
+ assert journal.backlog_count() == 0
+ assert registry.tried == ["gemini", "nvidia"] # consensus stopped the chain
+ assert isolated_health.snapshot()["last_chain_failure"] is None
+
+
@pytest.mark.asyncio
async def test_parseable_unusable_output_crosses_to_grounded_provider(
journal: CandidateJournal,
diff --git a/tests/unit/memory/wiki/test_health.py b/tests/unit/memory/wiki/test_health.py
index 2816f718ee..64dfe1a1c1 100644
--- a/tests/unit/memory/wiki/test_health.py
+++ b/tests/unit/memory/wiki/test_health.py
@@ -34,6 +34,14 @@ def test_chain_failure_and_backlog_recorded():
assert snap["journal_backlog"] == 5
+def test_chain_success_clears_the_failure_record():
+ h = WikiHealth()
+ h.record_chain_failure("openai 401; gemini 429")
+ assert h.snapshot()["last_chain_failure"] is not None
+ h.record_chain_success()
+ assert h.snapshot()["last_chain_failure"] is None
+
+
def test_chain_failure_detail_redacts_secrets():
h = WikiHealth()
secret = "sk-proj-" + "Q" * 32
diff --git a/tests/unit/memory/wiki/test_provider_chain.py b/tests/unit/memory/wiki/test_provider_chain.py
index 5669d39157..d68b0aacfe 100644
--- a/tests/unit/memory/wiki/test_provider_chain.py
+++ b/tests/unit/memory/wiki/test_provider_chain.py
@@ -354,6 +354,66 @@ async def test_two_valid_empty_opinions_stop_later_provider_attempts() -> None:
assert reg.tried == ["openrouter", "antigravity", "gemini"]
+async def test_allowed_rejection_never_cools_the_provider_down() -> None:
+ """A valid-but-empty answer is a CONTENT verdict, not provider damage —
+ it must not demote the provider for the next 15 minutes."""
+ from jarvis.memory.wiki import provider_chain as pc
+
+ reg = _ScriptedRegistry(
+ {"openrouter": "[]", "gemini": '[{"fact":"usable"}]'}
+ )
+ result = await complete_with_fallback(
+ registry=reg,
+ chain=[("openrouter", None), ("gemini", None)],
+ request=object(),
+ timeout_s=5.0,
+ label="test",
+ aggregate=_aggregate,
+ validate=lambda agg: "empty-needs-second-opinion" if agg.text == "[]" else None,
+ allow_last_rejection=lambda reason: reason == "empty-needs-second-opinion",
+ )
+ assert result is not None and result[1] == "gemini"
+ assert not pc._in_cooldown("openrouter")
+
+
+async def test_chain_success_clears_the_sticky_health_failure(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ """Live 2026-07-18: one exhausted chain painted the Wiki tab red forever
+ ("Obsidian not connected" perception) although later runs succeeded —
+ nothing ever cleared last_chain_failure. Any usable outcome must clear it."""
+ from jarvis.memory.wiki import health as health_module
+ from jarvis.memory.wiki.health import WikiHealth
+
+ isolated_health = WikiHealth()
+ monkeypatch.setattr(health_module, "health", isolated_health)
+
+ reg = _FakeRegistry(fail_providers={"openrouter", "gemini"})
+ chain = [("openrouter", None), ("gemini", None)]
+ failed = await complete_with_fallback(
+ registry=reg,
+ chain=chain,
+ request=object(),
+ timeout_s=5.0,
+ label="test",
+ aggregate=_aggregate,
+ )
+ assert failed is None
+ assert isolated_health.snapshot()["last_chain_failure"] is not None
+
+ reg._fail = set() # providers recover
+ ok = await complete_with_fallback(
+ registry=reg,
+ chain=chain,
+ request=object(),
+ timeout_s=5.0,
+ label="test",
+ aggregate=_aggregate,
+ )
+ assert ok is not None
+ assert isolated_health.snapshot()["last_chain_failure"] is None
+
+
# --- failure cooldown: dead rungs stop taxing every call ---------------------