Skip to content

Fix aspire start failing in VS Code integrated terminal#15980

Merged
adamint merged 5 commits intomicrosoft:mainfrom
adamint:fix/aspire-start-extension-env-vars
Apr 9, 2026
Merged

Fix aspire start failing in VS Code integrated terminal#15980
adamint merged 5 commits intomicrosoft:mainfrom
adamint:fix/aspire-start-extension-env-vars

Conversation

@adamint
Copy link
Copy Markdown
Member

@adamint adamint commented Apr 8, 2026

Description

When aspire start runs from the VS Code Aspire terminal, the detached child process (aspire run --non-interactive) inherits ASPIRE_EXTENSION_* environment variables from the terminal. This causes the child to detect extension mode and delegate back to the extension via StartDebugSessionAsync instead of launching the AppHost — resulting in an immediate exit with code 0.

Root cause: DetachedProcessLauncher.Start() inherits all parent environment variables, including extension backchannel vars. The child's RunCommand.ExecuteAsync sees IsExtensionHost=true and ExtensionDebugSessionId=empty, triggering the early-return delegation path.

Fix (two layers):

  1. Strip extension env vars from the detached child processDetachedProcessLauncher.Start() now accepts an optional set of env var names to remove. On Unix, vars are removed from ProcessStartInfo.Environment. On Windows, a filtered Unicode environment block is built for CreateProcessW.
  2. Guard RunCommand delegation with --non-interactive — When running in non-interactive mode (as the child of aspire start), skip the StartDebugSessionAsync early return.

Additional fixes:

  • StartCommand now sets isExtensionHost=false so the Dashboard URL always appears in aspire start output
  • RenderAppHostSummary column width calculation only includes labels that are actually displayed
  • Added missing KnownConfigNames constants for 6 extension-related env vars (ExtensionDebugRunMode, ExtensionCapabilities, DebugSessionPort, DebugSessionToken, DebugSessionServerCertificate, DcpInstanceIdPrefix)

Fixes #15786

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

When 'aspire start' runs from the VS Code Aspire terminal, the detached
child process inherits ASPIRE_EXTENSION_* environment variables, causing
it to detect extension mode and delegate back to the extension via
StartDebugSessionAsync instead of launching the AppHost. This results in
an immediate exit with code 0.

Fix:
- Strip extension-related env vars from the detached child process in
  DetachedProcessLauncher (Unix: remove from startInfo.Environment,
  Windows: build filtered environment block for CreateProcessW)
- Add --non-interactive guard in RunCommand to skip extension delegation
  when running as a child of 'aspire start'
- Set isExtensionHost=false in StartCommand so Dashboard URL always
  shows in 'aspire start' output
- Fix column width calculation in RenderAppHostSummary to only include
  labels that are actually displayed
- Add missing KnownConfigNames constants for extension env vars

Fixes microsoft#15786
Copy link
Copy Markdown
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

Fixes aspire start prematurely exiting when run from the VS Code integrated Aspire terminal by preventing the detached child (aspire run --non-interactive) from being treated as an extension-hosted invocation.

Changes:

  • Adds support in DetachedProcessLauncher to remove specified environment variables from the detached child process (Unix via ProcessStartInfo.Environment, Windows via a filtered Unicode environment block passed to CreateProcessW).
  • Updates RunCommand to skip VS Code extension delegation when --non-interactive is used, and adjusts summary column-width calculation to consider only displayed labels.
  • Adds missing extension/debug-session env var constants and a unit test covering the --non-interactive delegation guard.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Adds a regression test ensuring --non-interactive skips extension debug-session delegation.
src/Shared/KnownConfigNames.cs Adds missing constants for extension/debug-session related environment variables.
src/Aspire.Cli/Processes/DetachedProcessLauncher.cs Extends detached process start API with optional env-var removal set.
src/Aspire.Cli/Processes/DetachedProcessLauncher.Unix.cs Removes specified env vars from detached child process environment on Unix.
src/Aspire.Cli/Processes/DetachedProcessLauncher.Windows.cs Builds and passes a filtered Unicode environment block to CreateProcessW when env-var removal is requested.
src/Aspire.Cli/Commands/StartCommand.cs Forces isExtensionHost=false so dashboard URLs are shown even in VS Code terminal.
src/Aspire.Cli/Commands/RunCommand.cs Guards extension delegation with --non-interactive; fixes summary width calculation based on shown labels.
src/Aspire.Cli/Commands/AppHostLauncher.cs Uses env-var removal when spawning the detached aspire run --non-interactive child.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15980

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15980"

Preserve DEBUG_SESSION_* values when the detached child CLI is launched from the VS Code Aspire terminal so the AppHost keeps IDE execution and dashboard debug integration. Also address follow-up review issues in StartCommand and the Windows filtered environment block builder.

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

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Re-running the failed jobs in the CI workflow for this pull request because 1 job was identified as retry-safe transient failures in the CI run attempt.
GitHub was asked to rerun all failed jobs for that attempt, and the rerun is being tracked in the rerun attempt.
The job links below point to the failed attempt jobs that matched the retry-safe transient failure rules.

Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

2 comments: 1 actionable issue (unused using), 1 informational note (double-null termination is correct as-is).

@adamint adamint requested a review from JamesNK April 9, 2026 06:18
@adamint adamint merged commit 5edd15f into microsoft:main Apr 9, 2026
524 of 527 checks passed
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.

aspire start fails in VS Code integrated terminal — apphost exits immediately with code 0

3 participants