fix: fall back to cmd.exe when PowerShell is unavailable on Windows#12034
Open
octo-patch wants to merge 2 commits intocontinuedev:mainfrom
Open
fix: fall back to cmd.exe when PowerShell is unavailable on Windows#12034octo-patch wants to merge 2 commits intocontinuedev:mainfrom
octo-patch wants to merge 2 commits intocontinuedev:mainfrom
Conversation
…er.push() When onDidChangeVisibleTextEditors fires, deleteChain() calls push() on the DocumentHistoryTracker for the previous request filepath. Because onDidOpenTextDocument is currently disabled (pending PR continuedev#8364 merge), documents are never pre-added via addDocument(), so push() always takes the fallback path and logs a console.error on every editor switch. The fallback in push() already handles this gracefully by calling addDocument(), making the error log misleading noise. Downgrade it to console.debug so it remains accessible for debugging without polluting the Extension Host output. Fixes continuedev#11919
continuedev#11960) On Windows environments where PowerShell is blocked by corporate security policy (e.g., AppLocker), run_terminal_command would fail with 'spawn UNKNOWN'. This change introduces a module-level flag that is set when PowerShell fails to spawn (UNKNOWN or ENOENT error code). Once set, getShellCommand() falls back to cmd.exe via COMSPEC for all subsequent calls in the session, allowing the tool to work without further user intervention after the first failure.
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/tools/implementations/runTerminalCommand.ts">
<violation number="1" location="core/tools/implementations/runTerminalCommand.ts:381">
P2: Sticky PowerShell fallback is triggered by broad error codes (`UNKNOWN`/`ENOENT`) instead of a PowerShell-specific spawn failure, so one misclassified error can permanently switch future Windows commands to `cmd.exe`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| // mark it unavailable so future calls fall back to cmd.exe automatically. | ||
| if ( | ||
| process.platform === "win32" && | ||
| (error.code === "UNKNOWN" || error.code === "ENOENT") |
Contributor
There was a problem hiding this comment.
P2: Sticky PowerShell fallback is triggered by broad error codes (UNKNOWN/ENOENT) instead of a PowerShell-specific spawn failure, so one misclassified error can permanently switch future Windows commands to cmd.exe.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/tools/implementations/runTerminalCommand.ts, line 381:
<comment>Sticky PowerShell fallback is triggered by broad error codes (`UNKNOWN`/`ENOENT`) instead of a PowerShell-specific spawn failure, so one misclassified error can permanently switch future Windows commands to `cmd.exe`.</comment>
<file context>
@@ -360,6 +374,15 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => {
+ // mark it unavailable so future calls fall back to cmd.exe automatically.
+ if (
+ process.platform === "win32" &&
+ (error.code === "UNKNOWN" || error.code === "ENOENT")
+ ) {
+ _powershellUnavailable = true;
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #11960
Problem
On Windows environments where PowerShell is blocked by corporate security policy (e.g., AppLocker),
run_terminal_commandfails immediately with:This happens because
getShellCommand()always returnspowershell.exeon Windows, even when PowerShell cannot be executed.Solution
Introduce a module-level flag
_powershellUnavailablethat is set totruewhen a PowerShell spawn fails with anUNKNOWNorENOENTerror code. Once set,getShellCommand()falls back tocmd.exe(viaCOMSPEC) for all subsequent invocations in the session.This approach:
Testing
cmd.exeand succeedSummary by cubic
Automatically fall back to
cmd.exewhen PowerShell can't start on Windows, sorun_terminal_commandkeeps working in restricted environments (fixes #11960). Also reduces a noisy error log in the document history tracker (addresses #11919).UNKNOWN/ENOENT), set a session flag, and route subsequent commands tocmd.exeviaCOMSPEC; no change for users where PowerShell works.console.errortoconsole.debugwhen a document isn’t in the tracker, avoiding noisy logs while still adding the document.Written for commit 26c16ad. Summary will update on new commits.