Skip to content

Persist stable AppHost ports and add worktree isolation - #21013

Merged
David Negstad (danegsta) merged 11 commits into
mainfrom
danegsta-investigate-apphost-20653
Nov 9, 2026
Merged

David Negstad (danegsta) merged 11 commits into
mainfrom
danegsta-investigate-apphost-20653

Conversation

@danegsta

Copy link
Copy Markdown
Member

Description

Generated public ports are currently stable only in a few special cases, which means endpoint addresses can change across AppHost restarts and linked Git worktrees require explicit isolation. This change introduces a consistent persistent port model for both C# and polyglot AppHosts.

Generated public ports are stored in an AppHost-local key/value state file under .aspire/state. The state store uses cross-process locking, atomic replacement, per-value schema versioning, and a product-owned .gitignore. Port allocation continues to treat executable target ports as transient, while preserving generated public ports that form the user-observable endpoint identity.

The implementation also:

  • migrates existing Resources:<resource>:<endpoint>:port user-secret values when first encountered, without writing new allocations back to user secrets
  • adds features.gitWorktreeIsolationEnabled to automatically use isolated mode for AppHosts in linked Git worktrees, while preserving explicit --isolated true|false precedence
  • adds portAllocation.persistInIsolatedMode so isolated runs can opt into stable persisted ports
  • projects the AppHost-relative port policy consistently into managed C# and polyglot AppHosts

User-facing usage

{
  "features": {
    "gitWorktreeIsolationEnabled": true
  },
  "portAllocation": {
    "persistInIsolatedMode": true
  }
}

By default, isolated mode continues to skip persisted allocations. Setting persistInIsolatedMode to true gives each AppHost/worktree identity stable generated ports across restarts.

No additional dependencies are required.

Validation

  • dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-build --no-launch-profile -- --filter-class "*.DcpExecutorTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" - passed (314 succeeded, 1 platform-specific skip)
  • dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj --no-build --no-launch-profile -- --filter-class "*.AspireConfigFileTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" - passed (41 succeeded, 1 platform-specific skip)
  • ./build.sh --build /p:SkipNativeBuild=true - passed
  • CLI end-to-end coverage was added for C# and TypeScript linked-worktree restart stability; it was not run locally

Fixes #20653

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

Persist generated public ports in AppHost-local state and add feature-controlled worktree isolation for C# and polyglot AppHosts.

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

Or

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

@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 14, 2026 23:49
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 14, 2026

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

Allocation correctness, persistent-workload reuse, isolation propagation, and restart-test behavior have unresolved defects.

6 open findings
What changed in this PR

Adds AppHost-local persistence for generated public ports, supporting stable endpoint addresses across restarts and optional Git worktree isolation.

Changes:

  • Adds a locked, versioned state store and migrates legacy port allocations.
  • Introduces configurable worktree isolation and isolated-port persistence.
  • Updates configuration schemas and unit/end-to-end coverage.
File Description
tests/​Aspire.Hosting.Tests/​Dcp/​ProxylessEndpointPortAllocatorTests.cs Tests port reservations.
tests/​Aspire.Hosting.Tests/​Dcp/​DcpExecutorTests.cs Covers persistence, migration, and allocation behavior.
tests/​Aspire.Hosting.Tests/​Dcp/​ConfigureDefaultDcpOptionsTests.cs Tests persistence-option binding.
tests/​Aspire.Hosting.Tests/​Dcp/​AppHostLocalStateStoreTests.cs Tests state merging, versioning, and malformed data.
tests/​Aspire.Cli.Tests/​Projects/​GuestAppHostProjectTests.cs Refactors configuration-service setup.
tests/​Aspire.Cli.Tests/​Projects/​AppHostConfigurationProjectorTests.cs Tests persistence-policy projection.
tests/​Aspire.Cli.Tests/​Configuration/​AspireConfigFileTests.cs Tests legacy configuration migration.
tests/​Aspire.Cli.Tests/​Commands/​StartCommandTests.cs Tests worktree detection and explicit overrides.
tests/​Aspire.Cli.EndToEnd.Tests/​StartStopTests.cs Adds C# and TypeScript worktree restart scenarios.
src/​Shared/​KnownConfigNames.cs Defines the persistence environment variable.
src/​Aspire.Hosting/​DistributedApplicationBuilder.cs Registers persistence services.
src/​Aspire.Hosting/​Dcp/​ProxylessEndpointPortAllocator.cs Adds port reservation support.
src/​Aspire.Hosting/​Dcp/​PersistentPortAllocator.cs Coordinates persistent and transient allocations.
src/​Aspire.Hosting/​Dcp/​PersistentPortAllocationStore.cs Serializes versioned port allocations.
src/​Aspire.Hosting/​Dcp/​DcpOptions.cs Adds isolated-persistence configuration.
src/​Aspire.Hosting/​Dcp/​DcpModelUtilities.cs Centralizes public-port classification.
src/​Aspire.Hosting/​Dcp/​DcpExecutor.cs Integrates persistent allocation into service preparation.
src/​Aspire.Hosting/​ApplicationModel/​AppHostLocalStateStore.cs Implements locked, atomic local-state storage.
src/​Aspire.Cli/​Projects/​AppHostConfigurationProjector.cs Projects persistence policy into Hosting.
src/​Aspire.Cli/​KnownFeatures.cs Registers automatic worktree isolation.
src/​Aspire.Cli/​Configuration/​AspireJsonConfiguration.cs Adds legacy-format port configuration.
src/​Aspire.Cli/​Configuration/​AspireConfigFile.cs Defines and migrates port configuration.
src/​Aspire.Cli/​Commands/​RunCommand.cs Supplies AppHost context for isolation resolution.
src/​Aspire.Cli/​Commands/​AppHostLauncher.cs Resolves worktree isolation with explicit overrides.
extension/​schemas/​aspire-settings.schema.json Describes new local settings.
extension/​schemas/​aspire-global-settings.schema.json Describes new global settings.
extension/​schemas/​aspire-config.schema.json Describes new unified configuration options.

🧠 Review effort: Balanced

Comment thread src/Aspire.Cli/Commands/RunCommand.cs Resolved
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

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.

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

This comment has been minimized.

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

Port migration and launcher-dependent state identities can undermine isolation and stable endpoint reuse.

6 open findings
Previously missed (2)

In code that hasn't changed since last review

Medium severity Use a canonical AppHost identity across launchers

src/​Aspire.Hosting/​ApplicationModel/​AppHostLocalStateStore.cs:38

The same C# AppHost uses different state files depending on its launcher. The CLI sets DCP_WORKLOAD_ID to apphost-<path hash> (DotNetAppHostProject.cs:1588), while a direct launch without that variable falls back to AppHost:FilePath or AppHost:Path. Hashing these different strings selects separate stores, so switching launchers loses the saved public ports. Use a canonical AppHost identity shared by both launch paths, and test that both configurations reuse the same allocations.

Medium severity Preserve valid legacy ports outside the allocation range

src/​Aspire.Hosting/​Dcp/​ProxylessEndpointPortAllocator.cs:134

TryGetPortIndex rejects legacy ports outside the configured allocation range, even though the previous migration path accepted any valid port. For example, a saved port of 8080 is discarded with the default 10000–32767 range. Upgrading therefore changes the endpoint address and can recreate a persistent workload despite there being no conflict. Preserve valid legacy ports outside the scan range, tracking their reservations separately so duplicates and fixed-port conflicts are still rejected; keep new allocations within the configured range. Add an out-of-range migration regression test.

🧠 Review effort: Balanced

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

This comment has been minimized.

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.

🔵 Needs a closer look

Launcher-dependent state identities and rejected out-of-range legacy ports prevent consistent reuse of saved allocations.

0 open findings

6 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Inconsistent AppHost identity prevents state reuse

src/​Aspire.Hosting/​ApplicationModel/​AppHostLocalStateStore.cs:38

The same C# AppHost selects different state files depending on how it is launched. The CLI supplies DCP_WORKLOAD_ID=apphost-<path hash> (DotNetAppHostProject.cs:1588), while execution without that CLI environment falls back to AppHost:FilePath or AppHost:Path. Hashing these different identities prevents reuse of the other launcher's saved ports and can recreate persistent proxyless workloads. Use a consistent normalized AppHost-path identity across launchers, and add a regression that verifies reuse with and without the CLI-provided workload ID.

Medium severity Rejects valid legacy ports outside the current allocation range

src/​Aspire.Hosting/​Dcp/​ProxylessEndpointPortAllocator.cs:134

This rejects valid legacy ports outside the current generation range, even when allowInUse is true. For example, a saved port of 55000 was previously reusable because the old path checked only PortRange.IsValidPort, but it cannot migrate with the default 10000–32767 range. The endpoint address changes and a persistent workload may be recreated despite no conflict. Reserve valid legacy ports independently of the range for new allocations, while preserving availability checks, fixed-port exclusions, and duplicate detection. Add an out-of-range migration regression test.

🧠 Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot October 15, 2026 01:18
@danegsta David Negstad (danegsta) added area-cli and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 15, 2026
@danegsta David Negstad (danegsta) changed the title Persist stable AppHost port allocations Persist stable AppHost ports and add worktree isolation Oct 15, 2026
@github-actions

This comment has been minimized.

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.

🔵 Needs a closer look

The startup-delay risk and cross-process persistence changes need remediation and human review, with end-to-end validation still outstanding.

0 open findings

Previously missed (1)

In code that hasn't changed since last review

Medium severity Bound persistence retries to avoid per-endpoint startup delays

src/​Aspire.Hosting/​ApplicationModel/​AppHostLocalStateStore.cs:82

If .aspire/state and its .gitignore already exist but the lock file cannot be opened for writing, FileLock.Acquire retries for five seconds. A continuously held lock has the same effect. The initial read times out, but the store remains available, so every generated endpoint's SetPort waits again under the allocator lock. With 20 endpoints, this can add roughly 105 seconds to startup. Bound persistence retries across the launch, rather than per endpoint, or stop disk access after a failure. Preserve in-memory port reservations when disabling disk persistence.

🧠 Review effort: Balanced

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

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

# Conflicts:
#	src/Aspire.Hosting/Dcp/ProxylessEndpointPortAllocator.cs
#	tests/Aspire.Cli.Tests/Projects/GuestAppHostProjectTests.cs
#	tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs
#	tests/Aspire.Hosting.Tests/Dcp/ProxylessEndpointPortAllocatorTests.cs
@github-actions

This comment has been minimized.

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.

🔵 Needs a closer look

The new C# and TypeScript linked-worktree restart E2E scenarios were not run locally, leaving persisted-port reuse and worktree isolation across restarts unverified against the real CLI/server/DCP stack.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 1, 2026

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

github-actions Bot commented Nov 1, 2026

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.

@mitchdenny Mitch Denny (mitchdenny) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the current changes; no new blocking findings.

@mitchdenny

Copy link
Copy Markdown
Member

If there are concerns about merging this late in the 17.0 cycle, we could consider holding it for 17.1. The automatic worktree isolation is opt-in, but persistent generated public ports change the default behavior for normal AppHost runs, so holding would give us more time to exercise restart scenarios.

@danegsta

Copy link
Copy Markdown
Member Author

If there are concerns about merging this late in the 17.0 cycle, we could consider holding it for 17.1. The automatic worktree isolation is opt-in, but persistent generated public ports change the default behavior for normal AppHost runs, so holding would give us more time to exercise restart scenarios.

I don't think this is urgent for 17.0. I'm comfortable holding off merge until main becomes 17.1.

…apphost-20653

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

# Conflicts:
#	tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs
@github-actions

This comment has been minimized.

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.

🔵 Needs a closer look

Cross-process persistence and C#/TypeScript linked-worktree restart behavior still need runtime validation because the new worktree E2E cases remain unrun and cannot be executed in this environment.

No open issues 🎉

Review effort: Balanced

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

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Tests selector

58 / 101 PR test projects · 8 PR jobs, from 29 changed files.

Selected PR test projects (58 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Analyzers.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Kusto.Tests, Aspire.Hosting.Azure.Provisioning.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.DevTunnels.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.EntityFrameworkCore.Tests, Aspire.Hosting.Foundry.Tests, Aspire.Hosting.Garnet.Tests, Aspire.Hosting.Go.Tests, Aspire.Hosting.Java.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kafka.Tests, Aspire.Hosting.Keycloak.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests, Aspire.Hosting.MongoDB.Tests, Aspire.Hosting.MySql.Tests, Aspire.Hosting.Native.Core.Tests, Aspire.Hosting.Nats.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Oracle.Tests, Aspire.Hosting.Orleans.Tests, Aspire.Hosting.PostgreSQL.Tests, Aspire.Hosting.Python.Tests, Aspire.Hosting.Qdrant.Tests, Aspire.Hosting.RabbitMQ.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Redis.Tests, Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests, Aspire.Hosting.Seq.Tests, Aspire.Hosting.SqlServer.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Hosting.Valkey.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Managed.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests, Aspire.TerminalHost.Tests

Selected PR jobs (8)

cli-starter-validation, extension-e2e, extension-unit, homebrew-installer, native-dashboard-validation, polyglot, typescript-api-compat, winget-installer


How these were chosen — grouped by what changed

⚠️ 37 of the 58 selected test projects come from a single change — src/Aspire.Hosting/ApplicationModel/AppHostLocalStateStore.cs.

🔧 src/Aspire.Hosting/ApplicationModel/AppHostLocalStateStore.cs (changed source)
→ 37 via the project graph

show 37

Aspire.Hosting.Analyzers.Tests (2 hops), Aspire.Hosting.Azure.Kubernetes.Tests (2 hops), Aspire.Hosting.Azure.Kusto.Tests (2 hops), Aspire.Hosting.Azure.Provisioning.Tests (3 hops), Aspire.Hosting.Azure.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.CodeGeneration.Java.Tests, Aspire.Hosting.CodeGeneration.Python.Tests, Aspire.Hosting.CodeGeneration.Rust.Tests, Aspire.Hosting.CodeGeneration.TypeScript.Tests, Aspire.Hosting.DevTunnels.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.EntityFrameworkCore.Tests (2 hops), Aspire.Hosting.Foundry.Tests (2 hops), Aspire.Hosting.Garnet.Tests (2 hops), Aspire.Hosting.Go.Tests (2 hops), Aspire.Hosting.Java.Tests (2 hops), Aspire.Hosting.Kafka.Tests (2 hops), Aspire.Hosting.Keycloak.Tests (2 hops), Aspire.Hosting.Maui.Tests, Aspire.Hosting.Milvus.Tests (2 hops), Aspire.Hosting.MongoDB.Tests (2 hops), Aspire.Hosting.MySql.Tests (2 hops), Aspire.Hosting.Nats.Tests (2 hops), Aspire.Hosting.Oracle.Tests (2 hops), Aspire.Hosting.Orleans.Tests (2 hops), Aspire.Hosting.PostgreSQL.Tests (2 hops), Aspire.Hosting.Python.Tests (2 hops), Aspire.Hosting.Qdrant.Tests (2 hops), Aspire.Hosting.RabbitMQ.Tests (2 hops), Aspire.Hosting.Redis.Tests (2 hops), Aspire.Hosting.RemoteHost.Tests, Aspire.Hosting.Rust.Tests (2 hops), Aspire.Hosting.Seq.Tests (2 hops), Aspire.Hosting.SqlServer.Tests (2 hops), Aspire.Hosting.Valkey.Tests (2 hops), Aspire.Playground.Tests

🔧 src/Shared/KnownConfigNames.cs (changed source)
→ 15 via the project graph

show 15

Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Azure.EntraId.Tests, Aspire.Hosting.Browsers.Tests, Aspire.Hosting.Containers.Tests, Aspire.Hosting.Docker.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Kubernetes.Tests, Aspire.Hosting.Native.Core.Tests, Aspire.Hosting.OpenAI.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Yarp.Tests, Aspire.Managed.Tests, Aspire.Templates.Tests, Aspire.TerminalHost.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/AppHostLocalStateStoreTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests
→ 3 via the project graph: Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.Radius.Tests

📦 affected project Aspire.Hosting.Dotnet
→ 2 tests: Aspire.Cli.EndToEnd.Tests, Aspire.Templates.Tests

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

📦 affected project Aspire.Dashboard
→ 1 test: Aspire.Templates.Tests

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

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

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

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

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

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

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

🧪 tests/Aspire.Hosting.Tests/Dcp/ConfigureDefaultDcpOptionsTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

🧪 tests/Aspire.Hosting.Tests/Dcp/ProxylessEndpointPortAllocatorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.Tests

Job reasons

Job Triggered by
cli-starter-validation • affected project Aspire.Hosting.Native.Server
• affected project Aspire.Cli
extension-e2e • extension/schemas/aspire-config.schema.json, extension/schemas/aspire-global-settings.schema.json, extension/schemas/aspire-settings.schema.json, src/Aspire.Cli/Commands/AppHostLauncher.cs, src/Aspire.Cli/Commands/RunCommand.cs, src/Aspire.Cli/Configuration/AspireConfigFile.cs, src/Aspire.Cli/Configuration/AspireJsonConfiguration.cs, src/Aspire.Cli/KnownFeatures.cs, src/Aspire.Cli/Projects/AppHostConfigurationProjector.cs, src/Aspire.Cli/Projects/GuestAppHostProject.cs, src/Aspire.Hosting/ApplicationModel/AppHostLocalStateStore.cs, src/Aspire.Hosting/Dcp/DcpExecutor.cs, src/Aspire.Hosting/Dcp/DcpModelUtilities.cs, src/Aspire.Hosting/Dcp/DcpOptions.cs, src/Aspire.Hosting/Dcp/PersistentPortAllocationStore.cs, src/Aspire.Hosting/Dcp/PersistentPortAllocator.cs, src/Aspire.Hosting/Dcp/ProxylessEndpointPortAllocator.cs, src/Aspire.Hosting/DistributedApplicationBuilder.cs
• affected project Aspire.Hosting.Native.Server
• affected project Aspire.Cli
extension-unit extension/schemas/aspire-config.schema.json, extension/schemas/aspire-global-settings.schema.json, extension/schemas/aspire-settings.schema.json
homebrew-installer affected project Aspire.Hosting.Native.Server
native-dashboard-validation affected project Aspire.Dashboard
polyglot • affected project Aspire.Cli
• affected project Aspire.Hosting.Azure.Provisioning.AppService
typescript-api-compat affected project Aspire.Cli
winget-installer affected project Aspire.Hosting.Native.Server

Selection computed for commit a55250f.

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.

🔵 Needs a closer look

Human assessment is needed because the saved-port probe may treat TCP TIME_WAIT as a conflict, unexpectedly changing public URLs after restart without a competing listener.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 9, 2026

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.

@danegsta
David Negstad (danegsta) merged commit 168a8b4 into main Nov 9, 2026
730 of 734 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 9, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #2094

Generated by PR Documentation Check · copilot · auto · 27.7 AIC · ⌖ 1.19 AIC · ⊞ 7.4K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#2094 targeting release/17.0.

Documented new CLI settings features.gitWorktreeIsolationEnabled and portAllocation.persistInIsolatedMode, plus --isolated behavior in aspire run/aspire start. Signals: cli_command_file_changed (RunCommand.cs), pr_body_has_cli_flag_mention (--isolated true|false), pr_body_has_user_facing_section (JSON config usage). Files: config-settings-table.md, aspire-run.mdx, aspire-start.mdx.

Note

This draft PR needs human review before merging.

Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
## Description

Generated public ports are currently stable only in a few special cases,
which means endpoint addresses can change across AppHost restarts and
linked Git worktrees require explicit isolation. This change introduces
a consistent persistent port model for both C# and polyglot AppHosts.

Generated public ports are stored in an AppHost-local key/value state
file under `.aspire/state`. The state store uses cross-process locking,
atomic replacement, per-value schema versioning, and a product-owned
`.gitignore`. Port allocation continues to treat executable target ports
as transient, while preserving generated public ports that form the
user-observable endpoint identity.

The implementation also:

- migrates existing `Resources:<resource>:<endpoint>:port` user-secret
values when first encountered, without writing new allocations back to
user secrets
- adds `features.gitWorktreeIsolationEnabled` to automatically use
isolated mode for AppHosts in linked Git worktrees, while preserving
explicit `--isolated true|false` precedence
- adds `portAllocation.persistInIsolatedMode` so isolated runs can opt
into stable persisted ports
- projects the AppHost-relative port policy consistently into managed C#
and polyglot AppHosts

### User-facing usage

```json
{
  "features": {
    "gitWorktreeIsolationEnabled": true
  },
  "portAllocation": {
    "persistInIsolatedMode": true
  }
}
```

By default, isolated mode continues to skip persisted allocations.
Setting `persistInIsolatedMode` to `true` gives each AppHost/worktree
identity stable generated ports across restarts.

No additional dependencies are required.

### Validation

- `dotnet test --project
tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-build
--no-launch-profile -- --filter-class "*.DcpExecutorTests"
--filter-not-trait "quarantined=true" --filter-not-trait
"outerloop=true"` - passed (314 succeeded, 1 platform-specific skip)
- `dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj
--no-build --no-launch-profile -- --filter-class
"*.AspireConfigFileTests" --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"` - passed (41 succeeded, 1
platform-specific skip)
- `./build.sh --build /p:SkipNativeBuild=true` - passed
- CLI end-to-end coverage was added for C# and TypeScript
linked-worktree restart stability; it was not run locally

Fixes #20653

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] 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
  - [x] 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
  - [x] No

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 168a8b4)
Mitch Denny (mitchdenny) pushed a commit that referenced this pull request Nov 10, 2026
## Description

Generated public ports are currently stable only in a few special cases,
which means endpoint addresses can change across AppHost restarts and
linked Git worktrees require explicit isolation. This change introduces
a consistent persistent port model for both C# and polyglot AppHosts.

Generated public ports are stored in an AppHost-local key/value state
file under `.aspire/state`. The state store uses cross-process locking,
atomic replacement, per-value schema versioning, and a product-owned
`.gitignore`. Port allocation continues to treat executable target ports
as transient, while preserving generated public ports that form the
user-observable endpoint identity.

The implementation also:

- migrates existing `Resources:<resource>:<endpoint>:port` user-secret
values when first encountered, without writing new allocations back to
user secrets
- adds `features.gitWorktreeIsolationEnabled` to automatically use
isolated mode for AppHosts in linked Git worktrees, while preserving
explicit `--isolated true|false` precedence
- adds `portAllocation.persistInIsolatedMode` so isolated runs can opt
into stable persisted ports
- projects the AppHost-relative port policy consistently into managed C#
and polyglot AppHosts

### User-facing usage

```json
{
  "features": {
    "gitWorktreeIsolationEnabled": true
  },
  "portAllocation": {
    "persistInIsolatedMode": true
  }
}
```

By default, isolated mode continues to skip persisted allocations.
Setting `persistInIsolatedMode` to `true` gives each AppHost/worktree
identity stable generated ports across restarts.

No additional dependencies are required.

### Validation

- `dotnet test --project
tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-build
--no-launch-profile -- --filter-class "*.DcpExecutorTests"
--filter-not-trait "quarantined=true" --filter-not-trait
"outerloop=true"` - passed (314 succeeded, 1 platform-specific skip)
- `dotnet test --project tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj
--no-build --no-launch-profile -- --filter-class
"*.AspireConfigFileTests" --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"` - passed (41 succeeded, 1
platform-specific skip)
- `./build.sh --build /p:SkipNativeBuild=true` - passed
- CLI end-to-end coverage was added for C# and TypeScript
linked-worktree restart stability; it was not run locally

Fixes #20653

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] 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
  - [x] 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
  - [x] No

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 168a8b4)
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.

Support stable isolated port allocation for Git worktrees

3 participants