Skip to content

fix: preserve selected model during AI-initiated mode switches#12242

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/preserve-model-on-agent-mode-switch
Draft

fix: preserve selected model during AI-initiated mode switches#12242
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/preserve-model-on-agent-mode-switch

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented Apr 30, 2026

This PR attempts to address Issue #12237.

Problem

When the AI agent uses the switch_mode tool 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 preserveApiConfig option to handleModeSwitch(). When the SwitchModeTool (AI-initiated mode switch) calls handleModeSwitch, 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 lockApiConfigAcrossModes is enabled.

Changes

  • src/core/webview/ClineProvider.ts: Added options?: { preserveApiConfig?: boolean } parameter to handleModeSwitch. When preserveApiConfig is true, the method skips mode-specific config lookup/load (same early-return path as lockApiConfigAcrossModes).
  • src/core/tools/SwitchModeTool.ts: Passes { preserveApiConfig: true } when calling handleModeSwitch, so AI-driven mode switches preserve the current model.
  • src/core/webview/__tests__/ClineProvider.lockApiConfig.spec.ts: Added a test verifying that preserveApiConfig: true skips 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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant