Skip to content

[release/17.0] Persist stable AppHost ports and add worktree isolation - #22044

Closed
Mitch Denny (mitchdenny) wants to merge 1 commit into
mitchdenny-backport-17-0-45-pr21898from
mitchdenny-backport-17-0-46-pr21013
Closed

Mitch Denny (mitchdenny) wants to merge 1 commit into
mitchdenny-backport-17-0-45-pr21898from
mitchdenny-backport-17-0-46-pr21013

Conversation

@mitchdenny

Copy link
Copy Markdown
Member

Description

Backport of #21013 to release/17.0 (cherry-picked from 168a8b4 with no modifications).

Layer 46 of 55 in the release/17.0 backport stack; stacked on #22043.

Backport recommendation: No — Feature.

Validation: Stable patch IDs match the original commit. Builds/tests not run for this unchanged cherry-pick.

Backport of #21013

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

## 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)
@github-actions

This comment has been minimized.

@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.

@mitchdenny

Copy link
Copy Markdown
Member Author

Approved for inclusion in release/17.0. Do not merge yet.

@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 -- 22044

Or

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

@github-actions

This comment has been minimized.

@mitchdenny
Mitch Denny (mitchdenny) force-pushed the mitchdenny-backport-17-0-46-pr21013 branch from 5dfe984 to d9158bc Compare November 10, 2026 06:21
@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.

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.

2 participants