Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

No fallback in the Gemini CLI either, and a failed turn's reason is never the answer (#114)

github-actions[bot]f0ee4d2df8a3
diff --git a/runner/server.py b/runner/server.py
index 47236c6b..e4ccf1f3 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -3007,10 +3007,21 @@ def _gemini_settings(home: pathlib.Path, mcp_servers: list[dict] | None, model:
continue
servers[name] = entry
pinned = sorted(set(GEMINI_MODELS) | ({model} if model else set()))
+ # No fallback either: on a quota or transient error gemini-cli's fallback handler picks the next
+ # policy of the model's chain (its default preview chain ends in gemini-3-flash-preview as the
+ # last resort), and in headless mode that switch is silent; a 5-minute turn on gemini-3.8-flash
+ # finished its work on gemini-3-flash-preview that way (2026-09-07 02:10Z). Every chain the CLI
+ # can resolve for this turn is one policy, the turn's own model: with no other candidate the
+ # handler has nothing to switch to and the provider's error ends the turn, honestly. Retries
+ # stay on the same model (sticky_retry on transient and unknown failures).
+ own = [{"model": model or GEMINI_DEFAULT_MODEL, "isLastResort": True, "maxAttempts": 3,
+ "actions": {"terminal": "prompt", "transient": "prompt", "not_found": "prompt", "unknown": "prompt"},
+ "stateTransitions": {"terminal": "terminal", "transient": "sticky_retry", "not_found": "terminal", "unknown": "sticky_retry"}}]
cfg: dict = {"security": {"auth": {"selectedType": "gemini-api-key"}},
# the ids are honest: -m resolves through this table, and each entry pins an id to itself
"experimental": {"dynamicModelConfiguration": True},
- "modelConfigs": {"modelIdResolutions": {m: {"default": m, "contexts": []} for m in pinned}}}
+ "modelConfigs": {"modelIdResolutions": {m: {"default": m, "contexts": []} for m in pinned},
+ "modelChains": {k: own for k in ("preview", "default", "lite", "auto-preview", "auto-default")}}}
if servers:
cfg["mcpServers"] = servers
(gdir / "settings.json").write_text(json.dumps(cfg, indent=2))
@@ -3645,9 +3656,15 @@ def _gemini_to_claude(obj: dict, state: dict) -> list[dict]:
# completed. The settings pin every id to itself; this is the check that they held.
requested = str(state.get("model") or "")
other = [m for m in served.split(",") if m and requested and m != requested]
- if other and not err:
- err = {"type": "model_substituted", "message": f"the CLI ran {', '.join(other)} instead of {requested}"}
+ if other:
+ # the substitution is the more specific cause; the CLI's own error, when it says one, rides along
+ tail = f" (the CLI ended with {err.get('type') or 'an error'}: {err.get('message')})" if err and err.get("message") else ""
+ err = {"type": "model_substituted", "message": f"the CLI ran {', '.join(other)} instead of {requested}{tail}"}
msg = err["message"]
+ elif err and not msg:
+ # an error without a message: name its type, never the answer text (a failed turn whose
+ # reason read as the finished answer, 2026-09-07)
+ msg = f"the CLI ended the turn with an error ({err.get('type') or 'unknown'})"
ev = {"type": "result", "subtype": "error" if err else "success", "is_error": bool(err),
"result": msg or state.get("final", ""), "usage": _gemini_usage(stats)}
if served:
diff --git a/runner/tests/test_gemini_build.py b/runner/tests/test_gemini_build.py
index bbd7401f..ff819ead 100644
--- a/runner/tests/test_gemini_build.py
+++ b/runner/tests/test_gemini_build.py
@@ -232,3 +232,23 @@ def test_a_served_model_other_than_the_one_asked_for_fails_the_turn():
def test_the_default_model_is_the_newest_flash():
assert BACKENDS["gemini"]["default_model"] == "gemini-3.8-flash"
+def test_every_chain_is_one_policy_the_turns_own_model():
+ """No fallback: gemini-cli's handler switches to the chain's next policy on a quota or transient
+ error, silently in headless mode (a turn on gemini-3.8-flash finished on gemini-3-flash-preview,
+ 2026-09-07). Every chain it can resolve is one policy, the turn's model."""
+ d = tempfile.mkdtemp()
+ _build_gemini("google", Auth(api_key="k"), "gemini-3.8-flash", "hi", d, {})
+ chains = json.loads(pathlib.Path(d, ".harness", "home", ".gemini", "settings.json").read_text())["modelConfigs"]["modelChains"]
+ assert set(chains) == {"preview", "default", "lite", "auto-preview", "auto-default"}
+ for name, chain in chains.items():
+ assert len(chain) == 1 and chain[0]["model"] == "gemini-3.8-flash" and chain[0]["isLastResort"] is True, name
+ assert chain[0]["stateTransitions"]["transient"] == "sticky_retry"
+
+
+def test_a_failed_result_never_reads_as_the_answer_and_a_substitution_names_the_clis_error_too():
+ st = {"input_tokens": 10, "output_tokens": 2, "cached": 0, "models": {"gemini-3.8-flash": {}}}
+ out = _gemini_to_claude({"type": "result", "status": "error", "stats": st, "error": {"type": "FatalTurnError"}}, {"model": "gemini-3.8-flash", "final": "I built the deck."})
+ assert out[0]["is_error"] is True and out[0]["result"] == "the CLI ended the turn with an error (FatalTurnError)"
+ both = _gemini_to_claude({"type": "result", "status": "error", "stats": {**st, "models": {"gemini-3.8-flash": {}, "gemini-3-flash-preview": {}}},
+ "error": {"type": "unknown", "message": "[API Error: quota]"}}, {"model": "gemini-3.8-flash", "final": "I built the deck."})
+ assert both[0]["result"] == "the CLI ran gemini-3-flash-preview instead of gemini-3.8-flash (the CLI ended with unknown: [API Error: quota])"