Skip to content

fix(cli): prevent PowerShell command hangs and fix non-zero exit code rejection - #13274

Open
maoxin1234 wants to merge 1 commit into
continuedev:mainfrom
maoxin1234:fix/terminal-command-windows-timeout
Open

maoxin1234 wants to merge 1 commit into
continuedev:mainfrom
maoxin1234:fix/terminal-command-windows-timeout

Conversation

@maoxin1234

Copy link
Copy Markdown

Summary

Resolves #13273.

In extensions/cli, the runTerminalCommand test "should handle non-existent commands" was intermittently hanging on windows-latest until vitest's 30s timeout.

Root Causes & Fixes:

  1. PowerShell execution flags & stdin pipe:

    • On Windows, powershell.exe was invoked without -NoProfile and -NonInteractive. On CI runners, profile loading or commands that trigger interactive prompts could cause PowerShell to block indefinitely waiting for user input.
    • The spawned child process left stdin open as a pipe. Non-interactive CLI terminal commands never send stdin, so any subprocess waiting for EOF on standard input would hang.
    • Fix: Added -NoProfile and -NonInteractive to PowerShell arguments (both in extensions/cli and core), and immediately called child.stdin?.end().
  2. Rejection condition on non-zero exit code:

    • child.on("close") previously only rejected if code !== 0 && stderr. If a non-zero exit code was returned with an empty stderr (e.g. error message written to stdout or buffered/empty), the tool unexpectedly resolved the promise instead of rejecting it.
    • Fix: Always reject when code !== 0 && code !== null, using stderr || stdout || "Command failed" as the error message.
  3. Test timeout configuration:

    • TIMEOUT_MS was defaulting to 180s even during tests unless TEST_TERMINAL_TIMEOUT was set, which was higher than vitest's 30s testTimeout.
    • Fix: Configured TEST_TERMINAL_TIMEOUT = "15000" in vitest.setup.ts and provided a 15s fallback when NODE_ENV === "test" so tool timeouts always fire before the test runner timeout.

Verification

  • npx vitest run src/tools/runTerminalCommand.test.ts (9/9 passed, including new test for non-zero exit code with empty stderr)
  • npm run typecheck (0 errors)
  • npm run lint (0 errors)

@maoxin1234
maoxin1234 requested a review from a team as a code owner September 14, 2026 01:51
@maoxin1234
maoxin1234 requested review from sestinj and removed request for a team September 14, 2026 01:51
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.

CLI: runTerminalCommand "should handle non-existent commands" intermittently hangs to vitest's 30s timeout on windows-latest

1 participant