carlos / platform Public

stateless: hold a failed release and keep waking the last good build

Fix F10 from the stateless replicas Plan 1 dev fleet smoke (#511).
Classify a failed stateless release through the existing rollout hold,
including a durable failed coordinator observation. Keep the incumbent
recoverable even when the requested swap mode is hold.

Recover the exact committed good version and digest without selecting a
new coordinator deploy or rerunning its release; recheck the good build
and existing lifetime/placement gates at final launch. Cover always-on
recovery, request wake after service restart, a later successful deploy,
and three mutation checks. Leave F11 for its mode-transition follow-up.

The census overlay is proposed for the controller's independent review.
Co-Authored-By: Codex (gpt-6-astra) <noreply@openai.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 6e60dfcc140d81bea1556c385ee3ac9f59901b57 parent 2914921
10 files changed, +453 −7
  • docs/superpowers/notes/census-proposal-stateless-failed-release-held.md +26 −0
  • internal/activator/stateless.go +24 −4
  • internal/activator/stateless_test.go +70 −0
  • internal/activator/statelessrelease.go +4 −1
  • internal/activator/swap.go +9 −1
  • internal/host/stateless_failed_release_test.go +290 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/stateless_failed_release_census_test.go +16 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-stateless-failed-release-held.tsv +12 −0

Intent

Attributed to this commit: 27.2 g CO₂e (3,419,825 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-failed-release-held, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/notes/census-proposal-stateless-failed-release-held.md b/docs/superpowers/notes/census-proposal-stateless-failed-release-held.md
new file mode 100644
index 000000000..a3d160fee
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-stateless-failed-release-held.md
@@ -0,0 +1,26 @@
+# Census approval: stateless-failed-release-held
+
+Ruling `census-ruling-stateless-failed-release-held`. The independent reviewer approves or rejects every change below, 2 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/activator/statelessrelease.go` `Service.PrepareStatelessRelease` | body | unchanged (17) | Distinguish an observed failed coordinator deploy from a transient release admission refusal using a wrapped existing error; no new read or coordinator write. |
+| `internal/activator/swap.go` `Service.Swap` | body | unchanged (13) | Classify a proven stateless release failure, or the same deploy's durable failed phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input. |
+
+Envelopes re-pinned: `internal/activator`.
+
+Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/activator/statelessrelease.go` `Service.PrepareStatelessRelease`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Read durable deploy evidence and canonical target via existing-record observation seam; use coordinator authority only for this path, persist releasing before exec and require proof plus SafeUntil before success; commandless binary verifies staged artifact separately; R11 lets the current term retake pending via the typed begin gate; R12 follows renewed SafeUntil through the existing command supervisor instead of a fixed initial context deadline; no new store polling or direct typed record writer callsite. Fix round 1 replaces the frozen-carrier re-observation with an identical released writer replay; command execution, proof and authority gates remain. Fix 3b round 1 I2 / R20: only the matching released branch calls the backend escrow initializer. Held authority is reused; absent trio can acquire through the existing coordinator adapter. No release rerun, deploy mutation, new record read or loop; existing final-exec checks from 3a remain unchanged. Final review I2: keep pre-releasing refusals pending; only a command ReleaseError or an actual artifact digest mismatch becomes failed. Releasing uncertainty still fences automatic reruns; begin, authority, execution and proof gates remain.
+- `internal/activator/swap.go` `Service.Swap`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- reads `internal/activator/stateless.go:Service.prepareStateless`: +registry:Digest, +registry:Version ×2, +whole:Route ×3; keeps legacy, task accepted-legacy
+- reads `internal/activator/stateless.go:Service.statelessFinalRecord`: +registry:Digest, +registry:Version, +whole:Route; keeps legacy, task accepted-legacy
+
+Seal: `526d434888d043a8b09d8fe196f6324782d6ca20d759b080f99daa528adf6a32` → `4bc6e5fc577c8104e5229f4c699171309025b4a55d52c47dd5ca8b84bbc3867e`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-stateless-failed-release-held.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/activator/stateless.go b/internal/activator/stateless.go
index fbcdebb9a..a2d7b1e80 100644
--- a/internal/activator/stateless.go
+++ b/internal/activator/stateless.go
@@ -320,9 +320,16 @@ func (a *Service) statelessFinalRecord(ctx context.Context, rt registry.Route) e
return ErrFenced
}
if prepared, ok := ctx.Value(statelessPreparedKey{}).(*statelessPreparation); ok {
- d := facts.ReplicaDeploy
- if d == nil || d.ID != prepared.deployID || d.Incarnation != identity.Incarnation || d.Target != (replicas.Build{Version: prepared.id.Version, Digest: prepared.digest}) || d.Phase != "released" {
- return ErrFenced
+ if prepared.recovery {
+ good, err := a.committedGood(rt)
+ if err != nil || good.Version != prepared.id.Version || good.Digest != prepared.id.Digest {
+ return ErrFenced
+ }
+ } else {
+ d := facts.ReplicaDeploy
+ if d == nil || d.ID != prepared.deployID || d.Incarnation != identity.Incarnation || d.Target != (replicas.Build{Version: prepared.id.Version, Digest: prepared.digest}) || d.Phase != "released" {
+ return ErrFenced
+ }
}
}
return a.statelessCurrent(ctx, rt)
@@ -379,6 +386,19 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re
if err != nil {
return ctx, err
}
+ observation, _ := observed.Value(replicaObservationKey{}).(replicaObservation)
+ // Recovery uses the committed good build without replacing the failed
+ // deploy or rerunning its predecessor's release. The final gate checks it again.
+ if id.Version != rt.Version && id.Version != "" && id.Digest != "" {
+ good, err := a.committedGood(rt)
+ if err != nil {
+ return ctx, err
+ }
+ if good.Version == id.Version && good.Digest == id.Digest {
+ prepared := &statelessPreparation{route: rt, id: id, digest: digest, observation: observation, recovery: true}
+ return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
+ }
+ }
if a.ReplicaDeployID == nil {
return ctx, ErrFenced
}
@@ -391,7 +411,6 @@ func (a *Service) prepareStateless(ctx context.Context, rt registry.Route, id re
if err := a.PrepareStatelessRelease(observed, launch, id, deployID); err != nil {
return ctx, err
}
- observation, _ := observed.Value(replicaObservationKey{}).(replicaObservation)
prepared := &statelessPreparation{route: rt, id: id, digest: digest, deployID: deployID, observation: observation}
return context.WithValue(observed, statelessPreparedKey{}, prepared), nil
}
@@ -403,6 +422,7 @@ type statelessPreparation struct {
digest string
deployID string
observation replicaObservation
+ recovery bool
}
func carryStatelessPreparation(ctx context.Context, p *statelessPreparation) context.Context {
diff --git a/internal/activator/stateless_test.go b/internal/activator/stateless_test.go
index a580b83a7..6a3e20abb 100644
--- a/internal/activator/stateless_test.go
+++ b/internal/activator/stateless_test.go
@@ -677,3 +677,73 @@ func TestStatelessSwapMissingRowKeepsRefusalOrder(t *testing.T) {
})
}
}
+
+func TestStatelessGoodRecoveryRechecksEvidence(t *testing.T) {
+ for _, change := range []string{"unchanged", "good-version", "good-digest", "route-lifetime", "record-lifetime", "assignment"} {
+ t.Run(change, func(t *testing.T) {
+ r := newWakeRelRig(t)
+ store := wireStatelessRig(r)
+ r.rt.Version = r.next.Version
+ r.rt.Stateless = true
+ r.routes.set(r.rt)
+ ctx, err := r.a.prepareStateless(context.Background(), r.rt, r.good, "canonical")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if store.snapshot() != nil || store.acquires != 0 {
+ t.Fatal("recovery started a deploy")
+ }
+ now := r.rt
+ switch change {
+ case "good-version":
+ now.GoodVersion = "other"
+ case "good-digest":
+ now.GoodDigest = "other"
+ case "route-lifetime":
+ now.Incarnation++
+ case "assignment":
+ now.Assigned = "moved"
+ case "record-lifetime":
+ r.a.cfg.Record = func(context.Context, registry.Route) (RecordFacts, error) {
+ return RecordFactsOf(provision.Record{Account: r.rt.Account, App: r.rt.App, Host: r.rt.Host, CreatedAt: time.Unix(2, 0)})
+ }
+ }
+ r.routes.set(now)
+ err = r.a.statelessFinalRecord(ctx, r.rt)
+ if (err == nil) != (change == "unchanged") {
+ t.Fatalf("final check: %v", err)
+ }
+ })
+ }
+}
+
+func TestStatelessFailedReleaseBeforeHoldKeepsRecovery(t *testing.T) {
+ r := newWakeRelRig(t)
+ store := wireStatelessRig(r)
+ r.setPlan(WakePlan{Boot: r.good, Mode: ModeOverlap})
+ if err := waitErr(t, r.wake(r.a)); err != nil {
+ t.Fatal(err)
+ }
+ result := make(chan SwapResult, 1)
+ at := Attempt{Host: r.rt.Host, Build: r.next.Version, StagedPath: r.next.StagedPath, Digest: r.next.Digest, Mode: ModeHold, SchedRev: 1}
+ go func() { result <- r.a.Swap(context.Background(), at, func(string) uint64 { return 1 }) }()
+ r.nextUnit(t).done("exited", "3", "exit-code")
+ select {
+ case res := <-result:
+ if res.Outcome != SwapFailed || res.Mode != ModeOverlap || !res.Executed {
+ t.Fatalf("failed release: %+v", res)
+ }
+ case <-time.After(5 * time.Second):
+ t.Fatal("release did not settle")
+ }
+ if d := store.snapshot(); d == nil || d.Phase != "failed" {
+ t.Fatalf("deploy: %+v", d)
+ }
+ res := r.a.Swap(context.Background(), at, func(string) uint64 { return 1 })
+ if res.Outcome != SwapFailed || res.Mode != ModeOverlap || res.Executed {
+ t.Fatalf("observed failure: %+v", res)
+ }
+ if g, ok := r.a.Current(r.rt.Host); !ok || g.Build != r.good.Version {
+ t.Fatalf("incumbent: %+v %v", g, ok)
+ }
+}
diff --git a/internal/activator/statelessrelease.go b/internal/activator/statelessrelease.go
index 008a19a32..703774b5e 100644
--- a/internal/activator/statelessrelease.go
+++ b/internal/activator/statelessrelease.go
@@ -3,6 +3,7 @@ package activator
import (
"context"
"errors"
+ "fmt"
"sync"
"time"
@@ -11,6 +12,8 @@ import (
"github.com/carlosframework/platform/internal/replicas"
)
+var errReplicaReleaseFailed = fmt.Errorf("release: %w", errReleaseNotPassed)
+
func (a *Service) PrepareStatelessRelease(ctx context.Context, rt registry.Route, id release.StagedIdentity, deployID string) error {
ctx, end := a.attemptCtx(ctx)
defer end()
@@ -47,7 +50,7 @@ func (a *Service) PrepareStatelessRelease(ctx context.Context, rt registry.Route
return ErrReplicaReleaseUnknown
}
if old.Phase == "failed" {
- return errReleaseNotPassed
+ return errReplicaReleaseFailed
}
}
if a.releaseOpen(rt.Host) {
diff --git a/internal/activator/swap.go b/internal/activator/swap.go
index 4fe0a3aa0..350f86c90 100644
--- a/internal/activator/swap.go
+++ b/internal/activator/swap.go
@@ -370,7 +370,15 @@ func (a *Service) Swap(ctx context.Context, at Attempt, newest func(host string)
if mode {
prepared, err := a.prepareStateless(ctx, route, id, digest)
if err != nil {
- return abandon(err)
+ res := releaseSwapResult(err, false, a.releaseOpen(at.Host))
+ if errors.Is(err, errReplicaReleaseFailed) {
+ res = SwapResult{Outcome: SwapFailed, Reason: err.Error()}
+ }
+ if res.Outcome == SwapFailed {
+ // Preparation failed before the incumbent stopped, even for a hold.
+ res.Mode = ModeOverlap
+ }
+ return res
}
ctx = prepared
}
diff --git a/internal/host/stateless_failed_release_test.go b/internal/host/stateless_failed_release_test.go
new file mode 100644
index 000000000..58cd842c6
--- /dev/null
+++ b/internal/host/stateless_failed_release_test.go
@@ -0,0 +1,290 @@
+package host
+
+import (
+ "context"
+ "encoding/json"
+ "fmt"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/activator"
+ "github.com/carlosframework/platform/internal/instancectl"
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/rollout"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+type failedReleaseGates struct{ *activator.ExecBackend }
+type failedReleaseBackend struct {
+ *plannedBackend
+ failedReleaseGates
+ relMu sync.Mutex
+ releases []string
+}
+
+func (b *failedReleaseBackend) Processes(rt registry.Route, id release.StagedIdentity) (map[string]release.Process, error) {
+ return map[string]release.Process{release.ProcessWeb: {Command: []string{"web"}}, release.ProcessRelease: {Command: []string{"release"}}}, nil
+}
+func (b *failedReleaseBackend) ReleaseEnv(context.Context, registry.Route) (map[string]string, error) {
+ return nil, nil
+}
+func (b *failedReleaseBackend) StartRelease(ctx context.Context, _ registry.Route, id release.StagedIdentity, _ map[string]string, _ io.Writer) (activator.CmdUnit, error) {
+ if err := activator.RunExecGate(ctx); err != nil {
+ return nil, err
+ }
+ b.relMu.Lock()
+ b.releases = append(b.releases, id.Version)
+ b.relMu.Unlock()
+ exit := "0"
+ if id.Version == "B" {
+ exit = "3"
+ }
+ return failedReleaseUnit{exit}, nil
+}
+func (b *failedReleaseBackend) releaseBuilds() []string {
+ b.relMu.Lock()
+ defer b.relMu.Unlock()
+ return slices.Clone(b.releases)
+}
+
+type failedReleaseUnit struct{ exit string }
+
+func (failedReleaseUnit) Invocation() string { return "release-invocation" }
+func (u failedReleaseUnit) Poll(context.Context) (instancectl.CmdStatus, error) {
+ result := "success"
+ if u.exit != "0" {
+ result = "exit-code"
+ }
+ return instancectl.CmdStatus{State: instancectl.CmdDone, InvocationID: u.Invocation(), Code: "exited", Status: u.exit, Result: result}, nil
+}
+func (failedReleaseUnit) StopAndSettle(context.Context) error { return nil }
+func (failedReleaseUnit) Terminal() activator.Terminal { return nil }
+func (b *failedReleaseBackend) StartGenExe(ctx context.Context, rt registry.Route, n uint64, _ bool, id release.StagedIdentity) (activator.Proc, activator.Gen, error) {
+ g, p, err := b.StartStaged(ctx, rt, activator.Gen{N: n, Build: id.Version, StagedPath: id.StagedPath, Digest: id.Digest})
+ return p, g, err
+}
+
+type failedReleaseEvents struct {
+ mu sync.Mutex
+ starts int
+ t *testing.T
+}
+
+func (*failedReleaseEvents) App(string, string, string, string) {}
+func (e *failedReleaseEvents) Event(_, _, _, _, msg string) {
+ e.mu.Lock()
+ defer e.mu.Unlock()
+ e.t.Log(msg)
+ if strings.Contains(msg, "starting build B (") {
+ e.starts++
+ }
+}
+func (e *failedReleaseEvents) count() int { e.mu.Lock(); defer e.mu.Unlock(); return e.starts }
+
+func TestStatelessFailedReleaseHeldProductionWiring(t *testing.T) {
+ prev := activator.GenerationsEnabled()
+ activator.SetGenerations(true)
+ t.Cleanup(func() { activator.SetGenerations(prev) })
+ resetRollout(t)
+ ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
+ defer cancel()
+ dir := t.TempDir()
+ opt := filepath.Join(dir, "opt")
+ t.Setenv("CARLOS_OPT_DIR", opt)
+ reg, err := registry.Open(filepath.Join(dir, "registry.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer reg.Close()
+ store := release.NewDirStore(filepath.Join(dir, "store"))
+ hibernate := false
+ rec := provision.Record{Hibernate: &hibernate, Schema: 1, Account: "bab", App: "shop", Host: "shop.example.com", Channel: "edge", Runtime: registry.RuntimeRootfsV1, CreatedAt: time.Now().UTC()}
+ if err := provision.CreateRecord(ctx, store, rec); err != nil {
+ t.Fatal(err)
+ }
+ open := func(context.Context) (release.Store, error) { return store, nil }
+ facts := haRecordFacts(open, nil)
+ cfg := activator.Config{Bucket: "test", Idle: time.Hour, Record: facts, ReplicaRecord: func(rt registry.Route) (activator.RecordFacts, error) { return facts(ctx, rt) }}
+ eb := &activator.ExecBackend{Cfg: cfg, DataDir: dir, OptDir: opt, RunDirOverride: filepath.Join(dir, "run"), Control: &rootfsWireControl{}, NestedOK: func() error { return nil }, RootfsOK: func(context.Context) error { return nil }, RootfsPlacement: func(context.Context, registry.Route) error { return nil }}
+ be := &failedReleaseBackend{plannedBackend: &plannedBackend{socket: healthySocket(t)}, failedReleaseGates: failedReleaseGates{eb}}
+ rt := registry.Route{Host: rec.Host, Account: rec.Account, App: rec.App, Kind: "instance", Status: "ready", Channel: rec.Channel, Runtime: rec.Runtime, CreatedAt: rec.CreatedAt.Unix(), Version: "A", Stateless: true, DBPath: provision.NestedDBPath(dir, rec.Host), Socket: filepath.Join(eb.RunDirOverride, "instances", provision.InstanceID(rec.Host), "app.sock")}
+ for _, ver := range []string{"A", "B", "C"} {
+ data := []byte("rootfs " + ver)
+ if err := release.StageArtifact(opt, rec.Account, ver, rec.App, data); err != nil {
+ t.Fatal(err)
+ }
+ path := release.VersionPath(opt, rec.Account, ver, rec.App)
+ digest, err := release.FileSHA256(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ // The backend simulates rootfs processes; the canonical artifact uses
+ // this test machine's architecture so the witness also runs on amd64.
+ manifest := release.Manifest{Schema: 1, App: rec.App, Version: ver, Kind: "binary", Stateless: true, Artifacts: map[string]release.Artifact{release.BoxPlatform(): {File: "image.squashfs", SHA256: digest}}}
+ raw, err := json.Marshal(manifest)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := store.Put(ctx, release.ManifestKey(rec.Account, rec.App, ver), raw, ""); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path+".manifest.json", raw, 0600); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := reg.Upsert(rt); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.MkdirAll(filepath.Dir(rt.Socket), 0755); err != nil {
+ t.Fatal(err)
+ }
+ coordinator := newCoordinatorClient(store, "", "", "box", "")
+ defer closeReplicaCoordinator(coordinator)
+ _, pub, err := release.GenerateKey()
+ if err != nil {
+ t.Fatal(err)
+ }
+ events := &failedReleaseEvents{t: t}
+ newRuntime := func() (*activator.Service, *rollout.Manager) {
+ svc := activator.New(cfg, be, reg)
+ svc.Routes = reg
+ svc.MarkRootfsSwept()
+ svc.Coordinator = coordinator
+ svc.ObserveReplicaRelease = activator.ObservedReplicaRelease
+ svc.StorageDeclaration = storageDeclaration(open)
+ svc.Logs = events
+ m := armRollout(ctx, overlapEnv(pub), svc, reg, dir, events, open)
+ if m == nil {
+ t.Fatal("rollout did not arm")
+ }
+ return svc, m
+ }
+ svc, m := newRuntime()
+ defer func() {
+ cleanup, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+ svc.Shutdown(cleanup)
+ m.Close(cleanup)
+ }()
+ wait := func(what string, pred func() bool) {
+ t.Helper()
+ deadline := time.Now().Add(25 * time.Second)
+ for time.Now().Before(deadline) {
+ if pred() {
+ return
+ }
+ time.Sleep(10 * time.Millisecond)
+ }
+ t.Fatalf("timed out: %s; builds=%v releases=%v status=%+v", what, be.builds(), be.releaseBuilds(), m.Status())
+ }
+ request := func() {
+ t.Helper()
+ row, err := reg.Get(rt.Host)
+ if err != nil || row == nil {
+ t.Fatalf("route: %v", err)
+ }
+ w := httptest.NewRecorder()
+ req := httptest.NewRequest(http.MethodGet, "http://"+rt.Host+"/", nil).WithContext(ctx)
+ svc.ServeHTTP(w, req, *row, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ builds := be.builds()
+ if len(builds) == 0 {
+ t.Error("no serving process")
+ return
+ }
+ fmt.Fprint(w, builds[len(builds)-1])
+ }))
+ if w.Code != 200 || w.Body.String() != "A" {
+ t.Fatalf("request: %d %s; builds=%v releases=%v", w.Code, w.Body.String(), be.builds(), be.releaseBuilds())
+ }
+ }
+ request()
+ wait("A good", func() bool { row, _ := reg.Get(rt.Host); return row.GoodVersion == "A" })
+ install := func(ver string) {
+ t.Helper()
+ if err := reg.SetVersions(rt.Host, ver, ""); err != nil {
+ t.Fatal(err)
+ }
+ rows, err := reg.List()
+ if err != nil {
+ t.Fatal(err)
+ }
+ m.Pass(rows)
+ }
+ install("B")
+ wantReason := "release: " + (&activator.ReleaseError{Build: "B", Exit: 3}).Error()
+ wait("B held", func() bool {
+ report := m.Status()
+ h := report.Hosts[rt.Host]
+ app := report.Apps[rt.Account+"/"+rt.App]
+ return h.HeldBy == "B" && h.Reason == status.ReasonRelease && app.Running == 0 && app.Queued == 0
+ })
+ book, err := rollout.OpenFailureBook(dir)
+ if err != nil {
+ t.Fatal(err)
+ }
+ failure, ok := book.Lookup(rt.Account, rt.App, "B")
+ if !ok || failure.Reason != wantReason {
+ t.Fatalf("failure: %+v, %v; want %s", failure, ok, wantReason)
+ }
+ t.Logf("held B: %s", wantReason)
+ // Wait beyond the abandoned-attempt backoff while feeding real passes.
+ until := time.Now().Add(17 * time.Second)
+ for time.Now().Before(until) {
+ install("B")
+ time.Sleep(100 * time.Millisecond)
+ }
+ if got := be.releaseBuilds(); !slices.Equal(got, []string{"A", "B"}) {
+ t.Fatalf("release retried: %v", got)
+ }
+ if got := events.count(); got != 1 {
+ t.Fatalf("rollout retried B %d times", got)
+ }
+ svc.Start()
+ g, ok := svc.Current(rt.Host)
+ if !ok {
+ t.Fatal("A stopped after failed B")
+ }
+ be.mu.Lock()
+ be.procs[g.N].exited.Store(true)
+ be.mu.Unlock()
+ wait("always-on rewakes A", func() bool { g, ok := svc.Current(rt.Host); return ok && g.Build == "A" && len(be.builds()) >= 2 })
+ request()
+ // Restart the agent after another exit. With no sweeper on the new
+ // service, the request must wake A from the durable hold.
+ g, _ = svc.Current(rt.Host)
+ be.mu.Lock()
+ be.procs[g.N].exited.Store(true)
+ be.mu.Unlock()
+ svc.Shutdown(ctx)
+ m.Close(ctx)
+ svc, m = newRuntime()
+ request()
+ if len(be.builds()) != 3 {
+ t.Fatalf("request did not wake A: %v", be.builds())
+ }
+ if slices.Contains(be.builds(), "B") {
+ t.Fatalf("B started: %v", be.builds())
+ }
+ if got := be.releaseBuilds(); !slices.Equal(got, []string{"A", "B"}) {
+ t.Fatalf("recovery reran a release: %v", got)
+ }
+ current, err := provision.GetRecord(ctx, store, rec.Account, rec.App, rec.Host)
+ if err != nil || current.ReplicaDeploy == nil || current.ReplicaDeploy.Phase != "failed" || current.ReplicaDeploy.Target.Version != "B" {
+ t.Fatalf("recovery replaced B's coordinator evidence: %+v %v", current, err)
+ }
+ install("C")
+ wait("C good", func() bool { row, _ := reg.Get(rt.Host); return row.GoodVersion == "C" })
+ if got := be.releaseBuilds(); !slices.Equal(got, []string{"A", "B", "C"}) {
+ t.Fatalf("later deploy: %v", got)
+ }
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index c4287ffb8..54dce76f4 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := oneBoxCoordinatorWriteCensusInventory()
+ inventory := statelessFailedReleaseWriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/stateless_failed_release_census_test.go b/internal/provision/stateless_failed_release_census_test.go
new file mode 100644
index 000000000..82a264f00
--- /dev/null
+++ b/internal/provision/stateless_failed_release_census_test.go
@@ -0,0 +1,16 @@
+package provision
+
+// F10 self-review: statelessRecordKey still carries an in-memory route;
+// it is not a bucket key. Recovery reads the committed good build and
+// skips deploy selection. New deploys retain the existing coordinator
+// writer. Independent review remains with the controller.
+func statelessFailedReleaseWriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), oneBoxCoordinatorWriteCensusInventory()...)
+ for i, entry := range entries {
+ if entry.File == "internal/activator/stateless.go" && entry.Unit == "Service.prepareStateless" {
+ entries[i] = censusEntry{"internal/activator/stateless.go", "Service.prepareStateless", "reference", "key:statelessRecordKey", "e0fbea336ffbbc8522dc7b418c29b6ff9bc1a21374ca2f130a385b9df9837c3f"}
+ return entries
+ }
+ }
+ panic("missing prior prepareStateless census entry")
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index d9cc40bbc..d0d912174 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -87,3 +87,4 @@ plan14-root-reads-stateless-replicas-3.tsv 703d9a189185e2075ec088bf9349e58132573
plan14-root-reads-region-ha-p3b.tsv face84b4c688cd3c179b0a34ced4d3521e71de8e63cbd45f21c27972c5b1a921
plan14-root-reads-stateless-coordinator-oneboxfleet.tsv face84b4c688cd3c179b0a34ced4d3521e71de8e63cbd45f21c27972c5b1a921
plan14-root-reads-region-ha-group-rtb.tsv 526d434888d043a8b09d8fe196f6324782d6ca20d759b080f99daa528adf6a32
+plan14-root-reads-stateless-failed-release-held.tsv 4bc6e5fc577c8104e5229f4c699171309025b4a55d52c47dd5ca8b84bbc3867e
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-failed-release-held.tsv b/internal/provision/testdata/plan14-root-reads-stateless-failed-release-held.tsv
new file mode 100644
index 000000000..15f0ac8c4
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-stateless-failed-release-held.tsv
@@ -0,0 +1,12 @@
+# Census overlay stateless-failed-release-held, written by census-propose (#369). census-ruling-stateless-failed-release-held, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-stateless-failed-release-held.md.
+# 2 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 2 new dispositions: 2 reads re-frozen at their disposition with the claim, 0 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy aad4e2a2cb0aef4896cc00df320bbc004b0aa16761cb91f162b343c2d1b26880 internal/activator/statelessrelease.go Service.PrepareStatelessRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Read durable deploy evidence and canonical target via existing-record observation seam; use coordinator authority only for this path, persist releasing before exec and require proof plus SafeUntil before success; commandless binary verifies staged artifact separately; R11 lets the current term retake pending via the typed begin gate; R12 follows renewed SafeUntil through the existing command supervisor instead of a fixed initial context deadline; no new store polling or direct typed record writer callsite. Fix round 1 replaces the frozen-carrier re-observation with an identical released writer replay; command execution, proof and authority gates remain. Fix 3b round 1 I2 / R20: only the matching released branch calls the backend escrow initializer. Held authority is reused; absent trio can acquire through the existing coordinator adapter. No release rerun, deploy mutation, new record read or loop; existing final-exec checks from 3a remain unchanged. Final review I2: keep pre-releasing refusals pending; only a command ReleaseError or an actual artifact digest mismatch becomes failed. Releasing uncertainty still fences automatic reruns; begin, authority, execution and proof gates remain.;rev3=census-ruling-stateless-failed-release-held;basis=Distinguish an observed failed coordinator deploy from a transient release admission refusal using a wrapped existing error; no new read or coordinator write. registry:Account@544,registry:App@574,registry:GoodDemand@3105,registry:GoodDigest@3090,registry:GoodVersion@3074,registry:Host@1304,registry:Host@224,registry:Host@3161,registry:Host@3219,registry:Host@3435,registry:Host@3503,registry:Host@601,whole:Route@1110,whole:Route@3228,whole:Route@3235,whole:Route@3787,whole:Route@483 14ef72589299281bc83954ac78f2773922f0007de7501f4476fade02673b88e5
+@legacy 5f8f5e80a6bb271432dbeb9b396bbda87db7932a3b80c1312536a02150ba8876 internal/activator/swap.go Service.Swap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.;rev3=census-ruling-stateless-failed-release-held;basis=Classify a proven stateless release failure, or the same deploy's durable failed phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input. registry:Stateless@1340,registry:Stateless@1369,whole:Route@1013,whole:Route@1063,whole:Route@1072,whole:Route@1257,whole:Route@1333,whole:Route@1446,whole:Route@1690,whole:Route@1769,whole:Route@2324,whole:Route@785,whole:Route@801 081906905d3224263009acde31462ead8a9db52e96036654c73a7c8ee840d63d
+@legacy 7cfec88b0b164b164be282308fe88a95930a377551e333bf62ee7429c4bf5c6d internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@1290,registry:Host@250,registry:Host@273,registry:Stateless@1685,registry:Version@1127,registry:Version@1260,whole:Route@1210,whole:Route@1354,whole:Route@1361,whole:Route@1681,whole:Route@1756,whole:Route@1848,whole:Route@1855,whole:Route@259,whole:Route@293,whole:Route@333,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@832 e0fbea336ffbbc8522dc7b418c29b6ff9bc1a21374ca2f130a385b9df9837c3f
+@legacy 7396a6ae26224501171086322b7b03b3112533627eb79380b9972ccdc9a723f3 internal/activator/stateless.go Service.statelessFinalRecord legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Fix 3a round 1 I2: one fresh record read at final exec, after pending write and release/escrow preparation. Reuse Fleet.Record result or cfg.Record, never both. Validate placement/config/lifetime and prepared deploy ID/target/released phase; registry checks before and after.;rev3=census-ruling-stateless-failed-release-held;basis=At final launch, a recovery must still match the committed good version and artifact digest. Adds the existing committedGood registry read. The current record's lifetime, placement and launch-input checks remain; a new deployment still requires matching released coordinator evidence. registry:Channel@398,registry:Digest@993,registry:Environment@431,registry:Region@492,registry:Runtime@464,registry:Version@954,whole:Route@122,whole:Route@1358,whole:Route@208,whole:Route@285,whole:Route@629,whole:Route@930 68d5d132d7d9235bd9ee765773fbe4132da8d777b37b5a5698cb813abb032988
+internal/activator/statelessrelease.go Service.PrepareStatelessRelease legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Read durable deploy evidence and canonical target via existing-record observation seam; use coordinator authority only for this path, persist releasing before exec and require proof plus SafeUntil before success; commandless binary verifies staged artifact separately; R11 lets the current term retake pending via the typed begin gate; R12 follows renewed SafeUntil through the existing command supervisor instead of a fixed initial context deadline; no new store polling or direct typed record writer callsite. Fix round 1 replaces the frozen-carrier re-observation with an identical released writer replay; command execution, proof and authority gates remain. Fix 3b round 1 I2 / R20: only the matching released branch calls the backend escrow initializer. Held authority is reused; absent trio can acquire through the existing coordinator adapter. No release rerun, deploy mutation, new record read or loop; existing final-exec checks from 3a remain unchanged. Final review I2: keep pre-releasing refusals pending; only a command ReleaseError or an actual artifact digest mismatch becomes failed. Releasing uncertainty still fences automatic reruns; begin, authority, execution and proof gates remain.;rev3=census-ruling-stateless-failed-release-held;basis=Distinguish an observed failed coordinator deploy from a transient release admission refusal using a wrapped existing error; no new read or coordinator write. registry:Account@544,registry:App@574,registry:GoodDemand@3105,registry:GoodDigest@3090,registry:GoodVersion@3074,registry:Host@1304,registry:Host@224,registry:Host@3161,registry:Host@3219,registry:Host@3435,registry:Host@3503,registry:Host@601,whole:Route@1110,whole:Route@3228,whole:Route@3235,whole:Route@3787,whole:Route@483 14ef72589299281bc83954ac78f2773922f0007de7501f4476fade02673b88e5
+internal/activator/swap.go Service.Swap legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Verify the target canonical mode and prepare its durable stateless release before stopping the incumbent. A mode change forces the existing proven hold path; same-mode stateless overlap uses local lifecycle gates and the final current-record check, without a serving lease. CI fix 1: defer a missing registry row to the existing release checks only for stateful rootfs overlap, preserving disabled/newest checks and committedGood refusal. Stateless modes, transitions, binary/foreign/hold paths still fence before preparation. No new reads. Final review C1/R26: include incumbent Gen.Stateless as declaration evidence, so only matching good stateful recovery/config attempts can skip canonical lookup. Fresh route, release, ownership and stop gates unchanged.;rev3=census-ruling-stateless-failed-release-held;basis=Classify a proven stateless release failure, or the same deploy's durable failed phase, through the existing SwapFailed hold mechanism. Preparation precedes stopping the incumbent, so report overlap semantics even if the requested swap is hold. Stateful path unchanged; no new root input. registry:Stateless@1340,registry:Stateless@1369,whole:Route@1013,whole:Route@1063,whole:Route@1072,whole:Route@1257,whole:Route@1333,whole:Route@1446,whole:Route@1690,whole:Route@1769,whole:Route@2324,whole:Route@785,whole:Route@801 081906905d3224263009acde31462ead8a9db52e96036654c73a7c8ee840d63d
+internal/activator/stateless.go Service.prepareStateless legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Task 3a: Capture RecordFacts from the existing record source, obtain the durable FailureBook deploy ID, and call Task 2 PrepareStatelessRelease with the canonical verdict/digest carrier. Carry a successful attempt through its hold only after another current-record check; no serving lease or polling loop. Fix 3a round 1 I2: preparation uses reconcile observations and records the successful deploy ID. Carry prepared evidence through hold; fresh backend read must confirm that same released deploy before web runs.;rev3=census-ruling-stateless-failed-release-held;basis=For recovery onto a different installed version's exact committed good version and artifact digest, retain recovery evidence without selecting or writing another deploy. Adds the existing committedGood registry read, with its route and incarnation check. Canonical storage declaration and observed lifetime gates remain. registry:Account@284,registry:Account@310,registry:App@324,registry:App@346,registry:Digest@1290,registry:Host@250,registry:Host@273,registry:Stateless@1685,registry:Version@1127,registry:Version@1260,whole:Route@1210,whole:Route@1354,whole:Route@1361,whole:Route@1681,whole:Route@1756,whole:Route@1848,whole:Route@1855,whole:Route@259,whole:Route@293,whole:Route@333,whole:Route@540,whole:Route@597,whole:Route@714,whole:Route@832 e0fbea336ffbbc8522dc7b418c29b6ff9bc1a21374ca2f130a385b9df9837c3f
+internal/activator/stateless.go Service.statelessFinalRecord legacy accepted-legacy accepted-legacy;rev3=census-ruling-stateless-replicas-1;basis=Fix 3a round 1 I2: one fresh record read at final exec, after pending write and release/escrow preparation. Reuse Fleet.Record result or cfg.Record, never both. Validate placement/config/lifetime and prepared deploy ID/target/released phase; registry checks before and after.;rev3=census-ruling-stateless-failed-release-held;basis=At final launch, a recovery must still match the committed good version and artifact digest. Adds the existing committedGood registry read. The current record's lifetime, placement and launch-input checks remain; a new deployment still requires matching released coordinator evidence. registry:Channel@398,registry:Digest@993,registry:Environment@431,registry:Region@492,registry:Runtime@464,registry:Version@954,whole:Route@122,whole:Route@1358,whole:Route@208,whole:Route@285,whole:Route@629,whole:Route@930 68d5d132d7d9235bd9ee765773fbe4132da8d777b37b5a5698cb813abb032988
+@coverage internal/activator e073ac0298f7c5df183bd08c9405cc2babf425123dcee161202adb72314e3b05