carlos / platform Public

Fleet public routes Task 9: the fleet-create barrier and the three floor interleavings

handleAPIFleetNew, the only fleet-create door, holds fleetFloorMu from
its barrier through its registry write (createFleetAboveTheFloor). The
barrier (fleetCreateFloorRefusal) reads the router pointer of every
channel the fresh heartbeats follow (stable for a box naming none): a
pointer below release.FleetForwardFloor or unparseable is 409 FPR-C06;
an unreadable pointer, or heartbeats that cannot all be read, is 503
FPR-C07; an absent pointer passes (R2-2). fleetFloorHooks (beforeLock,
locked, createBeforeLock) are the test seams, as regionalFloorHooks.

Tests: the barrier's answers through the door, the mutex held through
the write, and §8 test 11's interleavings (a) fleet first, (b)
publication first, (c) the create held across the publication's write,
with a synchronous TryLock inside the publication. Copy: FPR-C06 and
FPR-C07 built. Spec §9 names the single door; §6 counts the heartbeat
read; §7 records Task 9's card (no unit).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 2b9490a975c19cd43a42a7cd212df8929d4ec766 parent 3895bf1
6 files changed, +500 −12
  • approved_fleet_routes_copy_test.go +1 −1
  • docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md +20 −9
  • internal/console/fleetfloor.go +105 −0
  • internal/console/fleetfloor_test.go +359 −0
  • internal/console/fleets.go +10 −1
  • internal/console/server.go +5 −1

Intent

Human

<task-notification> <task-id>ad1712f1645e0b704</task-id> <tool-use-id>toolu_01UzzA2udZzLfW5mCdkLzep1</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/ad1712f1645e0b704.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8: release floor" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status: DONE_WITH_CONCERNS.** None of the concerns are blockers; they are notes for the Astra review. The full report is in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/.superpowers/sdd/2026-10-30-fleet-public-routes/task-8-report.md`. **Commits** (on `design-fleet-public-routes`, not pushed): - `675b6361`: Step 1. The three console functions gain an unused `allowFleet` parameter, and all 30 callers pass `false`, matching the brief's list exactly; a grep found no others. The tests were green on this commit before any behaviour changed (ruling #18). - `3895bf1b`: Task 8 itself. - **Release side:** the floor (v0.32.0), its override flag (help text is FPR-C05 with the floor written in), and the signed pointer field, which is `omitempty` so pointers without it are byte-identical. - **Console:** new file `internal/console/fleetfloor.go` holds the judge, `fleetFloorPublish` and C02–C04. The floor is judged in `systemFloorSnapshot`, including a channel's first publication. It is judged again under `fleetFloorMu`, which is taken before `regionalMu`. - **Activations:** the override is part of the activation identity (`omitempty`, so existing ids are unchanged) and of the held-rollback check. - **Doors and CLI:** both doors return 409, and both CLI commands carry the flag. - **Copy and spec:** C02–C05 are byte for byte the approved rows and are added to `fleetRoutesCopyBuilt`. Spec §7 now records the census. **Tests:** the Step 3 pattern plus the #19 names (`TestPlacementsRefusesBelowAPublishedChannel|TestPlan9Operator`) pass in release, console and root. The new behavioural tests failed against a stubbed judge first. 18 console mutations and 7 release/root mutations were all caught. Build, vet, gofmt, cross-builds (darwin, windows, linux/arm64) and `TestPlan9B8RecordWriteCensus` pass. **Census:** the card shows no unit for any Task 8 declaration. They change only the `internal/release` and root package hashes, which earlier tasks had already re-pinned. I recorded that in spec §7. **Concerns:** 1. The brief's `-run` pattern contains `Rollback`, which also matches `TestControlPlaneAppRefusesAServiceRollback`. That test fails in this worktree on the known buildvcs problem and passes with `GOFLAGS=-buildvcs=false`, so my runs used that flag. Separately, `TestPlan14GenerationPinsPrivateMount` fails with "permission denied" when the whole release package runs here; it is outside the pattern and unrelated to this task. 2. Interleaving (a) is tested without Task 9's hooks: a store read hook creates the fleet between the early judgment and the one under the mutex. Task 9 may want to move these tests onto its hooks. 3. A fleet-listing error is a plain error, not the floor error. The update door's job fails with it, and the rollback door returns 500, which is how the regional floor treats a failed claims listing. 4. In a held rollback, the fleet and regional judges now share one read of the current pointer, made under `fleetFloorMu`. The publication's CAS still binds it, and it saves a GET. 5. `ctx` is unused inside `fleetForwardFloorJudge`, because the fleet listing it calls takes none; the parameter stays to match the brief's signature.</result> <usage><subagent_tokens>254967</subagent_tokens><tool_uses>98</tool_uses><duration_ms>2086051</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>b8d8324k6</task-id> <tool-use-id>toolu_01DGQUpfubhYWEmjph2xfvhi</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/b8d8324k6.output</output-file> <status>completed</status> <summary>Background command "Package Task 8 and run its Astra task review" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 22.6 g CO₂e (2,895,488 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-public-routes, 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_fleet_routes_copy_test.go b/approved_fleet_routes_copy_test.go
index 24c7c971a..23c77e2bc 100644
--- a/approved_fleet_routes_copy_test.go
+++ b/approved_fleet_routes_copy_test.go
@@ -44,7 +44,7 @@ var fleetRoutesCopyStatuses = []string{"pending", "approved", "struck"}
// row is approved. Task 3 builds the CLI refusal (FPR-C01); Task 8 the floor
// rows (FPR-C02 to FPR-C05); Task 9 the fleet-create barrier (FPR-C06,
// FPR-C07); Task 11 the REASON cell (FPR-C08).
-var fleetRoutesCopyBuilt = []string{"FPR-C01", "FPR-C02", "FPR-C03", "FPR-C04", "FPR-C05"}
+var fleetRoutesCopyBuilt = []string{"FPR-C01", "FPR-C02", "FPR-C03", "FPR-C04", "FPR-C05", "FPR-C06", "FPR-C07"}
func mustParseFleetRoutesRecord(t *testing.T) []copyRow {
t.Helper()
diff --git a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
index 2f53e8fdc..d8a0dc8b0 100644
--- a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
+++ b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
@@ -797,7 +797,7 @@ under `fleets/`, `B` = binding objects.
| build states, alias pass, edges-file assets | per their selectors | unchanged: forward rows excluded or read nothing |
| bindings pass | `1 + F + B` per pass on every platform box | on the hub only: saves `(N - 1) x 262 x (1 + F + B)` |
| edges file | written on change | one more PUT when a forward row appears or goes; readers' existing 30 s mirror |
-| console floor and barrier (§9) | none | none in steady state; one system-pointer GET per followed channel on each fleet create, and on a channel move that crosses the floor (as the regional floor) |
+| console floor and barrier (§9) | none | none in steady state; on each fleet create, one `status/boxes/` listing with a GET per report (the heartbeats that name the followed channels; Task 9) and one system-pointer GET per followed channel, and on a channel move that crosses the floor (as the regional floor) |
| fleet boxes | unchanged | unchanged |
So 1a is not free: each fleet app costs the hub about what a platform app
@@ -1214,6 +1214,15 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites):
`rootfsfloor.go`) is outside the root scope and no 9B8 unit
(`TestPlan9B8RecordWriteCensus` passes unchanged).
+ Task 9's card: no unit; the units and the seal (`78b7e7e3...`) are
+ Task 8's. The barrier (`fleetCreateFloorRefusal`,
+ `createFleetAboveTheFloor` and `fleetFloorHooks` in `fleetfloor.go`),
+ the hooks field in `server.go` and the door in `fleets.go`
+ (`handleAPIFleetNew`, no 9B8 unit: it writes the registry row and, as
+ before, the fleet owner record) are console code, outside the root
+ scope; the root package gains only a copy-gate list entry
+ (`fleetRoutesCopyBuilt` += FPR-C06, FPR-C07). Nothing to reconcile.
+
Root's own row readers (adopt, capability, named units, restart, stage,
rootfs, `layoutReversalIncomplete`) change no code and select by
`Kind == "instance"`, `IsSidecar()`, `Unit`, `Runtime`, `Backing`,
@@ -1425,14 +1434,16 @@ the old fleet indefinitely. The RegionalDomainsFloor pattern
returns no pointer instead of skipping. Lock order: `fleetFloorMu` is
taken before `regionalMu`, and nothing under either takes the other
first.
-- The barrier for the other order: the fleet-create doors
- (`handleAPIFleetNew`, `fleets.go:176`, and the page form) hold
- `fleetFloorMu` from their check to their registry write, and refuse
- while any channel the fresh heartbeats follow (stable for a box that
- names none, as `regionalChannelRefusal` reads them,
- `apiplacements.go:935-978`) has a pointer naming a release below the
- floor or one that does not parse; a pointer that cannot be read refuses
- (503). An absent pointer passes. That is the simpler correct choice:
+- The barrier for the other order: the fleet-create door
+ (`handleAPIFleetNew`, `fleets.go:176`; the only one, Task 9: there is
+ no page form, `fleet_byo.html` points at the CLI) holds `fleetFloorMu`
+ from its check to its registry write, and refuses while any channel
+ the fresh heartbeats follow (stable for a box that names none, as
+ `regionalChannelRefusal` reads them, `apiplacements.go:935-978`) has a
+ pointer naming a release below the floor or one that does not parse
+ (409, FPR-C06); a pointer that cannot be read refuses (503, FPR-C07),
+ and so do heartbeats that cannot all be read (an unread one may follow
+ a channel the barrier would miss; Task 9). An absent pointer passes. That is the simpler correct choice:
nothing is on its way to the boxes, and any later publication on that
channel, first included, is judged under the same mutex with this fleet
visible, so a below-floor one is refused (interleaving (a) in §8 test
diff --git a/internal/console/fleetfloor.go b/internal/console/fleetfloor.go
index ee5eb66dd..da6c873eb 100644
--- a/internal/console/fleetfloor.go
+++ b/internal/console/fleetfloor.go
@@ -5,6 +5,10 @@ import (
"errors"
"fmt"
"log"
+ "net/http"
+ "os"
+ "sort"
+ "time"
"github.com/carlosframework/platform/internal/release"
)
@@ -102,6 +106,9 @@ func (s *Server) fleetForwardFloorJudge(ctx context.Context, channel string, cur
// Callers pass their regionalFloorPublish call as publish, so fleetFloorMu
// is held before regionalMu.
func (s *Server) fleetFloorPublish(ctx context.Context, channel string, current func() (*release.SystemPointer, error), target string, allow bool, publish func() (*release.SystemPointer, error)) (*release.SystemPointer, error) {
+ if hook := s.fleetFloorHooks.beforeLock; hook != nil {
+ hook()
+ }
s.fleetFloorMu.Lock()
defer s.fleetFloorMu.Unlock()
if !allow {
@@ -113,5 +120,103 @@ func (s *Server) fleetFloorPublish(ctx context.Context, channel string, current
return nil, err
}
}
+ if hook := s.fleetFloorHooks.locked; hook != nil {
+ hook()
+ }
return publish()
}
+
+// fleetFloorHooks are test seams: beforeLock runs in fleetFloorPublish
+// after every earlier judgment and reservation and before fleetFloorMu is
+// taken; locked runs under fleetFloorMu after the judgment and before the
+// publication; createBeforeLock runs in the fleet-create door just before
+// it takes fleetFloorMu.
+type fleetFloorHooks struct {
+ beforeLock, locked, createBeforeLock func()
+}
+
+// The barrier for the other order (spec §9): a fleet created while a
+// channel's pointer stands below the floor would make that pointer a
+// crossing nobody judged, since it was published with no fleet. So the
+// fleet-create door (handleAPIFleetNew, the only one) holds fleetFloorMu
+// from its barrier through its registry write (createFleetAboveTheFloor),
+// as every publication holds it from its judgment through its pointer
+// write: either the pointer is published first and the barrier reads it,
+// or the fleet is written first and the publication's judgment sees it.
+// An absent pointer passes (R2-2): nothing is on its way to the boxes, and
+// any later publication on that channel, a first one included, is judged
+// under the same mutex with this fleet visible. Existing fleets are
+// unaffected.
+
+// consoleFleetCreateFloorRefusal (FPR-C06) takes the channel, its
+// release, the floor and the floor.
+const consoleFleetCreateFloorRefusal = "this deployment's %s channel is on %s, below %s. new fleets wait until every channel is on %s or later. try again after the deployment's next update"
+
+// consoleFleetCreateUnreadable (FPR-C07).
+const consoleFleetCreateUnreadable = "could not check this deployment's release channels. try again in a minute"
+
+// fleetCreateFloorRefusal is the barrier, read under s.fleetFloorMu: one
+// router pointer GET per system channel the fresh heartbeats follow (a box
+// that names none follows stable), as regionalChannelRefusal reads them. A
+// pointer naming a release below release.FleetForwardFloor, or one that
+// does not parse, is a 409 FPR-C06 naming the first such channel. A
+// pointer that cannot be read or verified is a 503 FPR-C07, and so are
+// heartbeats that cannot all be read: an unread one may follow a channel
+// this read would miss. An absent pointer passes. With no fresh heartbeat
+// no channel is followed and the barrier reads no pointer.
+func (s *Server) fleetCreateFloorRefusal(ctx context.Context) *doorRefusal {
+ boxes, complete, err := s.loadBoxes(ctx, s.cfg.Releases, "")
+ if err != nil || !complete {
+ log.Printf("console: fleet create barrier: heartbeats (complete %v): %v", complete, err)
+ return &doorRefusal{http.StatusServiceUnavailable, consoleFleetCreateUnreadable}
+ }
+ followed := map[string]bool{}
+ for _, b := range freshHeartbeats(boxes, time.Now()) {
+ ch := ""
+ if b.Metrics != nil {
+ ch = b.Metrics.SystemChannel
+ }
+ if ch == "" {
+ ch = release.RungStable
+ }
+ followed[ch] = true
+ }
+ channels := make([]string, 0, len(followed))
+ for ch := range followed {
+ channels = append(channels, ch)
+ }
+ sort.Strings(channels)
+ floor := "v" + release.FleetForwardFloor.String()
+ for _, ch := range channels {
+ p, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, s.cfg.ReleasePub, release.SystemComponentRouter, ch)
+ if errors.Is(err, os.ErrNotExist) {
+ continue
+ }
+ if err != nil {
+ log.Printf("console: fleet create barrier: system pointer %s: %v", ch, err)
+ return &doorRefusal{http.StatusServiceUnavailable, consoleFleetCreateUnreadable}
+ }
+ if v, ok := release.ParseReleaseVersion(p.Current.Version); !ok || v.Compare(release.FleetForwardFloor) < 0 {
+ return &doorRefusal{http.StatusConflict, fmt.Sprintf(consoleFleetCreateFloorRefusal, ch, p.Current.Version, floor, floor)}
+ }
+ }
+ return nil
+}
+
+// createFleetAboveTheFloor runs create, the fleet-create door's registry
+// write, under s.fleetFloorMu after the barrier passes. A refusal is
+// returned and create is not called. Only the barrier's reads and the
+// registry write are under the mutex; the door's bucket write (the fleet
+// owner record) comes after it is released.
+func (s *Server) createFleetAboveTheFloor(ctx context.Context, create func() (bool, error)) (bool, *doorRefusal, error) {
+ if hook := s.fleetFloorHooks.createBeforeLock; hook != nil {
+ hook()
+ }
+ s.fleetFloorMu.Lock()
+ defer s.fleetFloorMu.Unlock()
+ if ref := s.fleetCreateFloorRefusal(ctx); ref != nil {
+ return false, ref, nil
+ }
+ created, err := create()
+ return created, nil, err
+}
diff --git a/internal/console/fleetfloor_test.go b/internal/console/fleetfloor_test.go
index 7801b68f6..9f810588d 100644
--- a/internal/console/fleetfloor_test.go
+++ b/internal/console/fleetfloor_test.go
@@ -18,6 +18,7 @@ import (
"github.com/carlosframework/platform/internal/hostfloor"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/status"
)
// The fleet forward floor (fleet public routes spec §9, §8 test 11) mirrors
@@ -663,3 +664,361 @@ func TestSystemDoorsRefuseBelowTheFleetForwardFloor(t *testing.T) {
t.Fatalf("the override's rollback pointer = %+v", p)
}
}
+
+// The fleet-create barrier (spec §9, FPR-C06, FPR-C07): the other order of
+// §8 test 11. A fleet create reads the system pointers of the channels the
+// fresh heartbeats follow under fleetFloorMu, and writes its row under the
+// same mutex.
+
+// fcRelease is system release v for the console fixture's arm64 boxes.
+func fcRelease(v string) release.SystemRelease {
+ return release.SystemRelease{Version: v, Artifacts: map[string]release.SystemArtifact{"linux-arm64": {Key: release.SystemArtifactKey(v, "linux-arm64"), SHA256: strings.Repeat("a", 64)}}}
+}
+
+// fcFixture is a console whose owner holds a CLI token, with one fresh box
+// heartbeat (box-1) following stable. Without a fresh heartbeat no channel
+// is followed and the barrier has nothing to read.
+func fcFixture(t *testing.T, code string) (*consoleFixture, string) {
+ t.Helper()
+ fx, token := fleetFixture(t, code)
+ seedBox(t, fx, "box-1", "linux-arm64", "stable", "v0.32.0")
+ return fx, token
+}
+
+// fcPublish publishes v as channel's system pointer, outside the console.
+func fcPublish(t *testing.T, fx *consoleFixture, channel, v string) {
+ t.Helper()
+ if _, err := release.PromoteSystem(t.Context(), fx.rel, release.RootSigner(fx.priv), "router", channel, fcRelease(v), release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// fcCreate is `carlos fleets create name` through the door, with the
+// status and the error it answers. It reports failures as an error, so a
+// goroutine can call it.
+func fcCreate(fx *consoleFixture, token, name string) (int, string, error) {
+ raw, err := json.Marshal(map[string]string{"name": name, "bucket": name + "-data"})
+ if err != nil {
+ return 0, "", err
+ }
+ req, err := http.NewRequest(http.MethodPost, fleetsURL(fx, fx.sqid)+"/new", strings.NewReader(string(raw)))
+ if err != nil {
+ return 0, "", err
+ }
+ req.Header.Set("Content-Type", "application/json")
+ req.Header.Set("Authorization", "Bearer "+token)
+ res, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return 0, "", err
+ }
+ defer res.Body.Close()
+ var out struct {
+ Error string `json:"error"`
+ }
+ if err := json.NewDecoder(res.Body).Decode(&out); err != nil {
+ return res.StatusCode, "", err
+ }
+ return res.StatusCode, out.Error, nil
+}
+
+// fcFleets is the names of the fleets in fx's registry.
+func fcFleets(t *testing.T, fx *consoleFixture) []string {
+ t.Helper()
+ reg := openTestReg(t, fx)
+ defer reg.Close()
+ fleets, err := reg.ListFleets()
+ if err != nil {
+ t.Fatal(err)
+ }
+ var names []string
+ for _, f := range fleets {
+ names = append(names, f.Name)
+ }
+ return names
+}
+
+// fcBelowWant is FPR-C06 for channel at v.
+func fcBelowWant(channel, v string) string {
+ floor := "v" + release.FleetForwardFloor.String()
+ return fmt.Sprintf(consoleFleetCreateFloorRefusal, channel, v, floor, floor)
+}
+
+// [§9, FPR-C06, FPR-C07, R2-2] A fleet is not created while a channel the
+// fresh boxes follow has a pointer below the floor, or one whose version
+// does not parse (409, FPR-C06), or one that cannot be read, or while the
+// heartbeats that say which channels are followed cannot all be read (503,
+// FPR-C07). No fleet row is written. A pointer at the floor and an absent
+// pointer let the create through. Only fresh heartbeats count, and a box
+// naming no channel follows stable.
+func TestFleetCreateRefusedWhileAChannelIsBelowTheFloor(t *testing.T) {
+ refused := func(t *testing.T, fx *consoleFixture, token string, status int, want string) {
+ t.Helper()
+ st, msg, err := fcCreate(fx, token, "home")
+ if err != nil || st != status || msg != want {
+ t.Fatalf("create = %d %q, %v\nwant %d %q", st, msg, err, status, want)
+ }
+ if names := fcFleets(t, fx); len(names) != 0 {
+ t.Fatalf("a refused create wrote fleets %v", names)
+ }
+ }
+ created := func(t *testing.T, fx *consoleFixture, token string) {
+ t.Helper()
+ if st, msg, err := fcCreate(fx, token, "home"); err != nil || st != http.StatusOK {
+ t.Fatalf("create = %d %q, %v; want 200", st, msg, err)
+ }
+ if names := fcFleets(t, fx); len(names) != 1 || names[0] != "home" {
+ t.Fatalf("fleets after the create = %v, want [home]", names)
+ }
+ }
+ t.Run("below-the-floor", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-below")
+ fcPublish(t, fx, "stable", "v0.31.0")
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("stable", "v0.31.0"))
+ })
+ t.Run("at-the-floor", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-at")
+ fcPublish(t, fx, "stable", "v0.32.0")
+ created(t, fx, token)
+ })
+ t.Run("no-pointer", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-none")
+ fpNoPointer(t, fx.srv, "stable")
+ created(t, fx, token)
+ })
+ t.Run("unreadable-pointer", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c07-pointer")
+ if _, err := fx.rel.Put(t.Context(), release.SystemPointerKey("router", "stable"), []byte("not a pointer"), ""); err != nil {
+ t.Fatal(err)
+ }
+ refused(t, fx, token, http.StatusServiceUnavailable, consoleFleetCreateUnreadable)
+ })
+ t.Run("unparseable-pointer", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-unparseable")
+ fcPublish(t, fx, "stable", "4f3c2a1")
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("stable", "4f3c2a1"))
+ })
+ t.Run("unreadable-heartbeat", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c07-heartbeat")
+ fcPublish(t, fx, "stable", "v0.32.0")
+ if _, err := fx.rel.Put(t.Context(), "status/boxes/box-2.json", []byte("not a heartbeat"), ""); err != nil {
+ t.Fatal(err)
+ }
+ refused(t, fx, token, http.StatusServiceUnavailable, consoleFleetCreateUnreadable)
+ })
+ t.Run("every-followed-channel", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-canary")
+ fcPublish(t, fx, "stable", "v0.32.0")
+ seedBox(t, fx, "box-2", "linux-arm64", "canary", "v0.32.0")
+ fcPublish(t, fx, "canary", "v0.31.0")
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("canary", "v0.31.0"))
+ })
+ t.Run("a-box-naming-no-channel-follows-stable", func(t *testing.T) {
+ fx, token := fleetFixture(t, "code-fpr-c06-unnamed")
+ seedBox(t, fx, "box-1", "linux-arm64", "", "v0.32.0")
+ fcPublish(t, fx, "stable", "v0.31.0")
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("stable", "v0.31.0"))
+ })
+ t.Run("a-stale-box-is-not-followed", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-c06-stale")
+ fcPublish(t, fx, "stable", "v0.32.0")
+ b := status.CollectBox(nil, status.Probes{Release: "v0.32.0", Platform: "linux-arm64", SystemChannel: "edge"}, time.Now().Add(-time.Hour))
+ b.Label = "box-2"
+ if err := status.WriteBox(t.Context(), fx.rel, b); err != nil {
+ t.Fatal(err)
+ }
+ fcPublish(t, fx, "edge", "v0.31.0")
+ created(t, fx, token)
+ })
+}
+
+// [§9] createFleetAboveTheFloor runs createBeforeLock without fleetFloorMu,
+// then holds fleetFloorMu from the barrier through the write, and never
+// writes a refused create.
+func TestFleetCreateHoldsFleetFloorMuThroughTheWrite(t *testing.T) {
+ fx, _ := fcFixture(t, "code-fpr-create-mu")
+ s := fx.srv
+ hooked := false
+ s.fleetFloorHooks.createBeforeLock = func() {
+ hooked = true
+ if fpHeld(&s.fleetFloorMu) {
+ t.Error("createBeforeLock ran with fleetFloorMu held")
+ }
+ }
+ wrote := 0
+ create := func() (bool, error) {
+ wrote++
+ if !fpHeld(&s.fleetFloorMu) {
+ t.Error("the fleet row was written without fleetFloorMu")
+ }
+ return true, nil
+ }
+ if ok, ref, err := s.createFleetAboveTheFloor(t.Context(), create); !ok || ref != nil || err != nil || wrote != 1 || !hooked {
+ t.Fatalf("create with no pointer = %v %+v %v (wrote %d, hooked %v)", ok, ref, err, wrote, hooked)
+ }
+ if fpHeld(&s.fleetFloorMu) {
+ t.Fatal("fleetFloorMu is still held after the create")
+ }
+ fcPublish(t, fx, "stable", "v0.31.0")
+ if ok, ref, err := s.createFleetAboveTheFloor(t.Context(), create); ok || err != nil || wrote != 1 ||
+ ref == nil || ref.Status != http.StatusConflict || ref.Msg != fcBelowWant("stable", "v0.31.0") {
+ t.Fatalf("create below the floor = %v %+v %v (wrote %d)", ok, ref, err, wrote)
+ }
+ if fpHeld(&s.fleetFloorMu) {
+ t.Fatal("fleetFloorMu is still held after the refusal")
+ }
+}
+
+// fcResult is a fleet create's answer, from a goroutine.
+type fcResult struct {
+ status int
+ msg string
+ err error
+}
+
+// fcCreateAsync starts `carlos fleets create home` in a goroutine.
+func fcCreateAsync(fx *consoleFixture, token string) <-chan fcResult {
+ done := make(chan fcResult, 1)
+ go func() {
+ st, msg, err := fcCreate(fx, token, "home")
+ done <- fcResult{st, msg, err}
+ }()
+ return done
+}
+
+// fcWait waits for a signal or fails the test.
+func fcWait[T any](t *testing.T, ch <-chan T, what string) T {
+ t.Helper()
+ select {
+ case v := <-ch:
+ return v
+ case <-time.After(20 * time.Second):
+ t.Fatalf("timed out waiting for %s", what)
+ var zero T
+ return zero
+ }
+}
+
+// [§8 test 11, R2-2] The two orders of a fleet create and a first
+// publication below the floor, through the real doors, are mutually
+// exclusive through the write:
+//
+// - (a) the fleet first: no pointer, so the barrier lets the create
+// through, between the publication's up-front judgment and fleetFloorMu;
+// the publication judges again under the mutex, sees the fleet and is
+// refused (FPR-C03), and no pointer is written;
+// - (b) the publication first: it holds fleetFloorMu while the create
+// starts; once it has published, the create reads that pointer and is
+// refused (FPR-C06), and no fleet row is written;
+// - (c) through the write: the create, started between the publication's
+// judgment and its write, waits for fleetFloorMu and has written
+// nothing 200 ms later; the publication still holds the mutex as it
+// writes (a synchronous TryLock, so releasing the mutex early fails
+// here whatever the scheduler does); then the create is refused.
+func TestFleetFloorInterleavings(t *testing.T) {
+ t.Run("a/the-fleet-first", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-order-a")
+ s := fx.srv
+ fpNoPointer(t, s, "stable")
+ if _, err := s.systemFloorGate(t.Context(), "router", "stable", "v0.31.0", false, false, false); err != nil {
+ t.Fatalf("the up-front gate with no fleet = %v", err)
+ }
+ ran := false
+ s.fleetFloorHooks.beforeLock = func() {
+ ran = true
+ if fpHeld(&s.fleetFloorMu) {
+ t.Error("beforeLock ran with fleetFloorMu held")
+ }
+ if st, msg, err := fcCreate(fx, token, "home"); err != nil || st != http.StatusOK {
+ t.Errorf("the create with no pointer = %d %q, %v; want 200", st, msg, err)
+ }
+ }
+ s.fleetFloorHooks.locked = func() { t.Error("the publication passed its judgment with a fleet") }
+ _, err := s.promoteHostUpdate(t.Context(), fcRelease("v0.31.0"), "router", "stable", release.SystemPromoteOptions{})
+ if !ran {
+ t.Fatal("beforeLock never ran")
+ }
+ if want := fpFirstWant("stable", "v0.31.0"); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("the publication after the fleet = %v\nwant %q", err, want)
+ }
+ fpNoPointer(t, s, "stable")
+ if names := fcFleets(t, fx); len(names) != 1 || names[0] != "home" {
+ t.Fatalf("fleets = %v, want [home]", names)
+ }
+ })
+ t.Run("b/the-publication-first", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-order-b")
+ s := fx.srv
+ about := make(chan struct{}, 1)
+ s.fleetFloorHooks.createBeforeLock = func() { about <- struct{}{} }
+ var done <-chan fcResult
+ s.fleetFloorHooks.locked = func() {
+ if !fpHeld(&s.fleetFloorMu) {
+ t.Error("locked ran without fleetFloorMu")
+ }
+ done = fcCreateAsync(fx, token)
+ fcWait(t, about, "the create to reach fleetFloorMu")
+ }
+ p, err := s.promoteHostUpdate(t.Context(), fcRelease("v0.31.0"), "router", "stable", release.SystemPromoteOptions{})
+ if err != nil || p.Current.Version != "v0.31.0" {
+ t.Fatalf("the publication with no fleet = %+v, %v", p, err)
+ }
+ if done == nil {
+ t.Fatal("the locked hook never ran")
+ }
+ r := fcWait(t, done, "the create")
+ if want := fcBelowWant("stable", "v0.31.0"); r.err != nil || r.status != http.StatusConflict || r.msg != want {
+ t.Fatalf("the create after the publication = %+v\nwant 409 %q", r, want)
+ }
+ if names := fcFleets(t, fx); len(names) != 0 {
+ t.Fatalf("a refused create wrote fleets %v", names)
+ }
+ })
+ t.Run("c/through-the-write", func(t *testing.T) {
+ fx, token := fcFixture(t, "code-fpr-order-c")
+ s := fx.srv
+ about := make(chan struct{}, 1)
+ s.fleetFloorHooks.createBeforeLock = func() { about <- struct{}{} }
+ var done <-chan fcResult
+ var early *fcResult
+ s.fleetFloorHooks.locked = func() {
+ done = fcCreateAsync(fx, token)
+ fcWait(t, about, "the create to reach fleetFloorMu")
+ time.Sleep(200 * time.Millisecond)
+ select {
+ case r := <-done:
+ early = &r
+ t.Errorf("the create returned while the publication held fleetFloorMu: %+v", r)
+ default:
+ }
+ if names := fcFleets(t, fx); len(names) != 0 {
+ t.Errorf("a fleet row was written while the publication held fleetFloorMu: %v", names)
+ }
+ }
+ writing := false
+ s.regionalFloorHooks.locked = func() {
+ writing = true
+ if s.fleetFloorMu.TryLock() {
+ s.fleetFloorMu.Unlock()
+ t.Error("fleetFloorMu was free as the publication wrote its pointer")
+ }
+ }
+ p, err := s.promoteHostUpdate(t.Context(), fcRelease("v0.31.0"), "router", "stable", release.SystemPromoteOptions{})
+ if err != nil || p.Current.Version != "v0.31.0" {
+ t.Fatalf("the publication with no fleet = %+v, %v", p, err)
+ }
+ if done == nil || !writing {
+ t.Fatalf("the hooks never ran (locked %v, publish %v)", done != nil, writing)
+ }
+ r := early
+ if r == nil {
+ got := fcWait(t, done, "the create")
+ r = &got
+ }
+ if want := fcBelowWant("stable", "v0.31.0"); r.err != nil || r.status != http.StatusConflict || r.msg != want {
+ t.Fatalf("the create held across the publication = %+v\nwant 409 %q", *r, want)
+ }
+ if names := fcFleets(t, fx); len(names) != 0 {
+ t.Fatalf("a refused create wrote fleets %v", names)
+ }
+ })
+}
diff --git a/internal/console/fleets.go b/internal/console/fleets.go
index c40a460f8..a47dd7e71 100644
--- a/internal/console/fleets.go
+++ b/internal/console/fleets.go
@@ -228,7 +228,16 @@ func (s *Server) handleAPIFleetNew(w http.ResponseWriter, r *http.Request) {
jsonError(w, http.StatusInternalServerError, "could not reach the fleet registry")
return
}
- created, err := reg.CreateFleet(registry.Fleet{Name: name, Account: acct.Sqid, Bucket: bucket})
+ // The fleet forward floor's barrier (fleetfloor.go): no fleet is created
+ // while a system channel the boxes follow is below the floor, judged
+ // under fleetFloorMu through the write.
+ created, refused, err := s.createFleetAboveTheFloor(r.Context(), func() (bool, error) {
+ return reg.CreateFleet(registry.Fleet{Name: name, Account: acct.Sqid, Bucket: bucket})
+ })
+ if refused != nil {
+ jsonError(w, refused.Status, refused.Msg)
+ return
+ }
if err != nil {
log.Printf("console: fleet new %s/%s: %v", acct.Sqid, name, err)
jsonError(w, http.StatusInternalServerError, "could not create the fleet — try again")
diff --git a/internal/console/server.go b/internal/console/server.go
index 29c14ebca..517a920b5 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1389,8 +1389,12 @@ type Server struct {
// spec §9): every system pointer publication holds it from its last
// fleet floor judgment to its pointer write (fleetFloorPublish). It is
// taken before regionalMu, and nothing that holds regionalMu takes it.
- // The zero value is ready.
+ // The fleet-create door holds it from its barrier to its registry
+ // write (createFleetAboveTheFloor). The zero value is ready.
fleetFloorMu sync.Mutex
+ // fleetFloorHooks are test seams around fleetFloorPublish's and the
+ // fleet-create door's critical sections; nil in production.
+ fleetFloorHooks fleetFloorHooks
// The trash sweep's clock (lifetimes_purge.go) and the box floor
// watch's memory (lifetimes_floor.go).
trashSweepState