Skip to content

[release/17.0] Fix aspire agent init --non-interactive with multiple AppHosts - #22269

Merged
Jose Perez Rodriguez (joperezr) merged 2 commits into
release/17.0from
ellahathaway-fix-agent-init-noninteractive-apphost
Nov 16, 2026
Merged

Jose Perez Rodriguez (joperezr) merged 2 commits into
release/17.0from
ellahathaway-fix-agent-init-noninteractive-apphost

Conversation

@ellahathaway

Copy link
Copy Markdown
Contributor

Description

aspire agent init --non-interactive failed when the working directory contained more than one AppHost and no AppHost was saved in settings:

PS> aspire agent init --non-interactive
🤖 Detecting agent environments...
❌ An unexpected error occurred: This prompt requires interactive input but the CLI is running in non-interactive mode.
   This operation does not yet support non-interactive execution.

The failure came from AgentInitCommand.GetConfigurationDirectoryAsync, added in #21364. When the Aspire skill is selected (the default), agent init resolves a configuration directory so it can read skill-source settings. With two or more AppHost candidates it always prompted the user to pick one, and that prompt throws in non-interactive mode. Users could only work around it by running from a single AppHost folder or passing --skills none.

Agent init only reads optional settings from the selected AppHost and has no --apphost option, so the command now prompts only when interactive input is supported. In non-interactive mode with multiple candidates, it falls back to the working directory, which matches what it already does when no AppHost is found.

User-facing usage

From a folder that contains several AppHosts:

aspire agent init --non-interactive

This now completes successfully and uses the working directory's settings instead of failing.

Validation

  • Added AgentInit_NonInteractive_WithMultipleAppHosts_Succeeds. It uses the real non-interactive host and console interaction service, and it asserts success and that multi-AppHost discovery ran. With the fix temporarily removed, it fails with the same "requires interactive input" error shown above.
  • Updated AgentInit_UsesConfiguredOrSelectedAppHostSettings to use an interactive host, because the selection prompt now runs only in interactive mode.
  • dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj --no-launch-profile -- --filter-class "*.AgentInitCommandTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true": passed (77/77).

Fixes # (issue)

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
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

When no AppHost is saved in settings and several AppHosts exist under the
working directory, agent init prompted for a selection even in
non-interactive mode, which threw. Fall back to the working directory for
skill-source settings instead, matching the no-AppHost case.

Co-authored-by: Copilot App <[email protected]>
Assert success and multi-AppHost discovery instead of snapshotting generated config.

Co-authored-by: Copilot App <[email protected]>
@github-actions

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 -- 22269

Or

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

@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

2 / 101 PR test projects · 4 PR jobs, from 2 changed files.

Selected PR test projects (2 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

📦 affected project Aspire.Cli
→ 1 test: Aspire.Cli.EndToEnd.Tests

🧪 tests/Aspire.Cli.Tests/Commands/AgentInitCommandTests.cs (changed test)
→ 1 directly: Aspire.Cli.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Cli
extension-e2e • src/Aspire.Cli/Commands/AgentInitCommand.cs
• affected project Aspire.Cli
polyglot affected project Aspire.Cli
typescript-api-compat affected project Aspire.Cli

Selection computed for commit fcaf273.

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.

🟢 Approval recommended

No active review issues are reported for the fix restoring non-interactive initialization when multiple AppHosts are discovered.

No open issues 🎉

What changed in this PR

Fixes aspire agent init --non-interactive failing when multiple AppHosts are discovered, restoring unattended initialization after configurable skill sources introduced AppHost settings lookup.

Changes:

  • Prompts for AppHost selection only when interactive input is supported; otherwise uses the working directory’s settings.
  • Adds a regression test for non-interactive multi-AppHost initialization and updates the existing selection test to use an interactive host.
File Description
tests/​Aspire.Cli.Tests/​Commands/​AgentInitCommandTests.cs Adds non-interactive regression coverage and configures the selection test for interactive input.
src/​Aspire.Cli/​Commands/​AgentInitCommand.cs Guards AppHost selection prompts and falls back to the working directory without interactive input.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@joperezr
Jose Perez Rodriguez (joperezr) merged commit acb94c2 into release/17.0 Nov 16, 2026
642 of 650 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Nov 16, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

excluded → base_branch_is_release, title_release_prefix. Backport PR ([release/17.0] title, base release/17.0); docs belong to the original forward PR. Triggered signals (informational): cli_command_file_changed (AgentInitCommand.cs), pr_body_has_cli_flag_mention, pr_body_has_user_facing_section. It is also a bug fix for non-interactive mode.

@ellahathaway

Copy link
Copy Markdown
Contributor Author

/backport to main

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to main (link to workflow run)

Ella Hathaway (ellahathaway) added a commit that referenced this pull request Nov 16, 2026
Backport of #22269 to main

/cc @ellahathaway

## Customer Impact

## Testing

## Risk

## Regression?

---------

Co-authored-by: Ella Hathaway <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants