fix(tui): restore queued messages when a session is interrupted - #39189
Open
chaitanyarahalkar wants to merge 2 commits into
Open
fix(tui): restore queued messages when a session is interrupted#39189chaitanyarahalkar wants to merge 2 commits into
chaitanyarahalkar wants to merge 2 commits into
Conversation
Double-ESC aborts the session, which leaves any queued follow-up persisted but never run, so the typed text silently disappeared. Put the queued text back into the prompt before aborting, the way session.undo already does. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that may be of interest, though none appear to be direct duplicates of PR #39189: Related PRs:
These PRs suggest there's been ongoing work in this area (interrupt handling and queued messages), but PR #39189 appears to be unique in addressing the specific issue of restoring the lost queued message text to the input box after an interrupt. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #33812
Type of change
What does this PR do?
If you type a follow-up while the agent is streaming and then press ESC twice to interrupt, the message you typed is lost. It is still persisted server-side, but no turn ever runs for it and the QUEUED badge disappears, so you have to retype it.
The cause is that the interrupt handler aborts without checking whether a user message arrived after the running assistant turn started.
runLooponly picks up a queued message when the current assistant message completes, so interrupting before that point leaves the message with nothing to consume it.Before aborting, the handler now collects user messages newer than the running turn and puts their text and file parts back into the prompt box via
PromptRef.set— the same callsession.undoalready uses to return a reverted message's text to the input. It only restores when the prompt is empty, so it will not overwrite a draft you have already started typing.I used the client-side restore rather than re-arming the runner after
cancel. Re-arming would make double-ESC sometimes stop the session and sometimes immediately start another turn, and when you interrupt you usually want to edit the message before resending it anyway.One thing this does not fix: the orphaned user message still sits in the transcript. Removing it needs a
session.revertcall, which seemed like a separate change.How did you verify your code works?
bun test test/prompt/queued.test.tsinpackages/tui— 4 new tests covering thequeuedMessagesselector: one queued message, several stacked up, an idle session, and an abandoned turn that a later turn already completed.Full
packages/tuisuite: 195 pass, 1 skip, 0 fail. Baseline ondevis 191 pass, so that is the 4 added here and no regressions.To reproduce by hand: start a turn, type a second message while it is streaming, then press ESC twice. Before this change the input box is empty and the text is gone; after it, the text is back in the box.
Screenshots / recordings
No visual change — the diff is behavioural. The observable difference is that the prompt box contains your text after an interrupt instead of being empty.
Checklist