-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: preserve task state when extension host restarts in new window #8036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified ClineProvider.ts to check if tasks exist before clearing them - Only clear task stack on fresh start, not on webview restoration - Added logging to indicate when task state is preserved - Updated webviewMessageHandler to log when restoring active tasks This fixes the issue where prompts were lost after extension host restart in a new window. Fixes #8035
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| private taskCreationCallback: (task: Task) => void | ||
| private taskEventListeners: WeakMap<Task, Array<() => void>> = new WeakMap() | ||
| private currentWorkspacePath: string | undefined | ||
| private isWebviewRestored: boolean = false // Track if webview is being restored after restart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isWebviewRestored flag is set here but never cleared. If the webview is disposed and recreated multiple times during the extension's lifecycle, this could lead to incorrect behavior. Consider resetting this flag in the disposal logic or when appropriate to ensure proper state management across multiple webview lifecycles.
| // We're restoring after an extension host restart, preserve the task state | ||
| this.log("Preserving task state after extension host restart") | ||
| // Post the current state to the webview so it can restore the UI | ||
| await this.postStateToWebview() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider wrapping this postStateToWebview() call in a try-catch block or checking if the view is available first. If the webview isn't ready or has been disposed, this could throw an error.
| // If we have an active task (after extension host restart), notify the webview to restore it | ||
| const activeTask = provider.getCurrentTask() | ||
| if (activeTask) { | ||
| provider.log("Restoring active task after extension host restart") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems redundant since the actual restoration is handled by postStateToWebview() in ClineProvider. The logging statement already indicates what's happening. Consider removing the comment or making it more concise.
| await this.removeClineFromStack() | ||
| // Only clear task state if this is a fresh start, not when restoring after extension host restart | ||
| // When the extension host restarts in a new window, we want to preserve the task state | ||
| if (!hasExistingTasks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting this restoration logic into a separate method like shouldPreserveTaskState() for better readability and testability. This would make the intent clearer and allow for easier unit testing of the preservation logic.
|
It seems like when there's a new window and the extension host restarts the new window's webview stops processing the messages and these are instead sent to the main window's Roo Code instance, not sure if this is something we can fix really, might be related to how VSCode spawns the Roo Code instances. |
Description
This PR fixes an issue where RooCode loses prompts and becomes broken when the extension host is restarted in a new window.
Problem
When using RooCode in a new window and executing "Developer: Restart Extension Host", the extension would:
Solution
The fix preserves the task state during extension host restarts by:
Changes Made
ClineProvider.ts:
isWebviewRestoredflag to track restoration stateresolveWebviewView()to detect existing tasks during restorationwebviewMessageHandler.ts:
Testing
Reproduction Steps Tested
Fixes #8035
Important
Preserve task state during extension host restarts by modifying
resolveWebviewView()inClineProvider.tsand adding logging inwebviewMessageHandler.ts.resolveWebviewView()inClineProvider.ts.isWebviewRestoredflag inClineProvider.tsto track restoration state.webviewMessageHandler.ts.resolveWebviewView()inClineProvider.tsto conditionally clear task stack only on fresh starts.webviewMessageHandler.tsto track task restoration after restart.This description was created by
for 517896e. You can customize this summary. It will automatically update as commits are pushed.