carlos / platform Public

console: managed fleet growth stop; stricter #1008 witnesses

Astra round 2 P1: a managed fleet's add (handleAPIManagedFleetAdd ->
reserveManagedFleet -> enrolManagedBox -> AddManagedFleetBox) grew the
fleet without fleetGrowthRefusal, so a one-box managed fleet's
unlabelled stateless instance was cut off when its second box joined.
The add is now judged before the reservation (fleetGrowthBy, for N
boxes), so nothing is provisioned on a refusal (SR-5-C02).

Tests, per the review's P2s:
- TestManagedGrowthCannotCutOffStatelessInstance: refused with nothing
  reserved; the labelled control is reserved.
- TestNoTransitionCutsOffAStatelessInstance: each world names exactly the
  transitions it must refuse with the #1008 refusal and the ones it
  refuses for its own reason; every other transition must succeed,
  controls included. Worlds get an edge history so rollback selects a
  stateless build.
- The hibernating check requires the exact refusal.
- TestCopiesPublicationEvidence: a stateless publication reads the
  inventory and an unreadable one answers 503 (the deliberate rule
  change, agreed in round 1).
With the guard disabled, six cases fail.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9219e42c40544dec51f6fced6214ca2c5b2dff8e parent d0ff269
5 files changed, +130 −24
  • docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md +1 −1
  • internal/console/appcopies.go +15 −4
  • internal/console/copiespublication_test.go +9 −3
  • internal/console/copiesunlabelled_test.go +97 −15
  • internal/console/managedapi.go +8 −1

CI failed — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="e93c57d7-183a-4f28-9f77-53591dc22e69"> Agent manager 8a3d302: add the managed-growth stop at reservation (same fleetGrowthRefusal) plus the managed world in the invariant test and the P2 test strengthening, then a NARROW Astra confirm of just that diff (not a new round), and merge on green. Its refusal text joins the copy review: send me the strings file path when ready and I&apos;ll submit it. </paseo-system>

Human

<task-notification> <task-id>b8wp0ocm4</task-id> <tool-use-id>toolu_01FLfVv7VqA1Wt9DzK12Fn8Z</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/b8wp0ocm4.output</output-file> <status>completed</status> <summary>Background command "Report the managed-growth P1 to 8a3d302" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>byje5ru38</task-id> <tool-use-id>toolu_01W8eH3vK2uh4MDJDgVdc565</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/byje5ru38.output</output-file> <status>completed</status> <summary>Background command "Run the related console tests" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>bc2xk1rgi</task-id> <tool-use-id>toolu_01KjCe4n5HzThAEaQLYtZSyy</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/72128d15-58b8-452f-9f7e-8e864e8854d2/tasks/bc2xk1rgi.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on the trimmed guard" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 107 g CO₂e (13,617,298 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on stateless-unlabelled-guard, 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/plans/2026-11-01-stateless-replicas-copy.md b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
index 65a89e04b..87a60fce7 100644
--- a/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
+++ b/docs/superpowers/plans/2026-11-01-stateless-replicas-copy.md
@@ -167,4 +167,4 @@ copy too. Internal wire enums are not an excuse to expose unreviewed text.
| SR-4-C93 | docs/site/stateless-replicas.md | An app that creates its own instance.key or report.token file must take those values from a shared source, its configuration or its environment, or run one copy. The platform gives every copy the same CARLOS_INSTANCE_KEY, but it cannot stop each copy of an app from writing a different file of its own. | approved (controller; Luna house rules) (drill 1 round 2, A3 restriction) |
| SR-4-C94 | docs/site/stateless-replicas.md | When a copy switches, its old build stops once the new one serves. A response still streaming from the old build when it stops is cut, as when a box stops. Websockets on the old build disconnect and their clients reconnect to a healthy copy. | approved (controller; Luna house rules) (drill 3, H4) |
| SR-5-C01 | internal/console/appcopies.go | <host> is not tied to one box of fleet <fleet>, and that fleet has more than one box. a release without a local database needs that first, so keep this app on a release with a local database for now | DRAFT, awaiting Paul's copy review (#1008; refused at ship, at any publication of a stateless build, and at copies above 1) |
-| SR-5-C02 | internal/console/appcopies.go | <host> runs a release without a local database and is not tied to a box of fleet <fleet>, so a second active box would stop it. move it to a release with a local database before adding a box | DRAFT, awaiting Paul's copy review (#1008; refused at fleet add-box and box reactivation) |
+| SR-5-C02 | internal/console/appcopies.go | <host> runs a release without a local database and is not tied to a box of fleet <fleet>, so a second active box would stop it. move it to a release with a local database before adding a box | DRAFT, awaiting Paul's copy review (#1008; refused at fleet add-box, box reactivation and a managed fleet add) |
diff --git a/internal/console/appcopies.go b/internal/console/appcopies.go
index 638db3770..1c0499f4c 100644
--- a/internal/console/appcopies.go
+++ b/internal/console/appcopies.go
@@ -515,23 +515,34 @@ func unlabelledFleetRecordRefusal(reg consoleRegistry, recs []provision.Record)
// coordinator door accepts such a record only on a one-box fleet, so the
// growth alone would cut it off. Reads it can't finish answer 503.
func (s *Server) fleetGrowthRefusal(ctx context.Context, reg consoleRegistry, acct *Account, fleet, label string) *doorRefusal {
+ return s.fleetGrowthBy(ctx, reg, acct, fleet, label, 1)
+}
+
+// fleetGrowthBy is fleetGrowthRefusal for adding boxes boxes at once (a
+// managed fleet's add, judged at reservation so nothing is provisioned).
+// label, when set, is the one box being added: already active, it is not
+// growth.
+func (s *Server) fleetGrowthBy(ctx context.Context, reg consoleRegistry, acct *Account, fleet, label string, boxes int) *doorRefusal {
unread := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: msgFleetBoxNotAdded}
- boxes, err := reg.ListFleetBoxes(fleet)
+ listed, err := reg.ListFleetBoxes(fleet)
if err != nil {
return unread
}
active := 0
- for _, b := range boxes {
+ for _, b := range listed {
if b.Status == "active" {
- if b.Label == label {
+ if label != "" && b.Label == label {
return nil // already active: not growth (the door answers the duplicate)
}
active++
}
}
- if active+1 <= 1 || s.cfg.Releases == nil {
+ if boxes < 1 || active+boxes <= 1 {
return nil
}
+ if s.cfg.Releases == nil {
+ return unread
+ }
apps, err := s.store.AppsIn(acct.ID)
if err != nil {
return unread
diff --git a/internal/console/copiespublication_test.go b/internal/console/copiespublication_test.go
index ba4544803..dc226cda1 100644
--- a/internal/console/copiespublication_test.go
+++ b/internal/console/copiespublication_test.go
@@ -175,7 +175,10 @@ func TestCopiesPublicationEvidence(t *testing.T) {
{"unread config unsafe", false, false, "config", 503},
{"unread config safe", false, true, "config", 200},
{"unread inventory unsafe", true, false, "record", 503},
- {"unread inventory safe", true, true, "record", 200},
+ // A stateless target reads the inventory for #1008's guard (an
+ // unlabelled record on a multi-box fleet), and an unreadable one
+ // refuses with a retry rather than publish unchecked.
+ {"unread inventory safe", true, true, "record", 503},
} {
t.Run(tc.name, func(t *testing.T) {
fx, token := copiesWorld(t)
@@ -210,8 +213,11 @@ func TestCopiesPublicationEvidence(t *testing.T) {
if counter.gets[cfgKey] != 1 {
t.Fatalf("config GETs=%d, want exactly one", counter.gets[cfgKey])
}
- if (!tc.explicit || tc.safe) && counter.gets[recKey] != 0 {
- t.Fatal("legacy/safe target read assignments")
+ if !tc.explicit && !tc.safe && counter.gets[recKey] != 0 {
+ t.Fatal("legacy target read assignments")
+ }
+ if tc.safe && tc.failure != "record" && counter.gets[recKey] == 0 {
+ t.Fatal("stateless target published without reading the inventory (#1008)")
}
})
}
diff --git a/internal/console/copiesunlabelled_test.go b/internal/console/copiesunlabelled_test.go
index 09fd1a368..45196679d 100644
--- a/internal/console/copiesunlabelled_test.go
+++ b/internal/console/copiesunlabelled_test.go
@@ -2,12 +2,16 @@ package console
import (
"context"
+ "crypto/ed25519"
+ "crypto/rand"
"fmt"
"net/http"
"strings"
"testing"
+ "time"
"github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
)
@@ -65,8 +69,20 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
type world struct {
name string
setup func(t *testing.T, fx *consoleFixture)
- // guarded worlds expect some refusal; the control expects none.
- control bool
+ // refused names the transitions this world must refuse with the
+ // #1008 refusal; every other transition must succeed, except a
+ // reactivation of a box that is already active (the duplicate).
+ refused map[string]bool
+ // other names a transition this world refuses for its own reason
+ // (not #1008), by a fragment of the refusal.
+ other map[string]string
+ }
+ // edgeHistory gives edge a previous stateless build, so a rollback
+ // selects one (v2, then back to v1).
+ edgeHistory := func(t *testing.T, fx *consoleFixture) {
+ if err := release.Promote(context.Background(), fx.rel, fx.priv, fx.sqid, "shop", "edge", "v2"); err != nil {
+ t.Fatal(err)
+ }
}
worlds := []world{
{"two boxes, unlabelled, edge on a local-database build", func(t *testing.T, fx *consoleFixture) {
@@ -75,8 +91,9 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
if err := release.Promote(context.Background(), fx.rel, fx.priv, fx.sqid, "shop", "edge", "s1"); err != nil {
t.Fatal(err)
}
- }, false},
+ }, map[string]bool{"ship stateless": true, "promote stateless onto edge": true, "rollback edge": true, "copies 2": true}, nil},
{"one box, unlabelled, edge stateless and working", func(t *testing.T, fx *consoleFixture) {
+ edgeHistory(t, fx)
unlabel(t, fx)
placementEdit(t, fx, "b.example.com", func(r *provision.Record) { r.FleetBox = "pi-1" })
reg := openTestReg(t, fx)
@@ -84,8 +101,8 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
if err := reg.SetFleetBoxStatus("pi", "pi-2", "detached"); err != nil {
t.Fatal(err)
}
- }, false},
- {"two boxes, labelled", func(*testing.T, *consoleFixture) {}, true},
+ }, map[string]bool{"reactivate pi-2": true, "add pi-3": true}, map[string]string{"copies 2": "eligible boxes"}},
+ {"two boxes, labelled", edgeHistory, nil, nil},
}
type transition struct {
name string
@@ -116,7 +133,6 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
{"add pi-3", addBox("pi-3")},
}
for _, w := range worlds {
- refusedAny := false
for _, tr := range transitions {
t.Run(w.name+"/"+tr.name, func(t *testing.T) {
fx, token := copiesWorld(t)
@@ -125,11 +141,24 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
t.Fatalf("world starts broken: %v", cut)
}
code, out := tr.do(t, fx, token)
- ours := strings.Contains(out, "is not tied to") && code == http.StatusConflict
- if ours {
- refusedAny = true
- if w.control {
- t.Fatalf("control world refused: %d %s", code, out)
+ ours := code == http.StatusConflict && (strings.Contains(out, "is not tied to one box") || strings.Contains(out, "is not tied to a box"))
+ switch {
+ case w.refused[tr.name]:
+ if !ours {
+ t.Fatalf("want the #1008 refusal, got %d %s", code, out)
+ }
+ case w.other[tr.name] != "":
+ if code < 300 || ours || !strings.Contains(out, w.other[tr.name]) {
+ t.Fatalf("want this world's own refusal %q, got %d %s", w.other[tr.name], code, out)
+ }
+ case tr.name == "reactivate pi-2" && w.name != "one box, unlabelled, edge stateless and working":
+ // pi-2 is already active: the duplicate answer.
+ if code != http.StatusConflict || ours {
+ t.Fatalf("duplicate box: %d %s", code, out)
+ }
+ default:
+ if code >= 300 {
+ t.Fatalf("want accepted, got %d %s", code, out)
}
}
if code < 300 {
@@ -139,9 +168,6 @@ func TestNoTransitionCutsOffAStatelessInstance(t *testing.T) {
}
})
}
- if !w.control && !refusedAny {
- t.Errorf("%s: the guard refused nothing", w.name)
- }
}
}
@@ -156,7 +182,7 @@ func TestStatelessPublicationCoversHibernating(t *testing.T) {
if ref == nil || ref.Msg != fmt.Sprintf(copiesUnlabelled, "a.example.com", "pi") {
t.Fatalf("unlabelled guard: %+v", ref)
}
- if got := fx.srv.statelessPublicationRefusal(ctx, fx.sqid, "shop", "edge", m, nil, ""); got == nil || got.Status != http.StatusConflict {
+ if got := fx.srv.statelessPublicationRefusal(ctx, fx.sqid, "shop", "edge", m, nil, ""); got == nil || got.Status != http.StatusConflict || got.Msg != fmt.Sprintf(copiesUnlabelled, "a.example.com", "pi") {
t.Fatalf("hibernating stateless publication: %+v", got)
}
}
@@ -165,3 +191,59 @@ func metaStateless(t *testing.T, version string) shipPart {
t.Helper()
return shipPart{name: "meta", body: []byte(`{"version":"` + version + `","kind":"binary","stateless":true}`)}
}
+
+// TestManagedGrowthCannotCutOffStatelessInstance (#1008): a managed fleet's
+// add is the other way a fleet grows. With one active box and an unlabelled
+// instance whose channel runs a stateless build, the add is refused before
+// anything is reserved; with the record labelled, it is reserved.
+func TestManagedGrowthCannotCutOffStatelessInstance(t *testing.T) {
+ for _, labelled := range []bool{false, true} {
+ t.Run(fmt.Sprintf("labelled=%v", labelled), func(t *testing.T) {
+ s := managedAPIFixture(t)
+ ctx := context.Background()
+ managedAPIReply(t, managedAPICall(s, "create", "abc", "", managedAPIBody("a", 1)))
+ // The create has run its course; an add may be asked.
+ s.store.db.Exec(`UPDATE managed_ops SET state='failed',error='managed_preparation_failed'`)
+ reg, err := registry.Open(s.cfg.Registry)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer reg.Close()
+ if err := reg.AddManagedFleetBox(registry.FleetBox{Fleet: "production", Label: "m-1", TokenHash: strings.Repeat("a", 64), Status: "active", AddedAt: time.Now().Unix()}, time.Now().Unix()); err != nil {
+ t.Fatal(err)
+ }
+ pub, priv, _ := ed25519.GenerateKey(rand.Reader)
+ s.cfg.ReleasePub = pub
+ if _, err := s.store.CreateAppIn(42, "shop", "owner@example.com", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ m := release.Manifest{Schema: 1, Kind: "binary", App: "shop", Version: "v1", Stateless: true, Artifacts: map[string]release.Artifact{"linux-amd64": {File: "app"}}}
+ if err := release.Ship(ctx, s.cfg.Releases, "abc", m, map[string][]byte{"linux-amd64": []byte("app")}); err != nil {
+ t.Fatal(err)
+ }
+ if err := release.Promote(ctx, s.cfg.Releases, priv, "abc", "shop", "edge", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ rec := provision.Record{Schema: 1, Host: "a.example.com", Slug: "a", App: "shop", Account: "abc", Region: "fleet/production", Channel: "edge", CreatedAt: time.Now().UTC()}
+ if labelled {
+ rec.FleetBox = "m-1"
+ }
+ if err := provision.CreateRecord(ctx, s.cfg.Releases, rec); err != nil {
+ t.Fatal(err)
+ }
+ w := managedAPICall(s, "add", "abc", "production", `{"boxes":1,"request_id":"bbbbbbbbbbbbbbbbbbbbbb"}`)
+ var adds int
+ s.store.db.QueryRow(`SELECT count(*) FROM managed_ops WHERE kind='add'`).Scan(&adds)
+ want := fmt.Sprintf(copiesUnlabelledGrowth, "a.example.com", "production")
+ if labelled {
+ if w.Code >= 300 || adds != 1 {
+ t.Fatalf("labelled control: %d %s, add ops %d", w.Code, w.Body, adds)
+ }
+ return
+ }
+ if w.Code != http.StatusConflict || !strings.Contains(w.Body.String(), want) || adds != 0 {
+ t.Fatalf("unlabelled: %d %s, add ops %d, want 409 %q and nothing reserved", w.Code, w.Body, adds, want)
+ }
+ })
+ }
+}
diff --git a/internal/console/managedapi.go b/internal/console/managedapi.go
index cae3d2791..a957f8c5a 100644
--- a/internal/console/managedapi.go
+++ b/internal/console/managedapi.go
@@ -137,7 +137,7 @@ func (s *Server) handleAPIManagedFleetCreate(w http.ResponseWriter, r *http.Requ
s.managedAPIReserved(w, r, op)
}
func (s *Server) handleAPIManagedFleetAdd(w http.ResponseWriter, r *http.Request) {
- addr, acct, fleet, _, ok := s.apiFleet(w, r)
+ addr, acct, fleet, reg, ok := s.apiFleet(w, r)
if !ok {
return
}
@@ -181,6 +181,13 @@ func (s *Server) handleAPIManagedFleetAdd(w http.ResponseWriter, r *http.Request
if !s.managedAPIEntitlement(w, acct) {
return
}
+ // #1008: growth past one active box must not cut off an unlabelled
+ // instance running a stateless build. Judged before the reservation,
+ // so nothing is provisioned on a refusal.
+ if ref := s.fleetGrowthBy(r.Context(), reg, acct, fleet.Name, "", req.Boxes); ref != nil {
+ writeDoorRefusalJSON(w, r, ref)
+ return
+ }
op, _, _, err := s.reserveManagedFleet(r.Context(), req)
if err != nil {
s.managedAPIError(w, err)