fix: persist provider on model switch and add billing_provider fallback - #85977
Merged
kshitijk4poor merged 1 commit intoAug 14, 2026
Merged
kshitijk4poor merged 1 commit into
kshitijk4poor merged 1 commit into
Conversation
Salvage of NousResearch#79604 (webtecnica) + NousResearch#85721 (pierrenode), combined and rebased onto current main with simplify-code findings folded in. NousResearch#79604: update_session_model() wrote the model name to sessions.model but never persisted the provider into model_config. On resume, the runtime recombined the persisted model with the config.yaml primary provider (which may not serve that model), producing auth errors. Fix: add optional provider parameter to update_session_model, merged into model_config via the shared _merge_model_config_json helper (not hand-rolled SQL). Wire both gateway /model call sites to pass result.target_provider. NousResearch#85721: session_gateway_runtime() had no billing_provider fallback. A CLI session that never ran /model has no gateway_runtime or top-level provider in model_config — billing_provider (written on every session's first accounted API call) is the only durable record. Fix: add billing_provider as the last-resort fallback in session_gateway_runtime(), filtering bare billing buckets (auto/custom) that are not routable identities. Simplify-code findings addressed: - Use _merge_model_config_json instead of 40 lines of branched SQL - Share _BARE_BILLING_PROVIDERS from hermes_state.py (was duplicated as a set in tui_gateway/server.py) - Merge None-filtering from NousResearch#85920 with the billing_provider fallback into one coherent return path Co-authored-by: pierrenode <298902573+pierrenode@users.noreply.github.com>
This was referenced Aug 14, 2026
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
Salvage of #79604 (webtecnica) + #85721 (pierrenode), combined and rebased onto current main with /simplify-code findings folded in.
#79604 — persist provider on model switch:
update_session_model()wrote the model name tosessions.modelbut never persisted the provider intomodel_config. On resume, the runtime recombined the persisted model with theconfig.yamlprimary provider (which may not serve that model), producing auth errors. Fix: add optionalproviderparameter toupdate_session_model, merged intomodel_configvia the shared_merge_model_config_jsonhelper. Wire both gateway/modelcall sites to passresult.target_provider.#85721 — billing_provider fallback in session_gateway_runtime:
session_gateway_runtime()had nobilling_providerfallback. A CLI session that never ran/modelhas nogateway_runtimeor top-level provider inmodel_config—billing_provider(written on every session's first accounted API call) is the only durable record. Fix: addbilling_provideras the last-resort fallback, filtering bare billing buckets (auto/custom) that are not routable identities.Simplify-code findings addressed (3-reviewer review on #85261/#85920):
_merge_model_config_jsoninstead of ~40 lines of hand-rolled branched SQL (json_set/json_object/json_remove) — collapses to ~8 lines and stays consistent with the codebase's merge discipline_BARE_BILLING_PROVIDERSfromhermes_state.py(was duplicated as a set intui_gateway/server.py)billing_providerfallback into one coherent return pathTest plan
tests/cli/test_resume_model_restore.py— 22 passed (15 existing + 7 new)tests/cli/test_resume_display.py— passedtests/test_hermes_state.py— passedtests/gateway/test_model_switch_persistence.py— passedtests/test_tui_gateway_server.py— passed (822 total, 0 failures)Closes #79536