carlos / platform Public

fix: judge the stateless floor on followed platform channels

Use the memoized complete box-report snapshot to identify fresh boxes'
platform channels, defaulting an omitted channel to stable. Check only those
signed pointers and retain the assigned fleet box version gate. Unreadable
reports or followed pointers refuse; abandoned pointers are ignored.

Cover below-floor, at-floor, abandoned, unreadable and memoized cases across
API, browser, pending, pin and rollback paths. Stateful writes retain their
existing behavior.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 1da134870e217f8313cdafa2fb3af0c4553a4b95 parent 53f24ba
2 files changed, +73 −14
  • internal/console/rootfs.go +13 −13
  • internal/console/stateless_floor_test.go +60 −1
diff --git a/internal/console/rootfs.go b/internal/console/rootfs.go
index c1b4307fb..d48cea423 100644
--- a/internal/console/rootfs.go
+++ b/internal/console/rootfs.go
@@ -9,7 +9,6 @@ import (
"maps"
"net/http"
"slices"
- "strings"
"time"
"github.com/carlosframework/platform/internal/provision"
@@ -26,7 +25,7 @@ func atStatelessRuntimeFloor(version string) bool {
return ok && valid && v.Compare(floor) >= 0
}
-// R22 judges every platform channel, plus any already-loaded assigned box.
+// R25 judges channels followed by reported boxes, plus an assigned fleet box.
// Stateful selections read no platform evidence.
func (s *Server) statelessRuntimeRefusal(ctx context.Context, _ string, m *release.Manifest, fleet *fleetView, box string) *doorRefusal {
if m == nil || !m.Stateless {
@@ -36,25 +35,26 @@ func (s *Server) statelessRuntimeRefusal(ctx context.Context, _ string, m *relea
if s.cfg.Releases == nil || s.cfg.Key == nil {
return ref
}
- allowed, err := memoize(ctx, "stateless-system-pointer:all", func() (bool, error) {
- prefix, _ := strings.CutSuffix(release.SystemPointerKey(release.SystemComponentRouter, ""), ".json")
- keys, err := s.cfg.Releases.List(ctx, prefix)
- if err != nil {
+ allowed, err := memoize(ctx, "stateless-system-pointer:followed", func() (bool, error) {
+ boxes, complete, err := s.loadBoxes(ctx, s.cfg.Releases, "")
+ if err != nil || !complete {
return false, err
}
- found := false
- for _, key := range keys {
- channel, ok := systemChannelOf(prefix, key)
- if !ok {
- continue
+ followed := make(map[string]bool)
+ for _, b := range freshHeartbeats(boxes, time.Now()) {
+ channel := release.RungStable
+ if b.Metrics != nil && b.Metrics.SystemChannel != "" {
+ channel = b.Metrics.SystemChannel
}
- found = true
+ followed[channel] = true
+ }
+ for _, channel := range slices.Sorted(maps.Keys(followed)) {
cur, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key).RootPublicKey(), release.SystemComponentRouter, channel)
if err != nil || cur == nil || !atStatelessRuntimeFloor(cur.Current.Version) {
return false, err
}
}
- return found, nil
+ return true, nil
})
if err != nil || !allowed {
return ref
diff --git a/internal/console/stateless_floor_test.go b/internal/console/stateless_floor_test.go
index 7a6deb7cf..518a6350d 100644
--- a/internal/console/stateless_floor_test.go
+++ b/internal/console/stateless_floor_test.go
@@ -10,6 +10,7 @@ import (
"time"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
)
const statelessFloorWant = "this box needs platform v0.34.0 or later to run a stateless release. update the box and try again"
@@ -47,6 +48,7 @@ func TestStatelessRuntimeFloorAPIMutations(t *testing.T) {
} {
t.Run(action+"/"+tc.name, func(t *testing.T) {
fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable")
if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil {
t.Fatal(err)
}
@@ -55,6 +57,7 @@ func TestStatelessRuntimeFloorAPIMutations(t *testing.T) {
t.Fatal(err)
}
const channel = "canary/shop"
+ statelessFloorReports(t, fx, "canary")
statelessFloorPointer(t, fx, "canary", tc.platform)
// The app channel is independent of both platform channels.
statelessFloorPointer(t, fx, "stable", "v0.34.0")
@@ -106,7 +109,7 @@ type statelessPointerReads struct {
}
func (s *statelessPointerReads) List(ctx context.Context, prefix string) ([]string, error) {
- if strings.HasPrefix(prefix, "control/system/") {
+ if prefix == "status/boxes/" {
s.lists++
if s.failList {
return nil, context.DeadlineExceeded
@@ -127,6 +130,7 @@ func (s *statelessPointerReads) Get(ctx context.Context, key string) ([]byte, st
func TestStatelessRuntimeFloorSnapshotAndFleet(t *testing.T) {
fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable", "canary")
statelessFloorPointer(t, fx, "stable", "v0.34.0")
statelessFloorPointer(t, fx, "canary", "v0.34.0")
store := &statelessPointerReads{Store: fx.rel}
@@ -168,6 +172,7 @@ func TestStatelessRuntimeFloorPin(t *testing.T) {
for _, platform := range []string{"", "v0.33.9", "v0.34.0"} {
t.Run(platform, func(t *testing.T) {
fx := updatesFixture(t)
+ statelessFloorReports(t, fx.consoleFixture, "stable")
fx.boxesEnforce(true)
m := release.Manifest{Schema: 1, Kind: "binary", App: "km", Version: "v3", Stateless: true, Artifacts: map[string]release.Artifact{"linux-amd64": {File: "app"}}}
if err := release.Ship(t.Context(), fx.rel, "bab", m, map[string][]byte{"linux-amd64": []byte("app")}); err != nil {
@@ -199,6 +204,7 @@ func TestStatelessRuntimeFloorBrowserAndPending(t *testing.T) {
for _, action := range []string{"promote", "rollback", "canary", "fasttrack", "pending-promote", "pending-fasttrack"} {
t.Run(action, func(t *testing.T) {
fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable")
if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil {
t.Fatal(err)
}
@@ -299,6 +305,7 @@ func (s *statelessChangedPointer) Get(ctx context.Context, key string) ([]byte,
func TestStatelessRuntimeFloorChangedRollbackTarget(t *testing.T) {
fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable")
if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil {
t.Fatal(err)
}
@@ -347,6 +354,7 @@ func (s *statelessManifestReads) Get(ctx context.Context, key string) ([]byte, s
func TestStatelessRuntimeFloorManifestReadFailureAdmits(t *testing.T) {
fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable")
store := &statelessManifestReads{Store: fx.rel, fail: true}
fx.srv.cfg.Releases = store
ctx := withWriteMemo(t.Context())
@@ -359,3 +367,54 @@ func TestStatelessRuntimeFloorManifestReadFailureAdmits(t *testing.T) {
t.Fatalf("failed target read attempts = %d, want 1", store.reads)
}
}
+
+func statelessFloorReports(t *testing.T, fx *consoleFixture, channels ...string) {
+ t.Helper()
+ for _, channel := range channels {
+ b := status.Box{Label: channel, GeneratedAt: time.Now(), Metrics: &status.BoxMetrics{SystemChannel: channel, UpdateSettings: status.UpdateSettingsProtocol}}
+ raw, err := json.Marshal(b)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.rel.Put(t.Context(), "status/boxes/"+strings.ReplaceAll(channel, "/", "-")+".json", raw, ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+}
+
+func TestStatelessRuntimeFloorFollowedChannels(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ followed string
+ failReports, failPointer, refuse bool
+ }{
+ {name: "followed-below", followed: "v0.33.9", refuse: true},
+ {name: "abandoned-below-ignored", followed: "v0.34.0"},
+ {name: "all-followed-at-floor", followed: "v0.34.0"},
+ {name: "reports-unreadable", followed: "v0.34.0", failReports: true, refuse: true},
+ {name: "pointer-unreadable", followed: "v0.34.0", failPointer: true, refuse: true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ fx := newConsoleFixture(t)
+ statelessFloorReports(t, fx, "stable", "canary/live")
+ statelessFloorPointer(t, fx, "stable", "v0.34.0")
+ statelessFloorPointer(t, fx, "canary/live", tc.followed)
+ statelessFloorPointer(t, fx, "canary/abandoned", "v0.1.0")
+ store := &statelessPointerReads{Store: fx.rel, failList: tc.failReports, fail: tc.failPointer}
+ fx.srv.cfg.Releases = store
+ ctx := withWriteMemo(t.Context())
+ for range 2 {
+ ref := fx.srv.statelessRuntimeRefusal(ctx, "app-channel", &release.Manifest{Stateless: true}, nil, "")
+ if (ref != nil) != tc.refuse {
+ t.Fatalf("refusal=%v", ref)
+ }
+ }
+ if store.lists != 1 {
+ t.Fatalf("report listings=%d", store.lists)
+ }
+ if !tc.refuse && store.reads != 2 {
+ t.Fatalf("pointer reads=%d; want followed channels only, once each", store.reads)
+ }
+ })
+ }
+}