[PR #5124] fix: process queued messages after session interrupt #11253

Closed
opened 2026-02-16 18:16:03 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5124

State: closed
Merged: No


Issue

related #3543

Problem

When interrupting a session that has queued messages, the queued messages would appear as "QUEUED" in the UI but never get processed.

Root cause: When cancel() is called, it:

  1. Aborts the current operation
  2. Rejects all pending callbacks
  3. Deletes session state
  4. Sets status to idle

But user messages queued during the operation were already persisted to storage. After interrupt, no loop runs to process them.

Solution

  1. Track loop instances with loopId - Each loop gets a unique ID to distinguish it from other loops for the same session

  2. Restart loop after cancel if callbacks exist - When cancel() is called and there are pending callbacks (queued messages), automatically restart the loop to process them

  3. Prevent race condition - Pass loopId to the deferred cleanup so old loop's cleanup doesn't abort the newly started loop

Changes

  • Added loopId to session state tracking
  • Modified start() to return both signal and loopId
  • Modified cancel() to accept optional loopId and restart loop if pending callbacks exist
  • Modified loop() to use loopId in deferred cleanup
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5124 **State:** closed **Merged:** No --- ## Issue related #3543 ## Problem When interrupting a session that has queued messages, the queued messages would appear as "QUEUED" in the UI but never get processed. **Root cause:** When `cancel()` is called, it: 1. Aborts the current operation 2. Rejects all pending callbacks 3. Deletes session state 4. Sets status to idle But user messages queued during the operation were already persisted to storage. After interrupt, no loop runs to process them. ## Solution 1. **Track loop instances with `loopId`** - Each loop gets a unique ID to distinguish it from other loops for the same session 2. **Restart loop after cancel if callbacks exist** - When `cancel()` is called and there are pending callbacks (queued messages), automatically restart the loop to process them 3. **Prevent race condition** - Pass `loopId` to the deferred cleanup so old loop's cleanup doesn't abort the newly started loop ## Changes - Added `loopId` to session state tracking - Modified `start()` to return both signal and loopId - Modified `cancel()` to accept optional loopId and restart loop if pending callbacks exist - Modified `loop()` to use loopId in deferred cleanup
yindo added the pull-request label 2026-02-16 18:16:03 -05:00
yindo closed this issue 2026-02-16 18:16:03 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11253