Skip to content

Conversation

@f14XuanLv
Copy link
Contributor

@f14XuanLv f14XuanLv commented Aug 11, 2025

Related GitHub Issue

Closes: #6926

Roo Code Task Context (Optional)

Description

This PR adds a cancel functionality for context condensing operations, addressing the issue where users couldn't interrupt long-running condensing processes.

Key implementation details:

  • Added a cancel button (X icon) in the TaskHeader component that appears when isCondensing is true
  • Implemented frontend-to-backend cancel message passing mechanism (cancelCondenseContext message type)
  • Used AbortController API to gracefully cancel async stream operations
  • Added abort signal checking in the condenseContext stream processing
  • Properly distinguished between cancelled and failed operations in error handling
  • Added internationalization support for all 18 supported languages

Test Procedure

Testing steps:

  1. Accumulate enough messages in a chat conversation to trigger context condensing
  2. When condensing starts, observe the cancel button (X icon) appears in TaskHeader
  3. Click the cancel button
  4. Verify the condensing operation stops immediately
  5. Check that the UI properly reflects the cancelled state (condensing indicator disappears)
  6. Confirm no error messages are shown and the conversation can continue normally

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

[Screenshot 1: Shows cancel button during condensing]
108270c3537d3904509e23d2c706295

[Screenshot 2: State after clicking cancel]
ed2323c55e3395e1dc4abfc89fad57a

Documentation Updates

  • No documentation updates are required.

Additional Notes

This feature improves user experience, especially when dealing with large contexts. The cancellation operation uses the standard AbortController pattern, ensuring proper resource cleanup.

Update: Fixed test failures by adding the missing abortSignal parameter to summarizeConversation calls in sliding-window tests, and completed internationalization for all supported languages (18 languages total).

Update 2: Fixed missing condense_cancelled translation key in common.json files for all languages, addressing the issue identified by Roomote bot review.

Get in Touch

N/A - Available via GitHub @f14XuanLv

@f14XuanLv f14XuanLv requested review from cte, jr and mrubens as code owners August 11, 2025 08:58
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Aug 11, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 11, 2025
Copy link
Contributor

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! I've reviewed the changes and found that while the implementation is generally clean and follows good patterns, there are some critical issues that need attention before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

Critical Issue: The translation key is not defined in the i18n files. This will cause a runtime error when the cancellation occurs.

You need to add this key to under the section:

Also add translations for other supported languages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good use of AbortController pattern for cancellation! The implementation is clean and follows best practices for handling async cancellation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding proper TypeScript types instead of using type assertions. You could extend the Task interface to include these properties:

Copy link
Contributor

Choose a reason for hiding this comment

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

The type assertions here and should be replaced with proper TypeScript interfaces. This would improve type safety and make the code more maintainable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good addition of the English translation! However, you should also add this translation key to all other supported language files to maintain complete i18n coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good state management for the condensing operation. The UI properly reflects the condensing state and handles the cancellation cleanly.

@f14XuanLv f14XuanLv force-pushed the feat/add-condense-cancel-feature branch from b22c050 to 3d12e7c Compare August 11, 2025 11:37
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 13, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 13, 2025
@f14XuanLv f14XuanLv force-pushed the feat/add-condense-cancel-feature branch from 1a90efc to c6193ed Compare August 13, 2025 06:40
@daniel-lxs
Copy link
Member

Hey @f14XuanLv, I've been testing the cancel functionality and noticed a couple of issues:

  1. The condensing cooldown seems to be broken - I can trigger condensing multiple times in a row even though there's supposed to be a limit that prevents condensing if one happened recently.

  2. There's a weird bug with the cancel button - if I click condense, then cancel, then try to condense again, I get an error saying "Failed to condense, condense was cancelled" even though I'm trying to start a fresh condensing operation. Seems like the abort controller state might not be getting cleaned up properly?

I pushed a fix for the TypeScript type assertions to your branch, but these functional issues should probably be addressed before merging. The cancel state might need to be reset more thoroughly when starting a new condensing operation.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Aug 15, 2025
f14XuanLv and others added 5 commits August 16, 2025 19:40
…nslations

- Fix failing tests by adding undefined abortSignal parameter to summarizeConversation calls
- Add missing 'cancelCondense' translations for all supported languages
- Added 'condense_cancelled' error message translation for all 18 languages
- This fixes the missing translation key issue identified by the Roomote bot
- Backend uses t('common:errors.condense_cancelled') which was undefined
- Added isCondensing and cancelCondenseContext properties to TaskLike interface
- Removed all 'as any' type assertions from Task.ts and ClineProvider.ts
- State properties (customCondensingPrompt, condensingApiConfigId, listApiConfigMeta) are now properly typed through GlobalState
…tions

- Add concurrent operation check to prevent multiple condensing operations
- Implement cleanup delay after abort to ensure proper state transition
- Resolve cancel->restart sequence state conflicts

Note: After cancellation, there's an ~5 second cooldown period before new
condensing operations can be initiated, which appears to be existing system behavior.
@f14XuanLv f14XuanLv force-pushed the feat/add-condense-cancel-feature branch from 42cd68b to 95eda6d Compare August 16, 2025 12:00
@f14XuanLv
Copy link
Contributor Author

f14XuanLv commented Aug 16, 2025

Hey @daniel-lxs

Thanks for the detailed feedback! I've addressed both issues you mentioned:

Fixed Issues

1. Condensing cooldown mechanism

Added concurrency control check to prevent multiple condensing operations from running simultaneously:

if (this.isCondensing) {
    console.warn("Context condensing is already in progress")
    return
}

2. Cancel state cleanup

Added intelligent cleanup waiting mechanism to avoid race conditions:

if (this.condensingAbortController && this.condensingAbortController.signal.aborted) {
    await new Promise(resolve => setTimeout(resolve, 100))
}

✅ Testing Results

Verified through actual testing:

  • Cancel functionality: Clicking cancel button immediately stops condensing operation ✅
  • Concurrency control: Additional clicks during condensing are properly ignored ✅
  • State cleanup: After cancellation, there's ~5 second cooldown period, then condensing works normally ✅

Ready for re-review!

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Aug 25, 2025
@daniel-lxs
Copy link
Member

Hey @f14XuanLv there's some logic that prevents frequent condesing:

image

This is not possible on the current version but seems possible on this PR, can you take a look?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Aug 25, 2025
@f14XuanLv
Copy link
Contributor Author

Hi @daniel-lxs

I need some clarification on a few points:

  1. Version Reference Ambiguity:
    When you say "there's some logic that prevents frequent condensing," which version are you referring to? Are you saying:
  • The current version HAS this prevention logic, or
  • My PR HAS this prevention logic?
  1. Screenshot Source:
    Is the screenshot showing behavior from the current version or from my PR version?

  2. Testing Methodology:
    I'm curious about how you managed to trigger two condensing operations so quickly. In my testing, condensing operations typically take much longer than a few seconds to complete. Are you using a special testing environment, or did you encounter a specific scenario that allows rapid consecutive condensing? I haven't experienced cases where condensing completes within 5 seconds.

Understanding these details will help me better identify and fix the problem you've found.

Thanks for your patience!

@hannesrudolph hannesrudolph moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Sep 23, 2025
@hannesrudolph
Copy link
Collaborator

Moving to dans column so he answers

@daniel-lxs
Copy link
Member

daniel-lxs commented Sep 24, 2025

Hi @f14XuanLv - quick clarification:

  1. Version reference: the cooldown logic exists on main today. This PR bypasses it, so condense can be re-triggered within the cooldown window.

  2. Screenshot: it is demonstrating the behavior on this PR build (multiple back-to-back condenses within the cooldown window). On main this is blocked by the cooldown.

  3. Repro (no special env):

  • Let one condense finish, then click Condense again immediately (within the cooldown window).
    • On main: blocked by cooldown.
    • On this PR: starts a new condense (cooldown not enforced).
  • Also: Start condense -> Cancel -> immediately click Condense again.
    • On main: blocked by cooldown.
    • On this PR: it starts right away and sometimes shows "Failed to condense, condense was cancelled", which suggests abort state and/or cooldown state is not reset consistently.

Important: concurrency is not the same as cooldown. An isCondensing guard only prevents overlap while one is running; we also need the time-based guard after a condense completes or is cancelled. The PR appears to short-circuit that check.

What to update:

  • Reapply the cooldown check at the start of a condense attempt based on the last-completed-at timestamp (set it on both success and cancel).
  • Ensure the abort controller is fully replaced before starting a new run, and that cancellation also sets last-completed-at so the cooldown still applies.

Once these are in, I can re-test.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Sep 24, 2025
@f14XuanLv
Copy link
Contributor Author

@hannesrudolph Could you please move this to dan's column so he can answer these questions?


Hi @daniel-lxs,

Thank you for the clarification. However, I'm confused about your statement regarding the existing cooldown logic on main.

Current Analysis on main branch (commit: 87d50a7)

After examining the codebase on the latest main branch (commit 87d50a78cb92ab5f050a4ec1233afe7004a52e3c), I can only find message-based prevention logic, not time-based cooldown logic:

1. Message-based prevention in src/core/condense/index.ts:119-124:

const keepMessages = messages.slice(-N_MESSAGES_TO_KEEP)  // Last 3 messages
const recentSummaryExists = keepMessages.some((message) => message.isSummary)
if (recentSummaryExists) {
    const error = t("common:errors.condensed_recently")
    return { ...response, error }
}

2. The time-related logic I found is in Task.ts for general API rate limiting:

private static lastGlobalApiRequestTime?: number
// Used for general API rate limiting, not specifically for condensing

My Questions:

  1. Could you please point me to the specific file and code location where this time-based cooldown logic exists on main (commit 87d50a78c)?
  2. What is the default cooldown window duration?
  3. Where is the "last-completed-at timestamp" being tracked that you mentioned?

I want to ensure I'm addressing the right issue, but I cannot locate the time-based cooldown mechanism you're referring to. It's possible I'm missing something, so your guidance on the specific location would be very helpful.

Regarding the reproduction steps:

The behavior you described (immediate re-triggering after completion/cancellation) might be related to the concurrent execution guard (isCondensing) rather than a time-based cooldown, which could explain why my changes affect it.

Could you help me identify where this time-based cooldown logic is implemented on main? This will help me preserve it properly in my PR.

Thanks for your patience!

@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Sep 26, 2025
@daniel-lxs
Copy link
Member

Thanks for working on this! I'm closing this PR as part of cleanup for inactive PRs. The implementation would need some additional backend wiring to fully support the cancellation flow. If you'd like to revisit this feature, feel free to open a new PR or let me know if you want to continue with this one.

@daniel-lxs daniel-lxs closed this Oct 23, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 23, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants