feat: refuse stateless builds below the runtime floor
Judge stateless selections against the signed platform pointer for the instance channel, sharing one read per mutation and reusing assigned-box evidence already loaded by fleet creation. Check rollback and bake-waiver targets at their conditional pointer write. Cover promotions, pending execution, pins and instance creation with the approved SR-1-C08 refusal, tests and updated census evidence.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+490
−26
approved_stateless_replicas_copy_test.go+1 −1internal/console/apicli.go+16 −1internal/console/apiinstances.go+13 −0internal/console/pendinghandlers.go+5 −1internal/console/plancaps_doors_test.go+23 −7internal/console/reqmemo.go+6 −7internal/console/rootfs.go+59 −0internal/console/server.go+24 −2internal/console/stateless_floor_test.go+304 −0internal/console/updatescore.go+6 −0internal/provision/stateless_replicas_census_test.go+11 −0internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv+1 −1internal/release/claim_app_writes.go+3 −2internal/release/release.go+18 −4
CI passed — run details
Intent
Attributed to this commit: 19.1 g CO₂e (2,318,862 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-replicas-1-runtime, 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/approved_stateless_replicas_copy_test.go b/approved_stateless_replicas_copy_test.go| index 805589983..3fd9b1200 100644 |
| --- a/approved_stateless_replicas_copy_test.go |
| +++ b/approved_stateless_replicas_copy_test.go |
| @@ -9,7 +9,7 @@ import ( |
| const statelessReplicaCopyDeck = "docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md" |
| -var statelessReplicaBuiltCopy = []string{"SR-1-C06", "SR-1-C07", "SR-1-C01", "SR-1-C02", "SR-1-C03", "SR-1-C04", "SR-1-C05", "SR-1-C12", "SR-1-C09", "SR-1-C10", "SR-1-C13"} |
| +var statelessReplicaBuiltCopy = []string{"SR-1-C08", "SR-1-C06", "SR-1-C07", "SR-1-C01", "SR-1-C02", "SR-1-C03", "SR-1-C04", "SR-1-C05", "SR-1-C12", "SR-1-C09", "SR-1-C10", "SR-1-C13"} |
| func statelessReplicaCopyRows(t *testing.T) []copyRow { |
| t.Helper() |
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index b97832e51..fe081cc3e 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -960,6 +960,7 @@ func (s *Server) handleAPIPromote(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusBadGateway, planCheckFailedCopy) |
| return |
| } |
| + |
| // The pipeline is read ONCE, for the gate below and for the held answer |
| // further down. An unreadable one refuses outright: GetPipeline's error |
| // means "not safely nil", and treating it as "no pipeline" would drop |
| @@ -981,6 +982,10 @@ func (s *Server) handleAPIPromote(w http.ResponseWriter, r *http.Request) { |
| if s.refuseServiceControlPlane(w, p, acct.ID, app, "promote it") { |
| return |
| } |
| + if ref := s.statelessRuntimeRefusal(ctx, channel, man, nil, ""); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| // The channel's own gate, LAST — after auth, after the account/app 404, |
| // after the key check, and after every refusal that costs nothing to |
| // answer. Same load-bearing order handlePromote's comment explains: a |
| @@ -1295,6 +1300,11 @@ func (s *Server) handleAPIRollback(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusBadGateway, planCheckFailedCopy) |
| return |
| } |
| + if ref := s.statelessVersionRefusal(ctx, acct.Sqid, app, channel, target); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| + |
| // Rollback moves the same pointer promote moves, so it wears the same |
| // service refusal — a credential barred from promoting the control plane |
| // must not reach the identical effect through the other verb. |
| @@ -1352,7 +1362,12 @@ func (s *Server) handleAPIRollback(w http.ResponseWriter, r *http.Request) { |
| jsonError(w, http.StatusBadGateway, planCheckFailedCopy) |
| return |
| } |
| - if err := signer.RollbackAuthorized(ctx, s.cfg.Releases, acct.Sqid, app, channel, bothAuthorize(authorize, guard)); err != nil { |
| + if err := signer.RollbackAuthorized(ctx, s.cfg.Releases, acct.Sqid, app, channel, bothAuthorize(authorize, guard), s.statelessSelectionGuard(ctx, acct.Sqid, app, channel)); err != nil { |
| + var selection *statelessSelectionError |
| + if errors.As(err, &selection) { |
| + jsonError(w, selection.ref.Status, selection.ref.Msg) |
| + return |
| + } |
| if isPlanCap(err) { |
| writeJSON(w, http.StatusConflict, map[string]any{"error": err.Error(), "code": "cap"}) |
| return |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index 4503ebb55..8ebd58e0c 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -2045,6 +2045,13 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| } |
| + if chHead != nil { |
| + if ref := s.statelessRuntimeRefusal(ctx, channel, chHead.Manifest, nil, ""); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| + } |
| + |
| // The first-kind boundary (rootfs.go): no first ship has fixed the |
| // app's kind yet, so the record writer reads it again under the |
| // app lock. Every later context of this request derives from r. |
| @@ -2320,6 +2327,12 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| // record unlabelled, as on main. |
| if fleetActive != nil && fleetLabelsRecord(rec) && movable(rec) { |
| if box := fleetActive.chooseDestination(rec.Runtime == provision.RuntimeRootfsV1, ""); box != "" { |
| + if chHead != nil { |
| + if ref := s.statelessRuntimeRefusal(ctx, channel, chHead.Manifest, fleetActive, box); ref != nil { |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| + } |
| fleet, _ := registry.FleetPlacement(placed) |
| now := time.Now() |
| if err := reg.MarkFleetBoxLabelled(fleet, box, now.UnixNano()); err != nil { |
diff --git a/internal/console/pendinghandlers.go b/internal/console/pendinghandlers.go| index c28257532..20175872b 100644 |
| --- a/internal/console/pendinghandlers.go |
| +++ b/internal/console/pendinghandlers.go |
| @@ -557,6 +557,10 @@ func (s *Server) executePendingPromote(ctx context.Context, acct *Account, app, |
| return "", errors.New(planCheckFailedCopy) |
| } |
| } |
| + if ref := s.statelessVersionRefusal(ctx, acct.Sqid, app, p.Channel, p.Version); ref != nil { |
| + return "", &statelessSelectionError{ref} |
| + } |
| + |
| res, err := release.PromoteOnLadder(ctx, s.cfg.Releases, s.cfg.Key, acct.Sqid, app, p.Channel, p.Version, |
| release.PromoteOptions{Actor: actor, Hotfix: p.Hotfix, Retry: p.Retry}) |
| if err != nil { |
| @@ -636,7 +640,7 @@ func (s *Server) executePendingFastTrack(ctx context.Context, acct *Account, app |
| return "", errors.New("channel " + p.Channel + " now serves " + cur.Version + |
| ", not the " + p.Version + " this was proposed for — re-propose") |
| } |
| - ver, err := release.FastTrack(ctx, s.cfg.Releases, s.cfg.Key, acct.Sqid, app, p.Channel, actor) |
| + ver, err := release.FastTrack(ctx, s.cfg.Releases, s.cfg.Key, acct.Sqid, app, p.Channel, actor, s.statelessSelectionGuard(ctx, acct.Sqid, app, p.Channel)) |
| if err != nil { |
| log.Printf("console: execute fast-track %s %s: %v", app, p.Channel, err) |
| return "", err |
diff --git a/internal/console/plancaps_doors_test.go b/internal/console/plancaps_doors_test.go| index e78bdeff8..b7cf23071 100644 |
| --- a/internal/console/plancaps_doors_test.go |
| +++ b/internal/console/plancaps_doors_test.go |
| @@ -882,25 +882,41 @@ func TestPendingRollbackToADaemonReleaseRefusedUnderAPlan(t *testing.T) { |
| } |
| } |
| -// Astra plans-3b round 3 finding 1: with plans off a rollback reads no |
| -// manifest, so one that cannot be read does not stop it. |
| -func TestRollbackWithoutACatalogNeedsNoManifest(t *testing.T) { |
| +// R21 requires the storage declaration even with plans off: an unreadable |
| +// manifest cannot establish that this target is stateful. Once readable, |
| +// a stateful rollback still needs no platform pointer or plan catalog. |
| +func TestRollbackWithoutACatalogChecksStorageDeclaration(t *testing.T) { |
| fx := newConsoleFixture(t) |
| shipVersion(t, fx, "kass", "old1") |
| shipVersion(t, fx, "kass", "new2") |
| seedChannel(t, fx, "kass", "canary/x", "old1") |
| seedChannel(t, fx, "kass", "canary/x", "new2") |
| - if err := fx.rel.Delete(context.Background(), release.ManifestKey(release.OpsAccount, "kass", "old1")); err != nil { |
| + key := release.ManifestKey(release.OpsAccount, "kass", "old1") |
| + raw, _, err := fx.rel.Get(context.Background(), key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.rel.Delete(context.Background(), key); err != nil { |
| t.Fatal(err) |
| } |
| token := cliToken(t, fx, "paul@keymail.dev", "code-rollback-nomanifest") |
| - if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/kass/rollback", map[string]string{"channel": "canary/x"}, token); status != http.StatusOK { |
| - t.Fatalf("CLI rollback with plans off and the target's manifest unreadable = %d %v, want 200", status, out) |
| + if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/kass/rollback", map[string]string{"channel": "canary/x"}, token); status != http.StatusBadGateway || out["error"] != rootfsReleasesUnreadableMsg { |
| + t.Fatalf("rollback with unknown storage declaration = %d %v", status, out) |
| } |
| c := signInPaul(t, fx) |
| postForm(t, c, fx.u("/apps/kass/rollback"), url.Values{"csrf": {sessionToken(t, fx, c)}, "channel": {"canary/x"}, "confirmed": {"1"}}) |
| if p := fx.channelVersion(t, "kass", "canary/x"); p.Version != "new2" { |
| - t.Fatalf("canary/x = %s after a second rollback with plans off, want new2", p.Version) |
| + t.Fatalf("unreadable target selected: %+v", p) |
| + } |
| + if _, err := fx.rel.Put(context.Background(), key, raw, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/kass/rollback", map[string]string{"channel": "canary/x"}, token); status != http.StatusOK { |
| + t.Fatalf("stateful rollback without a platform pointer = %d %v", status, out) |
| + } |
| + postForm(t, c, fx.u("/apps/kass/rollback"), url.Values{"csrf": {sessionToken(t, fx, c)}, "channel": {"canary/x"}, "confirmed": {"1"}}) |
| + if p := fx.channelVersion(t, "kass", "canary/x"); p.Version != "new2" { |
| + t.Fatalf("stateful browser rollback = %+v", p) |
| } |
| } |
diff --git a/internal/console/reqmemo.go b/internal/console/reqmemo.go| index 2eaf9bbf6..457972be1 100644 |
| --- a/internal/console/reqmemo.go |
| +++ b/internal/console/reqmemo.go |
| @@ -21,9 +21,9 @@ import ( |
| // request: nothing is shared between requests, so nothing here can go stale. |
| // |
| // registerRoute installs it on GET and HEAD requests. A write door's |
| -// request gets a narrower one (withWriteMemo): only the live edges snapshot |
| -// and the box reports, which boxes write and the console never does, so no |
| -// write the door makes can change them under its own request. Every other |
| +// request gets a narrower one (withWriteMemo): live edges, box reports, and |
| +// the platform pointer used for stateless admission. A selection mutation |
| +// does not write those objects. Every other |
| // read a door decides on (a record, a manifest, a pointer) is still its own, |
| // made when it asks: a door may write the very object it read a moment ago. |
| // Before console-slow-writes a write door had no memo at all, and one |
| @@ -72,11 +72,10 @@ func withWriteMemo(ctx context.Context) context.Context { |
| return context.WithValue(ctx, reqMemoKey{}, &reqMemo{entries: map[string]*reqMemoEntry{}, only: writeMemoKey}) |
| } |
| -// writeMemoKey is the keys a write door's memo holds: the live edges |
| -// snapshot (liveEdges) and the box reports (loadBoxes), objects that boxes |
| -// write and the console never does. |
| +// writeMemoKey includes the stateless platform-floor snapshot so a preflight |
| +// and the guarded selection share one read, including a failed read. |
| func writeMemoKey(key string) bool { |
| - return key == "edges" || strings.HasPrefix(key, "boxes:") |
| + return key == "edges" || strings.HasPrefix(key, "boxes:") || strings.HasPrefix(key, "stateless-system-pointer:") |
| } |
| // memoOf is ctx's memo when it holds key, nil otherwise. |
diff --git a/internal/console/rootfs.go b/internal/console/rootfs.go| index 0d0884c34..16a31e8c2 100644 |
| --- a/internal/console/rootfs.go |
| +++ b/internal/console/rootfs.go |
| @@ -17,6 +17,65 @@ import ( |
| "github.com/carlosframework/platform/internal/status" |
| ) |
| +const statelessRuntimeFloorMsg = "this box needs platform %s or later to run a stateless release. update the box and try again" |
| + |
| +func atStatelessRuntimeFloor(version string) bool { |
| + v, ok := release.ParseReleaseVersion(version) |
| + floor, valid := release.ParseReleaseVersion(release.StatelessRuntimeFloor) |
| + return ok && valid && v.Compare(floor) >= 0 |
| +} |
| + |
| +// R21 uses the signed platform channel pointer, with any already-loaded |
| +// assigned-box evidence as an additional gate. Stateful selections read nothing. |
| +func (s *Server) statelessRuntimeRefusal(ctx context.Context, channel string, m *release.Manifest, fleet *fleetView, box string) *doorRefusal { |
| + if m == nil || !m.Stateless { |
| + return nil |
| + } |
| + ref := &doorRefusal{http.StatusConflict, fmt.Sprintf(statelessRuntimeFloorMsg, release.StatelessRuntimeFloor)} |
| + if s.cfg.Releases == nil || s.cfg.Key == nil { |
| + return ref |
| + } |
| + allowed, err := memoize(ctx, "stateless-system-pointer:"+channel, func() (bool, error) { |
| + cur, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key).RootPublicKey(), "router", channel) |
| + return err == nil && cur != nil && atStatelessRuntimeFloor(cur.Current.Version), err |
| + }) |
| + if err != nil || !allowed { |
| + return ref |
| + } |
| + if fleet != nil && box != "" { |
| + for _, b := range fleet.Boxes { |
| + if b.Label == box && atStatelessRuntimeFloor(b.Release) { |
| + return nil |
| + } |
| + } |
| + return ref |
| + } |
| + return nil |
| +} |
| + |
| +func (s *Server) statelessVersionRefusal(ctx context.Context, acct, app, channel, version string) *doorRefusal { |
| + m, err := release.GetManifest(ctx, s.cfg.Releases, acct, app, version) |
| + if err != nil { |
| + return &doorRefusal{http.StatusBadGateway, rootfsReleasesUnreadableMsg} |
| + } |
| + return s.statelessRuntimeRefusal(ctx, channel, m, nil, "") |
| +} |
| + |
| +type statelessSelectionError struct{ ref *doorRefusal } |
| + |
| +func (e *statelessSelectionError) Error() string { return e.ref.Msg } |
| + |
| +// The callback judges the version from the pointer used by the conditional |
| +// write, so a rollback or bake waiver cannot select an unchecked successor. |
| +func (s *Server) statelessSelectionGuard(ctx context.Context, acct, app, channel string) func(string) error { |
| + return func(version string) error { |
| + if ref := s.statelessVersionRefusal(ctx, acct, app, channel, version); ref != nil { |
| + return &statelessSelectionError{ref} |
| + } |
| + return nil |
| + } |
| +} |
| + |
| // The three questions every rootfs door asks (rootfs apps spec §5.0, §5.7; |
| // Plan 4 Task 2): what the creating release says (rootfsHeadFor), whether a |
| // placement is the account's own boxes (rootfsPlacementRefusal), and whether |
diff --git a/internal/console/server.go b/internal/console/server.go| index 02e93c86c..db019122e 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -5686,6 +5686,10 @@ func (s *Server) handlePromote(w http.ResponseWriter, r *http.Request) { |
| http.NotFound(w, r) |
| return |
| } |
| + if ref := s.statelessRuntimeRefusal(ctx, channel, man, nil, ""); ref != nil { |
| + back("err", ref.Msg) |
| + return |
| + } |
| if !confirmed(r) { |
| s.confirmPromote(w, r, addr, raw, acct, role, app, channel, version, pipe) |
| return |
| @@ -5921,6 +5925,10 @@ func (s *Server) handleRollback(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| target := cur.History[0] |
| + if ref := s.statelessVersionRefusal(ctx, acct.Sqid, app, channel, target); ref != nil { |
| + back("err", ref.Msg) |
| + return |
| + } |
| if err := s.checkDaemonVersion(ctx, acct, app, target); err != nil { |
| var planCap *planCapError |
| if errors.As(err, &planCap) { |
| @@ -5993,7 +6001,12 @@ func (s *Server) handleRollback(w http.ResponseWriter, r *http.Request) { |
| back("err", planCheckFailedCopy) |
| return |
| } |
| - if err := release.RootSigner(s.cfg.Key).RollbackAuthorized(ctx, s.cfg.Releases, acct.Sqid, app, channel, guard); err != nil { |
| + if err := release.RootSigner(s.cfg.Key).RollbackAuthorized(ctx, s.cfg.Releases, acct.Sqid, app, channel, guard, s.statelessSelectionGuard(ctx, acct.Sqid, app, channel)); err != nil { |
| + var selection *statelessSelectionError |
| + if errors.As(err, &selection) { |
| + back("err", selection.ref.Msg) |
| + return |
| + } |
| var planCap *planCapError |
| if errors.As(err, &planCap) { |
| back("err", planCap.Browser()) |
| @@ -6190,8 +6203,13 @@ func (s *Server) handleFastTrack(w http.ResponseWriter, r *http.Request) { |
| back(kind, msg) |
| return |
| } |
| - ver, err := release.FastTrack(ctx, s.cfg.Releases, s.cfg.Key, acct.Sqid, app, channel, addr) |
| + ver, err := release.FastTrack(ctx, s.cfg.Releases, s.cfg.Key, acct.Sqid, app, channel, addr, s.statelessSelectionGuard(ctx, acct.Sqid, app, channel)) |
| if err != nil { |
| + var selection *statelessSelectionError |
| + if errors.As(err, &selection) { |
| + back("err", selection.ref.Msg) |
| + return |
| + } |
| log.Printf("console: fast-track %s %s: %v", app, channel, err) |
| back("err", "Skipping the delay failed: "+err.Error()) |
| return |
| @@ -6365,6 +6383,10 @@ func (s *Server) handleNewCanary(w http.ResponseWriter, r *http.Request) { |
| back("err", "Version "+version+" is not a shipped release of "+app+".") |
| return |
| } |
| + if ref := s.statelessRuntimeRefusal(ctx, channel, man, nil, ""); ref != nil { |
| + back("err", ref.Msg) |
| + return |
| + } |
| if err := s.checkDaemonRelease(acct, app, man); err != nil { |
| var planCap *planCapError |
| if errors.As(err, &planCap) { |
diff --git a/internal/console/stateless_floor_test.go b/internal/console/stateless_floor_test.go| new file mode 100644 |
| index 000000000..44d20413c |
| --- /dev/null |
| +++ b/internal/console/stateless_floor_test.go |
| @@ -0,0 +1,304 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "net/http" |
| + "net/url" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +const statelessFloorWant = "this box needs platform v0.34.0 or later to run a stateless release. update the box and try again" |
| + |
| +func statelessFloorPointer(t *testing.T, fx *consoleFixture, channel, version string) { |
| + t.Helper() |
| + if version == "" { |
| + return |
| + } |
| + rel := release.SystemRelease{Version: version, Source: "release:" + version, ReleaseTag: version, Artifacts: map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey(version, "linux-amd64"), SHA256: strings.Repeat("a", 64)}}} |
| + if version == "dev" { |
| + raw, err := release.SignRootEnvelope(release.RootSigner(fx.priv), release.SystemPointer{Schema: 1, Component: "router", Channel: channel, Current: rel, Spread: "0s", PromotedAt: time.Now().UTC()}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(t.Context(), release.SystemPointerKey("router", channel), raw, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + return |
| + } |
| + |
| + if _, err := release.PromoteSystem(t.Context(), fx.rel, release.RootSigner(fx.priv), "router", channel, rel, release.SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +func TestStatelessRuntimeFloorAPIMutations(t *testing.T) { |
| + for _, action := range []string{"promote", "rollback"} { |
| + for _, tc := range []struct { |
| + name, platform string |
| + stateless, refused bool |
| + }{ |
| + {"below", "v0.33.9", true, true}, {"unreadable", "", true, true}, {"unparseable", "dev", true, true}, |
| + {"at-floor", "v0.34.0", true, false}, {"stateful", "", false, false}, |
| + } { |
| + t.Run(action+"/"+tc.name, func(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + m := release.Manifest{Schema: 1, Kind: "binary", App: "shop", Version: "v1", Stateless: tc.stateless, 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 { |
| + t.Fatal(err) |
| + } |
| + const channel = "canary/shop" |
| + statelessFloorPointer(t, fx, channel, tc.platform) |
| + // A different channel at the floor cannot admit this channel. |
| + statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| + if action == "rollback" { |
| + if err := release.Promote(t.Context(), fx.rel, fx.priv, "bab", "shop", channel, "v1"); err != nil { |
| + t.Fatal(err) |
| + } |
| + shipVersion(t, fx, "shop", "v2") |
| + if err := release.Promote(t.Context(), fx.rel, fx.priv, "bab", "shop", channel, "v2"); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + token := cliToken(t, fx, "paul@keymail.dev", "floor-"+action+"-"+tc.name) |
| + code, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/shop/"+action, map[string]string{"version": "v1", "channel": channel}, token) |
| + if tc.refused { |
| + if code != http.StatusConflict || out["error"] != statelessFloorWant { |
| + t.Fatalf("%d %v", code, out) |
| + } |
| + p, err := release.Channel(context.Background(), fx.rel, fx.srv.cfg.ReleasePub, "bab", "shop", channel) |
| + if action == "promote" && err == nil { |
| + t.Fatalf("refused promote wrote %+v", p) |
| + } |
| + if action == "rollback" && (err != nil || p.Version != "v2") { |
| + t.Fatalf("refused rollback changed pointer: %+v %v", p, err) |
| + } |
| + } else if code != http.StatusOK { |
| + t.Fatalf("%d %v", code, out) |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +type statelessPointerReads struct { |
| + release.Store |
| + reads int |
| + fail bool |
| +} |
| + |
| +func (s *statelessPointerReads) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if strings.HasPrefix(key, "control/system/") { |
| + s.reads++ |
| + if s.fail { |
| + return nil, "", context.DeadlineExceeded |
| + } |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +func TestStatelessRuntimeFloorSnapshotAndFleet(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| + store := &statelessPointerReads{Store: fx.rel} |
| + fx.srv.cfg.Releases = store |
| + m := &release.Manifest{Stateless: true} |
| + ctx := withWriteMemo(t.Context()) |
| + for _, tc := range []struct { |
| + version string |
| + refused bool |
| + }{{"v0.33.9", true}, {"dev", true}, {"", true}, {"v0.34.0", false}, {"v0.35.0", false}} { |
| + v := &fleetView{Boxes: []fleetBoxView{{Label: "assigned", Release: tc.version}, {Label: "other", Release: "v0.33.0"}}} |
| + ref := fx.srv.statelessRuntimeRefusal(ctx, "stable", m, v, "assigned") |
| + if (ref != nil) != tc.refused { |
| + t.Fatalf("%q: %v", tc.version, ref) |
| + } |
| + if ref != nil && ref.Msg != statelessFloorWant { |
| + t.Fatal(ref) |
| + } |
| + } |
| + if store.reads != 1 { |
| + t.Fatalf("pointer reads = %d, want one per mutation", store.reads) |
| + } |
| + store.fail = true |
| + if ref := fx.srv.statelessRuntimeRefusal(withWriteMemo(t.Context()), "stable", m, nil, ""); ref == nil || ref.Msg != statelessFloorWant { |
| + t.Fatalf("unreadable: %v", ref) |
| + } |
| + if ref := fx.srv.statelessRuntimeRefusal(withWriteMemo(t.Context()), "stable", &release.Manifest{}, nil, ""); ref != nil { |
| + t.Fatal(ref) |
| + } |
| + if store.reads != 2 { |
| + t.Fatalf("stateful read platform pointer: %d", store.reads) |
| + } |
| +} |
| + |
| +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) |
| + 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 { |
| + t.Fatal(err) |
| + } |
| + seedChannel(t, fx.consoleFixture, "km", "stable", "v3") |
| + statelessFloorPointer(t, fx.consoleFixture, "stable", platform) |
| + code, out := sendJSON(t, http.MethodPut, fx.ts.URL+updURL, map[string]string{"pin": "v3"}, fx.member) |
| + if platform != "v0.34.0" { |
| + if code != http.StatusConflict || !strings.Contains(out, statelessFloorWant) || fx.record("a.example.com").Pin != "" { |
| + t.Fatalf("%d %s", code, out) |
| + } |
| + } else if code != http.StatusOK || fx.record("a.example.com").Pin != "v3" { |
| + t.Fatalf("%d %s", code, out) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func shipStatelessFloorRelease(t *testing.T, fx *consoleFixture, app, version string) { |
| + t.Helper() |
| + m := release.Manifest{Schema: 1, Kind: "binary", App: app, Version: version, 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 { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +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) |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + shipStatelessFloorRelease(t, fx, "shop", "v1") |
| + channel := "canary/shop" |
| + if strings.Contains(action, "fasttrack") || strings.HasPrefix(action, "pending-") { |
| + channel = "beta" |
| + } |
| + seedChannel(t, fx, "shop", channel, "v1") |
| + if action == "canary" { |
| + channel = "canary/new" |
| + } |
| + if action == "rollback" { |
| + shipVersion(t, fx, "shop", "v2") |
| + seedChannel(t, fx, "shop", channel, "v2") |
| + } |
| + if strings.HasPrefix(action, "pending-") { |
| + setPipeline(t, fx, "shop", release.PipelineChannel{Name: channel}) |
| + acct, err := fx.st.AccountBySqid("bab") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var payload []byte |
| + var msg string |
| + if action == "pending-promote" { |
| + payload, _ = json.Marshal(promotePayload{Version: "v1", Channel: channel, Hotfix: true}) |
| + msg, err = fx.srv.executePendingPromote(withWriteMemo(t.Context()), acct, "shop", "paul@keymail.dev", &PendingChange{Payload: payload}) |
| + } else { |
| + payload, _ = json.Marshal(fastTrackPayload{Version: "v1", Channel: channel}) |
| + msg, err = fx.srv.executePendingFastTrack(withWriteMemo(t.Context()), acct, "shop", "paul@keymail.dev", &PendingChange{Payload: payload}) |
| + } |
| + if err == nil || err.Error() != statelessFloorWant { |
| + t.Fatalf("%q %v", msg, err) |
| + } |
| + return |
| + } |
| + c := signInPaul(t, fx) |
| + csrf := sessionToken(t, fx, c) |
| + path := "/apps/shop/" + action |
| + if action == "canary" { |
| + path = "/apps/shop/canary" |
| + } |
| + code, _, _ := postGated(t, fx, c, fx.u(path), url.Values{"csrf": {csrf}, "channel": {channel}, "version": {"v1"}, "name": {"new"}, "confirmed": {"1"}}) |
| + if code != http.StatusSeeOther { |
| + t.Fatalf("%d", code) |
| + } |
| + _, _, body := get(t, c, fx.u("/apps/shop")) |
| + if !strings.Contains(body, statelessFloorWant) { |
| + t.Fatalf("refusal absent: %s", body) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestStatelessRuntimeFloorCreateFleet(t *testing.T) { |
| + for _, version := range []string{"v0.33.9", "v0.34.0"} { |
| + t.Run(version, func(t *testing.T) { |
| + fx, token, _ := fleetBoxWorld(t, "stateless-create", "pi-1", "pi-2") |
| + shipStatelessFloorRelease(t, fx, "shop", "v1") |
| + seedChannel(t, fx, "shop", "stable", "v1") |
| + statelessFloorPointer(t, fx, "stable", "v0.34.0") |
| + piBeat(t, fx, "pi-1", true, time.Now(), version) |
| + piBeat(t, fx, "pi-2", true, time.Now(), "v0.34.0") |
| + code, out := postJSON(t, instancesURL(fx, "bab", "shop"), map[string]any{"host": "new.example.com", "channel": "stable"}, token) |
| + if version == "v0.33.9" { |
| + if code != http.StatusConflict || out["error"] != statelessFloorWant { |
| + t.Fatalf("%d %v", code, out) |
| + } |
| + } else if code != http.StatusCreated { |
| + t.Fatalf("%d %v", code, out) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +type statelessChangedPointer struct { |
| + release.Store |
| + key string |
| + replacement []byte |
| + reads int |
| +} |
| + |
| +func (s *statelessChangedPointer) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == s.key { |
| + s.reads++ |
| + if s.reads == 2 { |
| + _, etag, err := s.Store.Get(ctx, key) |
| + if err != nil { |
| + return nil, "", err |
| + } |
| + if _, err := s.Store.Put(ctx, key, s.replacement, etag); err != nil { |
| + return nil, "", err |
| + } |
| + } |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +func TestStatelessRuntimeFloorChangedRollbackTarget(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", "paul@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + shipStatelessFloorRelease(t, fx, "shop", "v1") |
| + for _, v := range []string{"v2", "v3", "v4"} { |
| + shipVersion(t, fx, "shop", v) |
| + } |
| + const channel = "canary/shop" |
| + seedChannel(t, fx, "shop", channel, "v1") |
| + seedChannel(t, fx, "shop", channel, "v4") |
| + key := release.ChannelKey("bab", "shop", channel) |
| + replacement, _, err := fx.rel.Get(t.Context(), key) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + seedChannel(t, fx, "shop", channel, "v2") |
| + seedChannel(t, fx, "shop", channel, "v3") |
| + fx.srv.cfg.Releases = &statelessChangedPointer{Store: fx.rel, key: key, replacement: replacement} |
| + token := cliToken(t, fx, "paul@keymail.dev", "changed-rollback") |
| + code, out := postJSON(t, fx.ts.URL+"/api/cli/apps/bab/shop/rollback", map[string]string{"channel": channel}, token) |
| + if code != http.StatusConflict || out["error"] != statelessFloorWant { |
| + t.Fatalf("%d %v", code, out) |
| + } |
| + p, err := release.Channel(t.Context(), fx.rel, fx.pub, "bab", "shop", channel) |
| + if err != nil || p.Version != "v4" { |
| + t.Fatalf("unchecked target published: %+v %v", p, err) |
| + } |
| +} |
diff --git a/internal/console/updatescore.go b/internal/console/updatescore.go| index 7cfb02b61..776884383 100644 |
| --- a/internal/console/updatescore.go |
| +++ b/internal/console/updatescore.go |
| @@ -163,6 +163,12 @@ func (s *Server) applyUpdates(ctx context.Context, acct *Account, app, principal |
| return updatesView{}, http.StatusBadGateway, fmt.Sprintf(updatewords.Text("settings.console.pin-check-failed"), next.Pin) |
| } |
| } |
| + if next.Pin != "" && next.Pin != rec.Pin { |
| + if ref := s.statelessVersionRefusal(ctx, acct.Sqid, app, next.Channel, next.Pin); ref != nil { |
| + return updatesView{}, ref.Status, ref.Msg |
| + } |
| + } |
| + |
| // Only a change that turns a setting ON waits for the fleet: manual newly |
| // set, a different pin, or a new major. A value re-sent unchanged beside |
| // a clear (a form that sends its full state) is not an enable, so the |
diff --git a/internal/provision/stateless_replicas_census_test.go b/internal/provision/stateless_replicas_census_test.go| index f13fdc7b6..eb693a99d 100644 |
| --- a/internal/provision/stateless_replicas_census_test.go |
| +++ b/internal/provision/stateless_replicas_census_test.go |
| @@ -20,6 +20,17 @@ func statelessReplicasWriteCensusInventory() []censusEntry { |
| // lock; both API callsites hold withRecordLock after fleet ownership, |
| // credential, assignment and payload identity checks. No direct Put added. |
| for _, next := range []censusEntry{ |
| + // Task 4 R21 self-review: the pin path reads the named release and |
| + // refuses stateless selections below the platform floor before the |
| + // existing typed UpdateRecord, under the same record lock and ETag. |
| + {"internal/console/updatescore.go", "Server.applyUpdates", "record-writer", "key:UpdateRecord", "e5e05fa023d7f235f971ee99935199f52b409cc567edaa4a21ce2aa3ef941a98"}, |
| + // Task 4 R21 self-review: optional target checks run before the same |
| + // conditional channel-pointer Put. Account/channel validation, signing, |
| + // digest rules and app mutation admission remain. No record key or |
| + // write destination changes. Independent review is controller-owned. |
| + {"internal/release/release.go", "Signer.claimRawRollbackAuthorized", "nonrecord", "sel:Put", "24fcbd5b759e9658583508a57ca1b4766dac6a80f27d9d0798d481edbde0bfd0"}, |
| + {"internal/release/release.go", "claimRawFastTrack", "nonrecord", "sel:Put", "bb9b5bbae8a083aa445f7a8735a74ce0e46b8bde3079397da3152c1cdf475f95"}, |
| + |
| // Task 3a fix 1 self-review: statelessRecordKey is an in-memory context |
| // key carrying the attempt's registry row. These four declarations do not |
| // construct a bucket key or add a record writer. prepareStateless still |
diff --git a/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv| index 02f92720d..4d07fccc7 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-stateless-replicas-1.tsv |
| @@ -208,7 +208,7 @@ internal/rollout/wakeplan.go Manager.planRow legacy accepted-legacy accepted-leg |
| @coverage internal/ops 67289ea5b95d14e295bc19e855fab6b00ed240b822e75d4be42b9ded59662e4d |
| @coverage internal/provision 98d437ab5b9838a252b4e8b517926cac9a568571eae6dc817f94f7ed489e19db |
| @coverage internal/registry 09ca13b89e733863570c1147f227f14aa8e1435c55f6ef3e4949a3f6b05effbf |
| -@coverage internal/release 62bf9d23afe7d59d1aa4c8d77051d8dbb2cdca2ecfe3b9e6c36fc79f8ead54ab |
| +@coverage internal/release c5648fedbd46820dd788081edd77866cec9eb99a93736cedb22d47555a80dce4 |
| @coverage internal/replicas 53b94eb040154539a0a977498b4b8bc1d53d82f67c1c6233667a0b823dd30d8a |
| @coverage internal/rollout 3eb995849e51ceae6255fed33eb411b61e5d5ce5d6d7d71a37fb53da059e02df |
| @fields A,Account,Accounts,AddedAt,Addr,Addrs,Alias,Aliases,Alive,AllowAbsent,App,Archives,Args,AssetGen,AssetsOff,Assigned,At,Attempts,B,Backing,Bucket,BuildState,By,Callback,CallbackError,CallbackFailed,Canary,Caps,CertExpiresAt,Changed,Channel,CheckedAt,Claim,ClaimIncarnation,ClaimOwner,ClaimOwnership,ClaimRowID,ClaimStamp,Class,Column,Contents,CreatedAt,DBPath,DNSCheckedAt,DNSStatus,Deadline,Default,Demand,Digest,DoneBefore,DrainingSince,Due,DueAt,EgressAllow,Env,EnvBefore,Environment,Error,ErrorKind,ExcludeHosts,ExpectGood,ExpectOp,ExpectPair,Expected,F,Failed,FenceGen,Field,Fleet,FleetBox,FleetBoxes,FleetLabel,Fleets,From,FromDB,FromOp,FromSock,Gate,GoodDemand,GoodDigest,GoodVersion,HA,Hash,Health,Held,Hibernate,HoldOp,Host,Hosts,ID,Id,IdValue,Idle,IdleSeconds,ImportGate,Incarnation,Journal,Keep,KeyFP,Kind,Label,LabelledAt,LastAt,LastError,LastMs,LastStatus,Limit,MaxRun,MaxRunSeconds,Method,Moved,Ms,Name,Next,NextAt,NextDue,NextGood,NextValue,Now,Number,Number64,Observed,ObservedValue,Old,On,OnConflict,Op,Original,Owner,Ownership,P,Pair,Path,Paths,Platform,PolicyExpiresAt,Pool,Prefix,Prev,PrevVersion,Provisioned,Pub,RDs,RateLimit,RecordKey,Region,Regional,Registration,Replica,Replicas,Replication,Retirement,Route,Routes,Row,Rows,Runtime,SecretsKeyFP,SecretsKeySetAt,SecretsKeySetBy,SecretsPub,Seed,SeedID,SeedSource,ServingSeq,ServingVersion,Size,Slug,Socket,Spec,Sqid,State,Stateless,Status,StatusNamed,Steering,StringMap,T,TValue,Tags,Target,Targets,Text,Timer,Timers,Times,To,ToDB,ToOp,ToSock,TokenHash,Tunnel,Type,Unit,UpdateSettings,Ver,Version,W,WakeIncarnation,Wildcards,closed,conn,connect,ctx,d,dec,done,enc,full,input,mu,output,path,readOnly,remote,sql,wait |
diff --git a/internal/release/claim_app_writes.go b/internal/release/claim_app_writes.go| index a2dcdc2a8..6a560f8d5 100644 |
| --- a/internal/release/claim_app_writes.go |
| +++ b/internal/release/claim_app_writes.go |
| @@ -48,9 +48,10 @@ func (sg Signer) PromoteOnLadder(ctx context.Context, s Store, acct, app, channe |
| } |
| // RollbackAuthorized is claimRawRollbackAuthorized under one app mutation. |
| -func (sg Signer) RollbackAuthorized(ctx context.Context, s Store, acct, app, channel string, authorize func(*Pipeline) error) error { |
| +// Each optional checkTarget judges the selected history entry before the CAS. |
| +func (sg Signer) RollbackAuthorized(ctx context.Context, s Store, acct, app, channel string, authorize func(*Pipeline) error, checkTarget ...func(string) error) error { |
| return WithAppMutation(ctx, s, acct, app, "release.Rollback", func(ctx context.Context) error { |
| - return sg.claimRawRollbackAuthorized(ctx, s, acct, app, channel, authorize) |
| + return sg.claimRawRollbackAuthorized(ctx, s, acct, app, channel, authorize, checkTarget...) |
| }) |
| } |
diff --git a/internal/release/release.go b/internal/release/release.go| index c69d1b38e..f19a54f58 100644 |
| --- a/internal/release/release.go |
| +++ b/internal/release/release.go |
| @@ -1381,7 +1381,7 @@ func (sg Signer) Rollback(ctx context.Context, s Store, acct, app, channel strin |
| // RollbackAuthorized is Rollback with an optional authorize hook, called on a |
| // pipeline read after the pointer read and before the conditional write. nil |
| // means no hook and no extra reads. |
| -func (sg Signer) claimRawRollbackAuthorized(ctx context.Context, s Store, acct, app, channel string, authorize func(*Pipeline) error) error { |
| +func (sg Signer) claimRawRollbackAuthorized(ctx context.Context, s Store, acct, app, channel string, authorize func(*Pipeline) error, checkTarget ...func(string) error) error { |
| if !ValidAccount(acct) { |
| return fmt.Errorf("rollback: invalid account %q", acct) |
| } |
| @@ -1413,6 +1413,12 @@ func (sg Signer) claimRawRollbackAuthorized(ctx context.Context, s Store, acct, |
| return &AuthorizationError{Err: aerr} |
| } |
| } |
| + for _, check := range checkTarget { |
| + if err := check(old.History[0]); err != nil { |
| + return err |
| + } |
| + } |
| + |
| marker, merr := ReadDigestMarker(ctx, s, pub, acct) |
| if merr != nil { |
| return fmt.Errorf(TextMarkerUnreadable, "rollback", acct, merr) |
| @@ -1459,7 +1465,7 @@ func (sg Signer) claimRawRollbackAuthorized(ctx context.Context, s Store, acct, |
| // keys on the box's own first sighting of the VERSION (bake.go), which this |
| // write does not change, and the console suppresses its bakes-until |
| // estimate for a waived head. |
| -func claimRawFastTrack(ctx context.Context, s Store, priv ed25519.PrivateKey, acct, app, channel, actor string) (string, error) { |
| +func claimRawFastTrack(ctx context.Context, s Store, priv ed25519.PrivateKey, acct, app, channel, actor string, checkTarget ...func(string) error) (string, error) { |
| sg := RootSigner(priv) |
| if !ValidAccount(acct) { |
| return "", fmt.Errorf("fast-track: invalid account %q", acct) |
| @@ -1476,6 +1482,12 @@ func claimRawFastTrack(ctx context.Context, s Store, priv ed25519.PrivateKey, ac |
| if err != nil { |
| return "", fmt.Errorf("fast-track: existing pointer at %s: %w", key, err) |
| } |
| + for _, check := range checkTarget { |
| + if err := check(old.Version); err != nil { |
| + return "", err |
| + } |
| + } |
| + |
| if old.FastTrack { |
| return old.Version, nil |
| } |
| @@ -1520,9 +1532,11 @@ func prependCapped[T any](v T, list []T, max int) []T { |
| } |
| return out |
| } |
| -func FastTrack(ctx context.Context, s Store, priv ed25519.PrivateKey, acct, app, channel, actor string) (claimResult0 string, claimResult1 error) { |
| + |
| +// FastTrack checks the selected head before waiving its bake window. |
| +func FastTrack(ctx context.Context, s Store, priv ed25519.PrivateKey, acct, app, channel, actor string, checkTarget ...func(string) error) (claimResult0 string, claimResult1 error) { |
| claimResult1 = WithAppMutation(ctx, s, acct, app, "release.FastTrack", func(claimContext context.Context) error { |
| - claimResult0, claimResult1 = claimRawFastTrack(claimContext, s, priv, acct, app, channel, actor) |
| + claimResult0, claimResult1 = claimRawFastTrack(claimContext, s, priv, acct, app, channel, actor, checkTarget...) |
| return claimResult1 |
| }) |
| return |