Skip to content

fix: prevent terminal hangs when PowerShell prompt fails - #376

Merged
xinyi-gong merged 1 commit into
mainfrom
fix/375-powershell-prompt-hang
Jul 29, 2026
Merged

fix: prevent terminal hangs when PowerShell prompt fails#376
xinyi-gong merged 1 commit into
mainfrom
fix/375-powershell-prompt-hang

Conversation

@xinyi-gong

Copy link
Copy Markdown
Member

Summary

Fixes Agent mode hanging indefinitely after a terminal command completes on Windows.

Root cause

The PowerShell integration invoked the original prompt using ScriptBlock.Invoke(). This method call is blocked in ConstrainedLanguage mode. A user-defined prompt could also throw an exception or return no output.

When the prompt failed, the shell integration did not emit its prompt-end marker. Consequently, the terminal command future never completed and Agent mode remained stuck on Running run_in_terminal tool.

Changes

  • Execute the original prompt using PowerShell's call operator instead of .Invoke().
  • Catch failures from user-defined prompt functions.
  • Fall back to a standard prompt containing the current directory when the original prompt fails or returns no output.
  • Ensure shell completion markers continue to be emitted.

Validation

  • Reproduced the hang in ConstrainedLanguage mode.
  • Verified terminal commands complete after the fix in ConstrainedLanguage mode.
  • Verified fallback behavior when a custom prompt:
    • throws an exception;
    • returns $null.
  • Verified normal PowerShell prompt behavior remains unchanged.
  • .\mvnw checkstyle:check passed.
  • .\mvnw test passed.

Fixes #375

Copilot AI review requested due to automatic review settings July 29, 2026 06:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a Windows-specific Agent mode hang by hardening the PowerShell shell-integration prompt handling so the tool completion markers are still emitted even when the user’s prompt fails (notably in ConstrainedLanguage mode).

Changes:

  • Invoke the original PowerShell prompt via the call operator (&) instead of ScriptBlock.Invoke() to avoid ConstrainedLanguage blocking.
  • Guard prompt execution with try/catch and suppress prompt errors to prevent breaking the integration flow.
  • Provide a fallback prompt (current directory) when the original prompt throws, returns $null, or returns an empty string.

@xinyi-gong
xinyi-gong merged commit f8728d4 into main Jul 29, 2026
11 of 14 checks passed
@xinyi-gong
xinyi-gong deleted the fix/375-powershell-prompt-hang branch July 29, 2026 09:31
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.

[Bug] Chat hangs after running a terminal command in Agent mode

3 participants