Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 22, 2025

This PR fixes issue #7316 where messages typed at follow-up question prompts were disappearing from history.

Problem

When users typed messages at choice prompts (follow-up questions), the messages would disappear and not be preserved in the chat history or accessible via up-arrow navigation. This was particularly problematic if the backend processing failed or if users navigated away.

Solution

  • Added a local message history buffer in the usePromptHistory hook that stores messages immediately upon sending
  • Modified ChatTextArea to save messages to local history before clearing the input field
  • Ensured messages typed at follow-up question prompts are preserved and accessible via up-arrow navigation
  • Added deduplication logic to prevent duplicate entries when messages are confirmed by backend

Changes Made

  1. webview-ui/src/components/chat/hooks/usePromptHistory.ts:

    • Added localSentMessages state to track messages before backend confirmation
    • Modified filteredPromptHistory to combine backend-confirmed messages with local sent messages
    • Added addToLocalHistory function to preserve messages locally
    • Implemented deduplication logic to avoid duplicates
  2. webview-ui/src/components/chat/ChatTextArea.tsx:

    • Integrated addToLocalHistory from the hook
    • Modified handleKeyDown to save messages to local history before sending
    • Ensures user input is preserved when Enter is pressed

Testing

  • All existing tests pass
  • Manually tested with follow-up questions to ensure messages are preserved
  • Verified up-arrow navigation works correctly with locally saved messages

Fixes #7316


Important

Fixes issue #7316 by preserving user messages at choice prompts in history, allowing access via up-arrow navigation and preventing duplicates.

  • Behavior:
    • Fixes issue Messages at choices disappear. #7316 by preserving user messages at choice prompts in history.
    • Messages are stored locally in usePromptHistory before backend confirmation.
    • Allows up-arrow navigation to access these messages.
    • Deduplication logic prevents duplicate entries.
  • ChatTextArea.tsx:
    • Integrates addToLocalHistory to save messages before clearing input.
    • Modifies handleKeyDown to ensure messages are preserved when Enter is pressed.
  • usePromptHistory.ts:
    • Adds localSentMessages state to track unconfirmed messages.
    • Combines local messages with backend-confirmed messages in filteredPromptHistory.
    • Clears local messages when task changes.
  • Testing:
    • All existing tests pass.
    • Manually tested to ensure messages are preserved and accessible via navigation.

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

- Added local message history buffer in usePromptHistory hook to store messages immediately upon sending
- Modified ChatTextArea to save messages to local history before clearing input field
- Ensured messages typed at follow-up question prompts are preserved and accessible via up-arrow navigation
- Added deduplication logic to prevent duplicate entries when messages are confirmed by backend

This fix ensures that user messages are never lost, even if typed at choice prompts or if backend processing fails.
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 22, 2025 11:30
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 22, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 22, 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.

Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.

}, [])

// Add a message to local sent history
const addToLocalHistory = useCallback((message: string) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missing test coverage for this new functionality. Could we add tests to verify that messages are properly saved to local history when Enter is pressed at choice prompts? The existing tests don't cover the addToLocalHistory function or the local message preservation logic.

const [tempInput, setTempInput] = useState("")
const [promptHistory, setPromptHistory] = useState<string[]>([])
// Local sent messages that haven't been confirmed by backend yet
const [localSentMessages, setLocalSentMessages] = useState<string[]>([])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Potential memory concern here. The localSentMessages array grows up to MAX_PROMPT_HISTORY_SIZE but is only cleared when clineMessages becomes empty. In a long-running session, could this accumulate duplicates? Consider adding deduplication when adding to localSentMessages or clearing confirmed messages from the local buffer.


// Add to local history before sending
if (inputValue.trim()) {
addToLocalHistory(inputValue.trim())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a potential race condition between adding to local history and the actual send? If onSend() fails or is delayed, the message is already in local history. Is this intentional to preserve the message even on send failure, or should we only add after confirming the send was initiated?

.map((message) => message.text!)

// If we have conversation messages, use those (newest first when navigating up)
// Combine conversation prompts with local sent messages (deduplicated)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This deduplication logic (lines 52-71) could be extracted into a utility function for better readability and potential reuse. Something like deduplicateAndMergePrompts(conversationPrompts, localSentMessages) would make the intent clearer.

) => boolean
resetHistoryNavigation: () => void
resetOnInputChange: () => void
addToLocalHistory: (message: string) => void
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider adding JSDoc comments for the new addToLocalHistory function and localSentMessages state to explain their purpose and when they're used. This would help future maintainers understand why we need this local buffer for fixing the UX issue.

@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 23, 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 23, 2025
@daniel-lxs
Copy link
Member

Closing in favor of #7394

@daniel-lxs daniel-lxs closed this Aug 25, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 25, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Aug 25, 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 PR - Needs Preliminary Review 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.

Messages at choices disappear.

4 participants