fix(api_server): pop fallback model kwarg to prevent AIAgent collision (salvage #35716) - #56170
Merged
Conversation
When the primary provider's auth fails (expired token / 429 quota cap), _resolve_runtime_agent_kwargs() falls through to the fallback provider chain, whose runtime dict carries its own 'model' key. api_server's _create_agent then did AIAgent(model=model, **runtime_kwargs), colliding on 'model' and 500ing every /v1/chat/completions request while a fallback was active. Pop the runtime model and let it override the config model, mirroring the native gateway path (_resolve_session_agent_runtime). Salvaged from #35716 by @ryo-solo (earliest submitter); the PR's second half (Mistral reasoning_content strip) is already handled on main and dropped. Co-authored-by: Hermes Agent <noreply@nousresearch.com>
This was referenced Jul 1, 2026
Closed
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.
Summary
The OpenAI-compatible
api_serverno longer 500s every/v1/chat/completionsrequest when a fallback provider activates.Root cause is a path asymmetry: when the primary provider's auth fails (expired token / 429 quota cap),
_resolve_runtime_agent_kwargs()falls through to the fallback chain, whose runtime dict carries its ownmodelkey.api_server._create_agentthen didAIAgent(model=model, **runtime_kwargs)→TypeError: got multiple values for keyword argument 'model'. The native gateway path already pops it (_resolve_session_agent_runtime,run.py);api_serverwas the one call site that never got the matching pop.Changes
gateway/platforms/api_server.py: popmodelfromruntime_kwargsbefore theAIAgent(...)call and let it override the config model, mirroring the native gateway path.tests/gateway/test_api_server.py: regression tests — collision handled + happy-path model preserved.Validation
Live E2E through the real resolution chain (not mocked): forced primary auth-fail → real
_resolve_runtime_agent_kwargs()returns the fallback dict withmodel→ real_create_agent./v1/chat/completionsw/ fallback activeTypeError→ 500TestAdapterInitAttribution
Salvaged from #35716 by @ryo-solo (earliest submitter of this fix; also independently fixed in #51170). The PR's second half (Mistral
reasoning_contentstrip) is already handled onmainvia the_needs_thinking_reasoning_padinversion (refs #45655) and is dropped.Infographic
Nous Research