Skip to content

Conversation

@thoughtlesslabs
Copy link

@thoughtlesslabs thoughtlesslabs commented Dec 5, 2025

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

When interrupting a session with queued messages, the queued messages
would show as 'QUEUED' but never get processed. This happened because
cancel() would reject all callbacks without restarting the loop.

Changes:
- Add loopId to track each loop instance
- Restart loop after cancel if there were pending callbacks
- Use loopId to prevent old loop's cleanup from aborting new loop

Fixes sst#3543
Identifier.ascending() only accepts specific prefixes (message, part,
permission, pty, session, user). Use ulid() which is already imported
and generates unique IDs without type constraints.
@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

lgtm

@rekram1-node
Copy link
Collaborator

Just curious so I could see the issue it solves, can u provide a video or steps to reproduce? wanna make sure i understand issue because I cant replicate it

@thoughtlesslabs
Copy link
Author

Here are two videos. The first video shows what happens with a queued command and then an interrupt on the current operation in build mode. The second video is my dev build where a queued messaged will activate after the interrupt.

Current system: https://github.com/user-attachments/assets/31d50b2d-f46e-49ce-82d1-9eacd67aaab6
Proposed fix: https://github.com/user-attachments/assets/265f4678-4859-4d8f-8247-277c08167ce9

however, on further reflection and resting, I've realized this solution may not solve all use cases, i.e. multiple queued messages are handled in reverse sequential order after cancellation with no ability to cancel earlier queued messages. I am working on a more robust solution for handling multiple queued messages properly.

I often use opencode to monitor logs on debugging which leaves a task running for quite sometime and I often queue up my followup. When I need to cancel the monito, I lose my queued message. If this is a not an issue for other users I understand just closing this out.

@thoughtlesslabs thoughtlesslabs marked this pull request as draft December 6, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants