Skip to content

fix(api_server): pop fallback model kwarg to prevent AIAgent collision (salvage #35716) - #56170

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-271d7d8b
Jul 1, 2026
Merged

fix(api_server): pop fallback model kwarg to prevent AIAgent collision (salvage #35716)#56170
teknium1 merged 1 commit into
mainfrom
hermes/hermes-271d7d8b

Conversation

@teknium1

@teknium1 teknium1 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Summary

The OpenAI-compatible api_server no longer 500s every /v1/chat/completions request 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 own model key. api_server._create_agent then did AIAgent(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_server was the one call site that never got the matching pop.

Changes

  • gateway/platforms/api_server.py: pop model from runtime_kwargs before the AIAgent(...) 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 with model → real _create_agent.

Before After
/v1/chat/completions w/ fallback active TypeError → 500 works
model passed to AIAgent (crash) fallback model overrides config model
happy path (no fallback) config model config model (unchanged)
TestAdapterInit 8 8/8 green

Attribution

Salvaged from #35716 by @ryo-solo (earliest submitter of this fix; also independently fixed in #51170). The PR's second half (Mistral reasoning_content strip) is already handled on main via the _needs_thinking_reasoning_pad inversion (refs #45655) and is dropped.

Infographic

api_server fallback crash fix

Nous Research

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>
@teknium1
teknium1 merged commit d578b61 into main Jul 1, 2026
31 checks passed
@teknium1
teknium1 deleted the hermes/hermes-271d7d8b branch July 1, 2026 08:26
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants