Skip to content

App Service deploy fails: cross-referencing a Foundry hosted agent from a non-Foundry resource has no resolution path #17749

@davidfowl

Description

@davidfowl

Description

aspire deploy fails when a resource deployed to App Service, Azure Container Apps, or AKS uses withReference() to reference a Foundry hosted agent. During Bicep generation, AzureAppServiceWebsiteContext.ProcessValue calls GetAppServiceContext() on every referenced resource. The hosted agent has no App Service context (it is Foundry-managed), so it throws unconditionally with no fallback. The same cross-context resolution gap exists in the ACA and AKS deployment pipelines.

Context

#16797 added support for Foundry resources referencing App Service/ACA/AKS resources (Foundry → compute targets). But the reverse direction — a compute resource deployed to App Service/ACA/AKS referencing a Foundry hosted agent — was never wired up. Cross-context reference resolution is currently one-way.

The fix likely needs to live at a shared layer (ProcessValue equivalent) across App Service, Container Apps, and AKS rather than being patched per-target.

Stack trace (from --include-exception-details)

01:01:09 (pipeline-execution) ✗ App Service context not found for resource agent-ha.
System.InvalidOperationException: App Service context not found for resource agent-ha.
   at Aspire.Hosting.Azure.AzureAppServiceEnvironmentContext.GetAppServiceContext(IResource resource)
         in AzureAppServiceEnvironmentContext.cs:line 66
   at Aspire.Hosting.Azure.AppService.AzureAppServiceWebsiteContext.ProcessValue(...)
         in AzureAppServiceWebsiteContext.cs:line 170
   at Aspire.Hosting.Azure.AppService.AzureAppServiceWebsiteContext.CreateAndConfigureWebSite(...)
         in AzureAppServiceWebsiteContext.cs:line 470
   at Aspire.Hosting.Azure.AppService.AzureAppServiceWebsiteContext.BuildWebSiteCore(...)
         in AzureAppServiceWebsiteContext.cs:line 694
   at Aspire.Hosting.Azure.AppService.AzureAppServiceWebsiteContext.BuildWebSite(...)
         in AzureAppServiceWebsiteContext.cs:line 332

Repro

AppHost (apphost.mts):

import { createBuilder, FoundryModels } from "./.aspire/modules/aspire.mjs";

const builder = await createBuilder();

const foundry = await builder.addFoundry("foundry");
const project = foundry.addProject("project");
const model = await foundry.addDeployment("chat", FoundryModels.OpenAI.Gpt4oMini);

const hostedAgent = await builder
    .addNodeApp("agent-ha", "../api", "src/server.js")
    .withHttpEndpoint({ env: "PORT" })
    .withExternalHttpEndpoints()
    .withHttpHealthCheck({ path: "/readiness" })
    .withReference(model);

await hostedAgent.asHostedAgent(project, {
    protocols: [{ protocol: "invocations", version: "1.0.0" }]
});

// This withReference crosses the Foundry boundary — triggers the failure
await builder
    .addViteApp("web", "../web")
    .withReference(hostedAgent)
    .withHttpEndpoint({ env: "PORT" });

await builder.build().run();

aspire.config.json packages:

"packages": {
    "Aspire.Hosting.JavaScript": "13.4.0",
    "Aspire.Hosting.Foundry": "13.4-*",
    "Aspire.Hosting.Azure.AppService": "13.4.0"
}

Root cause

AzureAppServiceWebsiteContext.ProcessValue (line 170) calls GetAppServiceContext() on every resource referenced via withReference(). When the referenced resource is a Foundry hosted agent (asHostedAgent()), it has no App Service context and the method throws with no fallback. The same pattern will reproduce in ACA and AKS pipelines.

Expected behavior

When a resource deployed to App Service/ACA/AKS holds a withReference() to a Foundry hosted agent, the deployment pipeline should inject the hosted agent's Foundry-published endpoint URL rather than calling GetAppServiceContext() and throwing.

Environment

  • Aspire CLI: 13.4.0
  • Channel: staging
  • AppHost language: TypeScript
  • OS: macOS Darwin arm64

Metadata

Metadata

Assignees

Labels

aiarea-integrationsIssues pertaining to Aspire Integrations packagesazureIssues associated specifically with scenarios tied to using AzurebugfoundryIssues about the Aspire.Hosting.Foundry integrationtriage:bot-seenAspire triage bot has seen this issue

Type

No fields configured for Bug.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions