-
Notifications
You must be signed in to change notification settings - Fork 1
fix(routing): classify primary provider transport failures explicitly #922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seonghobae
merged 7 commits into
main
from
claude/noema-opencode-strix-orchestration-sexqzc
Aug 31, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a20e69a
fix(routing): classify primary provider transport failures explicitly
claude 7791954
Merge remote-tracking branch 'origin/main' into claude/noema-opencode…
claude 17a6ed5
docs(routing): explain why ToolFallbackStoppedError stays terminal
claude 94d142b
Merge branch 'main' into claude/noema-opencode-strix-orchestration-se…
seonghobae c9f4a64
test(routing): prove non-retryable 4xx advances the free pool
claude 5d60b92
Merge remote-tracking branch into claude/noema-opencode-strix-orchest…
claude 3fea0af
docs: clarify failover 4xx coverage and models.dev retry count
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ | |
| ToolFailureKind, | ||
| ToolFallbackAction, | ||
| ToolFallbackStoppedError, | ||
| classify_provider_transport_failure, | ||
| classify_tool_failure, | ||
| downgrade_to_failover, | ||
| ) | ||
|
|
@@ -6472,10 +6473,37 @@ def call(agent: ModelAgent) -> tuple[str, str, dict[str, Any] | None]: | |
| if agent.group_name or allowed_agent_ids is not None: | ||
| self._group_router.observe_failure(agent.id) | ||
| if isinstance(exc, ToolFallbackStoppedError): | ||
| # Deliberately terminal, even inside a free/auto virtual | ||
| # pool with untried candidates remaining: every path that | ||
| # raises this (the provider's own explicit terminal | ||
| # tool-execution-state signal via | ||
| # _provider_tool_execution_stopped, or a FAIL_CLOSED | ||
| # verdict from classify_tool_failure below) resolves to | ||
| # ambiguous_outcome, permission_denied, policy_blocked, or | ||
| # invalid_arguments -- the exact ADR 0001 safety invariants | ||
| # ("permission and policy failures never fall through to | ||
| # another agent"; "non-idempotent timeout or transport | ||
| # uncertainty never replays automatically") that a | ||
| # different candidate cannot make safer: an ambiguous | ||
| # server-side outcome is ambiguous regardless of which | ||
| # agent asks next, and authorization/policy denial must | ||
| # not be worked around by trying a different one. Do not | ||
| # convert this to failover without an explicit product | ||
| # decision distinguishing which failure kinds that would | ||
| # actually be safe for. | ||
| raise | ||
| if isinstance(exc, ProviderUpstreamError): | ||
| last_upstream_error = exc | ||
| if isinstance(exc, ProviderResponseError): | ||
| # The primary chat call is a bounded, side-effect-free | ||
| # model request, not a tool invocation: classify from | ||
| # the provider's own already-computed retryability | ||
| # instead of classify_tool_failure's message-text | ||
| # heuristics, so free/auto virtual-model failover can | ||
| # never be accidentally downgraded to fail-closed by | ||
| # incidental wording in an upstream error body (e.g. a | ||
| # 400 that happens to mention "invalid arguments"). | ||
| decision = classify_provider_transport_failure(exc.retryable) | ||
|
Comment on lines
6495
to
+6505
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
6495
to
+6505
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| elif isinstance(exc, ProviderResponseError): | ||
| if allowed_agent_ids is None: | ||
| raise | ||
| bounded_provider_response_failures += 1 | ||
|
|
@@ -6484,15 +6512,9 @@ def call(agent: ModelAgent) -> tuple[str, str, dict[str, Any] | None]: | |
| self._record_tool_fallback(agent.id, decision, retry_attempt) | ||
| self._record_failure(agent.id) | ||
| break | ||
| decision = classify_tool_failure(exc) | ||
| else: | ||
| decision = classify_tool_failure(exc) | ||
| action = decision.action | ||
| if ( | ||
| isinstance(exc, ProviderUpstreamError) | ||
| and not exc.retryable | ||
| and action is ToolFallbackAction.RETRY_SAME_AGENT | ||
| ): | ||
| decision = downgrade_to_failover(decision) | ||
| action = decision.action | ||
| # A failed attempt is one Bernoulli stability observation | ||
| # for measured group routing regardless of what happens next. | ||
| if ( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,44 @@ def downgrade_to_failover(decision: ToolFailureDecision) -> ToolFailureDecision: | |
| ) | ||
|
|
||
|
|
||
| def classify_provider_transport_failure(retryable: bool) -> ToolFailureDecision: | ||
| """Map one plain (non-tool) provider transport failure to a fallback decision. | ||
|
|
||
| This is the classifier for a bounded, side-effect-free model completion | ||
| request -- the primary call a virtual ``orchestrator/free``/``orchestrator/auto`` | ||
| route makes, not an in-flight tool invocation. Because the request has no | ||
| external side effect, replaying it (same agent) or moving to the next | ||
| ranked candidate can never create the ambiguous-outcome risk | ||
| :func:`classify_tool_failure` exists to guard against, so this classifier | ||
| intentionally never returns :attr:`ToolFallbackAction.FAIL_CLOSED`. | ||
|
|
||
| ``retryable`` is the upstream classification already computed by | ||
| :func:`contextual_orchestrator.provider_errors.classify_provider_failure` | ||
| (true for a transient 429/500/502/503/504/408/network failure, false for a | ||
| non-transient 4xx such as 401/403/404). The decision is keyed on that | ||
| boolean alone -- never on the failure's message text -- so an upstream | ||
| error body that happens to mention "tool", "command", "invalid arguments", | ||
| or another :func:`classify_tool_failure` keyword can never accidentally | ||
| reclassify a plain provider outage as fail-closed (CWE-705: incorrect | ||
| control flow scoping between the tool-execution and provider-transport | ||
| failure domains). | ||
| """ | ||
| if not isinstance(retryable, bool): | ||
| raise TypeError("retryable must be a boolean") | ||
| if retryable: | ||
| return _decision( | ||
| ToolFailureKind.TRANSPORT_ERROR, | ||
| ToolFallbackAction.RETRY_SAME_AGENT, | ||
| retry_safe=True, | ||
| circuit_failure=True, | ||
| ) | ||
| return _decision( | ||
| ToolFailureKind.TRANSPORT_ERROR, | ||
| ToolFallbackAction.FAILOVER_AGENT, | ||
| circuit_failure=True, | ||
| ) | ||
|
Comment on lines
+155
to
+159
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
| _HTTP_FAILURE_KIND = { | ||
| 400: ToolFailureKind.INVALID_ARGUMENTS, | ||
| 401: ToolFailureKind.PERMISSION_DENIED, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Catalog retries preserve cost safety
Only parsed metadata reaches the exact model join. Exhaustion returns
None, leaving cost unknown rather than classifying any model as free.Was this helpful? React with 👍 or 👎 to provide feedback.