rootfs: a proven release failure carries the release's reason at every result boundary (hold, planned wake), so status words it as the release
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+205
−10
internal/activator/rootfs_wake_release_test.go+96 −2internal/activator/rootfsrelease.go+21 −6internal/activator/swaphold.go+5 −0internal/activator/wakeplan.go+4 −1internal/rollout/rootfs_release_outcomes_test.go+79 −1
diff --git a/internal/activator/rootfs_wake_release_test.go b/internal/activator/rootfs_wake_release_test.go| index 5568e9452..0fdd760ee 100644 |
| --- a/internal/activator/rootfs_wake_release_test.go |
| +++ b/internal/activator/rootfs_wake_release_test.go |
| @@ -373,6 +373,25 @@ func noBuildFailure(t *testing.T, evs *genLog) { |
| } |
| } |
| +// pinnedSettled is pinned read past a write in flight: the failed wake's |
| +// republish (wake(), after its entry goes) and the reaper's run in the |
| +// background, and the generations file's reader refuses the file while a |
| +// write holds its second link. It answers the first read that succeeds. |
| +func pinnedSettled(t *testing.T, a *Service, host, v string) bool { |
| + t.Helper() |
| + deadline := time.Now().Add(5 * time.Second) |
| + for { |
| + g, err := release.ReadGenerations(a.GenerationsFile) |
| + if err == nil { |
| + return g != nil && slices.Contains(g.Hosts[host], v) |
| + } |
| + if time.Now().After(deadline) { |
| + t.Fatalf("the generations file: %v", err) |
| + } |
| + time.Sleep(5 * time.Millisecond) |
| + } |
| +} |
| + |
| // raiseFence fences host as a maintenance operation would. |
| func raiseFence(a *Service, host string) { |
| a.mu.Lock() |
| @@ -949,7 +968,7 @@ func TestReleaseObligationOutlivesTheWake(t *testing.T) { |
| if n := r.b.leaseReleases(); n != 0 || r.index("release-lease") >= 0 { |
| t.Fatalf("the wake's lease was released (%d) while the release's unit may still write", n) |
| } |
| - if !pinned(t, r.a, host, "v2") { |
| + if !pinnedSettled(t, r.a, host, "v2") { |
| t.Fatal("the generations file no longer names v2 while its release is unproven") |
| } |
| if n := r.webStarts(); n != 0 { |
| @@ -1020,7 +1039,7 @@ func TestReleaseObligationRetriedUntilProven(t *testing.T) { |
| if p, l := r.index("release:proven:v2"), r.index("release-lease"); p < 0 || l < p { |
| t.Fatalf("order %v: the lease went back before the proof", r.b.events()) |
| } |
| - if pinned(t, r.a, host, "v2") { |
| + if pinnedSettled(t, r.a, host, "v2") { |
| t.Fatal("the generations file still names v2 after the proof") |
| } |
| ch := r.wake(r.a) |
| @@ -1202,3 +1221,78 @@ func TestHoldWebErrorBeforeExecIsNotABuildFailure(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// ---- whole-branch review round 1, P2 ------------------------------------ |
| + |
| +// A proven release failure carries the same reason at every result |
| +// boundary: "release: " or "release timed out: " before the release's own |
| +// text, as an overlap's SwapFailed does, so the rollout words it as the |
| +// release's (status.ReasonRelease, ReasonReleaseTimeout) and never as an |
| +// exit or a failed health check. Here a hold's SwapDown and a planned |
| +// first wake's GenFailed and GenFellBack. |
| +func TestReleaseFailureReasonsAtEveryBoundary(t *testing.T) { |
| + timed := map[string]release.Process{ |
| + release.ProcessWeb: {Command: []string{"/app/serve"}}, |
| + release.ProcessRelease: {Command: []string{"/app/bin/rails", "db:migrate"}, TimeoutSec: 1}, |
| + } |
| + for _, tc := range []struct { |
| + name string |
| + code, status, result string // the unit's end; "" waits for the timeout |
| + want string |
| + }{ |
| + {"an exit", "exited", "1", "exit-code", "release: " + (&ReleaseError{Build: "v2", Exit: 1}).Error()}, |
| + {"a signal", "killed", "9", "signal", "release: " + (&ReleaseError{Build: "v2", Signal: "9"}).Error()}, |
| + {"a timeout", "", "", "", "release timed out: " + (&ReleaseError{Build: "v2", TimedOut: true, Took: time.Second}).Error()}, |
| + } { |
| + t.Run("a hold, "+tc.name, func(t *testing.T) { |
| + f := newRelSwapFixture(t, true) |
| + armRootfsForTest(f.a) |
| + ownedWakeLeases(f.b.fakeBackend) |
| + if tc.code == "" { |
| + f.rb.rmu.Lock() |
| + f.rb.procs["v2"] = timed |
| + f.rb.rmu.Unlock() |
| + } |
| + ch := f.swapAsync(f.attempt(ModeHold)) |
| + u := f.nextUnit(t) |
| + if tc.code != "" { |
| + u.done(tc.code, tc.status, tc.result) |
| + } |
| + if res := waitSwap(t, ch); res.Outcome != SwapDown || res.Reason != tc.want { |
| + t.Fatalf("the hold = %+v; want down with reason %q", res, tc.want) |
| + } |
| + }) |
| + for _, fallback := range []bool{false, true} { |
| + name := "a planned first wake, " + tc.name |
| + if fallback { |
| + name += ", falling back" |
| + } |
| + t.Run(name, func(t *testing.T) { |
| + r := newWakeRelRig(t) |
| + p := WakePlan{Boot: r.next, Mode: ModeOverlap, FirstWake: true, Token: 1} |
| + if fallback { |
| + p.Fallback = &r.good |
| + } |
| + r.setPlan(p) |
| + if tc.code == "" { |
| + r.b.rmu.Lock() |
| + r.b.procs["v2"] = timed |
| + r.b.rmu.Unlock() |
| + } |
| + ch := r.wake(r.a) |
| + u := r.nextUnit(t) |
| + if tc.code != "" { |
| + u.done(tc.code, tc.status, tc.result) |
| + } |
| + waitErr(t, ch) |
| + kind := GenFailed |
| + if fallback { |
| + kind = GenFellBack |
| + } |
| + if ev := r.evs.wait(t, kind); ev.Reason != tc.want || ev.Failed.Version != "v2" { |
| + t.Fatalf("the wake's %s = %+v; want v2 with reason %q", kind, ev, tc.want) |
| + } |
| + }) |
| + } |
| + } |
| +} |
diff --git a/internal/activator/rootfsrelease.go b/internal/activator/rootfsrelease.go| index 7f8ed2ec3..ee6376dbe 100644 |
| --- a/internal/activator/rootfsrelease.go |
| +++ b/internal/activator/rootfsrelease.go |
| @@ -951,15 +951,30 @@ func (a *Service) releaseBeforeSwap(ctx context.Context, at Attempt, newest func |
| // (INV-R4). cancelled and refused are abandoned with executed as runRelease |
| // gave it: false when no unit started, true when one did (it ran, or may |
| // have). Never through classifyStep. |
| +// releaseFailureReason is the reason every result boundary gives a proven |
| +// release failure (a *ReleaseError in err's chain): "release timed out: " |
| +// or "release: " before the failure's own approved text (RFS-3-C05 to |
| +// C07), whatever wrapped it on the way. The rollout's reasonWord reads |
| +// these prefixes (status.ReasonRelease, ReasonReleaseTimeout) for an |
| +// overlap's SwapFailed, a hold's SwapDown and a planned wake's failure |
| +// alike (whole-branch review round 1, P2). ok is false when err carries |
| +// no ReleaseError. |
| +func releaseFailureReason(err error) (reason string, ok bool) { |
| + var rerr *ReleaseError |
| + if !errors.As(err, &rerr) { |
| + return "", false |
| + } |
| + if rerr.TimedOut { |
| + return "release timed out: " + rerr.Error(), true |
| + } |
| + return "release: " + rerr.Error(), true |
| +} |
| + |
| func releaseSwapResult(err error, executed, recordOpen bool) SwapResult { |
| switch classifyRelease(err, recordOpen) { |
| case releaseFailed: |
| - var rerr *ReleaseError |
| - prefix := "release: " |
| - if errors.As(err, &rerr) && rerr.TimedOut { |
| - prefix = "release timed out: " |
| - } |
| - return SwapResult{Outcome: SwapFailed, Reason: prefix + err.Error(), Executed: true} |
| + reason, _ := releaseFailureReason(err) |
| + return SwapResult{Outcome: SwapFailed, Reason: reason, Executed: true} |
| case releaseUnproven: |
| res := abandon(err) |
| res.Executed = true |
diff --git a/internal/activator/swaphold.go b/internal/activator/swaphold.go| index 81f896ade..5ae109bab 100644 |
| --- a/internal/activator/swaphold.go |
| +++ b/internal/activator/swaphold.go |
| @@ -339,6 +339,11 @@ func (a *Service) holdResult(sctx context.Context, at Attempt, newest func(strin |
| // An intentional stop ended the pinned wake (spec §6.4). |
| return abandon(errSwapStopped) |
| } |
| + // A failed release reads as the release's failure, as an overlap's |
| + // does (releaseFailureReason), not as the wake error that carried it. |
| + if reason, ok := releaseFailureReason(werr); ok { |
| + return SwapResult{Outcome: SwapDown, Gen: g, Reason: reason, Drain: drain} |
| + } |
| return SwapResult{Outcome: SwapDown, Gen: g, Reason: werr.Error(), Drain: drain} |
| } |
diff --git a/internal/activator/wakeplan.go b/internal/activator/wakeplan.go| index b54878d3c..343e5a5c3 100644 |
| --- a/internal/activator/wakeplan.go |
| +++ b/internal/activator/wakeplan.go |
| @@ -503,7 +503,10 @@ func (a *Service) spawnPlannedRelease(ctx context.Context, e *actEntry, rt regis |
| boot := plan.Boot |
| w.bootRan = true |
| if plan.FirstWake { |
| - w.failed, w.failReason = &boot, err.Error() |
| + // The reason the scheduler records and words is the release's, as |
| + // an overlap's is (releaseFailureReason). |
| + reason, _ := releaseFailureReason(err) |
| + w.failed, w.failReason = &boot, reason |
| } |
| if !canFall { |
| return nil, "", Gen{}, err |
diff --git a/internal/rollout/rootfs_release_outcomes_test.go b/internal/rollout/rootfs_release_outcomes_test.go| index a22b7beb1..b00308064 100644 |
| --- a/internal/rollout/rootfs_release_outcomes_test.go |
| +++ b/internal/rollout/rootfs_release_outcomes_test.go |
| @@ -12,13 +12,30 @@ package rollout |
| import ( |
| "context" |
| + "strings" |
| "testing" |
| "time" |
| "github.com/carlosframework/platform/internal/activator" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/status" |
| ) |
| +// assertFailureWord fails t unless the status report words host a's |
| +// failure of v2 as want. |
| +func assertFailureWord(t *testing.T, h *harness, want string) { |
| + t.Helper() |
| + for _, f := range h.m.Status().Failures { |
| + if f.Build == "v2" && f.Host == "a" { |
| + if f.Reason != want { |
| + t.Fatalf("status words v2's failure %q, want %q", f.Reason, want) |
| + } |
| + return |
| + } |
| + } |
| + t.Fatalf("status reports no failure of v2 on a: %+v", h.m.Status().Failures) |
| +} |
| + |
| // releaseRows is the activator's release contract as SwapResults, one row |
| // per release outcome and mode (TestReleaseSwapResultsAreTheContract |
| // pins the activator's side). |
| @@ -45,8 +62,19 @@ var releaseRows = []struct { |
| {"overlap, refused", activator.ModeOverlap, |
| activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "swap: another operation is in flight"}, |
| false, false, false}, |
| + {"overlap, a signal", activator.ModeOverlap, |
| + activator.SwapResult{Outcome: activator.SwapFailed, Reason: "release: " + (&activator.ReleaseError{Build: "v2", Signal: "9"}).Error(), Executed: true}, |
| + true, false, false}, |
| + // A hold's SwapDown carries the release's reason, as an overlap's |
| + // SwapFailed does (whole-branch review round 1, P2). |
| {"hold, failed", activator.ModeHold, |
| - activator.SwapResult{Outcome: activator.SwapDown, Reason: "start a: " + (&activator.ReleaseError{Build: "v2", Exit: 1}).Error(), Executed: true}, |
| + activator.SwapResult{Outcome: activator.SwapDown, Reason: "release: " + (&activator.ReleaseError{Build: "v2", Exit: 1}).Error(), Executed: true}, |
| + true, true, false}, |
| + {"hold, timed out", activator.ModeHold, |
| + activator.SwapResult{Outcome: activator.SwapDown, Reason: "release timed out: " + (&activator.ReleaseError{Build: "v2", TimedOut: true, Took: time.Minute}).Error(), Executed: true}, |
| + true, true, false}, |
| + {"hold, a signal", activator.ModeHold, |
| + activator.SwapResult{Outcome: activator.SwapDown, Reason: "release: " + (&activator.ReleaseError{Build: "v2", Signal: "9"}).Error(), Executed: true}, |
| true, true, false}, |
| {"hold, unproven", activator.ModeHold, |
| activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "start a: activator: a release command's unit is not proven stopped", Executed: true}, |
| @@ -103,6 +131,15 @@ func TestReleaseOutcomesThroughTheScheduler(t *testing.T) { |
| if _, marked := h.book.HoldRanOn("a"); marked != tc.marker { |
| t.Fatalf("the hold-ran marker is set %v; want %v", marked, tc.marker) |
| } |
| + if tc.record { |
| + // Status words the failure as the release's, never as an |
| + // exit or a failed health check. |
| + want := status.ReasonRelease |
| + if strings.HasPrefix(tc.res.Reason, "release timed out") { |
| + want = status.ReasonReleaseTimeout |
| + } |
| + assertFailureWord(t, h, want) |
| + } |
| }) |
| } |
| // A retried host's allowance is spent only by an attempt whose build |
| @@ -190,3 +227,44 @@ func TestAPlannedHoldReleaseThenRefusedWebKeepsTheMarker(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +// Whole-branch review round 1, P2, the planned wake's half: a first wake |
| +// whose release failed reports the failure with the release's reason |
| +// (activator spawnPlannedRelease, releaseFailureReason), and status words |
| +// it as the release's, whether the good build fell back or nothing did. |
| +func TestAPlannedWakeReleaseFailureIsWordedAsTheRelease(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + kind activator.GenEventKind |
| + reason string |
| + want string |
| + }{ |
| + {"failed, an exit", activator.GenFailed, "release: " + (&activator.ReleaseError{Build: "v2", Exit: 1}).Error(), status.ReasonRelease}, |
| + {"failed, a signal", activator.GenFailed, "release: " + (&activator.ReleaseError{Build: "v2", Signal: "9"}).Error(), status.ReasonRelease}, |
| + {"failed, timed out", activator.GenFailed, "release timed out: " + (&activator.ReleaseError{Build: "v2", TimedOut: true, Took: time.Minute}).Error(), status.ReasonReleaseTimeout}, |
| + {"fell back, an exit", activator.GenFellBack, "release: " + (&activator.ReleaseError{Build: "v2", Exit: 1}).Error(), status.ReasonRelease}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + h := newHarness(t, "a") |
| + r := h.rows.get("a") |
| + r.Runtime = registry.RuntimeRootfsV1 |
| + h.rows.put(r) |
| + h.onDisk() |
| + h.stage("v2") |
| + h.install("v2", "a") |
| + h.wakeHost("a") |
| + row := h.rows.get("a") |
| + p := h.m.Plan(context.Background(), row) |
| + if !p.FirstWake || p.Boot.Version != "v2" { |
| + t.Fatalf("plan %+v: want a first wake of v2", p) |
| + } |
| + ev := activator.GenEvent{Kind: tc.kind, Route: row, Mode: p.Mode, FirstWake: true, At: h.clock(), |
| + Failed: p.Boot, Reason: tc.reason, Token: p.Token, ConfigRev: p.ConfigRev, FailedUnder: p.FailedUnder} |
| + if tc.kind == activator.GenFellBack { |
| + ev.Gen = activator.Gen{Build: "v1"} |
| + } |
| + h.m.OnGen(ev) |
| + assertFailureWord(t, h, tc.want) |
| + }) |
| + } |
| +} |