-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Add pause/resume button for AI streaming responses (#8331) #8333
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
- Add pauseTask and resumeTask message types to WebviewMessage interface - Implement pause/resume handlers in webviewMessageHandler - Add pauseTask() and resumeTask() methods to ClineProvider - Update ChatView UI to show Pause/Resume button alongside Cancel during streaming - Add localization strings for pause and resume buttons - Utilize existing Task.isPaused property for pause state management Fixes #8331
- Add pause/resume message types to WebviewMessage interface - Implement pause/resume handlers in webviewMessageHandler - Update ChatView UI to show Pause/Resume buttons during streaming - Add pause mechanism in Task class streaming loop - Add pause/resume methods in ClineProvider with event emissions - Add localization strings for pause/resume buttons Fixes #8331
| content={ | ||
| isPaused | ||
| ? t("chat:resume.tooltip", { | ||
| defaultValue: "Resume the AI's response", |
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.
Inline fallback strings are used in translation calls (e.g. t('chat:resume.title', { defaultValue: 'Resume' }) and t('chat:pause.title', { defaultValue: 'Pause' })). According to our guidelines, remove these defaultValue options so that the system falls back on the English JSON file automatically.
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.
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.
Self-review: evaluating my own code like a mirror debugging itself—objective, emotionless, and mildly unsettling.
| while (!item.done) { | ||
| // Check if task is paused and wait if necessary | ||
| while (this.isPaused) { | ||
| // Wait for 100ms before checking again |
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.
[P1] If this.abort is set while paused, break exits only the inner pause loop and then the method continues processing the current chunk. This risks emitting partial content after an abort. Consider exiting the outer streaming loop (or returning) when abort is detected inside the pause wait.
| } | ||
|
|
||
| this.log(`[pauseTask] pausing task ${task.taskId}`) | ||
|
|
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.
[P2] API compatibility: resumeTask(taskId: string) was replaced by a no-arg variant. If any callers still pass taskId, this will break at compile time. Suggest keeping a backward-compatible overload (e.g., resumeTask(taskId?: string)) where a provided taskId delegates to showTaskWithId(taskId) and otherwise resumes the current task.
| this.log(`[resumeTask] resuming task ${task.taskId}`) | ||
|
|
||
| // Set the task as not paused | ||
| task.isPaused = false |
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.
[P2] Event typing: Emitting RooCodeEventName.TaskPaused/TaskUnpaused assumes these are defined in the event enum and included in TaskEvents. Please ensure the enum and listener types are updated so consumers can subscribe without any.
| vscode.postMessage({ type: "cancelTask" }) | ||
| setDidClickCancel(true) | ||
| // If paused, resume; otherwise pause | ||
| if (isPaused) { |
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.
[P2] isPaused is tracked only in local component state. After a reload or other state refresh, UI can desynchronize from provider. Consider sourcing from ExtensionStateContext (e.g., currentTask.isPaused) and syncing via postStateToWebview.
| "tooltip": "Cancel the current operation" | ||
| }, | ||
| "pause": { | ||
| "title": "Pause", |
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.
[P3] New i18n keys are added for en only. To avoid missing-translation warnings, consider adding placeholders for core locales or confirm fallback behavior is acceptable.
Description
This PR implements a pause/resume button feature that allows users to pause AI model responses mid-stream when they're taking too long or going in an unwanted direction. This enables users to change models or provide additional context before resuming.
Related Issue
Fixes #8331
Changes Made
Implementation Details
The pause mechanism works by:
Testing
Review Confidence
Code review confidence: 92% (HIGH)
Future Improvements (Optional)
Important
Adds pause/resume functionality for AI streaming responses with new message types, handlers, and UI updates in
ChatView.pauseTaskandresumeTaskmessage types toWebviewMessagefor communication between VSCode extension and webview.pauseTaskandresumeTaskhandlers inwebviewMessageHandlerto manage pause/resume requests.ChatViewUI to display Pause/Resume buttons during streaming.isPausedflag inTaskclass inTask.tsto control streaming loop.pauseTask()andresumeTask()methods inClineProviderto handle task state changes.chat.json.ChatView.tsxto manage button states and handle user interactions for pausing/resuming.This description was created by
for 9a66177. You can customize this summary. It will automatically update as commits are pushed.