Skip to content

The agent that grows with you

fix(agent): a no-fallback verdict wins over the local-ValueError fallback allowance

teknium179007efc4823
diff --git a/agent/turn_api_error.py b/agent/turn_api_error.py
index 25000481960..27b383f6f93 100644
--- a/agent/turn_api_error.py
+++ b/agent/turn_api_error.py
@@ -306,9 +306,11 @@ def settle_unrecovered_error(
retry_count = 0
return _verdict("continue")
# ``should_fallback=False`` marks a deterministic failure no other provider can fix (the
- # model's own malformed tool-call JSON, #12770): skip the cascade. Local validation errors
- # carry no classifier verdict and keep their historical fallback.
- if classified.should_fallback or is_local_validation_error:
+ # model's own malformed tool-call JSON, #12770; MoA preset/adapter faults, #55933): skip
+ # the cascade. An UNCLASSIFIED local ValueError/TypeError keeps its historical fallback;
+ # a recognised verdict that opts out wins even when the exception is a ValueError subclass.
+ _unclassified_local = is_local_validation_error and classified.reason == FailoverReason.unknown
+ if classified.should_fallback or _unclassified_local:
# Announce the fallback only when a chain exists, else "trying fallback..." lies
# before a silent abort.
if agent._has_pending_fallback():
diff --git a/tests/agent/test_malformed_tool_args_no_fallback.py b/tests/agent/test_malformed_tool_args_no_fallback.py
index 4cd7b054a89..985f5ce53dc 100644
--- a/tests/agent/test_malformed_tool_args_no_fallback.py
+++ b/tests/agent/test_malformed_tool_args_no_fallback.py
@@ -55,21 +55,39 @@ class _Agent:
return lambda *args, **kwargs: None
-def test_client_error_settlement_skips_fallback_when_classifier_says_so():
- agent = _Agent()
+def _settle(agent, err, provider, status_code):
retry = SimpleNamespace(copilot_stale_cred_retry_attempted=False, primary_recovery_attempted=False)
- err = _Err("invalid tool call arguments")
- classified = classify_api_error(err, provider="ollama")
-
+ classified = classify_api_error(err, provider=provider)
with patch("agent.conversation_loop._is_copilot_provider", lambda a: False):
- verdict = settle_unrecovered_error(
- agent, api_error=err, classified=classified, _retry=retry, status_code=400, error_msg=str(err),
+ return settle_unrecovered_error(
+ agent, api_error=err, classified=classified, _retry=retry, status_code=status_code, error_msg=str(err),
is_context_length_error=False, is_rate_limited=False, _is_zai_coding_overload=False,
- _provider="ollama", _base="http://127.0.0.1:11434/v1", _model="glm", messages=[], api_messages=[],
+ _provider=provider, _base="http://127.0.0.1:11434/v1", _model="glm", messages=[], api_messages=[],
api_kwargs={}, active_system_prompt="", conversation_history=None, approx_tokens=10,
retry_count=0, max_retries=3, compression_attempts=0, api_call_count=1,
)
+
+def test_client_error_settlement_skips_fallback_when_classifier_says_so():
+ agent = _Agent()
+ verdict = _settle(agent, _Err("invalid tool call arguments"), "ollama", 400)
assert verdict.action == "return"
assert verdict.result["failure_reason"] == FailoverReason.format_error.value
assert agent.activated == []
+
+
+def test_fallback_free_verdict_wins_over_local_valueerror_shape():
+ """A recognised no-fallback verdict raised as a ValueError subclass (MoA preset missing,
+ #55933) must not sneak through the unclassified-local-error fallback allowance; a truly
+ unclassified ValueError keeps it."""
+ from agent.errors import MoAPresetNotFoundError
+
+ agent = _Agent()
+ verdict = _settle(agent, MoAPresetNotFoundError("MoA preset 'old' was not found"), "moa", None)
+ assert verdict.action == "return"
+ assert agent.activated == []
+
+ agent = _Agent()
+ verdict = _settle(agent, ValueError("some local bug"), "openai", None)
+ assert verdict.action == "break"
+ assert agent.activated == [True]