Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@daniel-lxs
Copy link
Member

@daniel-lxs daniel-lxs commented Sep 11, 2025

When users invoke slash commands, the command content is appended to the first message. This fix ensures the first message is always preserved during condensing operations, preventing loss of vital context like slash command instructions.

Changes

  • Always preserve the first message intact during summarization
  • Only summarize messages from index 1 onwards
  • Maintains command context and initial user request throughout the conversation

Testing

  • Added comprehensive tests in src/core/condense/__tests__/condense.spec.ts
  • Tests verify first message preservation with slash commands
  • Tests ensure complex content types are preserved
  • All tests passing

Problem

When a user types a slash command (e.g., /prr), the command content is appended to the first message via parseMentions. However, when the conversation is condensed, this first message was replaced with a summary, losing the vital command content that was appended.

Solution

Modified the summarizeConversation function in src/core/condense/index.ts to always preserve the first message intact, similar to how truncateConversation in src/core/sliding-window/index.ts does.


Important

Preserve the first message during conversation summarization to retain slash command content.

  • Behavior:
    • summarizeConversation in index.ts now preserves the first message during summarization.
    • Only messages from index 1 onwards are summarized, maintaining initial context.
  • Testing:
    • Added tests in condense.spec.ts to verify first message preservation, handling of slash commands, and complex content.
    • Tests ensure error handling for insufficient messages and recent summaries.
  • Problem:
    • Slash command content appended to the first message was lost during conversation condensing.
  • Solution:
    • Modified summarizeConversation to preserve the first message, similar to truncateConversation.

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

When users invoke slash commands, the command content is appended to the first message. This fix ensures the first message is always preserved during condensing operations, preventing loss of vital context like slash command instructions.

- Always preserve the first message intact during summarization
- Only summarize messages from index 1 onwards
- Maintains command context and initial user request throughout the conversation
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 11, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Sep 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 this fix! The implementation correctly addresses the issue of preserving the first message during conversation condensing, which is crucial for maintaining slash command context. The approach elegantly mirrors the existing pattern in truncateConversation for consistency. I've left a few suggestions for consideration below.

const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))

// Always preserve the first message (which may contain slash command content)
const firstMessage = messages[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a safety check here to handle the edge case where the messages array might be empty? While unlikely in practice, it would make the code more robust. Consider checking if messages.length === 0 before accessing messages[0].

const response: SummarizeResponse = { messages, cost: 0, summary: "" }
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(0, -N_MESSAGES_TO_KEEP))

// Always preserve the first message (which may contain slash command content)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider enhancing this comment to explicitly mention why we preserve the first message: 'Always preserve the first message (which may contain slash command content, initial user request, and important context)'. This would help future maintainers understand the critical importance of this preservation.

// Always preserve the first message (which may contain slash command content)
const firstMessage = messages[0]
// Get messages to summarize, excluding the first message and last N messages
const messagesToSummarize = getMessagesSinceLastSummary(messages.slice(1, -N_MESSAGES_TO_KEEP))
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic here creates an implicit minimum of 4 messages (first + 3 to keep). Would it be clearer to extract this as a constant like MIN_MESSAGES_FOR_CONDENSING = N_MESSAGES_TO_KEEP + 1? Then the condition could be more explicit about the requirement.


const newMessages = [...messages.slice(0, -N_MESSAGES_TO_KEEP), summaryMessage, ...keepMessages]
// Reconstruct messages: [first message, summary, last N messages]
const newMessages = [firstMessage, summaryMessage, ...keepMessages]
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work maintaining consistency with the structure. The reconstruction clearly shows the preserved first message, followed by the summary, and then the recent messages.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 11, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Review] in Roo Code Roadmap Sep 11, 2025
@mrubens mrubens merged commit 3dfa526 into main Sep 11, 2025
9 checks passed
@mrubens mrubens deleted the fix/preserve-first-message-condensing branch September 11, 2025 20:00
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Sep 11, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 11, 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. lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants