carlos / platform Public

rootfs: a release that ran is execution evidence on every wake outcome; a hold's web error before its exec abandons, never down

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 2b551efcfaa47126736b5dc8098b49b333e4a08a parent 0331376
5 files changed, +187 −3
  • internal/activator/activator.go +6 −0
  • internal/activator/rootfs_wake_release_test.go +82 −0
  • internal/activator/swaphold.go +32 −2
  • internal/activator/wakeplan.go +4 −1
  • internal/rollout/rootfs_release_outcomes_test.go +63 −0
diff --git a/internal/activator/activator.go b/internal/activator/activator.go
index 0ddc40e2b..6495aff0f 100644
--- a/internal/activator/activator.go
+++ b/internal/activator/activator.go
@@ -644,6 +644,12 @@ type actEntry struct {
// hold is abandoned, never down (spec §6.4), and its refusal is no
// member's event.
pinExec bool
+ // pinWebExec is the part of pinExec that is the web's own (Group R,
+ // R3 fix round 1): the pinned build's web ran or may have. A rootfs
+ // release that ran sets pinExec alone (markPinReleaseExec), so an
+ // error before the web's exec abandons the hold with Executed, never
+ // as the build's failure. Under a.mu.
+ pinWebExec bool
// holdNext is a hold swap waiting for this entry's stop to finish.
// finishStop installs its pinned wake. Written under a.mu.
holdNext *holdSpec
diff --git a/internal/activator/rootfs_wake_release_test.go b/internal/activator/rootfs_wake_release_test.go
index 318287fb4..5568e9452 100644
--- a/internal/activator/rootfs_wake_release_test.go
+++ b/internal/activator/rootfs_wake_release_test.go
@@ -52,6 +52,9 @@ type wakeRelBackend struct {
cmdStarts int
leases []*orderedLease
leaseUntil func() time.Time
+ // onProven, when set, runs once a release's unit is proven gone, before
+ // runRelease returns: a test's moment between the release and the web.
+ onProven func()
}
// orderedLease is a wake's ownedLease whose Release is in the order log.
@@ -125,6 +128,12 @@ func (b *wakeRelBackend) StartRelease(ctx context.Context, _ registry.Route, id
return errors.New("processes remained in carlos-instance-rootfs-cmd@shop.example.com's cgroup")
}
b.record("release:proven:" + ver)
+ b.rmu.Lock()
+ hook := b.onProven
+ b.rmu.Unlock()
+ if hook != nil {
+ hook()
+ }
return nil
}
b.rmu.Lock()
@@ -1120,3 +1129,76 @@ func TestNoReleaseOnTheClaimPath(t *testing.T) {
t.Fatalf("web starts %d, acquires %d; want neither", n, acq)
}
}
+
+// ---- R3 fix round 1 (Astra R3 round 1, P1 1 and P1 2) -------------------
+
+// P1 1: a planned first wake whose release passed and whose web is then
+// refused before its exec (a fence raised between the two) reports that
+// B ran (GenCancelled with Executed), so a hold leaves the hold-ran
+// marker; nothing is recorded against B and no web starts.
+func TestPlannedReleaseCountsWhenTheWebIsRefused(t *testing.T) {
+ for _, mode := range []SwapMode{ModeHold, ModeOverlap} {
+ t.Run(string(mode), func(t *testing.T) {
+ r := newWakeRelRig(t)
+ p := WakePlan{Boot: r.next, Mode: mode, FirstWake: true, Token: 1}
+ if mode == ModeOverlap {
+ p.Fallback = &r.good
+ }
+ r.setPlan(p)
+ r.b.rmu.Lock()
+ r.b.onProven = func() { raiseFence(r.a, r.rt.Host) }
+ r.b.rmu.Unlock()
+ ch := r.wake(r.a)
+ r.nextUnit(t).done("exited", "0", "success")
+ err := waitErr(t, ch)
+ if err == nil || verdictOf(err) != gateNoOwnership {
+ t.Fatalf("the wake = %v, want the web refused (NoOwnership)", err)
+ }
+ if n := r.webStarts(); n != 0 {
+ t.Fatalf("%d web starts after the fence", n)
+ }
+ ev := r.evs.wait(t, GenCancelled)
+ if !ev.Executed || ev.Gen.Build != "v2" || ev.Mode != mode || !ev.FirstWake {
+ t.Fatalf("the wake's end = %+v, want v2's first wake executed (its release ran)", ev)
+ }
+ noBuildFailure(t, r.evs)
+ })
+ }
+}
+
+// P1 2: on a hold, a release that passed is execution evidence for the
+// attempt, not for the web. A web error before its exec (here the staged
+// start's preparation) abandons the hold with Executed, never SwapDown,
+// and tells the member nothing; a web that ran and failed is still down.
+func TestHoldWebErrorBeforeExecIsNotABuildFailure(t *testing.T) {
+ t.Run("the web's preparation fails", func(t *testing.T) {
+ f := newRelSwapFixture(t, true)
+ armRootfsForTest(f.a)
+ ownedWakeLeases(f.b.fakeBackend)
+ f.b.gmu.Lock()
+ f.b.genErr = errors.New("write the launch file: no space left on device")
+ f.b.gmu.Unlock()
+ ch := f.swapAsync(f.attempt(ModeHold))
+ f.nextUnit(t).done("1", "0", "success")
+ res := waitSwap(t, ch)
+ if res.Outcome != SwapAbandoned || !res.Executed || res.Mode != ModeHold {
+ t.Fatalf("the hold = %+v; want abandoned, executed (the release ran), hold", res)
+ }
+ for _, m := range f.sink.msgs() {
+ if strings.HasPrefix(m, "wake failed") {
+ t.Fatalf("the member was told the build failed: %q", m)
+ }
+ }
+ })
+ t.Run("the web ran and failed", func(t *testing.T) {
+ f := newRelSwapFixture(t, true)
+ armRootfsForTest(f.a)
+ ownedWakeLeases(f.b.fakeBackend)
+ f.a.genHealth = func(context.Context, Gen) error { return errors.New("GET / answered 500") }
+ ch := f.swapAsync(f.attempt(ModeHold))
+ f.nextUnit(t).done("1", "0", "success")
+ if res := waitSwap(t, ch); res.Outcome != SwapDown || !res.Executed {
+ t.Fatalf("the hold = %+v; want down, executed (the web ran and failed)", res)
+ }
+ })
+}
diff --git a/internal/activator/swaphold.go b/internal/activator/swaphold.go
index 753c9466b..81f896ade 100644
--- a/internal/activator/swaphold.go
+++ b/internal/activator/swaphold.go
@@ -265,6 +265,7 @@ func (a *Service) holdResult(sctx context.Context, at Attempt, newest func(strin
<-hw.next.ready
a.mu.Lock()
g, werr, proc, execed := hw.next.gen, hw.next.err, hw.next.proc, hw.next.pinExec
+ buildFailable := pinBuildFailedLocked(hw.next, werr)
a.mu.Unlock()
defer func() { out.Executed = execed || werr == nil || startMayHaveRun(nil, werr) }()
var kept releaseKept
@@ -295,6 +296,13 @@ func (a *Service) holdResult(sctx context.Context, at Attempt, newest func(strin
// of the build ran, so this is no failure of it and nothing is held
// down (spec §6.4, §8.3; index P5/P6). The attempt is abandoned.
return abandon(werr)
+ case werr != nil && !buildFailable:
+ // The build's release ran (pinExec) and its web never did: an
+ // error before the web's exec (its preparation, its gate, the
+ // release phase's record) is no failure of the build (INV-R3;
+ // Astra R3 round 1, P1 2). Abandoned, Executed: the release may
+ // have migrated the database, so the hold-ran marker stands.
+ return abandon(werr)
case werr == nil:
if at.Canary {
// A canary must survive the settle before it counts (spec §6.2,
@@ -393,7 +401,7 @@ func (a *Service) startPinnedChecked(ctx context.Context, e *actEntry, rt regist
}
executed, rerr := a.runRelease(ctx, e, rt, id, watchOf(lease), gate)
if executed {
- a.markPinExec(e)
+ a.markPinReleaseExec(e)
}
if rerr != nil {
return nil, "", pin, holdReleaseResult(rerr, a.releaseOpen(rt.Host))
@@ -412,11 +420,30 @@ func (a *Service) startPinnedChecked(ctx context.Context, e *actEntry, rt regist
// refused before its stop on this base (claimsSwapRefusal), so that path
// is never a hold's here.
func (a *Service) markPinExec(e *actEntry) {
+ a.mu.Lock()
+ e.pinExec, e.pinWebExec = true, true
+ a.mu.Unlock()
+}
+
+// markPinReleaseExec records that e's pinned build's release ran (Group R,
+// R3): execution evidence for the attempt (pinExec, so Executed and the
+// hold-ran marker), not for the web (pinWebExec). A web error before its
+// exec then abandons the hold; it is never the build's failure.
+func (a *Service) markPinReleaseExec(e *actEntry) {
a.mu.Lock()
e.pinExec = true
a.mu.Unlock()
}
+// pinBuildFailedLocked reports whether err, a pinned wake's error, can be the
+// build's failure by its evidence: the release failed (a *ReleaseError,
+// its unit proven gone), or the web ran or may have (pinWebExec). A
+// release that ran with a web that never did is not. The caller holds a.mu.
+func pinBuildFailedLocked(e *actEntry, err error) bool {
+ var rerr *ReleaseError
+ return e.pinWebExec || errors.As(err, &rerr)
+}
+
// pinExecReached reports whether e's pinned wake has execution evidence.
func (a *Service) pinExecReached(e *actEntry) bool {
a.mu.Lock()
@@ -438,7 +465,10 @@ func (a *Service) wakeFailureEvent(e *actEntry, err error) (string, bool) {
if e.pin == nil {
return memberSafeWakeReason(err), true
}
- if !a.pinExecReached(e) || classifyStep(nil, err) != stepFailed || errors.Is(err, errPinMismatch) {
+ a.mu.Lock()
+ failable := pinBuildFailedLocked(e, err)
+ a.mu.Unlock()
+ if !a.pinExecReached(e) || !failable || classifyStep(nil, err) != stepFailed || errors.Is(err, errPinMismatch) {
log.Printf("activator: %s: hold's pinned wake refused or abandoned: %v", e.host, err)
return "", false
}
diff --git a/internal/activator/wakeplan.go b/internal/activator/wakeplan.go
index d8e0aafaa..0fc9fb8b8 100644
--- a/internal/activator/wakeplan.go
+++ b/internal/activator/wakeplan.go
@@ -417,7 +417,10 @@ func (a *Service) spawnPlanned(ctx context.Context, e *actEntry, rt registry.Rou
// recovery boot (normally recorded at step 2b already), the good build
// booted untried and the fallback. Each exec's own context only.
proc, ver, g, err := a.startPinnedAt(withRecoverySelection(ctx, plan, rt, boot.Version), rt, genOf(boot), gate, healthBy)
- w.bootRan = err == nil || startMayHaveRun(proc, err)
+ // B ran when its release did, whatever happens to its web (Astra R3
+ // round 1, P1 1): a hold first wake refused before the web's exec still
+ // leaves the hold-ran marker (afterWake's GenCancelled with Executed).
+ w.bootRan = released || err == nil || startMayHaveRun(proc, err)
if proc == nil && errors.Is(err, errNoTimeForVerdict) {
// B never ran: too little of its window was left for a verdict at
// the exec. The good build boots in its place through the same
diff --git a/internal/rollout/rootfs_release_outcomes_test.go b/internal/rollout/rootfs_release_outcomes_test.go
index 740be15f9..a22b7beb1 100644
--- a/internal/rollout/rootfs_release_outcomes_test.go
+++ b/internal/rollout/rootfs_release_outcomes_test.go
@@ -11,9 +11,12 @@ package rollout
// started.
import (
+ "context"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/registry"
)
// releaseRows is the activator's release contract as SwapResults, one row
@@ -51,6 +54,9 @@ var releaseRows = []struct {
{"hold, cancelled after it ran", activator.ModeHold,
activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "start a: swap: the lease was lost", Executed: true},
false, false, true},
+ {"hold, release ran, web refused before its exec", activator.ModeHold,
+ activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "start a: write the launch file: no space left on device", Executed: true},
+ false, false, true},
{"hold, cancelled before it ran", activator.ModeHold,
activator.SwapResult{Outcome: activator.SwapAbandoned, Reason: "start a: swap: the lease was lost"},
false, false, false},
@@ -127,3 +133,60 @@ func TestReleaseOutcomesThroughTheScheduler(t *testing.T) {
})
}
}
+
+// Astra R3 round 1, P1 1, through the real planner and failure book: a
+// rootfs hold first wake whose release passed and whose web was then
+// refused before its exec ends as the activator reports it, GenCancelled
+// with Executed (w.bootRan counts the release). That leaves the hold-ran
+// marker, so a later failure of the build elsewhere in its cohort refuses
+// the next wake instead of booting the good build on the build's migrated
+// database. Executed false (the bug) would have booted v1.
+func TestAPlannedHoldReleaseThenRefusedWebKeepsTheMarker(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ executed bool
+ }{
+ {"the release ran (the activator's report)", true},
+ {"nothing ran (control)", false},
+ } {
+ 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.mu.Lock()
+ h.demands["v2"] = "hold"
+ h.mu.Unlock()
+ 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" || p.Mode != activator.ModeHold {
+ t.Fatalf("plan %+v: want a hold first wake of v2", p)
+ }
+ h.m.OnGen(activator.GenEvent{Kind: activator.GenCancelled, Route: row, Mode: p.Mode, FirstWake: true, At: h.clock(),
+ Executed: tc.executed, Token: p.Token, ConfigRev: p.ConfigRev,
+ Gen: activator.Gen{Build: p.Boot.Version, StagedPath: p.Boot.StagedPath, Digest: p.Boot.Digest, Demand: p.Boot.Demand}})
+ mark, marked := h.book.HoldRanOn("a")
+ if marked != tc.executed || (marked && mark.Build != "v2") {
+ t.Fatalf("hold-ran marker %+v, %v; want set %v", mark, marked, tc.executed)
+ }
+ // A later failure of v2 elsewhere in its cohort.
+ h.book.Record(FailureRecord{Account: "bab", App: "blog", Build: "v2", Host: "x", At: h.clock()})
+ h.advance(time.Second)
+ h.wakeHost("a")
+ next := h.m.Plan(context.Background(), h.rows.get("a"))
+ if tc.executed {
+ if next.Refuse == "" || next.Boot.Version == "v1" {
+ t.Fatalf("after a hold's release ran: plan %+v; want the wake refused, never the good build", next)
+ }
+ return
+ }
+ if next.Boot.Version != "v1" {
+ t.Fatalf("control: plan %+v; want the good build v1", next)
+ }
+ })
+ }
+}