Skip to content

Conversation

@cte
Copy link
Collaborator

@cte cte commented Jan 18, 2026

Summary

Fixes a crash in the CLI caused by rapidly pressing the Escape key during task cancellation.

Problem

When users spam the Escape key to cancel a running task, multiple cancelTask messages are sent to the extension before the first one finishes processing. This causes a crash in the CLI.

Solution

Add an isCancelling state to the UI store that:

  • Gets set to true when the first Escape press sends a cancelTask message
  • Blocks subsequent Escape presses from sending additional messages (shows "Cancel in progress..." instead)
  • Automatically resets to false when isLoading transitions from true to false, indicating the cancel completed

Changes

  • uiStateStore.ts: Added isCancelling state and setIsCancelling action
  • useGlobalInput.ts: Check isCancelling before sending cancel, reset flag when task finishes
  • uiStateStore.test.ts: Added comprehensive tests for the new state

Important

Fixes CLI crash by managing task cancellation state with isCancelling to prevent multiple cancel requests when Escape key is spammed.

  • Behavior:
    • Prevents CLI crash by managing task cancellation state with isCancelling in uiStateStore.ts.
    • Blocks multiple cancelTask messages by setting isCancelling to true on first Escape press.
    • Resets isCancelling to false when isLoading transitions to false.
  • Implementation:
    • Adds isCancelling state and setIsCancelling action in uiStateStore.ts.
    • Modifies useGlobalInput.ts to check isCancelling before sending cancel messages and reset it after task completion.
  • Testing:
    • Adds tests in uiStateStore.test.ts to verify isCancelling behavior and state transitions.

This description was created by Ellipsis for 543d8a9. You can customize this summary. It will automatically update as commits are pushed.

Add isCancelling state to UI store to debounce cancel requests.
When a cancel is in progress, subsequent Escape presses show a
'Cancel in progress...' message instead of sending multiple
cancelTask messages that crash the CLI.

The isCancelling flag is automatically reset when isLoading
transitions from true to false, indicating the cancel completed.

- Add isCancelling state and setIsCancelling action to uiStateStore
- Update useGlobalInput to check isCancelling before sending cancel
- Add useEffect to reset isCancelling when task finishes cancelling
- Add unit tests for isCancelling state behavior
@cte cte requested review from jr and mrubens as code owners January 18, 2026 18:17
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jan 18, 2026
@roomote
Copy link
Contributor

roomote bot commented Jan 18, 2026

Rooviewer Clock   See task on Roo Cloud

All issues resolved. The fix for preventing CLI crashes from spamming Escape is well-structured and follows React best practices.

  • Consider using useRef instead of module-level variable for prevIsLoading in useGlobalInput.ts
Previous reviews

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

Comment on lines 11 to 12
// Track previous isLoading state for effect
let prevIsLoading = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a module-level variable to track previous state is not idiomatic React and can cause issues in development with Strict Mode (effects run twice), or if multiple hook instances exist. Consider using a useRef instead, which properly scopes the value to the component instance:

Suggested change
// Track previous isLoading state for effect
let prevIsLoading = false
const prevIsLoadingRef = useRef(false)

Then update the effect to use prevIsLoadingRef.current instead of prevIsLoading. This would also require adding useRef to the React import on line 1.

Fix it with Roo Code or mention @roomote and request a fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomote Do you agree? If so please fix.

Copy link
Contributor

@roomote roomote bot Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixaroo Clock   See task on Roo Cloud

Fixed the reported issue. Replaced module-level prevIsLoading with useRef for proper React patterns. All local checks passed.

View commit | Revert commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

3 participants