Skip to content

Fix: Preserve chat history on task cancellation #3775

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented May 21, 2025

closes #2537
jules test
Previously, canceling a running task could lead to the loss of the most recent chat history if it hadn't been saved immediately prior to cancellation.

This commit addresses the issue by ensuring that both the Cline messages (user-facing chat) and the API conversation history are explicitly saved at the beginning of the abortTask method in src/core/task/Task.ts. This guarantees that the latest state of the conversation is persisted before the task is fully terminated and its resources are released.

An automated E2E test has been added to e2e/src/suite/task.test.ts to specifically verify this fix. The test simulates starting a task, sending messages, canceling the task, and then resuming it to assert that the chat history remains intact.

Manual testing also confirmed that the chat history is correctly preserved after canceling and resuming a task.

Related GitHub Issue

Closes: #

Description

Test Procedure

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

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.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

Fixes chat history loss on task cancellation by saving history at the start of abortTask in Task.ts, with E2E test added for verification.

  • Behavior:
    • Fixes chat history loss on task cancellation by saving clineMessages and apiConversationHistory at the start of abortTask in Task.ts.
    • Ensures chat history is preserved when a task is canceled and resumed.
  • Testing:
    • Adds E2E test in task.test.ts to verify chat history preservation on task cancellation and resumption.
    • Manual testing confirms chat history is maintained after task cancellation and resumption.

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

Previously, canceling a running task could lead to the loss of the most recent chat history if it hadn't been saved immediately prior to cancellation.

This commit addresses the issue by ensuring that both the Cline messages (user-facing chat) and the API conversation history are explicitly saved at the beginning of the `abortTask` method in `src/core/task/Task.ts`. This guarantees that the latest state of the conversation is persisted before the task is fully terminated and its resources are released.

An automated E2E test has been added to `e2e/src/suite/task.test.ts` to specifically verify this fix. The test simulates starting a task, sending messages, canceling the task, and then resuming it to assert that the chat history remains intact.

Manual testing also confirmed that the chat history is correctly preserved after canceling and resuming a task.
// We'd need an `api.getTaskMessages(taskId)` instead.

const initialPromptMessage = collectedMessages.find(
msg => msg.text === initialPrompt && (msg.say === "ask" || msg.type === "ask")
Copy link

Choose a reason for hiding this comment

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

The verification condition checks for messages with either msg.say === 'ask' or msg.type === 'ask', but the initial prompt is sent via say('text', ...) so its message will likely have say='text'. This mismatch could lead to false negatives. Consider verifying the message based solely on its text content (or adjust the expected message type).

@hannesrudolph hannesrudolph marked this pull request as draft May 21, 2025 03:47
@hannesrudolph hannesrudolph moved this from New to PR [Draft/WIP] in Roo Code Roadmap May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR [Draft/WIP]
Development

Successfully merging this pull request may close these issues.

Unable to fetch http page to include it in context when running roocode as remote ssh plugin as root
1 participant