Skip to content

Commit 48d24f0

Browse files
committed
fix: resolve multi-window mode interference (#5605)
- Add instance-specific mode storage to ClineProvider to isolate mode state per window - Modify handleModeSwitch() to use instance storage instead of global state - Update getState() and getStateToPostToWebview() to return instance-specific mode values - Maintain backward compatibility by initializing new instances with current global mode - Add comprehensive test suite for multi-window mode isolation scenarios - Update existing tests to reflect new behavior where mode switches don't update global state Fixes #5605
1 parent 99448fc commit 48d24f0

File tree

3 files changed

+438
-7
lines changed

3 files changed

+438
-7
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ export class ClineProvider
108108
private marketplaceManager: MarketplaceManager
109109
private mdmService?: MdmService
110110

111+
// Instance-specific mode state to prevent cross-window interference
112+
private instanceMode?: Mode
113+
111114
public isViewLaunched = false
112115
public settingsImportedAt?: number
113116
public readonly latestAnnouncementId = "jul-09-2025-3-23-0" // Update for v3.23.0 announcement
@@ -131,6 +134,9 @@ export class ClineProvider
131134
this.mdmService = mdmService
132135
this.updateGlobalState("codebaseIndexModels", EMBEDDING_MODEL_PROFILES)
133136

137+
// Initialize instance mode with current global mode for backward compatibility
138+
this.instanceMode = this.contextProxy.getValue("mode") ?? defaultModeSlug
139+
134140
// Start configuration loading (which might trigger indexing) in the background.
135141
// Don't await, allowing activation to continue immediately.
136142

@@ -805,7 +811,8 @@ export class ClineProvider
805811
cline.emit("taskModeSwitched", cline.taskId, newMode)
806812
}
807813

808-
await this.updateGlobalState("mode", newMode)
814+
// Store mode in instance-specific storage to prevent cross-window interference
815+
this.instanceMode = newMode
809816

810817
// Load the saved API config for the new mode if it exists
811818
const savedConfigId = await this.providerSettingsManager.getModeConfigId(newMode)
@@ -1478,7 +1485,7 @@ export class ClineProvider
14781485
currentApiConfigName: currentApiConfigName ?? "default",
14791486
listApiConfigMeta: listApiConfigMeta ?? [],
14801487
pinnedApiConfigs: pinnedApiConfigs ?? {},
1481-
mode: mode ?? defaultModeSlug,
1488+
mode: this.instanceMode ?? mode ?? defaultModeSlug,
14821489
customModePrompts: customModePrompts ?? {},
14831490
customSupportPrompts: customSupportPrompts ?? {},
14841491
enhancementApiConfigId,
@@ -1634,7 +1641,7 @@ export class ClineProvider
16341641
terminalZshP10k: stateValues.terminalZshP10k ?? false,
16351642
terminalZdotdir: stateValues.terminalZdotdir ?? false,
16361643
terminalCompressProgressBar: stateValues.terminalCompressProgressBar ?? true,
1637-
mode: stateValues.mode ?? defaultModeSlug,
1644+
mode: this.instanceMode ?? stateValues.mode ?? defaultModeSlug,
16381645
language: stateValues.language ?? formatLanguage(vscode.env.language),
16391646
mcpEnabled: stateValues.mcpEnabled ?? true,
16401647
enableMcpServerCreation: stateValues.enableMcpServerCreation ?? true,

0 commit comments

Comments
 (0)