Skip to content

fix(tui_gateway): restore openrouter provider on session resume (salvage #57593) - #85558

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/57593-openrouter-resume
Aug 13, 2026
Merged

fix(tui_gateway): restore openrouter provider on session resume (salvage #57593)#85558
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/57593-openrouter-resume

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Resuming an OpenRouter session after switching the global default to a custom endpoint now restores OpenRouter as the session's provider instead of routing the stored model to the new endpoint (which failed with a bogus "context window of 2,048 tokens" error).

Salvage of #57593 by @liuhao1024 onto current main (original branch is ~7,900 commits stale). Cherry-picked with authorship preserved.

Root cause: _BARE_BILLING_PROVIDERS in tui_gateway/server.py treated "openrouter" as a non-routable billing bucket (alongside "auto"/"custom"), so _stored_session_runtime_overrides dropped the provider on resume and the session fell through to the ambient default endpoint. Unlike bare "custom"/"auto", "openrouter" IS a fully routable provider identity — restoring it is safe: _make_agent re-resolves credentials via the normal provider resolution (no api_key is persisted), and resolve_billing_route() only writes billing_provider="openrouter" when the turn actually routed via openrouter (provider name or openrouter.ai host).

Changes

  • tui_gateway/server.py: remove "openrouter" from _BARE_BILLING_PROVIDERS (auto/custom remain filtered)
  • tests/test_tui_gateway_server.py: regression test test_openrouter_session_resume_restores_provider + updated bare-bucket loop

Validation

Before After
Resume OpenRouter session with custom endpoint as global default provider dropped → resume hits custom endpoint with OpenRouter slug → context-window error provider_override="openrouter" restored, resume routes correctly
Resume bare custom/auto rows (#44022) filtered still filtered
tests/test_tui_gateway_server.py 552 passed

E2E: real-import run against isolated HERMES_HOME with a custom-endpoint ambient config confirmed the #57588 row shape restores openrouter, bare buckets stay filtered, and explicit model_config.provider precedence is intact.

Fixes #57588
Closes #57593

Credit: @liuhao1024 (commit cherry-picked, authorship preserved). #57597 by @Ahmett101 implemented the same fix and is already closed as duplicate.

BARE_BILLING_PROVIDERS incorrectly included "openrouter" alongside
"auto" and "custom".  OpenRouter is a fully routable provider with
its own API key and base_url — sessions that used OpenRouter store
billing_provider="openrouter", and dropping it forces resume to the
current global model (e.g. a custom endpoint), which is the wrong
provider for the stored model.

Remove "openrouter" from the bare-bucket set so OpenRouter sessions
correctly restore their provider identity on resume.

Fixes NousResearch#57588
@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) provider/openrouter OpenRouter aggregator area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 13, 2026
The set is no longer in parity with agent_init's fail-fast gate (which
still skips openrouter for a different reason: default route, not
unroutable). Say so instead of claiming parity.
@kshitijk4poor
kshitijk4poor merged commit cdea821 into NousResearch:main Aug 13, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists provider/openrouter OpenRouter aggregator sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Adding new custom provider breaks all previous sessions. Provider changes, but not the model.

3 participants