carlos / platform Public

rootfs: refuse mixed versions up front (whole-branch P1-2)

The console's barrier: a rootfs create needs every fresh active box of
the placement (a fleet's registered active boxes; a single-tenant
region's boxes) to report a platform release at or above
RootfsLifecycleFloor. Missing or unparseable counts as below. C05/C06
as before, C07 when the evidence is unreadable.

The box's backstop: before minting a row for a record with no runtime,
Reconcile reads the app's kind marker (one GET per app per pass, only
for a record with no row yet) and leaves a rootfs app's record
unmaterialized and logged; an unreadable marker defers the mint.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ceea63533fd9b67b98e1e523bca6813e6a7917a8 parent 6189a9d
5 files changed, +315 −10
  • internal/console/rootfs.go +56 −9
  • internal/console/rootfs_test.go +56 −1
  • internal/provision/reconcile.go +45 −0
  • internal/provision/reconcile_rootfs_backstop_test.go +150 −0
  • internal/release/rootfs_ship.go +8 −0
diff --git a/internal/console/rootfs.go b/internal/console/rootfs.go
index 90b6c5bfa..d49190554 100644
--- a/internal/console/rootfs.go
+++ b/internal/console/rootfs.go
@@ -152,7 +152,8 @@ func (s *Server) rootfsPlacementRefusal(reg consoleRegistry, acct *Account, app,
// rootfsReadyRefusal is the box-local half of the predicate
// (host.RootfsBoxReady, as each box publishes it): one fresh box of the
-// placement that says rootfs_ready is enough. For a fleet the candidates are
+// placement that says rootfs_ready is enough, given the version barrier
+// below. For a fleet the candidates are
// its heartbeats whose label the registry lists as an active box of that
// fleet, the same join the fleet page makes, so a detached box's heartbeat,
// still fresh for a while, never counts. Otherwise they are the platform's
@@ -160,16 +161,42 @@ func (s *Server) rootfsPlacementRefusal(reg consoleRegistry, acct *Account, app,
// pools, so on a single-tenant deployment a box serving dedicated pools only
// still counts; the box's own refusal covers it.
//
-// None ready: 409 C05 naming the fleet, or C06 naming the region. A read
-// that fails, or any heartbeat that could not be read (LoadBoxesComplete:
-// incomplete evidence is neither ready nor not ready): 503 C07.
+// The mixed-version barrier (whole-branch review P1-2; ruling: refuse up
+// front): every fresh candidate must also run a platform release at or
+// above release.RootfsLifecycleFloor. A box from before it (v0.28.17 on
+// already publishes rootfs_ready) decodes a rootfs record without its
+// runtime and mints a binary row for it, which no later upgrade repairs,
+// and any box of the placement reconciles the record, not only the one
+// that serves it. A release that is missing or does not parse (a sha,
+// "dev") counts as below. Stale boxes are not candidates, as for
+// readiness.
+//
+// None ready, or a fresh candidate below the floor: 409 C05 naming the
+// fleet, or C06 naming the region (their second sentence names the
+// platform release). A read that fails, or any heartbeat that could not
+// be read (LoadBoxesComplete: incomplete evidence is neither ready nor not
+// ready): 503 C07.
func (s *Server) rootfsReadyRefusal(ctx context.Context, reg consoleRegistry, placed, region string) *doorRefusal {
unreadable := &doorRefusal{http.StatusServiceUnavailable, rootfsReadyUnreadableMsg}
if s.cfg.Releases == nil {
return unreadable
}
now := time.Now()
- ready := func(b status.Box) bool { return !status.BoxStale(b, now, status.SnapshotPeriod) && boxRootfsReady(b) }
+ fresh := func(b status.Box) bool { return !status.BoxStale(b, now, status.SnapshotPeriod) }
+ // admits: some fresh candidate is ready, and none is below the floor.
+ admits := func(candidates []status.Box) bool {
+ anyReady := false
+ for _, b := range candidates {
+ if !fresh(b) {
+ continue
+ }
+ if !boxAtRootfsFloor(b) {
+ return false
+ }
+ anyReady = anyReady || boxRootfsReady(b)
+ }
+ return anyReady
+ }
if fleet, ok := registry.FleetPlacement(placed); ok {
regBoxes, err := reg.ListFleetBoxes(fleet)
if err != nil {
@@ -187,11 +214,15 @@ func (s *Server) rootfsReadyRefusal(ctx context.Context, reg consoleRegistry, pl
log.Printf("console: rootfs ready: load fleet %s's heartbeats: complete %v, %v", fleet, complete, err)
return unreadable
}
+ var candidates []status.Box
for _, b := range hbs {
- if active[b.Label] && ready(b) {
- return nil
+ if active[b.Label] {
+ candidates = append(candidates, b)
}
}
+ if admits(candidates) {
+ return nil
+ }
return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsFleetNotReadyMsg, fleet)}
}
hbs, complete, err := status.LoadBoxesComplete(ctx, s.cfg.Releases)
@@ -199,11 +230,15 @@ func (s *Server) rootfsReadyRefusal(ctx context.Context, reg consoleRegistry, pl
log.Printf("console: rootfs ready: load the platform's heartbeats: complete %v, %v", complete, err)
return unreadable
}
+ var candidates []status.Box
for _, b := range hbs {
- if s.homeRegionIn(b.Region) == region && ready(b) {
- return nil
+ if s.homeRegionIn(b.Region) == region {
+ candidates = append(candidates, b)
}
}
+ if admits(candidates) {
+ return nil
+ }
return &doorRefusal{http.StatusConflict, fmt.Sprintf(rootfsRegionNotReadyMsg, s.rootfsRegionName(ctx, region))}
}
@@ -224,6 +259,18 @@ func boxRootfsReady(b status.Box) bool {
return b.Metrics != nil && b.Metrics.RootfsReady
}
+// boxAtRootfsFloor reports whether a box's heartbeat names a platform
+// release (BoxMetrics.Release, its version.Build) that parses at or above
+// release.RootfsLifecycleFloor, the first release whose record reader
+// keeps a rootfs record's runtime. Missing or unparseable is false.
+func boxAtRootfsFloor(b status.Box) bool {
+ if b.Metrics == nil {
+ return false
+ }
+ v, ok := release.ParseReleaseVersion(b.Metrics.Release)
+ return ok && v.Compare(release.RootfsLifecycleFloor) >= 0
+}
+
// rootfsCreateRefusal is the create door's refusals for a socket-backed
// instance of an app whose creating release is rootfs (Plan 4 Task 3), in
// this order: a seeded create (C09: copying a database into a new rootfs
diff --git a/internal/console/rootfs_test.go b/internal/console/rootfs_test.go
index 834423bb6..dfc771837 100644
--- a/internal/console/rootfs_test.go
+++ b/internal/console/rootfs_test.go
@@ -47,13 +47,20 @@ func shipRootfsRelease(t *testing.T, fx *consoleFixture, app, version string, hi
// writeFleetBox writes one heartbeat for a box of fleet (fleet == "" is a
// platform box in region).
func writeFleetBox(t *testing.T, fx *consoleFixture, fleet, label, region string, ready bool, at time.Time) {
+ t.Helper()
+ writeFleetBoxOn(t, fx, fleet, label, region, ready, at, "v"+release.RootfsLifecycleFloor.String())
+}
+
+// writeFleetBoxOn is writeFleetBox with the box's platform release named
+// (BoxMetrics.Release; "" for a heartbeat that names none).
+func writeFleetBoxOn(t *testing.T, fx *consoleFixture, fleet, label, region string, ready bool, at time.Time, rel string) {
t.Helper()
var s release.Store = fx.rel
if fleet != "" {
s = release.NewPrefixStore(fx.rel, "fleets/"+fleet+"/")
}
b := status.Box{GeneratedAt: at, Label: label, Region: region,
- Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: ready}}
+ Metrics: &status.BoxMetrics{Layout: &status.LayoutReport{Mode: "nested"}, RootfsReady: ready, Release: rel}}
if err := status.WriteBox(context.Background(), s, b); err != nil {
t.Fatal(err)
}
@@ -300,6 +307,54 @@ func TestRootfsReadyOnASingleTenantRegion(t *testing.T) {
}
}
+// [Whole-branch review P1-2] The mixed-version barrier: every fresh box
+// of the placement must run a platform release at or above the rootfs
+// floor, since a box from before it (one that already publishes
+// rootfs_ready) mints a binary row for a rootfs record. An old box among
+// new ones refuses, so does a heartbeat naming no release or one that does
+// not parse; all new passes; a stale old box, like a stale ready one, is
+// not a candidate. On a fleet (C05) and a single-tenant region (C06).
+func TestRootfsReadyRefusesAPlacementWithABoxBelowTheFloor(t *testing.T) {
+ fx, reg := rootfsDoorWorld(t, "code-rfs-ready-floor")
+ fx.srv.cfg.DeploymentSingleTenant = true
+ now := time.Now()
+ for _, l := range []string{"pi-1", "pi-2", "pi-3"} {
+ registerFleetBox(t, reg, "home", l)
+ }
+ fleetWant := fmt.Sprintf(rootfsFleetNotReadyMsg, "home")
+ regionWant := fmt.Sprintf(rootfsRegionNotReadyMsg, "home")
+ write := func(label, rel string, ready bool, at time.Time) {
+ t.Helper()
+ writeFleetBoxOn(t, fx, "home", label, "", ready, at, rel)
+ writeFleetBoxOn(t, fx, "", label, "", ready, at, rel)
+ }
+ check := func(what string, refused bool) {
+ t.Helper()
+ for placed, want := range map[string]string{"fleet/home": fleetWant, "": regionWant} {
+ ref := fx.srv.rootfsReadyRefusal(context.Background(), reg, placed, "")
+ if refused && (refStatus(ref) != http.StatusConflict || ref.Msg != want) {
+ t.Errorf("%s, %q: %v; want 409 %q", what, placed, ref, want)
+ }
+ if !refused && ref != nil {
+ t.Errorf("%s, %q: %v; want admitted", what, placed, ref)
+ }
+ }
+ }
+ write("pi-1", "v0.29.0", true, now)
+ write("pi-2", "v0.30.1", false, now)
+ check("all new", false)
+ for _, rel := range []string{"v0.28.17", "v0.28.99", "", "4f3c2a1", "dev"} {
+ write("pi-3", rel, rel == "v0.28.17", now)
+ check("an old or unplaceable box ("+rel+") beside new ones", true)
+ }
+ write("pi-3", "v0.28.17", true, now.Add(-2*time.Hour))
+ check("a stale old box", false)
+ // A fresh heartbeat with no metrics names no release.
+ if boxAtRootfsFloor(status.Box{Label: "pi-1"}) {
+ t.Error("a box with no metrics read as at the floor")
+ }
+}
+
func TestRootfsReadyRefusesWhenItCannotLook(t *testing.T) {
fx, reg := rootfsDoorWorld(t, "code-rfs-ready-err")
registerFleetBox(t, reg, "home", "pi-1")
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go
index bda1a9247..8418bc3d8 100644
--- a/internal/provision/reconcile.go
+++ b/internal/provision/reconcile.go
@@ -1393,6 +1393,45 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg
}
return m.Updates, true
}
+ // strippedRootfs is the box's backstop against an older console
+ // (whole-branch review P1-2): such a console decodes a rootfs record
+ // without its runtime, so a typed rewrite drops it, and its create door
+ // writes a record with none for a rootfs app. A row minted from that
+ // record would be a binary row, its runtime fixed at mint (§5.0), so
+ // before minting a row for a record with no runtime the pass reads the
+ // app's kind marker (release.ReadAppKindMarker: one GET, once per app
+ // per pass, only for a record with no row yet) and a rootfs app's
+ // record is left unmaterialized and logged, an inert refusal. Every
+ // rootfs app has a marker, written by its first ship and never
+ // rewritten; an app with none (binary apps shipped before markers) is
+ // not rootfs. A marker that cannot be read defers the mint this pass.
+ kindReads := map[acctApp]struct {
+ rootfs bool
+ err error
+ }{}
+ strippedRootfs := func(rec Record) bool {
+ if rec.Runtime != "" {
+ return false
+ }
+ k := acctApp{rec.Account, rec.App}
+ r, seen := kindReads[k]
+ if !seen {
+ mk, err := release.ReadAppKindMarker(ctx, freshStore(s), rec.Account, rec.App)
+ r.rootfs, r.err = err == nil && mk != nil && mk.Kind == release.KindRootfs, err
+ kindReads[k] = r
+ }
+ switch {
+ case r.err != nil:
+ log.Printf("provision: %s: not minted this pass: the app's kind could not be read: %v", rec.Host, r.err)
+ return true
+ case r.rootfs:
+ log.Printf("provision: %s: not minting a binary row: app %q (acct %q) is a rootfs app and this record carries no runtime, so a console from before rootfs support wrote it; leaving it unmaterialized",
+ rec.Host, rec.App, rec.Account)
+ return true
+ }
+ return false
+ }
+
// policyUnread says a row was not minted because policyFor could not
// read the app's policy. A read failure is not "no policy": minting now
// would mint an instance that inherits manual as auto, and root would
@@ -1496,6 +1535,9 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg
// clobber, and a later pass converges it once the manifest reads.
seed, seedIsKnown := seedFor(rec.Account, rec.App)
existing, ok := byHost[rec.Host]
+ if !ok && strippedRootfs(rec) {
+ continue
+ }
// A row with a runtime takes no seed (D5), so a seeded record over
// one is refused before seed dispatch: an aborted replica seed would
// otherwise retire the row (retireAbortedSeedRow), and a ready one
@@ -1552,6 +1594,9 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg
continue
}
ok, existing = false, registry.Route{}
+ if strippedRootfs(rec) {
+ continue
+ }
}
// Nor does a row with a runtime take the manifest's seed (D5): it is
// a binary's argv, and RouteFor mints a rootfs row without it, so
diff --git a/internal/provision/reconcile_rootfs_backstop_test.go b/internal/provision/reconcile_rootfs_backstop_test.go
new file mode 100644
index 000000000..ea43a8736
--- /dev/null
+++ b/internal/provision/reconcile_rootfs_backstop_test.go
@@ -0,0 +1,150 @@
+package provision
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// kindMarkerStore is a DirStore that counts the reads of apps' kind
+// markers and can fail them.
+type kindMarkerStore struct {
+ *release.DirStore
+ mu sync.Mutex
+ gets int
+ err error
+}
+
+func (s *kindMarkerStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if strings.HasSuffix(key, "/kind.json") {
+ s.mu.Lock()
+ s.gets++
+ err := s.err
+ s.mu.Unlock()
+ if err != nil {
+ return nil, "", err
+ }
+ }
+ return s.DirStore.Get(ctx, key)
+}
+
+func (s *kindMarkerStore) markerGets() int {
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ n := s.gets
+ s.gets = 0
+ return n
+}
+
+func putKindMarker(t *testing.T, s release.Store, sqid, kind string) {
+ t.Helper()
+ body, err := json.Marshal(release.AppKindMarker{Schema: 1, Account: sqid, App: "shop", Kind: kind, Version: "v1", CreatedAt: time.Now().UTC()})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.Put(ctx, release.AppKindMarkerKey(sqid, "shop"), body, ""); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// strippedRecord is a record of shop with no runtime: what an older
+// console writes for a rootfs app, or leaves after a typed rewrite.
+func strippedRecord(sqid, host string) Record {
+ return Record{Schema: 1, Host: host, Slug: strings.SplitN(host, ".", 2)[0], App: "shop",
+ Account: sqid, Region: "ie", Channel: "stable", CreatedAt: time.Now()}
+}
+
+// [Whole-branch review P1-2] The box's backstop: a record with no runtime
+// for an app whose kind marker says rootfs is never minted as a binary row.
+// It is left unmaterialized and logged, pass after pass. A binary app's
+// record, or one of an app with no marker, mints as before. The marker is
+// read once per app per pass and only for a record with no row yet; a
+// read that fails defers the mint.
+func TestReconcileRefusesABinaryRowForARootfsApp(t *testing.T) {
+ const a, b, c = "bab.shop.example.com", "cab.shop.example.com", "dab.shop.example.com"
+ t.Run("rootfs app", func(t *testing.T) {
+ d, sqid := rootfsSetup(t)
+ s := &kindMarkerStore{DirStore: d}
+ putKindMarker(t, s, sqid, release.KindRootfs)
+ for _, rec := range []Record{strippedRecord(sqid, a), strippedRecord(sqid, b), rootfsRecord(sqid, c, false)} {
+ if err := CreateRecord(ctx, s, rec); err != nil {
+ t.Fatal(err)
+ }
+ }
+ reg := regWith(t)
+ for pass := 1; pass <= 2; pass++ {
+ logged := captureLog(t)
+ reconcileOnce(t, s, reg, rootfsCfg(nil))
+ for _, host := range []string{a, b} {
+ if got, err := reg.Get(host); err != nil || got != nil {
+ t.Fatalf("pass %d: %s minted %+v, %v; want no row", pass, host, got, err)
+ }
+ line := "provision: " + host + `: not minting a binary row: app "shop" (acct "` + sqid + `") is a rootfs app and this record carries no runtime`
+ if !strings.Contains(logged.String(), line) {
+ t.Fatalf("pass %d: no refusal line for %s:\n%s", pass, host, logged)
+ }
+ }
+ if got := mustGet(t, reg, c); got.Runtime != registry.RuntimeRootfsV1 {
+ t.Fatalf("pass %d: the rootfs record's row = %+v", pass, got)
+ }
+ if n := s.markerGets(); n != 1 {
+ t.Fatalf("pass %d: %d marker reads, want 1 (once per app per pass)", pass, n)
+ }
+ }
+ })
+ for _, kind := range []string{"binary", ""} {
+ t.Run("app kind "+kind, func(t *testing.T) {
+ d, sqid := rootfsSetup(t)
+ s := &kindMarkerStore{DirStore: d}
+ if kind != "" {
+ putKindMarker(t, s, sqid, kind)
+ }
+ if err := CreateRecord(ctx, s, strippedRecord(sqid, a)); err != nil {
+ t.Fatal(err)
+ }
+ reg := regWith(t)
+ reconcileOnce(t, s, reg, rootfsCfg(nil))
+ if got := mustGet(t, reg, a); got.Runtime != "" {
+ t.Fatalf("minted %+v, want a binary row", got)
+ }
+ if n := s.markerGets(); n != 1 {
+ t.Fatalf("%d marker reads at mint, want 1", n)
+ }
+ // The row exists: no later pass reads the marker.
+ reconcileOnce(t, s, reg, rootfsCfg(nil))
+ if n := s.markerGets(); n != 0 {
+ t.Fatalf("%d marker reads with the row minted, want 0", n)
+ }
+ })
+ }
+ t.Run("unreadable marker", func(t *testing.T) {
+ d, sqid := rootfsSetup(t)
+ s := &kindMarkerStore{DirStore: d, err: errors.New("SlowDown: please reduce your request rate")}
+ if err := CreateRecord(ctx, s, strippedRecord(sqid, a)); err != nil {
+ t.Fatal(err)
+ }
+ reg := regWith(t)
+ logged := captureLog(t)
+ reconcileOnce(t, s, reg, rootfsCfg(nil))
+ if got, err := reg.Get(a); err != nil || got != nil {
+ t.Fatalf("minted %+v, %v with the marker unreadable; want the mint deferred", got, err)
+ }
+ if !strings.Contains(logged.String(), "provision: "+a+": not minted this pass: the app's kind could not be read") {
+ t.Fatalf("no deferral line:\n%s", logged)
+ }
+ s.mu.Lock()
+ s.err = nil
+ s.mu.Unlock()
+ reconcileOnce(t, s, reg, rootfsCfg(nil))
+ if got := mustGet(t, reg, a); got.Runtime != "" {
+ t.Fatalf("after the read recovered: %+v, want a binary row", got)
+ }
+ })
+}
diff --git a/internal/release/rootfs_ship.go b/internal/release/rootfs_ship.go
index 43d2c8b36..6c35bc9c9 100644
--- a/internal/release/rootfs_ship.go
+++ b/internal/release/rootfs_ship.go
@@ -185,6 +185,14 @@ func validMarkerKind(kind string) bool {
return kind == "binary" || kind == "static" || kind == KindRootfs
}
+// ReadAppKindMarker is readAppKindMarker for a box's reconcile pass, which
+// reads the marker alone (one GET) before it mints a row for a record with
+// no runtime (whole-branch review P1-2): the marker is create-only and
+// never rewritten, and every rootfs app's first ship wrote one.
+func ReadAppKindMarker(ctx context.Context, s Store, acct, app string) (*AppKindMarker, error) {
+ return readAppKindMarker(ctx, s, acct, app)
+}
+
// readAppKindMarker reads and validates an app's kind marker. (nil, nil)
// when absent. A body that does not decode strictly, has another schema,
// names another account or app, or carries no valid kind or version is an