You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[BUG] Switching mode/apiConfig while parallel tools are running may corrupt task state
Problem
When a tab is running parallel tools (PR #359 [Epic 4] Parallel Tool Execution) and another tab switches mode or apiConfig, it may affect shared resources (e.g., API provider, tool execution context). The current handleModeSwitch() + activateProviderProfile() logic does not account for state isolation during parallel tool execution.
1. Open Tab A (sidebar) → start task with parallel tools enabled (#359)
2. Parallel tools are running: Tool 1 (read file), Tool 2 (execute command), Tool 3 (write file)
3. In Tab B (editor): switch mode from "code" to "architect" via handleModeSwitch()
4. What happens?
- Tab A's parallel tools still running — do they use old mode or new mode?
- If they use global state, they see Tab B's mode change
- If they use viewLocalState, they keep old mode (correct)
- BUT: shared resources (API provider, tool execution context) may be affected
5. Check if parallel tools complete correctly with original mode/apiConfig
Current test coverage:
✅ View-local isolation: ClineProvider.parallelMode.spec.ts — tests state isolation during normal operation
❌ Parallel execution: No test for mode switch during parallel tool execution
// ClineProvider.ts (simplified)asynchandleModeSwitch(newMode: string): Promise<void>{// Step 1: Update viewLocalState (local-first pattern)awaitthis.saveViewState("mode",newMode)// Step 2: Update global state (broadcast to all tabs)awaitthis.updateGlobalState("mode",newMode)}asyncactivateProviderProfile(profileName: string): Promise<void>{// Similar pattern: viewLocalState first, then global stateawaitthis.saveViewState("currentApiConfigName",profileName)awaitthis.activateProviderInContext(profileName)}
Tools use shared resources (API provider, tool execution context) from Tab A's viewLocalState
Tab B: handleModeSwitch("architect") → updates global state
Shared resources may be affected by Tab B's mode change
Problem: parallel tools in Tab A may see inconsistent state (some use old mode, some use new mode)
This issue is related to the DispatchState machine in #359 [Epic 4] Parallel Tool Execution, but #359 does not account for multi-tab scenarios.
Proposed Fix
Option A: Capture tool execution context at start (recommended)
// In ClineProvider.ts — capture state when parallel tools start, not during executionasyncexecuteParallelTools(tasks: ToolTask[]): Promise<ToolResult[]>{// Capture snapshot of viewLocalState at execution timeconstexecutionContext={mode: this.viewLocalState.mode??this.globalState.mode,apiConfigName: this.viewLocalState.currentApiConfigName??this.globalState.currentApiConfigName,apiConfiguration: this.viewLocalState.apiConfiguration??this.globalState.apiConfiguration,// ... other fields needed for tool execution}// Pass executionContext to each parallel taskconstresults=awaitPromise.all(tasks.map(task=>this.executeToolWithContext(task,executionContext)))returnresults}asyncexecuteToolWithContext(tool: ToolTask,context: ExecutionContext): Promise<ToolResult>{// Use captured context, not current viewLocalState (which may change during execution)constprovider=awaitthis.getProviderForMode(context.mode,context.apiConfigName)returntool.execute(provider,context)}
Option B: Lock mode/apiConfig during parallel execution
// In ClineProvider.ts — prevent mode switch while parallel tools are runningclassParallelExecutionLock{privateisExecuting=falseasyncwithParallelExecution<T>(fn: ()=>Promise<T>): Promise<T>{if(this.isExecuting){thrownewError("Cannot change mode/apiConfig during parallel tool execution")}this.isExecuting=truetry{returnawaitfn()}finally{this.isExecuting=false}}}// Usage in handleModeSwitch():asynchandleModeSwitch(newMode: string): Promise<void>{if(this.parallelExecutionLock.isExecuting){// Option 1: Block mode switch until parallel execution completesawaitthis.parallelExecutionLock.waitForCompletion()// Option 2: Queue the mode switch for after completionthis.pendingModeSwitch=newModereturn}awaitthis.saveViewState("mode",newMode)awaitthis.updateGlobalState("mode",newMode)}
Option C: Per-tool state isolation
Each parallel tool captures its own viewLocalState snapshot at start time
Tool execution uses the snapshot, not global state
Suitable for fine-grained control, but increases complexity
it("parallel tools complete correctly when another tab switches mode during execution",async()=>{// Create 2 ClineProvider instances (Tab A, Tab B)// Tab A: start parallel tool execution (3 concurrent tools)// Tab B: switch mode/apiConfig while Tab A's tools are running// Verify Tab A's tools use original state, not Tab B's new state})it("parallel tools handle apiConfig change during execution",async()=>{// Tab A: start parallel tools with profile "A"// Tab B: switch to profile "B"// Verify Tab A's tools still use profile "A" (not corrupted)})
Test with 5+ concurrent parallel tools across different tabs
Test concurrent handleModeSwitch + activateProviderProfile during parallel execution
Test that mode switch is blocked/queued if parallel execution is in progress (Option B)
[BUG] Switching mode/apiConfig while parallel tools are running may corrupt task state
Problem
When a tab is running parallel tools (PR #359 [Epic 4] Parallel Tool Execution) and another tab switches mode or apiConfig, it may affect shared resources (e.g., API provider, tool execution context). The current
handleModeSwitch()+activateProviderProfile()logic does not account for state isolation during parallel tool execution.Evidence
Code locations:
ClineProvider.ts:handleModeSwitch()— updates viewLocalState then global stateactivateProviderProfile()— updates apiConfig in viewLocalState + global stateClineProvider.parallelMode.spec.ts: Tests view-local isolation, but NOT during parallel tool executionReproduction:
Current test coverage:
ClineProvider.parallelMode.spec.ts— tests state isolation during normal operationRoot Cause
PR #909's view-local state isolation design:
When parallel tools are running:
parallelTools.execute()→ starts Tool 1, Tool 2, Tool 3 concurrentlyhandleModeSwitch("architect")→ updates global stateThis issue is related to the
DispatchStatemachine in #359 [Epic 4] Parallel Tool Execution, but #359 does not account for multi-tab scenarios.Proposed Fix
Option A: Capture tool execution context at start (recommended)
Option B: Lock mode/apiConfig during parallel execution
Option C: Per-tool state isolation
Scope
Related Issues
presentAssistantMessagefix(webview): isolate parallel provider view stateTesting Requirements
Add test in
ClineProvider.parallelMode.spec.ts:Test with 5+ concurrent parallel tools across different tabs
Test concurrent
handleModeSwitch+activateProviderProfileduring parallel executionTest that mode switch is blocked/queued if parallel execution is in progress (Option B)
Notes