Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 16, 2025

Summary

This PR fixes issue #6932 where chat history was being truncated during message-related operations (edit/delete).

Problem

The findMessageIndices function in webviewMessageHandler.ts was using a 1-second timestamp buffer when searching for messages to delete or edit. This caused unintended deletion of unrelated messages that happened to fall within the 1-second window, resulting in chat history truncation.

Solution

  • Changed findMessageIndices to use exact timestamp matching (msg.ts === messageTs) instead of the 1-second buffer
  • This ensures only the intended message (and subsequent messages) are affected by delete/edit operations
  • Updated test expectations to match the correct behavior

Testing

  • All existing tests pass
  • Updated 4 test cases to reflect the correct behavior with exact timestamp matching
  • Verified that message deletion and editing now work correctly without truncating unrelated messages

Related Issues

Fixes #6932


Important

Fixes chat history truncation by using exact timestamp matching for message operations in webviewMessageHandler.ts.

  • Behavior:
    • Fixes chat history truncation by changing findMessageIndices in webviewMessageHandler.ts to use exact timestamp matching instead of a 1-second buffer.
    • Ensures only intended messages are affected by delete/edit operations.
  • Testing:
    • Updated 4 test cases in ClineProvider.spec.ts to reflect exact timestamp matching behavior.
    • Verified message deletion and editing work correctly without truncating unrelated messages.

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

- Changed findMessageIndices to use exact timestamp matching (ts === messageTs)
- Removed 1-second buffer that was causing unintended message deletion
- Updated test expectations to match correct behavior
- Fixes #6932 where chat history was being truncated during message operations
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 16, 2025 12:32
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 16, 2025
Copy link
Contributor Author

@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.

Reviewed my own code. Found it surprisingly coherent for something I wrote 3 minutes ago.

const timeCutoff = messageTs - 1000 // 1 second buffer before the message
const messageIndex = currentCline.clineMessages.findIndex((msg: ClineMessage) => msg.ts && msg.ts >= timeCutoff)
// Use exact timestamp matching to prevent unintended message deletion
const messageIndex = currentCline.clineMessages.findIndex((msg: ClineMessage) => msg.ts === messageTs)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While this exact timestamp matching fixes the immediate issue, consider what happens if multiple messages share the same timestamp. Would adding a secondary check using message content or index as a tiebreaker make this more robust?


/**
* Shared utility to find message indices based on timestamp
* Shared utility to find message indices based on exact timestamp matching
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good addition of validation! Consider adding a comment explaining why we use exact timestamp matching instead of the previous buffer approach, perhaps referencing issue #6932 for future maintainers?

}

// Log deletion for debugging
const messagesToDelete = currentCline.clineMessages.length - messageIndex
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice defensive programming with the validation checks. For consistency, could we standardize all console logs in this file to use the prefix? Some logs have it, others don't.

expect(mockCline.overwriteClineMessages).toHaveBeenCalledWith([mockMessages[0], mockMessages[1]])
// With exact timestamp matching, we find the message at index 3 (ts: 4000)
// and keep messages 0, 1, and 2 (all before timestamp 4000)
expect(mockCline.overwriteClineMessages).toHaveBeenCalledWith([
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good job updating the test expectations to match the new exact timestamp behavior. Consider adding a dedicated test case specifically for the function to ensure it handles edge cases like duplicate timestamps correctly.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 16, 2025
@daniel-lxs daniel-lxs closed this Aug 18, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 18, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Chat history gets truncated during message-related operations

4 participants