-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: prevent UI flicker and enable resumption after task cancellation #8986
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: - Clicking Terminate during streaming caused the entire chat view to blink - Task would close, user pushed to home, then back into the task - Cancel → Resume flow would grey the Resume button but not restart the loop - Input would become disabled and messages couldn't be sent Root causes: 1. Hard abort (abandoned=true) was disposing the task instance immediately 2. Provider was rehydrating a new task instance from disk after abort 3. Abort flags stayed set (abort=true) preventing loop resumption 4. No deterministic spinner stopping on cancellation 5. Streaming state wasn't reset on resume Solution: - Soft-interrupt: Cancel now uses abortTask(false) to keep instance alive - No rehydration: Provider skips task recreation for user_cancelled aborts - Resume pipeline: Added presentResumableAsk() for in-place resume flow - Abort state reset: Clear abort flags and streaming state before resuming - Spinner determinism: Inject cancelReason into last api_req_started - Transactional UI: Pause state updates during checkpoint operations Changes: - Task.presentResumableAsk(): New method for soft-interrupt resume - Task.resumeTaskFromHistory(): Reset abort/streaming state after user confirms - Task.abortTask(): Distinguish soft (keep alive) vs hard abort (dispose) - ClineProvider.cancelTask(): Soft abort + schedule presentResumableAsk() - ClineProvider.onTaskAborted: Skip rehydration for user_cancelled - ChatView: Handle cancelReason for deterministic streaming state Tests: - Task.presentResumableAsk.abort-reset.spec.ts: Verify abort flag reset - ClineProvider.cancelTask.present-ask.spec.ts: Verify soft-interrupt flow - Task.spec.ts: Updated abort semantics (soft vs hard) Result: - No UI flicker or navigation on Cancel - Resume button successfully restarts the agent loop - Input remains enabled throughout cancel/resume cycle - Spinner stops deterministically on cancellation - Task history stable, no duplicate entries
Contributor
|
All previously identified issues have been resolved. No new issues found in the latest commit.
Previous ReviewsMention @roomote in a comment to trigger your PR Fixer agent and make changes to this pull request. |
The logic was inverted - when cost is defined in api_req_started, it means the API request has finished (streaming is complete), so should return false, not true.
When api_req_started exists without cost or cancelReason fields, the API request is still in progress and should be treated as streaming. Only return false when cost (completed) or cancelReason (cancelled) are present.
b8bafd1 to
ac57bd0
Compare
…SON parsing - Extract duplicated abort/streaming state reset logic into private helper method resetAbortAndStreamingState() - Update resumeTaskFromHistory() and presentResumableAsk() to use the helper method - Replace unsafe JSON.parse() with safeJsonParse() in ClineProvider.ts for better error handling Addresses review feedback from @mrubens on PR #8986
mrubens
approved these changes
Nov 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
lgtm
This PR has been approved by a maintainer
PR - Needs Review
size:L
This PR changes 100-499 lines, ignoring generated files.
UI/UX
UI/UX related or focused
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Clicking Terminate during streaming caused several issues:
Root Causes
Solution
Soft-Interrupt Pattern
State Management
Changes
Core Logic
UI
Tests
Result
Testing Steps
Related Issues
Fixes the UI blink issue when terminating tasks during streaming.
Important
Implements soft-interrupt pattern and state management improvements to prevent UI flicker and enable task resumption after cancellation.
abortTask(false)to prevent task instance disposal on cancel.presentResumableAsk()inTask.tsfor in-place resume flow.cancelReasonintoapi_req_startedfor deterministic spinner stop.Task.presentResumableAsk()andTask.resumeTaskFromHistory()for task resumption.Task.abortTask()to distinguish between soft and hard aborts.ClineProvider.cancelTask()to handle soft aborts and schedulepresentResumableAsk().ChatView.tsxto handlecancelReasonfor streaming state management.Task.presentResumableAsk.abort-reset.spec.tsto verify abort flag reset.ClineProvider.cancelTask.present-ask.spec.tsto verify soft-interrupt flow.Task.spec.tsfor new abort semantics.This description was created by
for 1520618. You can customize this summary. It will automatically update as commits are pushed.