fix(iac): refresh-outputs tolerates ErrResourceNotFound (ghosts) — skip+continue#572
Merged
Merged
Conversation
…ip+continue Ghost resources (deleted out-of-band, still in persisted IaC state) previously caused refresh-outputs to hard-fail with ErrResourceNotFound before the downstream ghost-prune phase could act on them. refreshOne now treats errors.Is(err, interfaces.ErrResourceNotFound) as a skip-and-continue condition: leaves the ghost's Outputs unchanged (state remains intact for prune), returns nil so the batch proceeds. All other Read errors still propagate as hard failures. Surfaced by TC2 cutover run 25476341708 (ghost Droplet coredump-staging-pg DO ID 568721969 aborted the cascade before Phase-1 ghost-prune ran). - iac/refreshoutputs/refresh.go: ghost skip logic in refreshOne - iac/refreshoutputs/refresh_test.go: TestRefresh_TolerateGhosts + TestRefresh_PropagateNonGhostError - decisions/0011-refresh-outputs-tolerate-ghosts.md: ADR Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adjusts wfctl infra refresh-outputs to tolerate “ghost” resources (cloud reports not-found) by skipping them instead of hard-failing, allowing downstream ghost-prune to handle cleanup.
Changes:
- Treat
interfaces.ErrResourceNotFoundfrom providerReadas skip+continue inrefreshOne. - Add tests covering ghost tolerance and non-ghost error propagation.
- Add ADR documenting the decision and alternatives.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| iac/refreshoutputs/refresh.go | Skip ErrResourceNotFound during output refresh to avoid aborting on ghosts |
| iac/refreshoutputs/refresh_test.go | Add tests for ghost skipping and normal error propagation |
| decisions/0011-refresh-outputs-tolerate-ghosts.md | Document the behavior change and rationale |
| // unchanged so that the downstream ghost-prune phase (wfctl infra apply | ||
| // --refresh) can act on it. This separates "refresh outputs of live resources" | ||
| // from "remove state entries for gone resources" — they are orthogonal. | ||
| func refreshOne(ctx context.Context, p interfaces.IaCProvider, dst *interfaces.ResourceState, src interfaces.ResourceState) error { |
Comment on lines
93
to
104
| ref := interfaces.ResourceRef{Name: src.Name, Type: src.Type, ProviderID: src.ProviderID} | ||
| live, err := d.Read(ctx, ref) | ||
| if err != nil { | ||
| if errors.Is(err, interfaces.ErrResourceNotFound) { | ||
| // Ghost: cloud reports the resource does not exist. Leave Outputs | ||
| // unchanged; the caller's --refresh phase (or operator) handles | ||
| // ghost-prune separately. Refresh-outputs is non-mutating for | ||
| // ghosts: state remains intact for the prune phase to act on. | ||
| return nil | ||
| } | ||
| return fmt.Errorf("could not refresh %q: %w", src.Name, err) | ||
| } |
| @@ -0,0 +1,57 @@ | |||
| # 0011 — refresh-outputs tolerates ErrResourceNotFound (ghosts) — skip with warn, not error | |||
… "warn" Copilot round 1 findings: 1. refreshOne ghost path now explicitly assigns dst.Outputs = src.Outputs so the function is self-contained and does not depend on the caller having pre-copied src into dst (even though Refresh does — defensive). 2. ADR title + refreshOne godoc changed from "skip with warn" to "skip silently" — no warning mechanism exists in refreshOne (no logger param); the original phrasing was misleading. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
| // does not rely on the caller having pre-copied src into dst. | ||
| // The caller's --refresh phase (or operator) handles ghost-prune | ||
| // separately; refresh-outputs is non-mutating for ghosts. | ||
| dst.Outputs = src.Outputs |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a sequencing gap in
wfctl infra refresh-outputs(subcommand) and theWFCTL_REFRESH_OUTPUTSapply-time pre-step where ghost resources (cloud reports not-found) cause hard-failure instead of being skipped for the downstream ghost-prune phase to handle.Surfaced by: core-dump TC2 cutover run 25476341708 — ghost Droplet
coredump-staging-pg(DO ID 568721969, deleted out-of-band) caused refresh-outputs to error withiac: resource not foundbefore Phase 1.0 ghost-prune could act on it.Root cause:
iac/refreshoutputs/refresh.go::refreshOnepropagated every Read error uniformly.ErrResourceNotFound(ghost) was not differentiated from transient/auth errors.Changes
iac/refreshoutputs/refresh.go:refreshOnetreatserrors.Is(err, interfaces.ErrResourceNotFound)as a skip+continue condition — leaves the ghost's stateOutputsunchanged, returns nil so the batch proceeds. All other errors still propagate as hard failures.iac/refreshoutputs/refresh_test.go:TestRefresh_TolerateGhosts(skip ghost, refresh live resources, no error) +TestRefresh_PropagateNonGhostError(non-ghost errors propagate, existing semantics unchanged).decisions/0011-refresh-outputs-tolerate-ghosts.md: ADR documenting the decision and alternatives considered.Test plan
go test ./iac/refreshoutputs/...PASS (5 tests)go test -race ./iac/refreshoutputs/...PASSgo vet ./iac/refreshoutputs/...cleangolangci-lint run ./iac/refreshoutputs/...0 issues🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com