Skip to content

Add publish and deploy finalization boundaries - #19720

Draft
Adam Ratzman (adamint) wants to merge 14 commits into
microsoft:mainfrom
adamint:adamint-pipeline-finalization-boundaries
Draft

Adam Ratzman (adamint) wants to merge 14 commits into
microsoft:mainfrom
adamint:adamint-pipeline-finalization-boundaries

Conversation

@adamint

@adamint Adam Ratzman (adamint) commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Description

Pipeline contributors previously had no explicit barrier between ordinary publish/deploy work and hooks that must run after that work. This adds publish-finalize and deploy-finalize while keeping publish and deploy as the final command-completion aggregates:

publish-prereq -> normal publish work -> publish-finalize -> post-finalize hooks -> publish
deploy-prereq  -> normal deploy work  -> deploy-finalize  -> post-finalize hooks -> deploy

Normal first-party work now targets the matching finalizer across Docker Compose, Kubernetes, Azure, Foundry, Radius, JavaScript, and Entity Framework Core. The scheduler adds prerequisite gates only when the selected command reaches that finalizer, including nested publish work during deploy, so shared build steps stay isolated when build is selected.

Direct third-party attachments to publish or deploy remain supported and may run in parallel with the finalizer branch. The intentional first-party direct references that remain are:

  • the built-in publish and deploy aggregate definitions;
  • Dotnet project command-root detection;
  • Docker Compose and Helm deploy preparation, which depend on complete publish output.

Aspire.dev documentation: microsoft/aspire.dev#1587.

User-facing usage

Ordinary publish work should complete before PublishFinalize:

step.RequiredBy(WellKnownPipelineSteps.PublishFinalize);

A hook that runs after ordinary publish work but before command completion should use both edges:

step.DependsOn(WellKnownPipelineSteps.PublishFinalize);
step.RequiredBy(WellKnownPipelineSteps.Publish);

The same pattern applies to DeployFinalize and Deploy.

Real CLI scenarios

Installed the dogfood artifact and confirmed it matches this PR's head commit:

$ aspire --version
13.6.0-pr.19720.g1a612f92

The temporary C# AppHost registered one normal step before each finalizer and one post-finalize hook before each final aggregate:

builder.Pipeline.AddStep(
    "publish-normal-work",
    RunPublishWorkAsync,
    requiredBy: WellKnownPipelineSteps.PublishFinalize);

builder.Pipeline.AddStep(
    "publish-post-finalize-hook",
    RunPublishHookAsync,
    dependsOn: WellKnownPipelineSteps.PublishFinalize,
    requiredBy: WellKnownPipelineSteps.Publish);

The same setup used DeployFinalize and Deploy for deploy.

aspire publish --list-steps resolved the expected structure:

$ aspire publish --apphost apphost.cs --list-steps --non-interactive --nologo
4. publish-prereq
   └─ Depends on: process-parameters, validate-build-only-container-references,
                  publish-prerequisite-observer

5. publish-normal-work
   └─ Depends on: publish-prereq

6. publish-finalize
   └─ Depends on: publish-prereq, publish-normal-work

7. publish-post-finalize-hook
   └─ Depends on: publish-finalize

8. publish
   └─ Depends on: publish-finalize, publish-post-finalize-hook

The real publish command executed in that order and did not complete the aggregate until the post-finalize hook completed:

$ aspire publish --apphost apphost.cs --output-path publish-output --non-interactive --nologo
13:38:59 (publish-prerequisite-observer) i [INF] BOUNDARY publish: prerequisite complete
13:38:59 (publish-prereq) ✓ publish-prereq completed successfully
13:38:59 (publish-normal-work) i [INF] BOUNDARY publish: normal work started
13:38:59 (publish-normal-work) i [INF] BOUNDARY publish: normal work complete
13:38:59 (publish-finalize) ✓ publish-finalize completed successfully
13:38:59 (publish-post-finalize-hook) i [INF] BOUNDARY publish: post-finalize hook started
13:39:00 (publish-post-finalize-hook) i [INF] BOUNDARY publish: post-finalize hook complete
13:39:00 (publish) ✓ publish completed successfully
✓ 11/11 steps succeeded • Total time: 0.46s
✓ Pipeline succeeded

aspire deploy --list-steps resolved the corresponding deploy structure:

$ aspire deploy --apphost apphost.cs --list-steps --non-interactive --nologo
4. deploy-prereq
   └─ Depends on: process-parameters, validate-build-only-container-references,
                  deploy-prerequisite-observer

5. deploy-normal-work
   └─ Depends on: deploy-prereq

6. deploy-finalize
   └─ Depends on: deploy-prereq, deploy-normal-work

7. deploy-post-finalize-hook
   └─ Depends on: deploy-finalize

8. deploy
   └─ Depends on: deploy-finalize, deploy-post-finalize-hook

The real deploy command produced the same runtime ordering:

$ aspire deploy --apphost apphost.cs --output-path deploy-output --non-interactive --nologo --clear-cache
13:39:17 (deploy-prerequisite-observer) i [INF] BOUNDARY deploy: prerequisite complete
13:39:17 (deploy-prereq) ✓ deploy-prereq completed successfully
13:39:17 (deploy-normal-work) i [INF] BOUNDARY deploy: normal work started
13:39:17 (deploy-normal-work) i [INF] BOUNDARY deploy: normal work complete
13:39:17 (deploy-finalize) ✓ deploy-finalize completed successfully
13:39:17 (deploy-post-finalize-hook) i [INF] BOUNDARY deploy: post-finalize hook started
13:39:17 (deploy-post-finalize-hook) i [INF] BOUNDARY deploy: post-finalize hook complete
13:39:17 (deploy) ✓ deploy completed successfully
✓ 11/11 steps succeeded • Total time: 0.47s
✓ Pipeline succeeded

Validation

  • ./restore.sh — passed
  • dotnet test --project tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj --no-launch-profile -- --filter-class "*.DistributedApplicationPipelineTests" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true" — 94 passed
  • focused Dotnet project finalizer tests — 4 passed
  • focused Entity Framework Core migration tests — 3 passed
  • focused Kubernetes finalizer test — 1 passed
  • Docker Compose provider-backed build-isolation test — failed before the fix, then passed
  • Python, TypeScript, Java, and Go code-generation snapshot tests — 1 passed per language
  • builds for Aspire.Hosting, Aspire.Hosting.Tests, Docker, Kubernetes, Azure App Containers, and Azure App Service — passed with zero warnings/errors
  • git diff --check — passed
  • no generated */api/*.cs baseline changed
  • dogfood aspire publish scenario — 11/11 steps passed
  • dogfood aspire deploy scenario — 11/11 steps passed

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

Copilot AI balanced review requested due to automatic review settings August 26, 2026 20:01
@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 -- 19720

Or

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

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

Adds publish/deploy finalization boundaries and updates first-party pipeline work to target them.

Changes:

  • Adds PublishFinalize and DeployFinalize pipeline steps.
  • Applies command-specific prerequisite gating without affecting build-only execution.
  • Updates integrations, tests, and generated SDK snapshots.
Show a summary per file
File Description
tests/Aspire.Hosting.Tests/Pipelines/DistributedApplicationPipelineTests.cs Tests finalizer ordering and gating.
tests/Aspire.Hosting.Kubernetes.Tests/KubernetesHelmChartTests.cs Updates Helm finalizer assertion.
tests/Aspire.Hosting.EntityFrameworkCore.Tests/EFMigrationPipelineTests.cs Updates migration assertions.
tests/Aspire.Hosting.Dotnet.Tests/DotnetProjectResourceTests.cs Covers finalizer command roots.
tests/Aspire.Hosting.Docker.Tests/DockerComposeTests.cs Tests build isolation.
tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts Updates TypeScript exports.
tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py Updates Python exports.
tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.java Updates Java exports.
tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go Updates Go exports.
src/Aspire.Hosting/Pipelines/WellKnownPipelineSteps.cs Defines public finalizer constants.
src/Aspire.Hosting/Pipelines/DistributedApplicationPipeline.cs Adds finalizers and prerequisite normalization.
src/Aspire.Hosting.Radius/Secrets/RadiusSecretStoreExtensions.cs Retargets validation gates.
src/Aspire.Hosting.Radius/Publishing/RadiusDeploymentPipelineStep.cs Retargets Radius deployment.
src/Aspire.Hosting.Radius/Publishing/RadiusBicepPublishingContext.cs Retargets Radius publishing.
src/Aspire.Hosting.Kubernetes/KubernetesResource.cs Retargets summary work.
src/Aspire.Hosting.Kubernetes/KubernetesHelmChartExtensions.cs Retargets Helm installation.
src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs Retargets Kubernetes work.
src/Aspire.Hosting.Kubernetes/Deployment/HelmDeploymentEngine.cs Retargets Helm deployment.
src/Aspire.Hosting.Kubernetes/CertManagerExtensions.cs Retargets issuer application.
src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs Retargets publish validation.
src/Aspire.Hosting.Foundry/PromptAgent/AzurePromptAgentResource.cs Retargets prompt-agent deployment.
src/Aspire.Hosting.Foundry/Project/ProjectResource.cs Retargets Foundry URL computation.
src/Aspire.Hosting.Foundry/HostedAgent/AzureHostedAgentResource.cs Retargets hosted-agent deployment.
src/Aspire.Hosting.EntityFrameworkCore/EFResourceBuilderExtensions.cs Retargets migration generation.
src/Aspire.Hosting.Docker/DockerComposeServiceResource.cs Retargets service summaries.
src/Aspire.Hosting.Docker/DockerComposeEnvironmentResource.cs Retargets Compose pipeline work.
src/Aspire.Hosting.Azure/AzureEnvironmentResource.cs Retargets Azure publish/deploy work.
src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebSiteResource.cs Retargets website summaries.
src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs Retargets App Service work.
src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppResource.cs Retargets container-app summaries.
src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs Retargets Container Apps work.

Review details

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 31/31 changed files
  • Comments generated: 7
  • Review effort level: Balanced

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

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

Fix sequential target resolution without changing callback-selected targets, and refresh affected tests and snapshots.

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

Copilot-Session: 5bb7f4d6-1610-4c03-b31d-24f9a33f8499
Copilot AI review requested due to automatic review settings August 27, 2026 03:16

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.

Review details

Suppressed comments (1)

src/Aspire.Hosting/Pipelines/DistributedApplicationPipeline.cs:770

  • This gates only steps directly RequiredBy the finalizer, so transitive normal work can still start before the command prerequisite. A concrete first-party path is Radius: deploy-radius-* is required by DeployFinalize and depends on publish-radius-*; only the deploy step gains deploy-prereq, leaving the nested Bicep publish step free to run concurrently with parameter/deployment initialization. The same occurs for any intermediate aggregate. Gate the finalizer's normal-work dependency closure (excluding the prerequisite closure) rather than only direct RequiredBySteps members.
            if (step.RequiredBySteps.Contains(finalizeStep, StringComparer.Ordinal)
                && !step.DependsOnSteps.Contains(prerequisiteStep, StringComparer.Ordinal))
            {
                step.DependsOnSteps.Add(prerequisiteStep);
  • Files reviewed: 42/42 changed files
  • Comments generated: 1
  • Review effort level: Balanced

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

Copilot-Session: 5bb7f4d6-1610-4c03-b31d-24f9a33f8499
Copilot AI review requested due to automatic review settings August 27, 2026 03:44

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.

Review details

Suppressed comments (1)

src/Aspire.Hosting/Pipelines/DistributedApplicationPipeline.cs:359

  • The diagnostics command still feeds its target-specific resolved graph into the section labeled “full pipeline execution.” When diagnostics is selected, no finalizer is active, so normal deploy/publish work lacks the prerequisite edges; the updated snapshots consequently show build work before deploy-prereq. That differs from an actual unfiltered execution, where both finalizers are active (and is explicitly covered by ExecuteAsync_WithoutSelectedStep_GatesBothFinalizerWorkloads). Build the full-analysis graph from the pre-finalization baseline and normalize it with no selected target before rendering it; keep the per-target clones for the what-if section.
                DumpDependencyGraphDiagnostics(stepsToAnalyze, simulationSteps, context);
  • Files reviewed: 42/42 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

/// this step so post-finalize hooks can run after normal work and before final command completion.
/// </remarks>
[AspireValue("WellKnownPipelineSteps")]
public const string DeployFinalize = "deploy-finalize";

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.

The other design we considered here was to have a "RunsAfter" concept, which means when pipeline step A runs, once it is done running we run the steps that "run after" it.

Was that option considered at all? It would be the more flexible option, so you could run after any step, and then if someone did aspire do stepA, your step would run.

This is a concept MSBuild has, but we cut it out of the initial pipeline design.

I wonder how hard it would be to add it.

I think this is my only high level concern with this approach. And it doesn't mean we can't have both. We could do the "finalize" option today, and still add the "RunsAfter" concept in the future.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think RunsAfter is a separate feature because it changes what aspire do stepA selects. We should define transitivity, consumer ordering, and failure semantics first. The finalizers solve the narrower completion-boundary problem without changing targeted execution, and we can add RunsAfter later.

Preserve configuration callback mutations while keeping resolution-local graph normalization, gate nested finalizer work behind command prerequisites, and render full diagnostics with unfiltered finalization boundaries.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings September 1, 2026 01:19

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.

Copilot review overview

Review tier: Balanced
Findings: None

@github-actions

github-actions Bot commented Sep 1, 2026

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

github-actions Bot commented Sep 1, 2026

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

github-actions Bot commented Sep 1, 2026

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.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 7c01c030-226e-41c5-81ca-a6483a1856df
Copilot AI review requested due to automatic review settings September 1, 2026 22:14

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.

Copilot review overview

🟡 Changes recommended

Azure Sandbox deployment still bypasses the finalizer, allowing post-finalize hooks to run before sandbox deployment completes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​Aspire.Hosting/​Pipelines/​DistributedApplicationPipeline.cs — The Azure Sandbox deploy step still uses RequiredBySteps = [WellKnownPipelineSteps.Deploy] in…

Description = "Aggregation step for all deploy operations. All deploy steps should be required by this step.",
Description = "Final aggregation step for deploy command completion. Post-finalize hooks should depend on deploy-finalize and be required by this step.",
Action = _ => Task.CompletedTask,
DependsOnSteps = [WellKnownPipelineSteps.DeployFinalize],
@adamint

Copy link
Copy Markdown
Member Author

Good call, this sandbox step is still required by deploy instead of deploy-finalize. I’ll move the edge and update the existing sandbox pipeline test so post-finalize hooks cannot overlap deployment.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 7c01c030-226e-41c5-81ca-a6483a1856df
Copilot AI review requested due to automatic review settings September 2, 2026 05:42

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.

Copilot review overview

🔵 Needs a closer look

RPC list-step requests can normalize against a different target and incorrectly introduce deploy prerequisites into build results.

Review tier: Balanced
Findings: 1 High severity

Pre-existing issues (1)
Severity Finding
High severity src/​Aspire.Hosting/​Pipelines/​DistributedApplicationPipeline.cs — The Azure Sandbox deploy step still uses RequiredBySteps = [WellKnownPipelineSteps.Deploy] in… View comment
Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Aspire.Hosting/Pipelines/DistributedApplicationPipeline.cs:640

  • ResolveStepsAsync now chooses command-specific gates only from PipelineOptions.Step, but AppHostRpcTarget.GetPipelineStepsAsync resolves through this method and then filters with request.Step (AppHostRpcTarget.cs:305-313). If an inspection host starts without --step and the RPC requests build, both finalizers are activated before filtering, so shared build work incorrectly acquires deploy-prereq. Thread the RPC target into the target-aware resolution path so list-step filtering uses the same target as normalization.

@github-actions

github-actions Bot commented Sep 2, 2026

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants