fix(agent): respect fallback api_mode overrides - #16346
Open
Kayphoon wants to merge 2 commits into
Open
Conversation
19 tasks
This was referenced May 21, 2026
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating a real fallback-routing gap. The defect remains on current main: agent/chat_completion_helpers.py:1330-1346 does not forward a fallback entry's api_mode, and :1363-1411 then derives transport solely from heuristics.
Problems
- The patch targets historical code.
run_agent.py:4771-4774is now only a forwarder; the live implementation isagent/chat_completion_helpers.py:1232.git apply --checkconfirms this branch cannot apply, including becausetests/run_agent/test_fallback_model.pyno longer exists. - The new fixed allowlist would reject valid
codex_app_server; canonical validation includes it athermes_cli/runtime_provider.py:332-352. - The sibling init-time and gateway-auth fallback paths also omit the entry override at
agent/agent_init.py:1005-1013andgateway/run.py:1966-1970.
Suggested changes
- Salvage the precedence logic into
agent/chat_completion_helpers.py, aligned with current validation, and move coverage totests/run_agent/test_provider_fallback.py. - Include the init-time and gateway paths if the intended guarantee is that every fallback entry honors its explicit transport.
This is an automated hermes-sweeper review.
Kayphoon
force-pushed
the
fix/fallback-provider-api-mode
branch
from
July 13, 2026 21:16
e85a2c4 to
5fbf892
Compare
Kayphoon
force-pushed
the
fix/fallback-provider-api-mode
branch
from
July 14, 2026 07:30
5fbf892 to
5e97ca2
Compare
Author
|
Updated this PR after addressing the review feedback and cleaned up the commit history. Commit structure:
Verification:
The related inline review thread has been addressed and resolved. |
1 task
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Makes provider fallback activation honor an explicit
api_modeonfallback_providersentries before falling back to provider/base URL/model heuristics.This fixes custom fallback providers that need Anthropic Messages routing (
/v1/messages) but do not use a base URL ending in/anthropic. Before this change, those fallbacks were treated as OpenAI chat completions and could hit the wrong endpoint.Related Issue
Fixes #
Type of Change
Changes Made
run_agent.pyapi_modeoverride from fallback config entries.resolve_provider_client(...).api_modeinto the context compressor update.tests/run_agent/test_fallback_model.pyprovider: customfallbacks that explicitly setapi_mode: anthropic_messageswhile using a non-/anthropicbase URL.How to Test
anthropic_messagesmode and builds the native Anthropic client instead of keeping an OpenAI chat-completions client.Test commands run locally:
Results:
tests/run_agent/test_fallback_model.py: 29 passedtests/run_agent/test_provider_fallback.py: 19 passedI also attempted the full wrapper command required by the local development guide:
Notes:
scripts/run_tests.shwith no args failed locally withARGS[@]: unbound variablebefore pytest collection.scripts/run_tests.sh tests/completed collection/execution but failed on unrelated local environment/platform issues, including missing optional modules such asfaster_whisperand ACP/MCP/TTS/web/platform-specific tests. The new fallback tests above passed.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AFor New Skills
N/A
Screenshots / Logs
N/A