Skip to content

Fix Foundry hosted agent endpoint resolution - #16797

Merged
David Fowler (davidfowl) merged 3 commits into
mainfrom
eerhardt/fix-publish-hosted-agent-ref-hang
May 6, 2026
Merged

David Fowler (davidfowl) merged 3 commits into
mainfrom
eerhardt/fix-publish-hosted-agent-ref-hang

Conversation

@eerhardt

Copy link
Copy Markdown
Member

Description

PublishAsHostedAgent(...) resolved target environment variables through context-free value providers, which could wait forever on endpoint allocation snapshots during aspire deploy when a hosted agent referenced an Azure Container Apps endpoint. This change makes hosted-agent environment resolution publish-aware: endpoint values are resolved through the target compute environment's deployed endpoint expressions, including nested ReferenceExpression values and direct EndpointReferenceExpression values.

The change adds a default IComputeEnvironmentResource.GetEndpointPropertyExpression(...) implementation plus Azure Container Apps and App Service overrides so publish-time endpoint URL, host, port, scheme, and host-and-port behavior stays aligned with those environments. Referenced internal endpoints now fail fast with an actionable exception instead of hanging.

Fixes #16608

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?

Resolve hosted-agent environment endpoint references through compute environment deployment expressions during publish so aspire deploy does not wait on endpoint allocation snapshots. Throw for unsupported internal referenced endpoints and add regression coverage for direct and nested endpoint expressions.

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

github-actions Bot commented May 5, 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/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16797

Or

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

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

This PR fixes PublishAsHostedAgent(...) hanging during aspire deploy by making hosted-agent environment-variable resolution publish-aware, resolving endpoint-related values via the target compute environment’s deployed endpoint expressions (rather than waiting on runtime endpoint allocation snapshots).

Changes:

  • Added IComputeEnvironmentResource.GetEndpointPropertyExpression(...) with a default implementation, plus Azure Container Apps and App Service overrides for publish-time endpoint properties.
  • Updated Foundry hosted agent environment variable resolution to correctly handle EndpointReference, EndpointReferenceExpression, and nested ReferenceExpression values in publish mode (and to fail fast for internal-only endpoints).
  • Added unit tests covering default/ACA/App Service endpoint property expressions and hosted-agent publish-time resolution scenarios.

Reviewed changes

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

Show a summary per file
File Description
tests/Aspire.Hosting.Tests/ComputeEnvironmentValidationTests.cs Adds tests for the default compute-environment endpoint property expression behavior (including failure case for custom schemes without ports).
tests/Aspire.Hosting.Azure.Tests/FoundryExtensionsTests.cs Adds publish-mode tests validating hosted-agent environment variable resolution for external ACA endpoints and reference/endpoint expressions.
tests/Aspire.Hosting.Azure.Tests/AzureContainerAppsTests.cs Adds tests for ACA-specific endpoint property expression behavior in publish mode.
tests/Aspire.Hosting.Azure.Tests/AzureAppServiceTests.cs Adds tests for App Service-specific endpoint property expression behavior in publish mode.
src/Aspire.Hosting/ApplicationModel/IComputeEnvironmentResource.cs Introduces new (experimental) public API for resolving deployed endpoint properties via compute environments.
src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs Implements publish-aware environment variable resolution for hosted agents to avoid hangs on allocated-endpoint snapshots.
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs Overrides endpoint property expression resolution to match App Service deployed endpoint semantics.
src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs Overrides endpoint property expression resolution to match Azure Container Apps deployed endpoint semantics.

Eric Erhardt (eerhardt) and others added 2 commits May 5, 2026 17:51
Fix endpoint resolution diagnostics, reuse the shared formatting helper, keep upgraded endpoint TLS values consistent with the effective scheme, and document endpoint property resolution behavior.

Co-authored-by: Copilot <[email protected]>
Clarify that compute environment endpoint property expressions are generally useful whenever callers need environment-specific reference expressions, not only for deployment publishers.

Co-authored-by: Copilot <[email protected]>
@eerhardt

Copy link
Copy Markdown
Member Author

/backport to release/13.3

@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/13.3 (link to workflow run)

@sebastienros

Copy link
Copy Markdown
Contributor

A follow up to add the new api to test polyglot apphosts will be necessary

@eerhardt

Copy link
Copy Markdown
Member Author

A follow up to add the new api to test polyglot apphosts will be necessary

Is the existing GetHostAddressExpression API already exposed to polyglot apphosts?

@github-actions

github-actions Bot commented May 6, 2026

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.

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 76 recordings uploaded (commit f214071)

View all recordings
Status 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
❔ Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
❔ CertificatesClean_RemovesCertificates ▶️ View Recording
❔ CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
❔ CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
❔ ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
❔ CreateAndRunAspireStarterProject ▶️ View Recording
❔ CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
❔ CreateAndRunEmptyAppHostProject ▶️ View Recording
❔ CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
❔ CreateAndRunJsReactProject ▶️ View Recording
❔ CreateAndRunPythonReactProject ▶️ View Recording
❔ CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
❔ CreateAndRunTypeScriptStarterProject ▶️ View Recording
❔ CreateJavaAppHostWithViteApp ▶️ View Recording
❔ CreateTypeScriptAppHostWithViteApp_UsesConfiguredToolchain ▶️ View Recording
❔ DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
❔ DeployK8sBasicApiService ▶️ View Recording
❔ DeployK8sWithGarnet ▶️ View Recording
❔ DeployK8sWithMongoDB ▶️ View Recording
❔ DeployK8sWithMySql ▶️ View Recording
❔ DeployK8sWithPostgres ▶️ View Recording
❔ DeployK8sWithRabbitMQ ▶️ View Recording
❔ DeployK8sWithRedis ▶️ View Recording
❔ DeployK8sWithSqlServer ▶️ View Recording
❔ DeployK8sWithValkey ▶️ View Recording
❔ DeployTypeScriptAppToKubernetes ▶️ View Recording
❔ DescribeCommandResolvesReplicaNames ▶️ View Recording
❔ DescribeCommandShowsRunningResources ▶️ View Recording
❔ DetachFormatJsonProducesValidJson ▶️ View Recording
❔ DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
❔ DoListStepsShowsPipelineSteps ▶️ View Recording
❔ DocsCommand_RendersInteractiveMarkdownFromLocalSource ▶️ View Recording
❔ DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
❔ DoctorCommand_TypeScriptAppHostReportsMissingConfiguredToolchain ▶️ 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
❔ InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
❔ InteractiveCSharpInitCreatesExpectedFiles ▶️ View Recording
❔ InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
❔ LatestCliCanStartStableChannelAppHost ▶️ View Recording
❔ LatestCliCanStartStableChannelTypeScriptAppHost ▶️ View Recording
❔ LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
❔ LogsCommandShowsResourceLogs ▶️ View Recording
❔ OtelLogsReturnsStructuredLogsFromStarterAppCore ▶️ View Recording
❔ PsCommandListsRunningAppHost ▶️ View Recording
❔ PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
❔ PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
❔ PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
❔ PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
❔ RestoreGeneratesSdkFiles ▶️ View Recording
❔ RestoreGeneratesSdkFiles_WithConfiguredToolchain ▶️ View Recording
❔ RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
❔ RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
❔ RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
❔ SecretCrudOnDotNetAppHost ▶️ View Recording
❔ SecretCrudOnTypeScriptAppHost ▶️ View Recording
❔ StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
❔ StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
❔ StopAllAppHostsFromAppHostDirectory ▶️ View Recording
❔ StopNonInteractiveSingleAppHost ▶️ View Recording
❔ StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
❔ UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #25406750024

@davidfowl
David Fowler (davidfowl) merged commit 3dd1d0e into main May 6, 2026
838 of 855 checks passed
@github-actions github-actions Bot added this to the 13.4 milestone May 6, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

No documentation PR is required for this change.

This is a bug fix that corrects PublishAsHostedAgent endpoint resolution hanging during aspire deploy when a hosted agent references an Azure Container Apps endpoint. The fix makes endpoint resolution publish-aware, but it doesn't introduce new user-facing APIs, configuration options, or behavioral changes that users need to know about. The corrected behavior is what users would expect from existing documentation.

Generated by PR Documentation Check for issue #16797 · ● 107.4K · ◷

Nell Shamrell-Harrington (nellshamrell) pushed a commit to nellshamrell/aspire that referenced this pull request May 18, 2026
* Fix hosted agent endpoint resolution

Resolve hosted-agent environment endpoint references through compute environment deployment expressions during publish so aspire deploy does not wait on endpoint allocation snapshots. Throw for unsupported internal referenced endpoints and add regression coverage for direct and nested endpoint expressions.

Co-authored-by: Copilot <[email protected]>

* Address hosted agent review comments

Fix endpoint resolution diagnostics, reuse the shared formatting helper, keep upgraded endpoint TLS values consistent with the effective scheme, and document endpoint property resolution behavior.

Co-authored-by: Copilot <[email protected]>

* Refine endpoint property documentation

Clarify that compute environment endpoint property expressions are generally useful whenever callers need environment-specific reference expressions, not only for deployment publishers.

Co-authored-by: Copilot <[email protected]>

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PublishAsHostedAgent hangs resolving referenced ACA app endpoint during aspire deploy

4 participants