Skip to content

Propagate Go child resource errors through Build - #21969

Merged
David Pine (IEvangelist) merged 6 commits into
mainfrom
ievangelist-go-child-errors
Nov 10, 2026
Merged

David Pine (IEvangelist) merged 6 commits into
mainfrom
ievangelist-go-child-errors

Conversation

@IEvangelist

@IEvangelist David Pine (IEvangelist) commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

Generated Go AppHosts use fluent resource methods that return resource handles and record failures on those handles. Previously, unchecked child-resource failures could be missed, allowing Build() to proceed with an invalid application model.

This change records one owned error per failed wrapper on the shared generated client and combines all resource failures with errors.Join. DistributedApplicationBuilder.Err() and Build() now return the complete error summary, while independent resource additions continue after an earlier child fails so every resource error can be collected. Errors propagated through an already-failed chain are not recorded again, preserving wrapper-local first-error semantics without duplicating failures in the builder aggregate.

FormatError renders every joined CapabilityError, includes ordinary errors in mixed aggregates, and preserves the original contextual message for ordinary multi-wrapped errors. Error collection remains synchronized for callbacks and concurrent callers, and the existing cancellation behavior is unchanged.

User-facing usage

All failures from fluent resource declarations are returned by the existing Build() boundary:

builder.AddRedis("")
builder.AddPostgres("")

app, err := builder.Build()
if err != nil {
	log.Fatal(aspire.FormatError(err))
}

The formatted error includes both resource failures, and the build capability is not invoked after errors have been collected.

Validation

dotnet test --project tests\Aspire.Hosting.CodeGeneration.Go.Tests\Aspire.Hosting.CodeGeneration.Go.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

Passed: 130/130 tests, including the embedded Go runtime tests with race detection, multiple independent resource failures, concurrent error recording, duplicate-propagation prevention, and joined-error formatting.

dotnet test --project tests\Aspire.Hosting.RemoteHost.Tests\Aspire.Hosting.RemoteHost.Tests.csproj --no-launch-profile -- --filter-method "*.WithField_GeneratedSdkAcceptsStructuredValues" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

Passed: 5/5 tests.

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

A failed AddX or With* call records its error only on the handle it returns, so a caller that never checks that child saw builder.Err() == nil and Build() succeeded against a half-built model.

The client now owns a mutex-protected first-error sink. handleWrapperBase.setErr and newErroredHandleWrapperBase record into it, the generated builder's Err() returns the first error any handle of its client recorded, and Build() fails with it before the build request is sent. Handle Err() semantics and every public signature are unchanged.

Adds a runtime test with a fake AppHost: a failed child, or a failed With* call on a child, reaches builder.Err() and Build(); the first error wins; a clean run still builds; concurrent writers keep the first error.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
The test asserts that the builder reports one of the recorded errors and keeps reporting it. Which concurrent error is first is not defined, and the runtime tests do not run the race detector, so the name and comment say that instead of claiming the first error wins.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c8717a87-0ee5-4296-a6fd-ea6e2d91a57e
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

The public builder interface’s Err() documentation still incorrectly promises a wrapper-local error despite propagating unchecked child failures, so it and the affected snapshots need updating.

1 open issue
What changed in this PR

Propagates child-resource failures to the generated Go AppHost builder, so callers can rely on Err() and Build() instead of checking every resource handle.

Changes:

  • Records the first handle error on the shared client with synchronized access.
  • Makes builder error checks surface child failures before invoking the build capability.
  • Adds runtime tests for error propagation, first-error behavior, concurrency, and successful builds; updates generated snapshots.
File Description
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​Snapshots/​TwoPassScanningGeneratedAspire.verified.go Updates the generated builder error method.
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​Snapshots/​AtsGeneratedAspire.verified.go Captures generated builder and runtime error propagation.
tests/​Aspire.Hosting.CodeGeneration.Go.Tests/​AtsGoCodeGeneratorTests.cs Adds child-error propagation and build regression tests.
src/​Aspire.Hosting.CodeGeneration.Go/​Resources/​transport.go Stores the first client-wide error under a mutex.
src/​Aspire.Hosting.CodeGeneration.Go/​Resources/​base.go Reports wrapper errors to the shared client.
src/​Aspire.Hosting.CodeGeneration.Go/​AtsGoCodeGenerator.cs Emits the builder’s client-wide error check.

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 9, 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 -- 21969

Or

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

@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

FormatError renders only the first matching CapabilityError from aggregated failures, hiding additional capability and ordinary errors from logged output.

1 open issue
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

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.

🟡 Changes recommended

The error handling strips contextual labels from ordinary multi-wrapped errors, violating the documented preservation of non-SDK error messages and requiring a fix with regression coverage.

1 open issue
1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

This comment has been minimized.

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.

🔵 Needs a closer look

Human assessment is needed because a moderate-severity concern about incomplete error reporting was omitted from the published review.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danegsta David Negstad (danegsta) left a comment

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.

1 issue found: test problem (error identity comparisons against values that can be errors.Join results).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Tests selector

4 / 101 PR test projects · 4 PR jobs, from 8 changed files.

Selected PR test projects (4 / 101)

Aspire.Cli.EndToEnd.Tests, Aspire.Cli.Tests, Aspire.Hosting.CodeGeneration.Go.Tests, Aspire.Hosting.RemoteHost.Tests

Selected PR jobs (4)

cli-starter-validation, extension-e2e, polyglot, typescript-api-compat


How these were chosen — grouped by what changed

🔧 src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs (changed source)
→ 2 directly: Aspire.Cli.Tests, Aspire.Hosting.CodeGeneration.Go.Tests

📦 affected project Aspire.Hosting.CodeGeneration.Go
→ 1 test: Aspire.Cli.EndToEnd.Tests

🔧 src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go (changed source)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🔧 src/Aspire.Hosting.CodeGeneration.Go/Resources/transport.go (changed source)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/AtsGoCodeGeneratorTests.cs (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/AtsGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/EscapedMetadataGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go (changed test)
→ 1 directly: Aspire.Hosting.CodeGeneration.Go.Tests

🧪 tests/Aspire.Hosting.RemoteHost.Tests/Snapshots/KubernetesManifestTests.WithField_GeneratedSdkAcceptsStructuredValues_language=Go.verified.go (changed test)
→ 1 directly: Aspire.Hosting.RemoteHost.Tests

Job reasons

Job Triggered by
cli-starter-validation affected project Aspire.Hosting.CodeGeneration.Go
extension-e2e • src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs, src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go, src/Aspire.Hosting.CodeGeneration.Go/Resources/transport.go
• affected project Aspire.Hosting.CodeGeneration.Go
polyglot affected project Aspire.Hosting.CodeGeneration.Go
typescript-api-compat affected project Aspire.Hosting.CodeGeneration.Go

Selection computed for commit 7dd9ff8.

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.

🔵 Needs a closer look

Human assessment is needed because wrapped error aggregates can lose failures, while child-resource errors can prevent otherwise independent builder operations from continuing.

No open issues 🎉

Review effort: Balanced

@IEvangelist
David Pine (IEvangelist) merged commit 031536b into main Nov 10, 2026
225 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.1 milestone Nov 10, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

Pull request created: #2098

Generated by PR Documentation Check · copilot · auto · 26 AIC · ⌖ 1.17 AIC · ⊞ 7.4K

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

📝 Documentation has been drafted in microsoft/aspire.dev#2098 targeting release/17.0.

Updated go-apphost-conventions.mdx Errors section: Build()/builder.Err() now return all joined resource errors; FormatError renders every joined CapabilityError. Signals: polyglot_code_generator_changed (AtsGoCodeGenerator.cs, base.go, transport.go), pr_body_has_user_facing_section, pr_body_has_cli_flag_mention (false positive from test command).

Note

This draft PR needs human review before merging.

@IEvangelist

Copy link
Copy Markdown
Member Author

/backport to release/17.0

@github-actions

Copy link
Copy Markdown
Contributor

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

@aspire-repo-bot

Copy link
Copy Markdown
Contributor

David Pine (@IEvangelist) backporting to release/17.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Report failed Go child resources through the builder's Err and Build
Using index info to reconstruct a base tree...
M	src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs
M	src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go
M	src/Aspire.Hosting.CodeGeneration.Go/Resources/transport.go
M	tests/Aspire.Hosting.CodeGeneration.Go.Tests/AtsGoCodeGeneratorTests.cs
M	tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/AtsGeneratedAspire.verified.go
M	tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go
Falling back to patching base and 3-way merge...
Auto-merging src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs
Auto-merging src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go
CONFLICT (content): Merge conflict in src/Aspire.Hosting.CodeGeneration.Go/Resources/base.go
Auto-merging src/Aspire.Hosting.CodeGeneration.Go/Resources/transport.go
Auto-merging tests/Aspire.Hosting.CodeGeneration.Go.Tests/AtsGoCodeGeneratorTests.cs
Auto-merging tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/AtsGeneratedAspire.verified.go
CONFLICT (content): Merge conflict in tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/AtsGeneratedAspire.verified.go
Auto-merging tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Report failed Go child resources through the builder's Err and Build
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

David Pine (IEvangelist) added a commit that referenced this pull request Nov 10, 2026
Backport #21969, adapting error-state synchronization from its missing prerequisite and regenerating snapshots for the release branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 49a47166-ab67-4803-96ab-0c647ca2c169
Jose Perez Rodriguez (joperezr) added a commit that referenced this pull request Nov 12, 2026
## Description

Consolidate the Go AppHost release backports into one PR against
`release/17.0`, so shipping the complete Go changes requires one merge
rather than three remaining dependent backport merges.

David Pine's [November 11 release-order
message](https://teams.microsoft.com/l/message/19:86b689da3ce444f8952d0b79157f7562@thread.tacv2/1794418391504?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=f2e0b0b6-f130-46fa-8ec6-2ef4a7168ed2&parentMessageId=1794418391504&teamName=Aspire&channelName=Tactics%20And%20Shiproom&createdTime=1794418391504)
opens with "These backports, in this order to get Go AppHost release
ready:" and lists #22123, #22057, #22064, and #22121 in that order. The
existing backport descriptions specify the same sequence.

At preparation time, `release/17.0` points to
`9a97ab889bfb731de74ead0280be279ffdd000bf`, the already-merged #22123.
This branch first reverts that commit, then reapplies the four original
source commits with `git cherry-pick -x` in Pine's order:

1. #21827 / #22123: `e7ff435302acb88f9cfe7c9a61e3633e0f553f08` - harden
the Go SDK runtime and complete typed API export metadata.
2. #21969 / #22057: `031536bc9eea22ee9ce2cc1d31bfd30d0c14cfd2` -
propagate child resource errors through Build.
3. #21976 / #22064: `cd9e0e8d159d20f3cf7e64eda2415dcc3d40c168` - make
generated Go SDK APIs idiomatic.
4. #21874 / #22121: `209d9226e0463b638a5d68a034505e874cae9091` - add the
React frontend to the Go starter.

The revert exists only on this consolidation branch; the shared release
branch was not changed. All four source patches are unchanged (verified
with matching patch IDs), with their original source references retained
in commit messages. Earlier release prerequisites remain untouched. This
PR supersedes #22057, #22064, and #22121, which have been closed with
comments linking here. Existing review discussions remain available on
those PRs.

### User-facing usage

The starter provides a Go API, React frontend, and optional Redis:

```console
aspire new aspire-go-starter --non-interactive --use-redis-cache false
```

Use `--use-redis-cache true` to include Redis. Generated projects
contain `apphost.go`, `api/`, and `frontend/`.

### Breaking changes

The #21976 source change updates generated Go SDK signatures and names.
Existing Go AppHosts need to regenerate their SDK and update affected
calls. Shared ATS metadata changes are also included.

### Screenshots / Recordings

> **This PR includes UI changes.** Please add screenshots or screen
recordings so reviewers can evaluate the visual changes without running
locally.
>
> - For before/after comparisons, place them side-by-side or label them
clearly.
> - For interactive changes (animations, transitions, new flows), prefer
a short screen recording (GIF or video).
> - If you cannot capture visuals now, note what scenario to test and
mark this section as TODO.

<!-- Add screenshots/recordings here -->

TODO: Visual evidence was not captured. Run the generated Go starter and
inspect its React frontend, weather data through the Vite proxy, and
optional Redis scenario.

### Security considerations

These are unchanged source backports, not new security fixes. They
include Go transport/callback/cancellation handling and starter process,
proxy, and deployment behavior. Existing review comments on #22057 still
need disposition; consolidation does not resolve or invalidate those
comments. No new threat-model or security-review result is claimed here.

Fixes # (issue)

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [x] 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?
  - [x] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [ ] No

## Customer Impact

Go AppHost users receive the compatible generated SDK, child-resource
error propagation, runtime hardening, and a complete Go/React starter
together, without having to assemble dependent backports.

## Testing

Validation was performed on the consolidated release-based head
`065867bf777dd1e755e2718e8ac979a83fd37613`, not inherited from the
source PRs. Test processes used the repo-local `artifacts\tools\go\bin`
on PATH (`go version go1.27.4 windows/amd64`).

- `.\restore.cmd` - passed; pre-existing NuGet vulnerability warnings
were reported.
- `dotnet test --project
tests\Aspire.Hosting.CodeGeneration.Go.Tests\Aspire.Hosting.CodeGeneration.Go.Tests.csproj
--no-launch-profile -- --filter-not-trait "quarantined=true"
--filter-not-trait "outerloop=true"` - passed, **137 tests, 0 skipped**,
including Go build/vet/runtime and gofmt-dependent tests. An
intermediate rerun found generated frontend `node_modules` copied into
the scaffold test fixture; removing only generated `node_modules`/`dist`
artifacts restored the clean run without source changes.
- `dotnet test --project tests\Aspire.Cli.Tests\Aspire.Cli.Tests.csproj
--no-launch-profile -- --filter-method "*.GoStarterTemplate*"
--filter-method "*.GoStarterHonorsRedisChoice*" --filter-not-trait
"quarantined=true" --filter-not-trait "outerloop=true"` - passed, **10
tests**.
- `dotnet test --project
tests\Aspire.Hosting.Go.Tests\Aspire.Hosting.Go.Tests.csproj
--no-launch-profile -- --filter-method "*.WithModTidyIsIdempotent"
--filter-method "*.WithModTidyCreatesChildResource" --filter-not-trait
"quarantined=true" --filter-not-trait "outerloop=true"` - passed, **2
tests**.
- `dotnet test --project
tests\Aspire.Hosting.RemoteHost.Tests\Aspire.Hosting.RemoteHost.Tests.csproj
--no-launch-profile -- --filter-class "*.CancellationTokenRegistryTests"
--filter-not-trait "quarantined=true" --filter-not-trait
"outerloop=true"` - passed, **14 tests**. An earlier attempted filter
named `RemoteCancellationRegistryTests` selected zero tests; the
corrected run above is the validation result.
- `dotnet build
tests\Aspire.Cli.EndToEnd.Tests\Aspire.Cli.EndToEnd.Tests.csproj
--no-restore` - passed, **0 warnings/errors**. E2E execution was not run
on this Windows host.
- `npm ci` followed by `npm run build` in
`src\Aspire.Cli\Templating\Templates\go-starter\frontend` - passed;
TypeScript and Vite production build succeeded. Generated build
artifacts were removed afterward.
- `dotnet run --project tools\SelectTests -- --from origin/release/17.0
--to HEAD --explain` - passed; **0 unattributed changed files**.
`.gitattributes` selects all PR test projects/jobs, including starter
validation and polyglot.
- `dotnet test --project
tests\Infrastructure.Tests\Infrastructure.Tests.csproj
--no-launch-profile -- --filter-namespace
"Infrastructure.Tests.TestTriggerMap" --filter-not-trait
"quarantined=true" --filter-not-trait "outerloop=true"` - **364 passed,
22 failed**. Failures are Windows test-harness limitations: Bash
subprocesses cannot resolve backslash-delimited Windows script paths,
and five git-fixture cleanup cases throw `UnauthorizedAccessException`
deleting git objects. This suite is not claimed green; Linux/CI
validation is still required. No test or script source was changed.
- `git diff --check origin/release/17.0...HEAD` - passed.

Starter runtime, Docker deployment, screenshots, full polyglot
compatibility suites, and GitHub CI execution were not validated
locally.

## Risk

Medium. The source changes include shared ATS metadata, breaking
generated Go SDK changes, transport/error handling, and starter/frontend
deployment behavior. Consolidation preserves the source patches but does
not replace review or CI validation.

## Regression?

Unknown: the source material does not identify a regressed release.

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

4 participants