fix(tui_gateway): restore openrouter provider on session resume (salvage #57593) - #85558
Merged
kshitijk4poor merged 2 commits intoAug 13, 2026
Merged
Conversation
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
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.
19 tasks
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
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_PROVIDERSintui_gateway/server.pytreated"openrouter"as a non-routable billing bucket (alongside"auto"/"custom"), so_stored_session_runtime_overridesdropped 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_agentre-resolves credentials via the normal provider resolution (no api_key is persisted), andresolve_billing_route()only writesbilling_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/customremain filtered)tests/test_tui_gateway_server.py: regression testtest_openrouter_session_resume_restores_provider+ updated bare-bucket loopValidation
provider_override="openrouter"restored, resume routes correctlycustom/autorows (#44022)tests/test_tui_gateway_server.pyE2E: real-import run against isolated
HERMES_HOMEwith a custom-endpoint ambient config confirmed the #57588 row shape restoresopenrouter, bare buckets stay filtered, and explicitmodel_config.providerprecedence 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.