Skip to content

Use home-based CLI cache and randomized socket paths - #15346

Merged
Jose Perez Rodriguez (joperezr) merged 8 commits into
release/13.2from
sebros/cli-user-cache-paths
Mar 19, 2026
Merged

Jose Perez Rodriguez (joperezr) merged 8 commits into
release/13.2from
sebros/cli-user-cache-paths

Conversation

@sebastienros

@sebastienros Sébastien Ros (sebastienros) commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Updates the Aspire CLI to keep its managed NuGet package cache and runtime socket paths under ~/.aspire/cli instead of temp locations.

This also makes the socket layout explicit:

  • CLI-managed runtime sockets now live under ~/.aspire/cli/runtime/sockets/ with randomized names such as cli.sock.{id} and apphost.sock.{id}.
  • AppHost backchannel sockets continue to use a discoverable prefix, but now use the format ~/.aspire/cli/backchannels/auxi.sock.{appHostHash}.{instanceId}.{pid}.

The stable {appHostHash} is derived with xxHash so the CLI can cheaply rediscover sockets for the same AppHost path without treating the value as a security boundary. The per-instance {instanceId} is random so socket names are not deterministic across runs, which reduces collisions and makes them harder to guess than a path-only scheme while keeping the overall path short.

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
  • Does the change require an update in our Aspire docs?

@github-actions

github-actions Bot commented Mar 18, 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15346

Or

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

@mitchdenny

Copy link
Copy Markdown
Member

Code Review Comments

🔴 src/Shared/BackchannelConstants.cs — ComputeHash: SHA256 → XxHash3 is a cross-version breaking change

Line ~115 (ComputeHash method)

ComputeHash is compiled into both Aspire.Hosting (AppHost creates the socket via ComputeSocketPath) and Aspire.Cli (CLI discovers sockets via FindMatchingSockets). Since the CLI and AppHost are versioned independently — CLI via dotnet tool/package managers, AppHost via NuGet in user projects — users can easily upgrade one before the other.

When a user upgrades the CLI but still has an older AppHost running:

  • Old AppHost socket: auxi.sock.{sha256_hash}.{pid}
  • New CLI searches for: auxi.sock.{xxhash3_hash}.*
  • Result: socket not found — CLI silently fails to connect.

Suggestion: Add dual-hash fallback to FindMatchingSockets during a transition period:

public static string[] FindMatchingSockets(string appHostPath, string homeDirectory)
{
    // Try current (XxHash3) hash first
    var results = FindMatchingSocketsWithHash(
        ComputeHash(appHostPath), homeDirectory);

    if (results.Length == 0)
    {
        // Fallback to legacy SHA256 hash for cross-version compat
        var legacyHash = ComputeLegacySha256Hash(appHostPath);
        results = FindMatchingSocketsWithHash(legacyHash, homeDirectory);
    }

    return results;
}

private static string ComputeLegacySha256Hash(string appHostPath)
{
    var hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(appHostPath));
    return Convert.ToHexString(hashBytes)[..HashLength].ToLowerInvariant();
}

Or, simpler: search for all auxi.sock.* files in the backchannels directory and filter by PID liveness, removing the need to match hashes at discovery time at all.


🟡 src/Aspire.Cli/Utils/CliPathHelper.cs + src/Shared/BackchannelConstants.cs — duplicated random hash logic

CliPathHelper.CreateRandomHash (line ~46) and BackchannelConstants.CreateRandomInstanceHash (line ~350) are functionally identical: 8 random bytes → XxHash3 → hex → truncate to 12 chars. The only difference is CreateRandomHash takes a length parameter.

Consider having CreateRandomInstanceHash delegate to CliPathHelper.CreateRandomHash(InstanceHashLength), or extract a shared utility since both files are in the same compilation units.


🟡 CliPathHelper.CreateRandomHash / BackchannelConstants.CreateRandomInstanceHash — unnecessary XxHash3 on random bytes

Both methods generate cryptographically random bytes via RandomNumberGenerator.Fill, then hash them through XxHash3. Since the input is already uniformly random, XxHash3 only serves to normalize to fixed-length output. A simpler alternative:

Span<byte> bytes = stackalloc byte[(length + 1) / 2];
RandomNumberGenerator.Fill(bytes);
return Convert.ToHexString(bytes)[..length].ToLowerInvariant();

This is equivalent in randomness quality, avoids the System.IO.Hashing dependency for randomization, and is more straightforward.


💭 src/Aspire.Cli/Packaging/NuGetConfigMerger.cs — GetGlobalPackagesFolderPath test coverage gap

The existing test covers the happy path (explicit channel with mappings). Consider adding tests for:

  • Implicit channel (null/empty Mappings) — verifies the channel.Name fallback path
  • Hash stability — two channels with identical mappings in different order produce the same path (validates the OrderBy sort)
  • Hash uniqueness — two channels with different mappings produce different paths

@github-actions

Copy link
Copy Markdown
Contributor

The transient CI rerun workflow requested reruns for the following jobs after analyzing the failed attempt.
GitHub's job rerun API also reruns dependent jobs, so the retry is being tracked in the rerun attempt.
The job links below point to the failed attempt that matched the retry-safe transient failure rules.

  • Tests / Hosting.Redis / Hosting.Redis (windows-latest) - Failed step 'Build test project' will be retried because the job log shows a likely transient infrastructure network failure. Matched pattern: /Unable to load the service index for source https://(?:pkgs.dev.azure.com/dnceng|dnceng.pkgs.visualstudio.com)/public/_packaging//i.

Comment thread src/Aspire.Cli/Utils/CliPathHelper.cs Resolved
Comment thread src/Aspire.Cli/Utils/CliPathHelper.cs Resolved
Comment thread src/Shared/BackchannelConstants.cs Resolved
Comment thread src/Shared/BackchannelConstants.cs Resolved
Comment thread src/Shared/BackchannelConstants.cs Resolved
Comment thread src/Shared/BackchannelConstants.cs Resolved

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.

See inline comments. Main issues: missing homeDirectory passthrough in GetGlobalPackagesFolderPath, tautological test, and duplicated random hash logic.

Comment thread src/Aspire.Cli/Utils/CliPathHelper.cs Resolved
@sebastienros
Sébastien Ros (sebastienros) marked this pull request as ready for review March 18, 2026 17:45
Copilot AI review requested due to automatic review settings March 18, 2026 17:45

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

Updates Aspire CLI pathing to use a stable home-based layout (~/.aspire/cli) for managed NuGet cache and runtime sockets, and refreshes backchannel socket naming to include a stable AppHost hash plus per-instance randomness.

Changes:

  • Introduces CliPathHelper to centralize ~/.aspire/cli subpaths and create randomized socket paths.
  • Updates backchannel socket naming/parsing to support current + previous + legacy formats.
  • Adjusts NuGet.config merge logic and tests to use the new CLI-local global packages folder layout.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Utils/CliPathHelperTests.cs Adds coverage for new CLI home paths and randomized socket naming.
tests/Aspire.Cli.Tests/Utils/AppHostHelperTests.cs Extends socket parsing tests for current/previous backchannel formats.
tests/Aspire.Cli.Tests/Packaging/PackagingServiceTests.cs Updates expectations for globalPackagesFolder to new CLI-local cache location.
src/Shared/BackchannelConstants.cs Switches AppHost hash to xxHash-based stable ID and adds per-instance socket randomness; updates matching/parsing helpers.
src/Aspire.Cli/Utils/CliPathHelper.cs New helper for CLI home/runtime/socket/NuGet cache paths + randomized socket creation.
src/Aspire.Cli/Utils/AppHostHelper.cs Updates docs to reflect the new socket naming shape.
src/Aspire.Cli/Projects/AppHostServerProject.cs Uses CliPathHelper.CreateSocketPath("apphost.sock") instead of temp/deterministic paths.
src/Aspire.Cli/Program.cs Uses CliPathHelper.GetAspireHomeDirectory() for ~/.aspire resolution.
src/Aspire.Cli/Packaging/NuGetConfigMerger.cs Computes per-channel global packages folder under ~/.aspire/cli/nuget/packages/{id} and threads optional home override through.
src/Aspire.Cli/DotNet/DotNetCliRunner.cs Uses CliPathHelper.CreateSocketPath("cli.sock") for CLI-managed runtime sockets.
src/Aspire.Cli/Aspire.Cli.csproj Adds System.IO.Hashing package reference to support xxHash usage.

@sebastienros

Copy link
Copy Markdown
Contributor Author

Addressed the compatibility concerns from #15346 (comment) in 8c771c5. FindMatchingSockets now falls back to the legacy SHA-256 AppHost hash when the new xxHash-based prefix finds no matches, and I added the missing NuGetConfigMerger tests for implicit-channel, mapping-order stability, and mapping uniqueness.

@JamesNK

Copy link
Copy Markdown
Member

Addressed the compatibility concerns from #15346 (comment) in 8c771c5. FindMatchingSockets now falls back to the legacy SHA-256 AppHost hash when the new xxHash-based prefix finds no matches, and I added the missing NuGetConfigMerger tests for implicit-channel, mapping-order stability, and mapping uniqueness.

I don't think this is a real problem. SHA256 never shipped, no? It's true this PR breaks compatibility but not with a released version.

@sebastienros Sébastien Ros (sebastienros) added the Servicing-consider Issue for next servicing release review label Mar 18, 2026

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.

LGTM — just one minor indentation nit on the XML doc.

Comment thread src/Shared/BackchannelConstants.cs Resolved
@sebastienros

Copy link
Copy Markdown
Contributor Author

James Newton-King (@JamesNK) I didn't realize that, I trusted the comment, will check and react then

@JamesNK

James Newton-King (JamesNK) commented Mar 18, 2026 •

Copy link
Copy Markdown
Member

Addressed the compatibility concerns from #15346 (comment) in 8c771c5. FindMatchingSockets now falls back to the legacy SHA-256 AppHost hash when the new xxHash-based prefix finds no matches, and I added the missing NuGetConfigMerger tests for implicit-channel, mapping-order stability, and mapping uniqueness.

I don't think this is a real problem. SHA256 never shipped, no? It's true this PR breaks compatibility but not with a released version.

I approved PR, but this should be fixed before merge.

@sebastienros

Copy link
Copy Markdown
Contributor Author

Addressed the compatibility concerns from #15346 (comment) in 8c771c5. FindMatchingSockets now falls back to the legacy SHA-256 AppHost hash when the new xxHash-based prefix finds no matches, and I added the missing NuGetConfigMerger tests for implicit-channel, mapping-order stability, and mapping uniqueness.

I don't think this is a real problem. SHA256 never shipped, no? It's true this PR breaks compatibility but not with a released version.

So this was added in b645e6f7f which I believe was not shipped (Jan 23rd)

@joperezr Jose Perez Rodriguez (joperezr) added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Mar 18, 2026
@sebastienros

Copy link
Copy Markdown
Contributor Author

Follow-up: I removed the legacy SHA-256 discovery fallback in d247f31 after verifying that the SHA-256 socket format never shipped in a tagged 13.x release. The format existed on release/13.2, but it is not contained in any shipped v13.* tag, so we do not need a cross-version fallback for released CLI/AppHost combinations.

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.

This looks good to me. Let me know when ready to merge.

@sebastienros Sébastien Ros (sebastienros) added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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.

  • Tests / Azure.AI.Inference / Azure.AI.Inference (windows-latest) - Failed step 'Build test project' will be retried because the job log shows a likely transient infrastructure network failure. Matched pattern: /Unable to load the service index for source https:\/\/(?:pkgs\.dev\.azure\.com\/dnceng|dnceng\.pkgs\.visualstudio\.com)\/public\/_packaging\//i.

@sebastienros Sébastien Ros (sebastienros) removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Mar 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 53 recordings uploaded (commit 32f0694)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23300548423

@joperezr
Jose Perez Rodriguez (joperezr) merged commit 1fab1b1 into release/13.2 Mar 19, 2026
255 of 258 checks passed
@joperezr
Jose Perez Rodriguez (joperezr) deleted the sebros/cli-user-cache-paths branch March 19, 2026 18:38
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.2 milestone Mar 19, 2026
Jose Perez Rodriguez (joperezr) added a commit to joperezr/aspire that referenced this pull request Mar 20, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants