feat: /model --once one-turn model override (salvages #29923) - #67113
Merged
Conversation
Adds --once to /model across CLI, TUI, and gateway: switch model for the next turn only, restoring the previous model in a finally block so success, exception, and interrupt all revert. Parsing extends parse_model_flags_detailed(); resolve_persist_behavior() treats --once as a persistence opt-out; --global + --once is rejected. Salvaged from PR #29923 (image-generation lane split to #59815 per review; conflict resolution against current main by the maintainers).
Fixes the two review defects that kept PR #29923 open, plus docs: - gateway: exclude --once from the session-store write-through. The once-override lived only in memory before, but the write-through persisted it, so a gateway restart before the finally-restore rehydrated a supposedly one-turn model permanently. - TUI: skip _sync_agent_model_with_config while a one-turn restore is pending. The once-model is deliberately not pinned as a session model_override, so the config sync saw a model mismatch and clobbered the once-override back to the config model before the turn ran. - tests: real _handle_model_command drive asserting --once never touches set_model_override while --session still does; restore-pop idempotency. - docs: /model --once in configuring-models.md with an honest prompt-cache cost note (one-shot switch breaks the cached prefix twice; wins for short sessions and cheap-to-expensive escalation).
Collaborator
6 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
/model <name> --onceswitches the model for the next turn only and restores the previous model afterward — on success, error, and interrupt alike, with nothing persisted anywhere. Salvages PR #29923 (@deusyu, fixes the design ask in #29914's user-explicit lane) with both review defects fixed on top.Changes
parse_model_flags_detailed()+ModelFlagParseResult(legacy 5-tupleparse_model_flagskept for existing call sites),resolve_persist_behavior(is_once=...)opt-out, CLI/TUI/gateway--oncelanes with restore-in-finally,--global+--oncerejected, model-switch note tells the model the override is one-turn--oncenow excluded from the session-store write-through — previously a gateway restart before the finally-restore rehydrated the "one-turn" model permanently_sync_agent_model_with_configskipped while a one-turn restore is pending — previously the config sync clobbered the once-override back to the config model before the turn ranimage_generateoverride lane stays out (split to fix(image_generate): honor per-call provider/model overrides and warn-fallback unknown FAL overrides #59815)--oncein configuring-models.md with an honest prompt-cache cost noteDesign notes
--onceonly, no automatic/agent-callable routingValidation
—once--oncenever awaitsset_model_override;--sessionstill doesInfographic