Skip to content

include debug extension host env in shell env (#241078)#298276

Merged
meganrogge merged 3 commits intomicrosoft:mainfrom
eliericha:richa/shell-env
Mar 2, 2026
Merged

include debug extension host env in shell env (#241078)#298276
meganrogge merged 3 commits intomicrosoft:mainfrom
eliericha:richa/shell-env

Conversation

@eliericha
Copy link
Contributor

This PR proposes a fix for #241078 .

With some investigation and some help from AI, I managed to produce this fix which includes adds the debug extension host environment to the terminal environment.

With that I was able to observe that environment variables added in the env property of a launch configuration or through an env file and the envFile, are correctly inherited into terminals spawned by the debugged instance.

More specifically, tasks now inherit the environment provided by the debug launch configuration.

Given my little experience with the codebase, I'm not sure this works in all configurations (web, electron, remote, etc) so guidance would be appreciated to steer this in the right direction.

Thanks!

Copilot AI review requested due to automatic review settings February 27, 2026 15:21
Copy link
Contributor

Copilot AI left a comment

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 fixes an issue where environment variables specified in an extension debug launch configuration (via env or envFile properties) are not inherited by terminals and tasks spawned within the Extension Development Host. The fix adds these debug environment variables to the shell environment used by terminals in the local terminal backend.

Changes:

  • Modified LocalTerminalBackend.getShellEnvironment() to merge debug extension host environment variables into the shell environment
  • Added INativeWorkbenchEnvironmentService dependency injection to access debug configuration environment

Copy link
Collaborator

@meganrogge meganrogge left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! The approach is directionally correct and consistent with how localProcessExtensionHost.ts already applies debugExtensionHost.env.

One issue that needs addressing:

Mutating a potentially shared object: mergeEnvironments mutates env in place. Since getShellEnv() delegates to process.shellEnv(), which may cache and return the same object reference, this mutation could leak debug env vars into other consumers of process.shellEnv(). Please clone first:

const env = { ...await this._shellEnvironmentService.getShellEnv() };

Minor note: this only covers the local (Electron) terminal backend — remote extension host debugging won't benefit. Not a blocker for this PR but worth tracking separately if needed.

@eliericha
Copy link
Contributor Author

Thanks for the feedback!

Mutating a potentially shared object: mergeEnvironments mutates env in place. Since getShellEnv() delegates to process.shellEnv(), which may cache and return the same object reference, this mutation could leak debug env vars into other consumers of process.shellEnv(). Please clone first:

Great catch, fixed.

Minor note: this only covers the local (Electron) terminal backend — remote extension host debugging won't benefit. Not a blocker for this PR but worth tracking separately if needed.

I would like to address that as well as I often do extension development in remote mode. But indeed let's leave it out of this PR.

@meganrogge meganrogge enabled auto-merge (squash) March 2, 2026 14:50
@meganrogge meganrogge merged commit b9b33d2 into microsoft:main Mar 2, 2026
18 checks passed
DonJayamanne pushed a commit that referenced this pull request Mar 2, 2026
* include debug extension host env in shell env (#241078)

* Use terminalEnvironment.mergeEnvironments for platform-specific considerations

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Clone the shell env to avoid mutation of a shared object

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

4 participants