@@ -879,27 +879,31 @@ export class ClineProvider
879879 await this . updateGlobalState ( "mode" , historyItem . mode )
880880
881881 // Load the saved API config for the restored mode if it exists.
882- const savedConfigId = await this . providerSettingsManager . getModeConfigId ( historyItem . mode )
883- const listApiConfig = await this . providerSettingsManager . listConfig ( )
884-
885- // Update listApiConfigMeta first to ensure UI has latest data.
886- await this . updateGlobalState ( "listApiConfigMeta" , listApiConfig )
887-
888- // If this mode has a saved config, use it.
889- if ( savedConfigId ) {
890- const profile = listApiConfig . find ( ( { id } ) => id === savedConfigId )
891-
892- if ( profile ?. name ) {
893- try {
894- await this . activateProviderProfile ( { name : profile . name } )
895- } catch ( error ) {
896- // Log the error but continue with task restoration.
897- this . log (
898- `Failed to restore API configuration for mode '${ historyItem . mode } ': ${
899- error instanceof Error ? error . message : String ( error )
900- } . Continuing with default configuration.`,
901- )
902- // The task will continue with the current/default configuration.
882+ // Skip mode-based profile activation if historyItem.apiConfigName exists,
883+ // since the task's specific provider profile will override it anyway.
884+ if ( ! historyItem . apiConfigName ) {
885+ const savedConfigId = await this . providerSettingsManager . getModeConfigId ( historyItem . mode )
886+ const listApiConfig = await this . providerSettingsManager . listConfig ( )
887+
888+ // Update listApiConfigMeta first to ensure UI has latest data.
889+ await this . updateGlobalState ( "listApiConfigMeta" , listApiConfig )
890+
891+ // If this mode has a saved config, use it.
892+ if ( savedConfigId ) {
893+ const profile = listApiConfig . find ( ( { id } ) => id === savedConfigId )
894+
895+ if ( profile ?. name ) {
896+ try {
897+ await this . activateProviderProfile ( { name : profile . name } )
898+ } catch ( error ) {
899+ // Log the error but continue with task restoration.
900+ this . log (
901+ `Failed to restore API configuration for mode '${ historyItem . mode } ': ${
902+ error instanceof Error ? error . message : String ( error )
903+ } . Continuing with default configuration.`,
904+ )
905+ // The task will continue with the current/default configuration.
906+ }
903907 }
904908 }
905909 }
@@ -1476,8 +1480,7 @@ export class ClineProvider
14761480 const taskHistoryItem = history . find ( ( item ) => item . id === task . taskId )
14771481
14781482 if ( taskHistoryItem ) {
1479- taskHistoryItem . apiConfigName = apiConfigName
1480- await this . updateTaskHistory ( taskHistoryItem )
1483+ await this . updateTaskHistory ( { ...taskHistoryItem , apiConfigName } )
14811484 }
14821485 } catch ( error ) {
14831486 // If persistence fails, log the error but don't fail the profile switch.
0 commit comments