fix(webview): isolate parallel provider view state#966
fix(webview): isolate parallel provider view state#966easonLiangWorldedtech wants to merge 6 commits into
Conversation
Add view-local state loading and syncing for parallel ClineProvider instances, with safe initialization and configuration listener handling for test/shim environments. Key changes: - Add viewId property for unique provider instance identification - Implement viewLocalState buffer to isolate mode, profile, and apiConfig per view - Load view-local state after provider dependencies are initialized - Merge viewLocalState in getState() with local apiConfiguration taking precedence - Clear local overrides when saveViewState receives undefined or null values - Sync mode/profile changes through saveViewState(), loadViewState(), and profile activation - Preserve restored task mode in both global state and viewLocalState - Guard global configuration listener setup when VS Code workspace events are unavailable - Keep sticky-mode task restore compatible with view-local state isolation Tests: - Add 22 parallel mode cases covering viewId uniqueness, state isolation, save/load behavior, merge precedence, local override clearing, config listener handling, mode switching, profile activation, and multi-instance isolation - Verify sticky-mode restore compatibility
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughChangesParallel view state isolation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Webview as App/ExtensionStateContext
participant Handler as webviewMessageHandler
participant Provider as ClineProvider
participant State as ContextProxy
Webview->>Webview: getViewStateId()
Webview->>Handler: webviewDidLaunch(viewStateId)
Handler->>Provider: setViewStateId(viewStateId)
Provider->>State: load and save view-local state
Provider-->>Webview: post updated extension state
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/webview/ClineProvider.ts`:
- Around line 534-558: The setupGlobalStateListener method incorrectly relies on
vscode.workspace.onDidChangeConfiguration for values stored in
ContextProxy/global state. Remove this configuration-based trigger and connect
loadViewState() and postStateToWebview() to the existing mode/profile mutation
flow or a provider-level in-process event, ensuring updates from other views
trigger the reload and webview notification.
- Around line 435-437: Update ClineProvider.dispose() to remove all three
per-view globalState entries generated by viewStateKeyFor(): "mode",
"currentApiConfigName", and "apiConfiguration". Perform the cleanup during
disposal using the existing ContextProxy/globalState removal mechanism, while
preserving normal state persistence before disposal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4262c6fe-ad0e-47b5-8e2e-9d0efc509eca
📒 Files selected for processing (9)
packages/types/src/vscode-extension-host.tssrc/core/webview/ClineProvider.tssrc/core/webview/__tests__/ClineProvider.parallelMode.spec.tssrc/core/webview/__tests__/ClineProvider.spec.tssrc/core/webview/webviewMessageHandler.tswebview-ui/src/App.tsxwebview-ui/src/__tests__/App.spec.tsxwebview-ui/src/context/ExtensionStateContext.tsxwebview-ui/src/utils/vscode.ts
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Summary
Isolate per-provider view state for parallel mode instances. Each tab/editor instance maintains independent
modeandapiConfigurationselections without interfering with other open tabs.Changes
viewId/viewStateIdcounters to uniquely identify each provider instanceviewLocalStateper-provider-instance as a local cache overlay on top of global stategetState()now returns{ ...stateValues, ...this.viewLocalState }, giving view-local values precedence over shared defaultsloadViewState(),saveViewState(),_updateViewLocalStateFromMutation(), and_clearViewLocalState()for consistent state lifecycle managementgetViewStateIdthrough webview message handler +webviewDidLaunch → setViewStateIdflowFiles Changed
src/core/webview/ClineProvider.tssrc/core/webview/__tests__/ClineProvider.parallelMode.spec.tssrc/core/webview/ExtensionStateContext.tsxsrc/core/webview/ModesView.tsxsrc/core/webview/__tests__/ClineProvider.spec.tssrc/core/api/index.tssrc/core/webview/types.tssrc/shared/ExtensionMessage.tssrc/utils/state.tsVerification
getState()output unchanged when no view-local overrides exist (verified no-op on single-instance mode)Known Limitation
Per-view state is stored in memory (
viewLocalStatebuffer). On extension reload, view-specific values fall back to shared global defaults. Tracked as follow-up issue: #967Summary by CodeRabbit
New Features
Bug Fixes
Tests