Skip to content

Conversation

@roomote
Copy link

@roomote roomote bot commented Oct 7, 2025

This PR attempts to address Issue #8553 where the "enhance prompt" feature incorrectly overwrites both the edit message box and the new message box when editing a message.

Problem

When a user is editing a message and uses the enhance prompt feature, the enhanced text appears in both:

  1. The edit box (correct behavior)
  2. The main new message box (incorrect behavior)

Solution

Added a context parameter to distinguish between different ChatTextArea instances:

  • The backend now includes a context field in enhanced prompt response messages
  • Each ChatTextArea instance sends its context ("main" or "edit") when requesting enhancement
  • Each instance only responds to enhanced prompt messages matching its specific context

Changes

  • Backend: Modified webviewMessageHandler.ts to include context from request in response
  • Frontend: Updated ChatTextArea.tsx to send context and filter incoming messages
  • Tests: Added comprehensive test coverage for the new context-aware behavior

Testing

  • All existing tests pass
  • Added new tests to verify context-specific behavior
  • Manually tested the fix works as expected

Fixes #8553

Feedback and guidance are welcome!


Important

Fixes 'enhance prompt' feature to correctly target only the intended message box by using context parameters.

  • Behavior:
    • Fixes issue where 'enhance prompt' overwrites both edit and new message boxes by adding a context parameter.
    • ChatTextArea instances now send their context ('main' or 'edit') when requesting enhancement.
    • Only responds to enhanced prompt messages matching its context.
  • Backend:
    • Modified webviewMessageHandler.ts to include context in enhanced prompt responses.
  • Frontend:
    • Updated ChatTextArea.tsx to send context and filter messages based on context.
  • Tests:
    • Added tests in ChatTextArea.spec.tsx to verify context-specific behavior.
    • Tests ensure enhanced prompts are handled correctly for matching contexts and ignored for non-matching contexts.

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

…e boxes

- Add context parameter to enhance prompt messages to distinguish between main and edit mode
- Update ChatTextArea to only respond to enhance prompt messages matching its context
- Add comprehensive test coverage for context-specific behavior

Fixes #8553
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 7, 2025 18:42
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Oct 7, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 7, 2025
Copy link
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.

Self-review: reviewing my own code like a hall of mirrors for robots—still cheaper than therapy.

// Only handle the enhanced prompt if it's for this specific textarea instance
// Edit mode textareas have context "edit", main textarea has context "main"
const expectedContext = isEditMode ? "edit" : "main"
if (message.context === expectedContext) {
Copy link
Author

Choose a reason for hiding this comment

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

[P2] Backward-compatibility edge case: if older backends emit 'enhancedPrompt' without a context field, this instance will ignore the event and the spinner may never clear. Consider defaulting undefined context to 'main' so the main textarea still handles legacy messages.

Example:

const expectedContext = isEditMode ? "edit" : "main"
const incomingContext = message.context ?? "main"
if (incomingContext === expectedContext) {
  // ...
}

})
})

describe("enhanced prompt response", () => {
Copy link
Author

Choose a reason for hiding this comment

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

[P2] Missing error-path coverage: when an enhancedPrompt arrives with matching context but no text (error response), the component should still stop the loading spinner. Add a test asserting setIsEnhancingPrompt(false) is called (or the UI state reflects it) when message.text is undefined.

window.addEventListener("message", messageHandler)
return () => window.removeEventListener("message", messageHandler)
}, [setInputValue, searchRequestId, inputValue])
}, [setInputValue, searchRequestId, inputValue, isEditMode])
Copy link
Author

Choose a reason for hiding this comment

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

[P3] Performance: the message event listener re-subscribes on every inputValue change due to being in a useEffect with inputValue in deps. This can be avoided by using a ref for latest inputValue or the existing useEvent hook (already imported) so the handler stays stable while reading current state via refs, reducing listener churn.

@hannesrudolph
Copy link
Collaborator

Fix tested and works, did not review code

@hannesrudolph hannesrudolph moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Oct 28, 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 Oct 28, 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:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: PR [Needs Prelim Review]

Development

Successfully merging this pull request may close these issues.

[BUG] Editing a message with "enhance prompt" feature puts new text in edit box, but also in new message box

3 participants