run_in_terminal: detect shell continuation prompts and abort#316271
run_in_terminal: detect shell continuation prompts and abort#316271meganrogge wants to merge 2 commits into
Conversation
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>
There was a problem hiding this comment.
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
isContinuationPromptandwaitForContinuationPrompthelpers and exclude continuation prompts fromdetectsCommonPromptPattern. - Race continuation-prompt detection in
RichExecuteStrategy,BasicExecuteStrategy, andNoneExecuteStrategy; on detection send Ctrl+C and return an explanatory error. - Add unit tests for
isContinuationPromptand for the newdetectsCommonPromptPatternrejection 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
…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>
|
/requires-eval-assessment terminalbench2 gpt-5.4,claude-opus-4.6,claude-opus-4.7 |
|
⏳ Queued vscode build for
|
|
I actually think this is overkill / too narrowly scoped and will be fixed by #315885 |
|
🚀 Queued eval-assessment publish build for
|
|
❌ Eval-assessment build did not succeed (result: |
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:isContinuationPrompt()to detect known shell continuation prompts (dquote>,quote>,bquote>,pipe>,cmdsubst>,heredoc>)waitForContinuationPrompt()that monitors terminal idle state and checks for continuation prompt patterns on the cursor linedetectsCommonPromptPattern()to exclude continuation prompts so they are not falsely detected as ready prompts (previouslydquote>matched the generic[>%]pattern)All three execute strategies (rich, basic, none):
waitForContinuationPrompt()as a race candidate alongside existing completion signalsHow 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:
This prevents the hang and gives the agent actionable feedback to fix the command.