Skip to content

Fix event order and callback calling during container creation#15503

Open
karolz-ms wants to merge 8 commits intomainfrom
dev/karolz/tunnel-handling-5
Open

Fix event order and callback calling during container creation#15503
karolz-ms wants to merge 8 commits intomainfrom
dev/karolz/tunnel-handling-5

Conversation

@karolz-ms
Copy link
Contributor

Description

This change fixes issues related to environment and invocation argument callback calling and application model events introduced by #14557. It ensures that

  • callbacks are invoked after BeforeResourceStart handlers complete for given resource,
  • callbacks are invoked only once during resource startup, and that
  • exceptions thrown by callbacks do not affect startup of other resources.

Fixes:
#14954
#15358

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?

Copilot AI review requested due to automatic review settings March 23, 2026 20:57
@github-actions
Copy link
Contributor

github-actions bot commented Mar 23, 2026

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

Or

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

@karolz-ms
Copy link
Contributor Author

@afscrome please share your feedback too--I tried to add you as a reviewer, but this new repository has contributor caching issues that prevents me from doing that 😞

@karolz-ms karolz-ms requested a review from joperezr March 23, 2026 21:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes regressions in Aspire Hosting/DCP startup sequencing introduced by container tunnel changes, ensuring environment/args callbacks run once, run after BeforeResourceStarted, and are isolated on failure.

Changes:

  • Adds callback result caching for env/args annotations and resets cache on resource restart.
  • Refactors DCP container creation to coordinate tunnel setup with container creation and adjusts lifecycle event publishing (including new connection-string event).
  • Updates/extends tests to validate callback invocation order/count and removes quarantine from the proxyless tunnel test via shorter test resource names.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Hosting.Tests/Dcp/DcpExecutorTests.cs Adds coverage for callback invocation ordering/count, failure isolation, and mixed tunnel-dependent/independent container startup.
tests/Aspire.Hosting.Tests/ContainerTunnelTests.cs Un-quarantines proxyless tunnel test and shortens test name to avoid invalid resource name length.
src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs Subscribes to and publishes connection-string availability separately from resource-starting.
src/Aspire.Hosting/Dcp/Model/ContainerTunnel.cs Adds UpdatedTunnels state to tunnel proxy resource (non-serialized).
src/Aspire.Hosting/Dcp/DcpNameGenerator.cs Adds stable service-name caching to prevent duplicate service creation for the same endpoint/network.
src/Aspire.Hosting/Dcp/DcpExecutorEvents.cs Introduces OnConnectionStringAvailableContext.
src/Aspire.Hosting/Dcp/DcpExecutor.cs Major refactor: container creation orchestration, tunnel setup coordination, endpoint-advertisement de-dupe, callback cache reset on restart.
src/Aspire.Hosting/Dcp/ContainerCreationContext.cs New coordination primitives for container creation vs tunnel creation.
src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Adds optional caching behavior when discovering dependencies by evaluating annotation callbacks once.
src/Aspire.Hosting/ApplicationModel/ResourceDependencyDiscoveryMode.cs Converts discovery mode to [Flags] and adds CacheAnnotationCallbackResults.
src/Aspire.Hosting/ApplicationModel/ICallbackResourceAnnotation.cs New internal interface for “evaluate once + forget cache” callback annotations.
src/Aspire.Hosting/ApplicationModel/EnvironmentVariablesConfigurationGatherer.cs Switches to cached evaluation for environment callbacks.
src/Aspire.Hosting/ApplicationModel/EnvironmentCallbackAnnotation.cs Implements cached evaluation for env callbacks.
src/Aspire.Hosting/ApplicationModel/EndpointAnnotation.cs Adds an internal unique endpoint ID.
src/Aspire.Hosting/ApplicationModel/CommandLineArgsCallbackAnnotation.cs Implements cached evaluation for args callbacks.
src/Aspire.Hosting/ApplicationModel/ArgumentsExecutionConfigurationGatherer.cs Switches to cached evaluation for args callbacks.

@github-actions
Copy link
Contributor

🎬 CLI E2E Test Recordings — 52 recordings uploaded (commit 5088bed)

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
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 #23466872106

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