Skip to content

Conversation

@daniel-lxs
Copy link
Member

Description

Fixes #9435

The Cancel button was previously unresponsive for 1-70+ seconds during streaming/reasoning because:

  • Clicking Cancel only set an abort flag that was checked between stream chunks
  • If the endpoint was slow or hung before sending the next chunk, the loop would never see the abort flag
  • No mechanism existed to cancel the underlying HTTP request
  • Users had to wait for network timeout (~70s for dead endpoints)

Changes

Core Fix: AbortController-Based Cancellation

  1. Added currentRequestAbortController to Task class (src/core/task/Task.ts:218)

    • Stores the AbortController for the active HTTP request
    • Created at the start of each API request in attemptApiRequest()
  2. Created cancelCurrentRequest() method (src/core/task/Task.ts:1693)

    • Public method that immediately calls abort() on the current controller
    • Called from ClineProvider.cancelTask() before task.abortTask()
    • Also called during Task.dispose() for cleanup
  3. Wired AbortController into streaming (src/core/task/Task.ts:3203)

    • Race first chunk with abort signal using Promise.race()
    • Race all subsequent chunks with abort signal in streaming loop
    • When signal fires, promise rejects immediately with "Request cancelled by user"
    • Clean up controller in finally block and abort event listener

Test Coverage

Added comprehensive tests in src/core/task/__tests__/Task.spec.ts:

  • ✅ Verifies cancelCurrentRequest() calls abort() on the controller
  • ✅ Verifies controller is cleared after cancellation
  • ✅ Tests graceful handling when no controller exists
  • ✅ Confirms cancelCurrentRequest() is called during dispose()

All tests pass: 4150 passed | 48 skipped

Manual Testing

Tested with a dummy slow-streaming server (slow chunks, 5s delays):

  • Before: Cancel appeared unresponsive for 5+ seconds per chunk
  • After: Cancel works immediately (~100ms), server logs "Client disconnected"

Tested with hung endpoint (never sends chunks):

  • Before: Had to wait ~70 seconds for network timeout
  • After: Cancel works immediately, no waiting

Impact

Before:

  • 1-70+ second delays when clicking Cancel mid-stream
  • UI appeared frozen/unresponsive
  • Had to wait for next chunk or network timeout

After:

  • ~100ms response time regardless of endpoint state
  • Cancel immediately terminates the HTTP request
  • UI becomes responsive right away

Breaking Changes

None - this is a pure enhancement to existing cancel behavior.

Previously, clicking Cancel during streaming/reasoning would appear
unresponsive for 1-70+ seconds because:
- Cancel only set an abort flag checked between stream chunks
- If the endpoint was slow or hung, the next chunk would never arrive
- No mechanism existed to cancel the underlying HTTP request

This fix introduces AbortController-based cancellation:
- Task.currentRequestAbortController tracks the active request
- ClineProvider.cancelTask() calls task.cancelCurrentRequest()
- cancelCurrentRequest() immediately aborts the HTTP stream
- Both first chunk and subsequent chunks race with abort signal
- When aborted, Promise.race rejects immediately (~100ms)

Impact:
- Before: 1-70+ second delays waiting for next chunk/timeout
- After: ~100ms response time regardless of endpoint state
- Tested with slow streaming, hung endpoints, and normal cases

Fixes #9435
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Nov 20, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 20, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. No issues found.

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Nov 20, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Nov 20, 2025
@roomote
Copy link
Contributor

roomote bot commented Nov 20, 2025

Oroocle Clock   Follow along on Roo Cloud

Reviewing your PR now. Feedback coming shortly!

@hannesrudolph hannesrudolph added PR - Needs Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Nov 20, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 21, 2025
@mrubens mrubens merged commit 1dd223d into main Nov 21, 2025
25 checks passed
@mrubens mrubens deleted the fix/cancel-button-responsiveness-9435 branch November 21, 2025 22:34
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Nov 21, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Nov 21, 2025
mini2s added a commit to zgsm-ai/costrict that referenced this pull request Nov 22, 2025
* Changeset version bump (RooCodeInc#9005)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Chris Estreich <[email protected]>

* config(rooignore): remove ignored directories from exclusion list

* fix: correct OpenRouter Mistral model dimension from 3072 to 1536 (RooCodeInc#9028)

* Revert "fix: prevent UI flicker and enable resumption after task cancellation" (RooCodeInc#9032)

* chore: add changeset for v3.30.1 (RooCodeInc#9033)

* Changeset version bump (RooCodeInc#9034)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: eliminate UI flicker during task cancellation (RooCodeInc#9037)

* fix: eliminate UI flicker during task cancellation

- Modify ClineProvider.createTaskWithHistoryItem() to detect when rehydrating current task
- Implement in-place task replacement to avoid empty stack state that causes UI flicker
- Add comprehensive unit tests for flicker-free cancel behavior
- Maintain backward compatibility and proper event listener cleanup

Fixes the jarring navigation to home view when cancelling tasks

* fix: ensure proper garbage collection of old task during flicker-free rehydration

- Call abortTask(true) on old task before replacement to stop processes and mark as abandoned
- This ensures proper cleanup and prevents memory leaks during task cancellation
- Add test verification for abortTask cleanup

* feat: add file path tooltips with centralized PathTooltip component (RooCodeInc#9030)

- Add PathTooltip component that wraps StandardTooltip with proper styling
- Use maxWidth='min(300px,100vw)' via inline style to override defaults
- Apply '[text-wrap:wrap]' class to override text-balance behavior
- Add formatPathTooltip helper for consistent path content formatting
- Update CodeAccordian, ChatRow, and BatchFilePermission to use PathTooltip
- Centralizes tooltip behavior and reduces duplication

Supersedes PR RooCodeInc#8797.

* fix: keep pinned models fixed at top of scrollable list (RooCodeInc#8813)

* fix: keep pinned models fixed at top of scrollable list

- Separated pinned and unpinned configs into different containers
- Pinned configs now stay fixed at the top
- Only unpinned configs are scrollable
- Added tests to verify the fixed behavior

Fixes RooCodeInc#8812

* fix: resolve sticky header visual artifact in ApiConfigSelector

- Changed sticky header background from bg-vscode-editorWidget-background to bg-vscode-dropdown-background to match popover container
- Moved separator logic into sticky container as conditional bottom border to prevent scroll artifacts
- Updated tests to match new separator structure
- All 21 tests passing

---------

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* Set Claude Sonnet 4.5 as default for key providers (RooCodeInc#8922)

* fix(checkpoints): resolve incorrect commit location when GIT_DIR set in Dev Containers (RooCodeInc#8811)

* Update cerebras.ts (RooCodeInc#9024)

* fix: update Opus 4.1 max tokens from 8K to 32K (RooCodeInc#9046)

Aligns claude-opus-4-1-20250805 max token limit with claude-opus-4-20250514,
both models now supporting 32K output tokens (overridable to 8K when
enableReasoningEffort is false).

Fixes RooCodeInc#9045

Co-authored-by: Roo Code <[email protected]>

* Merge remote-tracking branch 'upstream/main' into roo-to-main

* feat(api): add mode parameter to ZgsmAiHandler and add tooltips to ChatRow buttons

* chore: simplify Google Analytics to standard implementation (RooCodeInc#9044)

Co-authored-by: Roo Code <[email protected]>

* feat: add conditional test running to pre-push hook (RooCodeInc#9055)

* Fix dynamic provider model validation to prevent cross-contamination (RooCodeInc#9054)

* Fix Bedrock user agent to report full SDK details (RooCodeInc#9043)

* feat: add Qwen3 embedding models (0.6B and 4B) to OpenRouter support (RooCodeInc#9060)

Co-authored-by: Roo Code <[email protected]>

* web: Agent Landing Page A/B testing toolkit (RooCodeInc#9018)

Co-authored-by: Roo Code <[email protected]>

* feat: Global Inference for Bedrock models (RooCodeInc#8750) (RooCodeInc#8940)

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* Release v3.30.2 (RooCodeInc#9065)

chore: add changeset for v3.30.2

* Changeset version bump (RooCodeInc#9066)

* changeset version bump

* Revise CHANGELOG for version 3.30.2

Updated changelog for version 3.30.2 with new features and fixes.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* Merge branch 'main' of github.com:zgsm-ai/costrict into roo-to-main

* feat(error-handling): add HTTP 413 payload too large error handling

* fix(webview): correct default value for useZgsmCustomConfig and fix settings message order

* feat: add kimi-k2-thinking model to moonshot provider (RooCodeInc#9079)

* ux: Home screen visuals (RooCodeInc#9057)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* feat: add MiniMax-M2-Stable model and enable prompt caching (RooCodeInc#9072)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Daniel <[email protected]>

* fix(task): auto-retry on empty assistant response (RooCodeInc#9076) (RooCodeInc#9083)

* feat(chat): Improve diff appearance in main chat view (RooCodeInc#8932)

Co-authored-by: daniel-lxs <[email protected]>

* Clarify: setting 0 disables Error & Repetition Limit (RooCodeInc#8965)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* fix: use system role for OpenAI Compatible provider when streaming is disabled (RooCodeInc#8216)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: daniel-lxs <[email protected]>

* fix: prevent shell injection in pre-push hook environment loading (RooCodeInc#9059)

* feat: auto-switch to imported mode with architect fallback (RooCodeInc#9003)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Seth Miller <[email protected]>
Co-authored-by: heyseth <[email protected]>
Co-authored-by: Roo Code <[email protected]>

* fix: prevent notification sound on attempt_completion with queued messages (RooCodeInc#8540)

Co-authored-by: Roo Code <[email protected]>

* chore(deps): update dependency @changesets/cli to v2.29.7 (RooCodeInc#8490)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* chore: add changeset for v3.30.3 (RooCodeInc#9092)

* Changeset version bump (RooCodeInc#9094)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: respect custom OpenRouter URL for all API operations (RooCodeInc#8951)

Co-authored-by: Roo Code <[email protected]>

* feat: Add comprehensive error logging to Roo Cloud provider (RooCodeInc#9098)

feat: add comprehensive error logging to Roo Cloud provider

- Add detailed error logging in handleOpenAIError() to capture error details before transformation
- Enhanced getRooModels() to log HTTP response details on failed requests
- Added error context logging to RooHandler streaming and model loading
- All existing tests passing (48 total)

* ux: Less Caffeine (RooCodeInc#9104)

Prevents stress on Roo's hip bones

* fix: prevent crash when streaming chunks have null choices array (RooCodeInc#9105)

* ux: Improvements to to-do lists and task headers (RooCodeInc#9096)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: prevent context condensing on settings save when provider/model unchanged (RooCodeInc#9108)

Co-authored-by: Matt Rubens <[email protected]>

* Release v3.31.0 (RooCodeInc#9111)

* Changeset version bump (RooCodeInc#9112)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* fix: improve mobile responsiveness of hero section on /reviewer page (RooCodeInc#9138)

Co-authored-by: Roo Code <[email protected]>

* feat(integrations): update export markdown filename to include 'costrict' prefix

* feat(core): enhance attempt_completion parsing with flexible result handling

* test(core): update test configurations and CSP settings

* feat: add Google Tag Manager to marketing website (RooCodeInc#9148)

* feat: add Google Tag Manager to marketing website using Next.js Script component

* refactor: remove Google Ads implementation in favor of Tag Manager

* fix: wrap GTM script in consent-checking client component for GDPR compliance

---------

Co-authored-by: Roo Code <[email protected]>

* IPC command for sending messages to the current task (RooCodeInc#9149)

* fix: prevent command_output ask from blocking in cloud/headless environments (RooCodeInc#9152)

* chore: add changeset for v3.31.1 (RooCodeInc#9153)

* Release: v1.85.0 (RooCodeInc#9155)

* Gate XML out when native tool protocol is ON (RooCodeInc#9107)

* Add native tool definitions (RooCodeInc#9156)

* feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158)

- Updated variant A content to match variant B messaging
- Both variants now show the same improved copy focused on catching meaningful bugs
- Emphasizes depth over token-saving and repository-aware analysis

Co-authored-by: Roo Code <[email protected]>

* feat: sync reviewer landing page copy - variant B to variant A (RooCodeInc#9158)

- Updated variant A content to match variant B messaging
- Both variants now show the same improved copy focused on catching meaningful bugs
- Emphasizes depth over token-saving and repository-aware analysis

Co-authored-by: Roo Code <[email protected]>

* Move auto-approval from `ChatView` to `Task` (RooCodeInc#9157)

* feat(i18n): add internationalization for unexpected API response error message

* fix(task): use consistent error message for API response failures and ensure message queue is never undefined

* test: update vscode mock and improve test coverage

* fix: Model switch re-applies selected profile (sync task.apiConfiguration) (RooCodeInc#9179) (RooCodeInc#9181)

* Add custom Button component with variant system (RooCodeInc#9150)

Co-authored-by: roomote[bot] <219738659+roomote[bot]@users.noreply.github.com>
Co-authored-by: Roo Code <[email protected]>

* Changeset version bump (RooCodeInc#9154)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Matt Rubens <[email protected]>

* feat(core): detect API configuration changes for model switching

* fix: include mcpServers in getState() for auto-approval (RooCodeInc#9199)

* fix: replace rate-limited badges with badgen.net (RooCodeInc#9200)

* Batch settings updates from the webview to the extension host (RooCodeInc#9165)

Co-authored-by: Roo Code <[email protected]>

* fix: Apply updated API profile settings when provider/model unchanged (RooCodeInc#9208) (RooCodeInc#9210)

fix: apply updated API profile settings when provider/model unchanged (RooCodeInc#9208)

* fix: migrate