Skip to content

fix races in prompt for input #287651

Merged
meganrogge merged 1 commit intomainfrom
strange-platypus
Jan 13, 2026
Merged

fix races in prompt for input #287651
meganrogge merged 1 commit intomainfrom
strange-platypus

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

@meganrogge meganrogge commented Jan 13, 2026

fixes #287642

When a user manually entered input into the terminal before the input prompt was created, the prompt would still appear and hang around even after the command finished.

This happened bc the input listener was being set up too late - only after the LLM finished analyzing the terminal output. Any user input that happened between idle detection and prompt creation was missed.

Fixes:

  1. The input listener is now set up immediately when idle is detected inside waitForIdle, not after returning from it. This eliminates the race window between detecting idle and handling the idle state.

  2. Added checks for _userInputtedSinceIdleDetectedat multiple points:

  • Before calling the LLM to determine user input options
  • After the LLM call returns
  • After _selectAndHandleOption() (another LLM call)
  • Right before showing any prompt UI

If the user has inputted at any of these checkpoints, we skip showing the prompt and continue polling instead.

  1. Updated the LLM prompt to explicitly require that detected input prompts must appear at the VERY END of the terminal output with no content following them. Added examples showing prompts that were already answered should return null:
"Continue (y/n)? y" → null (already answered with 'y')
"Do you want to proceed? (yes/no)\nyes\nProceeding..." → null (answered with subsequent output)

@meganrogge meganrogge requested review from Tyriar and Copilot and removed request for Copilot January 13, 2026 23:19
@meganrogge meganrogge self-assigned this Jan 13, 2026
@meganrogge meganrogge added this to the January 2026 milestone Jan 13, 2026
@meganrogge meganrogge enabled auto-merge (squash) January 13, 2026 23:19
*/
private _setupIdleInputListener(): void {
// Clean up any existing listener
this._userInputListener?.dispose();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MutableDisposable is the right pattern to avoid this duplication

// Set up new listener
this._userInputListener = this._execution.instance.onDidInputData((data) => {
if (data === '\r' || data === '\n' || data === '\r\n') {
this._userInputtedSinceIdleDetected = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The user could input without a newline, read doesn't need to read full lines

@meganrogge meganrogge merged commit 96a75ab into main Jan 13, 2026
27 of 28 checks passed
@meganrogge meganrogge deleted the strange-platypus branch January 13, 2026 23:40
eli-w-king pushed a commit that referenced this pull request Jan 14, 2026
meganrogge added a commit that referenced this pull request Jan 14, 2026
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Feb 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prompt for input showing after input has been typed in the terminal

3 participants