Skip to content

Preserve unresolved variables in process task command path (fixes #160891) - #316369

Merged
Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
RealThanhNguyxn:fix/160891-task-process-command-variable
Nov 4, 2026
Merged

Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
RealThanhNguyxn:fix/160891-task-process-command-variable

Conversation

@RealThanhNguyxn

Copy link
Copy Markdown
Contributor

Problem

A process-type task that uses a command-backed variable produces a corrupted executable path on Windows:

{
  "version": "2.0.0",
  "tasks": [{
    "label": "python: run",
    "type": "process",
    "command": "${command:python.interpreterPath}"
  }]
}

Running it currently fails with:

The terminal process failed to launch: Path to shell executable
"C:\projects\foo\C:\Python310\python.exe" does not exist.

The original report (#160891) already pinpointed the location: findExecutable is fed the literal ${command:python.interpreterPath} and falls back to path.join(cwd, command). The resulting concatenation later has the placeholder expanded inside it and the workspace path is left in front of the real interpreter path.

Root cause

Two code paths share the same "resolve, then findExecutable, otherwise prefix with cwd" logic and both run before the command/input variables can be expanded:

  • extHostTask.$resolveVariables (extension host, Node)
  • _resolveAndFindExecutable in terminalTaskSystem.ts (main thread on Windows)

Neither of these resolvers can expand ${command:...} or ${input:...} on its own — those variables require an interaction step that runs later in the pipeline. After that interaction step the task system performs a second pass over the __process__ variable when assembling the shell launch config (_createShellLaunchConfig calls _resolveVariable twice). It is at that point that command/input values are known and the path can be substituted correctly.

The fix is to recognize when the local resolve step left a ${...} placeholder behind and return the value as-is, instead of pushing it through findExecutable and the cwd-prefix fallback. The downstream resolve pass then produces the correct path.

Fix

src/vs/workbench/api/node/extHostTask.ts — $resolveVariables:

  • After resolver.resolveAsync runs over process.name, check for a remaining ${...} placeholder and, if found, return the unmodified processName so the task system can resolve it later.

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts — _resolveAndFindExecutable:

  • After IConfigurationResolverService.resolveAsync, the same placeholder check; return the value directly when unresolved variables remain.

Both changes are guarded by /\$\{.+?\}/.test(...) so behavior is unchanged for any command name that fully resolves in the local scope.

Why not resolve the command earlier?

Resolving ${command:...} happens on the main thread via IConfigurationResolverService.resolveWithInteraction. The extension host has no command service, and _resolveAndFindExecutable runs before that interaction. Reordering would need the wider pipeline rework discussed in the issue. The minimal, targeted fix here lets the existing later resolve step do its job by simply not corrupting the value first.

Testing

  • Verified both files have no diagnostics after the change.
  • The placeholder check is purely additive: when no ${...} remains the original branches (findExecutable → path.isAbsolute → path.join(cwd, ...)) are taken unchanged.

Fixes #160891

When a `process`-type task uses a variable that is only known to the
main thread (for example `${command:python.interpreterPath}`), the
variable cannot be expanded by either:

- the extension host's variable resolver in `extHostTask.$resolveVariables`,
  which has no command/input value mapping, or
- `_resolveAndFindExecutable` in `terminalTaskSystem`, which calls
  `IConfigurationResolverService.resolveAsync` without an interaction
  step.

Both code paths nevertheless treated the literal placeholder as a path,
fed it to `findExecutable`, and finally fell back to
`path.join(cwd, command)` when no executable was found. The resulting
string was a concatenation of the cwd and the unresolved placeholder
(for example `C:\\projects\\foo\\${command:python.interpreterPath}`).
A later resolution step then expanded the placeholder *inside* that
concatenation, producing a corrupted path such as
`C:\\projects\\foo\\C:\\Python310\\python.exe` and the user-facing
error:

```
The terminal process failed to launch: Path to shell executable
"C:\\projects\\foo\\C:\\Python310\\python.exe" does not exist.
```

Fix it by detecting an unresolved `${...}` placeholder after the local
resolve attempt and returning the value as-is. The task system already
runs another resolve pass over the resulting `__process__` variable
when constructing the shell launch config, which has access to the
fully resolved command/input values and produces the correct
executable path.

The change is symmetrical in the two places that share the
"resolve, find executable, otherwise prefix with cwd" pattern. No
behavior changes for command names that fully resolve in the local
scope.

Fixes microsoft#160891
Copilot AI review requested due to automatic review settings May 14, 2026 07:29

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 PR prevents process-type task command variables from being prematurely treated as executable paths, preserving unresolved ${...} placeholders so the later task variable resolution pass can substitute command/input values correctly.

Changes:

  • Skips executable lookup/cwd-prefixing in the extension host when a resolved process name still contains a placeholder.
  • Applies the same guard in the terminal task system’s Windows process executable resolution path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/vs/workbench/api/node/extHostTask.ts Preserves unresolved process command placeholders instead of passing them through executable lookup.
src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts Avoids corrupting unresolved process task command placeholders before later task resolution.

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix!

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.

🟡 Changes recommended

Windows process-task resolution can launch the default shell for empty commands or resolve the wrong executable due to cwd/PATH handling, and regression tests covering the final executable are missing.

4 open issues

Review effort: Max

Comment on lines +702 to +703
if (/\$\{.+?\}/.test(command)) {
return command;
Comment on lines +702 to +703
if (/\$\{.+?\}/.test(command)) {
return command;
Comment on lines +702 to +703
if (/\$\{.+?\}/.test(command)) {
return command;
Comment on lines +185 to 186
if (/\$\{.+?\}/.test(processName)) {
result.process = processName;
@meganrogge
Megan Rogge (meganrogge) merged commit 00735e5 into microsoft:main Nov 4, 2026
59 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 4, 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.

Incorrect Command Variable Resolution in tasks.json if task type is 'process'

6 participants