Skip to content

Fix CLI Ctrl+C/SIGTERM shutdown: responsive cancellation and double-signal bug - #17588

Merged
David Fowler (davidfowl) merged 9 commits into
mainfrom
fix/cli-ctrlc-shutdown-17569
May 29, 2026
Merged

David Fowler (davidfowl) merged 9 commits into
mainfrom
fix/cli-ctrlc-shutdown-17569

Conversation

@JamesNK

@JamesNK James Newton-King (JamesNK) commented May 28, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes the CLI's Ctrl+C/SIGTERM handling to be responsive during all phases and prevents a double-signal bug that caused immediate force-kill instead of graceful shutdown.

Problems Fixed

  1. Sluggish Ctrl+C during AppHost startup: When a user pressed Ctrl+C during AppHost startup (before the AppHost connects back to the CLI), the CLI would wait for the full 5-second startup timeout before exiting.

  2. Double-signal bug causing force-kill: Both PosixSignalRegistration(SIGINT) and Console.CancelKeyPress were registered simultaneously. On Linux, when SIGINT arrives both handlers fire for the same signal, each calling Cancel(), so _cancelCalled reaches 2 immediately — triggering the force-kill path instead of graceful shutdown.

  3. No way to force-exit: If graceful shutdown was taking too long, there was no mechanism for a second Ctrl+C to force immediate termination.

Changes

src/Aspire.Cli/ConsoleCancellationManager.cs (new file in this PR):

  • Central signal handler managing Ctrl+C, SIGINT, SIGTERM, and SIGQUIT with a shared CancellationTokenSource
  • First signal requests cooperative cancellation with a configurable timeout
  • Second signal forces immediate termination via ProcessTerminationCompletionSource
  • Fix: Console.CancelKeyPress is now only registered on platforms without PosixSignalRegistration (Android, iOS, tvOS, Browser) — eliminates the double-signal bug
  • Added SIGQUIT registration for Windows Ctrl+Break parity
  • Supports SetLogger() for diagnostic observability and SetStartedHandler() for timeout tracking

src/Aspire.Cli/Program.cs:

  • Creates ConsoleCancellationManager early in startup and wires it through the command pipeline
  • Uses Task.WhenAny(handlerTask, processTerminationCompletionSource.Task) so forced termination is observed immediately

src/Aspire.Cli/Commands/RunCommand.cs:

  • CancelAppHostStartupAsync now receives the cancellation token and passes it to WaitAsync, so the startup-timeout wait exits immediately on Ctrl+C

tests/Aspire.Cli.Tests/ConsoleCancellationManagerTests.cs (new):

  • Unit tests for single-signal cooperative cancellation, double-signal force termination, and timeout behavior

tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs:

  • Tests verifying Ctrl+C during AppHost startup cancels immediately

tests/Shared/Hex1bAutomatorTestHelpers.cs:

  • Removed old WaitForSuccessPromptAsync (which would hang on errors instead of failing fast)
  • Renamed WaitForSuccessPromptFailFastAsync → WaitForSuccessPromptAsync (now the only variant, always fails fast on ERR prompts)
  • Removed duplicate RunCommandFailFastAsync (was identical to RunCommandAsync)

E2E test files (59 files):

  • Updated all call sites from WaitForSuccessPromptFailFastAsync → WaitForSuccessPromptAsync
  • Updated all call sites from RunCommandFailFastAsync → RunCommandAsync

Fixes #17569

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

@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

🚀 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 -- 17588

Or

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

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

Improves Aspire CLI termination responsiveness when users press Ctrl+C during run/AppHost startup, aiming to avoid multi-second waits and provide a “second signal” forced termination path.

Changes:

  • Refactors ConsoleCancellationManager so the first signal triggers non-blocking cancellation and schedules forced termination asynchronously; subsequent signals trigger immediate forced-termination signaling.
  • Threads the command cancellation token into RunCommand.CancelAppHostStartupAsync so its startup-cancellation wait exits promptly on Ctrl+C.
  • Adds unit coverage for the cancellation manager behavior and a regression test ensuring run exits promptly when cancelled during the startup-timeout cancellation path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/ConsoleCancellationManagerTests.cs Adds tests for first/second signal behavior, async timeout forcing, and non-blocking cancel.
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Adds regression test to ensure Ctrl+C cancels out of the startup-cancellation timeout promptly.
src/Aspire.Cli/Program.cs Wires a logger into cancellation handling for diagnostics.
src/Aspire.Cli/ConsoleCancellationManager.cs Makes signal handling non-blocking; adds async forced-termination timeout and second-signal behavior; adds logging hook.
src/Aspire.Cli/Commands/RunCommand.cs Passes the command cancellation token through to WaitAsync during startup cancellation.

Comment thread src/Aspire.Cli/Program.cs Resolved
Comment thread src/Aspire.Cli/Program.cs Resolved
@JamesNK James Newton-King (JamesNK) changed the title Fix CLI Ctrl+C shutdown taking too long during AppHost startup Fix CLI Ctrl+C/SIGTERM shutdown: responsive cancellation and double-signal bug May 28, 2026
@JamesNK James Newton-King (JamesNK) added this to the 13.4 milestone May 28, 2026
@JamesNK

Copy link
Copy Markdown
Member Author

PR Testing Report

PR Information

CLI Version Verification

  • Installed Version: 13.5.0-dev (local debug build from PR branch)
  • Status: ✅ Verified (CI native artifact still building; used local build from checked-out PR branch)

Test Scenarios Executed

Scenario 1: Normal Start and Stop

Objective: Verify basic aspire start / aspire stop lifecycle works correctly with the refactored signal handler
Status: ✅ Passed

Steps:

  1. Created new Aspire starter project (aspire new aspire-starter)
  2. Ran aspire start --apphost <path>
  3. Verified AppHost started successfully with dashboard URL
  4. Ran aspire stop --apphost <path>
  5. Verified clean shutdown

Observations:

  • AppHost started and reported dashboard URL normally
  • Stop command sent signal and confirmed successful shutdown
  • No regressions in the normal (non-signal) path

Scenario 2: ConsoleCancellationManager Unit Tests

Objective: Verify all signal handling logic — first signal cooperative cancellation, second signal force-kill, timeout behavior
Status: ✅ Passed (10/10 tests)

Tests executed:

  • FirstSignal_RequestsCancellation
  • FirstSignal_TokenIsCancelled
  • SecondSignal_ForcesImmediateTermination
  • FirstSignal_WithNoHandler_ForcesTerminationAfterTimeout
  • FirstSignal_HandlerCompletesWithinTimeout_DoesNotForceTermination
  • FirstSignal_HandlerExceedsTimeout_ForcesTermination
  • Cancel_IsNonBlocking
  • MultipleSignals_OnlyFirstAndSecondHaveEffect
  • Dispose_AllowsSubsequentCancelWithoutException
  • Token_RemainsAccessibleAfterDispose

Scenario 3: Ctrl+C During Startup Timeout

Objective: Verify that when Ctrl+C fires during AppHost startup, the CLI exits promptly rather than blocking for the full 5-second CancelAppHostStartupAsync timeout
Status: ✅ Passed

Test: RunCommand_WhenCancelledDuringStartupTimeout_ExitsWithoutWaitingForFullTimeout

Observations:

  • Confirms the cancellationToken plumbing to WaitAsync exits immediately on cancellation
  • Without the fix, this would block for the full 5-second timeout

Scenario 4: Startup Timeout Regression Tests

Objective: Ensure existing startup timeout behavior is preserved
Status: ✅ Passed (2/2 tests)

Tests executed:

  • RunCommand_WhenAppHostStartupTimesOut_DisplaysTimeoutGuidance
  • RunCommand_StartupTimeoutBudgetIncludesBuildAndBackchannelWaits

Summary

Scenario Status Notes
Normal start/stop ✅ Passed No regressions
ConsoleCancellationManager (10 tests) ✅ Passed All signal logic verified
Ctrl+C during startup ✅ Passed Prompt exit confirmed
Startup timeout regression ✅ Passed Existing behavior preserved

Overall Result

✅ PR VERIFIED — All 13 targeted tests pass. The normal start/stop lifecycle works correctly. Signal handling changes are well-covered by unit tests that directly exercise the Cancel() method and verify timing constraints.

@davidfowl

David Fowler (davidfowl) commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Tried this, still takes forever (5 seconds is forever):

Screen.Recording.2026-05-28.104823.mp4

It also feels like forever because there's no feedback.

@alexTr3

Alexandre Trepanier (alexTr3) commented May 28, 2026 •

Copy link
Copy Markdown

David Fowler (@davidfowl)
With this will we be able to trigger a ResourceKnownCommand stop(graceful, sigterm) and kill(ungraceful) on any resources when testing??

@davidfowl

Copy link
Copy Markdown
Collaborator

This is purely for the CLI itself, nothing to do with graceful shutdown of resources, which happens when you stop a resource from the dashboard or cli, but isn't graceful in the debugger in VS.

@alexTr3

Copy link
Copy Markdown

This is purely for the CLI itself, nothing to do with graceful shutdown of resources, which happens when you stop a resource from the dashboard or cli, but isn't graceful in the debugger in VS.

but it should be supported... We should be able to trigger a stop cmd that would send a sigterm to a resource when testing our distributed app..

You should at least rename KnownRessourcesCommand to Kill instead of Stop.. since this is what you truly are doing.. killing the process

@davidfowl

Copy link
Copy Markdown
Collaborator

but it should be supported... We should be able to trigger a stop cmd that would send a sigterm to a resource when testing our distributed app..

aspire resource stop.

Lets not use this pr to discuss feature requests though

@adamint

Copy link
Copy Markdown
Member

Will this fix #17625?

- Make ConsoleCancellationManager.Cancel() non-blocking so Ctrl+C handler
  returns immediately
- Pass cancellation token through to WaitAsync in CancelAppHostStartupAsync
  so Ctrl+C exits promptly instead of waiting for the full 5s timeout
- Support second Ctrl+C for immediate force exit (Environment.Exit)
- Add logging support to ConsoleCancellationManager via SetLogger()
- Add comprehensive unit tests for ConsoleCancellationManager
- Add integration test for RunCommand cancellation during startup timeout

Fixes #17569
Replace WaitForSuccessPromptAsync with WaitForSuccessPromptFailFastAsync
across all CLI E2E tests. The fail-fast variant detects error prompts
immediately and throws instead of hanging for up to 500s waiting for a
success prompt that will never arrive. This prevents 10+ minute CI
timeouts when a command fails with a non-zero exit code.
- Fix ConsoleCancellationManager double-signal bug: move Console.CancelKeyPress
  to else branch so it only registers on platforms without PosixSignalRegistration.
  Previously both handlers fired for the same SIGINT, causing immediate force-kill.
- Add SIGQUIT/Ctrl+Break registration for Windows parity.
- Remove old WaitForSuccessPromptAsync (no fail-fast) and rename
  WaitForSuccessPromptFailFastAsync to WaitForSuccessPromptAsync.
- Remove duplicate RunCommandFailFastAsync (identical to RunCommandAsync).
@microsoft-github-policy-service microsoft-github-policy-service Bot modified the milestones: 13.4, 13.5 May 29, 2026
@JamesNK

Copy link
Copy Markdown
Member Author

/backport to release/13.4

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/13.4 (link to workflow run)

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

James Newton-King (@JamesNK) backporting to release/13.4 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix CLI Ctrl+C shutdown taking too long during AppHost startup
Applying: Fix review comments: volatile logger, accurate comments, clearer warning
Applying: Clean up
Applying: Use WaitForSuccessPromptFailFastAsync in CLI E2E tests
Using index info to reconstruct a base tree...
M	tests/Aspire.Cli.EndToEnd.Tests/AgentCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/AgentMcpLogsTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/BannerTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/CentralPackageManagementTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/CertificatesCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ChannelUpdateWorkflowTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ConfigHealingTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ConfigMigrationTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DashboardRunTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DescribeCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DockerDeploymentTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DocsCommandE2ETests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DoctorCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/DotnetToolSmokeTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/EmptyAppHostTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2EAutomatorHelpers.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JavaCodegenValidationTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JavaEmptyAppHostTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotApphostDirectoryTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JavaScriptPublishTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/JsReactTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/KubernetesDeployTypeScriptTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/KubernetesDeployWithHelmChartTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishRequiresExternalEndpointTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ListStepsTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/LocalConfigMigrationTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/LogLevelTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/LogsCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/MultipleAppHostTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/NewWithAgentInitTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/OtelLogsTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/PlaywrightCliInstallTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/PodmanDeploymentTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ProjectReferenceTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/PsCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/PythonReactTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/ResourceCommandTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/SecretDotNetAppHostTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/SecretTypeScriptAppHostTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/SmokeTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/StagingChannelTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/StartStopTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/StopNonInteractiveTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptCodegenValidationTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptEmptyAppHostTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptLegacyAppHostTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotApphostDirectoryTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPublishTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptReusablePackageTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptSqlServerNativeAssetsBundleTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptStarterSmokeTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/TypeScriptStarterTemplateTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/UpdateChannelNuGetConfigOrderingTests.cs
M	tests/Aspire.Cli.EndToEnd.Tests/WaitCommandTests.cs
Falling back to patching base and 3-way merge...
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/AgentCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/AgentCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/AgentMcpLogsTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/BannerTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/BannerTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/CentralPackageManagementTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/CentralPackageManagementTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/CertificatesCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/CertificatesCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ChannelUpdateWorkflowTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ConfigHealingTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ConfigMigrationTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/ConfigMigrationTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DashboardRunTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/DashboardRunTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DescribeCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/DescribeCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DockerDeploymentTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DocsCommandE2ETests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/DocsCommandE2ETests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DoctorCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/DoctorCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/DotnetToolSmokeTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/DotnetToolSmokeTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/EmptyAppHostTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/Helpers/CliE2EAutomatorHelpers.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JavaCodegenValidationTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JavaEmptyAppHostTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotApphostDirectoryTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotApphostDirectoryTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/JavaPolyglotTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JavaScriptPublishTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/JavaScriptPublishTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/JsReactTemplateTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/JsReactTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/KubernetesDeployTypeScriptTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/KubernetesDeployWithHelmChartTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishRequiresExternalEndpointTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishRequiresExternalEndpointTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/KubernetesPublishTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ListStepsTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/LocalConfigMigrationTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/LogLevelTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/LogLevelTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/LogsCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/LogsCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/MultipleAppHostTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/MultipleAppHostTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/NewWithAgentInitTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/NewWithAgentInitTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/OtelLogsTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/PlaywrightCliInstallTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/PlaywrightCliInstallTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/PodmanDeploymentTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ProjectReferenceTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/ProjectReferenceTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/PsCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/PsCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/PythonReactTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/ResourceCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/ResourceCommandTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/SecretDotNetAppHostTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/SecretDotNetAppHostTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/SecretTypeScriptAppHostTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/SecretTypeScriptAppHostTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/SmokeTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/SmokeTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/StagingChannelTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/StagingChannelTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/StartStopTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/StartStopTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/StopNonInteractiveTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/StopNonInteractiveTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptCodegenValidationTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptEmptyAppHostTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptLegacyAppHostTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotApphostDirectoryTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotApphostDirectoryTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPolyglotTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPublishTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/TypeScriptPublishTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptReusablePackageTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptSqlServerNativeAssetsBundleTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptStarterSmokeTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/TypeScriptStarterTemplateTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/UpdateChannelNuGetConfigOrderingTests.cs
Auto-merging tests/Aspire.Cli.EndToEnd.Tests/WaitCommandTests.cs
CONFLICT (content): Merge conflict in tests/Aspire.Cli.EndToEnd.Tests/WaitCommandTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0004 Use WaitForSuccessPromptFailFastAsync in CLI E2E tests
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

aspire-repo-bot Bot added a commit to microsoft/aspire.dev that referenced this pull request May 29, 2026
- Add 'Stopping the AppHost' section explaining graceful shutdown
- Document that a second Ctrl+C forces immediate termination
- Note that Ctrl+C during startup cancels immediately

Documents changes from microsoft/aspire#17588

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #1119

Generated by PR Documentation Check

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#1119 targeting release/13.4.

Added a new Stopping the AppHost section to aspire-run.mdx documenting the improved Ctrl+C/SIGTERM shutdown behavior: graceful shutdown on first signal, force-termination on second signal, and immediate cancellation during startup.

  • src/frontend/src/content/docs/reference/cli/commands/aspire-run.mdx — updated

Note

This draft PR needs human review before merging.

David Pine (IEvangelist) added a commit that referenced this pull request May 29, 2026
…romptAsync rename

Per davidfowl's review: we own the Aspire skills bundle and write its
contents, so the defense-in-depth ValidateSkillName check is modelling the
wrong threat. Drop the validator, its helpers, the reserved-device list,
the now-unused System.Text using, and the unit tests that exercised it.

Also rename the AgentCommandTests call site of WaitForSuccessPromptFailFastAsync
to WaitForSuccessPromptAsync to match the consolidated helper that landed
on main in #17588 (the FailFast variant was folded back into the canonical
WaitForSuccessPromptAsync).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
David Fowler (davidfowl) pushed a commit that referenced this pull request May 29, 2026
* Add TerminalRun IAsyncDisposable for consistent CLI E2E diagnostics capture (#17576)

* Fix CLI Ctrl+C/SIGTERM shutdown: responsive cancellation and double-signal bug (#17588)

* Fix CLI Ctrl+C shutdown taking too long during AppHost startup

- Make ConsoleCancellationManager.Cancel() non-blocking so Ctrl+C handler
  returns immediately
- Pass cancellation token through to WaitAsync in CancelAppHostStartupAsync
  so Ctrl+C exits promptly instead of waiting for the full 5s timeout
- Support second Ctrl+C for immediate force exit (Environment.Exit)
- Add logging support to ConsoleCancellationManager via SetLogger()
- Add comprehensive unit tests for ConsoleCancellationManager
- Add integration test for RunCommand cancellation during startup timeout

Fixes #17569

* Fix review comments: volatile logger, accurate comments, clearer warning

* Clean up

* Use WaitForSuccessPromptFailFastAsync in CLI E2E tests

Replace WaitForSuccessPromptAsync with WaitForSuccessPromptFailFastAsync
across all CLI E2E tests. The fail-fast variant detects error prompts
immediately and throws instead of hanging for up to 500s waiting for a
success prompt that will never arrive. This prevents 10+ minute CI
timeouts when a command fails with a non-zero exit code.

* Fix double-signal bug and consolidate test helpers

- Fix ConsoleCancellationManager double-signal bug: move Console.CancelKeyPress
  to else branch so it only registers on platforms without PosixSignalRegistration.
  Previously both handlers fired for the same SIGINT, causing immediate force-kill.
- Add SIGQUIT/Ctrl+Break registration for Windows parity.
- Remove old WaitForSuccessPromptAsync (no fail-fast) and rename
  WaitForSuccessPromptFailFastAsync to WaitForSuccessPromptAsync.
- Remove duplicate RunCommandFailFastAsync (identical to RunCommandAsync).

* Fix stale comment and restrict SIGQUIT to Windows only

* Remove unused legacy builder methods and update E2E skill docs

* Don't force when debugging

* More logging
David Pine (IEvangelist) added a commit that referenced this pull request May 29, 2026
* Load Aspire skills catalog from bundle manifest

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

* Address Aspire skill catalog review feedback

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

* Harden dynamic Aspire skill catalog

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

* Trim bundle skill descriptions, sort alphabetically, silence bundle-unavailable warning

- Extract just the first sentence (after stripping the leading bold `**TYPE SKILL**` tag) for bundle skill descriptions shown in the agent init selection prompt so the list stays readable.

- Sort the merged skill catalog deterministically by name (OrdinalIgnoreCase) so prompt ordering is stable regardless of manifest order.

- When the Aspire skills bundle is unavailable (network failure, version mismatch, etc.), silently fall back to the CLI-defined skills instead of surfacing a user-visible warning. The installer already logs the underlying cause at debug, and the equivalent `LogWarning` paths on the corrupt-bundle catch blocks are demoted to `LogDebug` to match.

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

* Trust embedded and cached Aspire skills bundles regardless of supports range

The embedded Aspire skills bundle ships inside the CLI binary as the
trusted last-resort fallback, and the on-disk cache is populated by this
installer itself. Both sources are gated by bundle version (the cache
directory is version-keyed), so the bundle manifest's supports range
should only gate fresh downloads from GitHub.

Previously, a prerelease CLI build whose version fell outside the
embedded snapshot's stamped range (e.g., a 13.5.x dogfood build paired
with a snapshot supporting '>=13.4.0 <13.5.0') would reject the embedded
bundle on every offline invocation, leaving the user with only the
CLI-defined PlaywrightCli and DotnetInspect skills.

Add a skipCompatibilityCheck parameter to AspireSkillsBundle.LoadAsync,
plumb it through CacheArchiveAsync, and apply it to the embedded install
and cache-load paths. The GitHub-download path keeps strict validation
because we don't otherwise know what we're getting.

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

* Replace AgentInitSkillDefaultMode enum with predicate + add coverage

The default-skill selection in agent init was driven by a two-value enum
(AgentInitSkillDefaultMode) whose IncludeAspireify member named a specific
skill. That locks the design into a named set: every time a caller needs a
different default-selection rule, the enum has to grow another member.

Replace the enum with an optional Func<SkillDefinition, bool>? predicate
parameter on AgentInitCommand.PromptAndChainAsync. Semantics:

- null  -> trust the bundle author's SkillDefinition.IsDefault as-is
          (what 'aspire init' wants so aspireify chains into the flow)
- non-null -> caller decides which skills are pre-selected

The 'aspireify is one-time wiring' decision moves to the two call sites
that need it ('aspire new' and standalone 'aspire agent init') via an
internal AgentInitCommand.ExcludeAspireifyFromDefaults helper method.
No new enum values are needed when future contexts emerge.

Drops the dead IsDefaultSkill helper and the enum type. No user-visible
behavior change beyond what the predicate expresses.

Tests:
- Rename PromptAndChainAsync_WithIncludeAspireifyDefault_SelectsAspireify
  to PromptAndChainAsync_WithoutPredicateOverride_PreSelectsBundleDefaultsIncludingAspireify
  to match the new contract (no override = trust bundle's IsDefault).
- Add PromptAndChainAsync_WithExcludeAspireifyPredicate_DoesNotPreSelectAspireify
  to lock in the predicate-based override path.
- Add AgentInitCommand_NonInteractive_WithAllBundleSkillNames_InstallsEverySkillSurfacedByBundle
  as a regression guard: passing every bundle skill name to --skills must
  materialize all six SKILL.md files (aspire-init, aspire-monitoring,
  aspire-orchestration were invisible before this PR).
- Add AgentInitCommand_NonInteractive_WithExplicitBundleSkillName_InstallsBundleSkill
  proving bundle-only names are selectable via --skills now that the
  catalog comes from the manifest.
- Extend the Hex1b cache fixture to seed all six bundle skills and add
  AgentInitCommand_NonInteractive_WithAllSkills_InstallsEverySkillSurfacedByBundle
  as a full-stack regression guard against the original report.

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

* Make catalog tests resilient to future bundle skill additions

Adding a skill to the bundle (or to the test fixture) no longer requires
mirroring the change in test assertions:

- Integration test now derives the skill list from the bundle's manifest
  via IAspireSkillsInstaller, so --skills and the install assertions are
  data-driven against whatever the fake produces.
- Hex1b regression test now narrows to the bundle-only skill names
  (aspire-init/-monitoring/-orchestration) that the original bug hid.
  Future bundle additions don't widen this scope; the test stays a
  focused snapshot of the original regression.

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

* Gate Aspire skills remote fetch behind aspireSkillsRemoteFetchEnabled feature

13.4 ships with the GitHub bundle fetch path disabled; users get the embedded snapshot only. Setting features:aspireSkillsRemoteFetchEnabled to true re-enables the GitHub release acquisition and sigstore provenance verification path. The cache lookup and embedded fallback are unaffected, so cached bundles still load without network access.

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

* Address self-review observations on bundle skill catalog

- Fix 1: SimplifyDescription only strips leading -/: when a **TYPE** prefix was actually trimmed; preserves descriptions like `-Quickly do X.` and `:memo notes`.
- Fix 2: ValidateSkillName adds explicit char.IsControl() check so U+0001..U+001F / U+0085 are rejected on Linux/macOS where Path.GetInvalidFileNameChars only returns { 0, / }.
- Fix 3: rename ExcludeAspireifyFromDefaults -> ExcludeOneTimeSetupSkillsFromDefaults backed by a single OneTimeSetupSkillNames set so future bundle bootstrap skills do not silently start auto-selecting.
- Fix 4: ResolveAvailableSkillsAsync now returns the bundle install failure message and AgentInitCommand surfaces it before MatchChoicesOrThrow when --skills names a non-CLI skill the bundle was expected to provide.
- Fix 5: ValidateSkillName also rejects empty strings, NFC-incorrect names, and Windows reserved device names (CON, PRN, AUX, NUL, COM1-9, LPT1-9 with or without extension) to match the PR description.
- Comment 5.1: ThrowNonInteractiveInvalidValue strips Spectre markup from each formatted choice so [[bold]]/[[dim]] tokens do not leak verbatim.
- Comment 5.2: PromptForSelectionsAsync gains an optional bindingChoices parameter; the MCP applicator (UX-only prompt item) is now excluded from --skills non-interactive validation.

Adds regression tests for the SimplifyDescription edge case and a parameterized rejection theory covering control chars, NFC, and Windows reserved names.

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

* Add regression tests for --skills rejection message

Adds two ConsoleInteractionService tests covering the rejection-message behaviors flagged by the PR testing report:

- OmitsItemsOutsideBindingChoices: items present in the visible multi-select prompt but excluded from bindingChoices (e.g. the MCP applicator entry) must not appear in the non-interactive Available values list.

- StripsSpectreMarkupFromChoiceLabels: [bold]/[dim] tokens from choice formatters used by the interactive prompt must be stripped before the plain-text rejection message is printed.

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

* Remove bundle skill-name validation and follow main's WaitForSuccessPromptAsync rename

Per davidfowl's review: we own the Aspire skills bundle and write its
contents, so the defense-in-depth ValidateSkillName check is modelling the
wrong threat. Drop the validator, its helpers, the reserved-device list,
the now-unused System.Text using, and the unit tests that exercised it.

Also rename the AgentCommandTests call site of WaitForSuccessPromptFailFastAsync
to WaitForSuccessPromptAsync to match the consolidated helper that landed
on main in #17588 (the FailFast variant was folded back into the canonical
WaitForSuccessPromptAsync).

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

* Default all bundle skills to on in install prompt

Bundle-sourced skills (aspire, aspireify, aspire-deployment, aspire-init,
aspire-monitoring, aspire-orchestration) are now uniformly pre-selected in
the agent-init install prompt instead of respecting per-skill IsDefault
from the manifest. The CLI is the source of truth for the installable
catalog; bundle authors no longer opt in per skill via the manifest.
ExcludeOneTimeSetupSkillsFromDefaults continues to strip aspireify from
'aspire new' and standalone 'aspire agent init' flows.

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

* Mark AspireSkillsRemoteFetchEnabled feature flag as preview

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

---------

Co-authored-by: IEvangelist <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adam Ratzman (adamint) added a commit to adamint/aspire that referenced this pull request May 29, 2026
Pulls in microsoft#17701 (Fix TypeScript deadlock repro E2E test) so PR
GitHub Actions can complete. Main has been broken for PR events
since microsoft#17575 added a test calling RunCommandFailFastAsync which
microsoft#17588 renamed to RunCommandAsync. microsoft#17701 updates the call sites.

No infra changes from this branch are affected by this merge.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI Ctrl+C shutdown can take too long during AppHost startup

6 participants