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: remember Gemini thinking capability across calls

Ruben Lütke5f5e8d7702cb
diff --git a/jarvis/plugins/brain/gemini.py b/jarvis/plugins/brain/gemini.py
index 084cfedd16..d2e43bc8ae 100644
--- a/jarvis/plugins/brain/gemini.py
+++ b/jarvis/plugins/brain/gemini.py
@@ -60,6 +60,15 @@ _MAX_CACHE_SLOTS = 4
# the cache isn't worth it — then we skip it and fall back to the direct path.
_MIN_CACHE_TOKENS = 4096
+# Runtime capability memory shared by every short-lived GeminiBrain instance.
+# Curator/UltraWiki calls deliberately instantiate a fresh brain per item, so
+# an instance-only rejection cache made every item repeat the same doomed 400
+# probe before succeeding. The process lifetime is the right scope: model
+# capabilities are stable across calls, while a restart naturally re-probes
+# after an SDK or remote-model change. Keys include the budget so rejecting
+# the router's zero budget never disables a positive budget in another tier.
+_REJECTED_THINKING_BUDGETS: set[tuple[str, int]] = set()
+
def _is_stale_context_cache_error(exc: Exception) -> bool:
"""True if *exc* is Gemini's stale-context-cache failure (BUG-019).
@@ -780,6 +789,8 @@ class GeminiBrain:
if (
effective_thinking_budget is not None
and effective_thinking_budget not in self._rejected_thinking_budgets
+ and (self._model, effective_thinking_budget)
+ not in _REJECTED_THINKING_BUDGETS
):
try:
from google.genai import types as _genai_types
@@ -992,6 +1003,9 @@ class GeminiBrain:
# on this instance skip that budget (and the extra 400)
# entirely.
self._rejected_thinking_budgets.add(pending_rejected_budget)
+ _REJECTED_THINKING_BUDGETS.add(
+ (self._model, pending_rejected_budget)
+ )
log.info(
"Gemini model %s rejects thinking_budget=%d — "
"omitting it from now on",
@@ -1071,6 +1085,9 @@ class GeminiBrain:
# The message names the thinking config — no
# further evidence needed.
self._rejected_thinking_budgets.add(rejected_budget)
+ _REJECTED_THINKING_BUDGETS.add(
+ (self._model, rejected_budget)
+ )
elif not dropped_cache:
pending_rejected_budget = rejected_budget
continue
diff --git a/tests/unit/brain/test_gemini_reasoning_effort.py b/tests/unit/brain/test_gemini_reasoning_effort.py
index 8df17df1a6..c7b340f796 100644
--- a/tests/unit/brain/test_gemini_reasoning_effort.py
+++ b/tests/unit/brain/test_gemini_reasoning_effort.py
@@ -24,18 +24,29 @@ so these tests skip cleanly on environments without the SDK.
"""
from __future__ import annotations
-from collections.abc import AsyncIterator
+from collections.abc import AsyncIterator, Iterator
from types import SimpleNamespace
from typing import Any
import pytest
from jarvis.core.protocols import BrainMessage, BrainRequest
-from jarvis.plugins.brain.gemini import GeminiBrain
+from jarvis.plugins.brain.gemini import (
+ _REJECTED_THINKING_BUDGETS,
+ GeminiBrain,
+)
pytest.importorskip("google.genai")
[email protected](autouse=True)
+def _clear_process_capability_memory() -> Iterator[None]:
+ """Keep process-wide production capability memory isolated per test."""
+ _REJECTED_THINKING_BUDGETS.clear()
+ yield
+ _REJECTED_THINKING_BUDGETS.clear()
+
+
class _FakeGeminiClient:
"""Records every ``config`` passed to ``generate_content_stream``."""
@@ -219,6 +230,31 @@ async def test_parameterless_400_recovers_and_is_remembered() -> None:
assert "thinking_config" not in fake.calls[2]
+async def test_parameterless_400_is_remembered_across_instances() -> None:
+ """Short-lived curator brains must share a proven model capability.
+
+ UltraWiki creates a fresh provider for each distilled item. An
+ instance-only cache therefore paid one rejected request per item even
+ though the first accepted retry had already proved the capability.
+ """
+ first = GeminiBrain(model="gemini-short-lived-curator")
+ first_fake = _FakeGeminiClient(reject_thinking_generic=True)
+ first._client = first_fake # type: ignore[assignment]
+
+ await _drain(first.complete(_request("none")))
+ assert len(first_fake.calls) == 2
+
+ second = GeminiBrain(model="gemini-short-lived-curator")
+ second_fake = _FakeGeminiClient(reject_thinking_generic=True)
+ second._client = second_fake # type: ignore[assignment]
+
+ await _drain(second.complete(_request("none")))
+
+ assert len(second_fake.calls) == 1
+ assert "thinking_config" not in second_fake.calls[0]
+
+
@pytest.mark.asyncio
async def test_unrelated_400_still_propagates_and_forgets_nothing() -> None:
"""A parameterless 400 whose retry ALSO fails is not the thinking