fix: preserve selected model during AI-initiated mode switches#12242
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: preserve selected model during AI-initiated mode switches#12242roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
When the AI agent uses the switch_mode tool, the user's selected model should not change. Previously, handleModeSwitch would load mode-specific API configurations even for AI-initiated switches, unexpectedly changing the model mid-task. This adds a preserveApiConfig option to handleModeSwitch and passes it from SwitchModeTool so the current API config is preserved. User-initiated mode switches from the UI continue to load per-mode configs as before. Closes #12237
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.
This PR attempts to address Issue #12237.
Problem
When the AI agent uses the
switch_modetool to change modes during a task,handleModeSwitch()loads a different per-mode API configuration, unexpectedly changing the user's selected model mid-task.Solution
Added a
preserveApiConfigoption tohandleModeSwitch(). When theSwitchModeTool(AI-initiated mode switch) callshandleModeSwitch, it now passes{ preserveApiConfig: true }, which skips the mode-specific API config loading -- keeping the user's selected model stable.User-initiated mode switches from the UI continue to work as before, loading per-mode configs unless
lockApiConfigAcrossModesis enabled.Changes
src/core/webview/ClineProvider.ts: Addedoptions?: { preserveApiConfig?: boolean }parameter tohandleModeSwitch. WhenpreserveApiConfigis true, the method skips mode-specific config lookup/load (same early-return path aslockApiConfigAcrossModes).src/core/tools/SwitchModeTool.ts: Passes{ preserveApiConfig: true }when callinghandleModeSwitch, so AI-driven mode switches preserve the current model.src/core/webview/__tests__/ClineProvider.lockApiConfig.spec.ts: Added a test verifying thatpreserveApiConfig: trueskips mode-specific config loading.Test Results
All existing and new tests pass (3/3 in lockApiConfig spec, 19/19 in sticky-mode spec). Lint and type checks pass across the monorepo.
Feedback and guidance are welcome.
Interactively review PR in Roo Code Cloud