Skip to content

run_in_terminal: detect shell continuation prompts and abort#316271

Closed
meganrogge wants to merge 2 commits into
mainfrom
merogge/fix-continuation-prompt-hang
Closed

run_in_terminal: detect shell continuation prompts and abort#316271
meganrogge wants to merge 2 commits into
mainfrom
merogge/fix-continuation-prompt-hang

Conversation

@meganrogge
Copy link
Copy Markdown
Collaborator

Fixes #315694

When a command with unmatched quotes is sent to the terminal, the shell enters a continuation prompt (e.g. dquote>, quote>) and waits for more input. Previously this caused the terminal tool to hang indefinitely because no command-finished event ever fires.

Changes

executeStrategy.ts:

  • Adds isContinuationPrompt() to detect known shell continuation prompts (dquote>, quote>, bquote>, pipe>, cmdsubst>, heredoc>)
  • Adds waitForContinuationPrompt() that monitors terminal idle state and checks for continuation prompt patterns on the cursor line
  • Fixes detectsCommonPromptPattern() to exclude continuation prompts so they are not falsely detected as ready prompts (previously dquote> matched the generic [>%] pattern)

All three execute strategies (rich, basic, none):

  • Integrates waitForContinuationPrompt() as a race candidate alongside existing completion signals
  • When a continuation prompt is detected, sends Ctrl+C to abort the malformed command and returns an error message explaining the quoting issue

How it works

The fix monitors the terminal data stream for idle periods. When the terminal goes idle, it checks if the cursor line matches a known continuation prompt pattern. If so, it:

  1. Sends Ctrl+C to abort the stuck command
  2. Returns an error to the agent: "The command has a syntax error — the shell showed a "dquote>" continuation prompt, indicating unmatched quotes or brackets. Fix the quoting and retry."

This prevents the hang and gives the agent actionable feedback to fix the command.

When a command with unmatched quotes is sent to the terminal, the shell
enters a continuation prompt (e.g. dquote>, quote>) and waits for input.
Previously this caused the terminal tool to hang indefinitely because no
command-finished event ever fires.

This change:
- Adds isContinuationPrompt() to detect known zsh continuation prompts
- Adds waitForContinuationPrompt() that monitors terminal idle state for
  continuation prompt patterns
- Integrates detection as a race candidate in all three execute
  strategies (rich, basic, none)
- When detected, sends Ctrl+C to abort and returns an error message
  explaining the quoting issue
- Fixes detectsCommonPromptPattern() to exclude continuation prompts so
  they are not falsely detected as ready prompts

Fixes #315694

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 13, 2026 16:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a hang in the run_in_terminal tool when commands contain unmatched quotes/brackets and the shell drops into a continuation prompt (e.g. dquote>). All three execute strategies now race a new continuation-prompt detector alongside their existing completion signals, send Ctrl+C when one is seen, and report a syntax-error message back to the agent. detectsCommonPromptPattern is also fixed so it no longer mistakes continuation prompts for ready prompts.

Changes:

  • Add isContinuationPrompt and waitForContinuationPrompt helpers and exclude continuation prompts from detectsCommonPromptPattern.
  • Race continuation-prompt detection in RichExecuteStrategy, BasicExecuteStrategy, and NoneExecuteStrategy; on detection send Ctrl+C and return an explanatory error.
  • Add unit tests for isContinuationPrompt and for the new detectsCommonPromptPattern rejection cases.
Show a summary per file
File Description
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/executeStrategy.ts Adds continuation-prompt patterns/helpers and excludes them from common prompt detection.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/richExecuteStrategy.ts Races continuation-prompt detection and aborts with Ctrl+C on detection.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/basicExecuteStrategy.ts Same continuation-prompt race + abort handling for the basic strategy.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/executeStrategy/noneExecuteStrategy.ts Adds continuation-prompt branch to the prompt/alt-buffer race; Ctrl+C call is not awaited unlike sibling strategies.
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/browser/executeStrategy.test.ts Tests for isContinuationPrompt and the new rejection cases in detectsCommonPromptPattern.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 2

@meganrogge meganrogge added this to the 1.121.0 milestone May 13, 2026
…prompt detection

- Await sendText('\x03') in noneExecuteStrategy for consistency with
  rich and basic strategies
- Use 2x idle interval for continuation prompt detection to reduce
  false positives from commands that briefly print prompt-like text
- Add cursor column check to verify the shell is actually awaiting
  input at the prompt, not mid-line in command output

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meganrogge
Copy link
Copy Markdown
Collaborator Author

/requires-eval-assessment terminalbench2 gpt-5.4,claude-opus-4.6,claude-opus-4.7

@meganrogge meganrogge added the ~requires-eval-assessment Evals will be run and will generate a report upon completion label May 13, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

⏳ Queued vscode build for e89ec443ed257e71e82d091c3ea0c1ed8798b5fd (step 1/2).

@meganrogge
Copy link
Copy Markdown
Collaborator Author

I actually think this is overkill / too narrowly scoped and will be fixed by #315885

@meganrogge meganrogge closed this May 13, 2026
@vs-code-engineering
Copy link
Copy Markdown
Contributor

🚀 Queued eval-assessment publish build for 4ef9a0030e63e8479431d875059fc234d9035ed7 (step 2/2).

@vs-code-engineering
Copy link
Copy Markdown
Contributor

❌ Eval-assessment build did not succeed (result: failed).

@vs-code-engineering vs-code-engineering Bot removed the ~requires-eval-assessment Evals will be run and will generate a report upon completion label May 13, 2026
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.

bad quoting can cause terminal to hang

3 participants