carlos / platform Public

Fleet public routes Task 9 fix round 1: the barrier judges every published pointer, repairs skip it, a deterministic early-unlock witness

P1 (controller ruling): fleetCreateFloorRefusal no longer reads
heartbeats. It lists control/system/router/ and reads every channel
pointer: below the floor or unparseable, and not published with the
signed override, is 409 FPR-C06; a listing or pointer that cannot be
read is 503 FPR-C07; no pointer passes. A stale or missing heartbeat no
longer hides a below-floor channel.

P2: handleAPIFleetNew reads the name first. An existing row creates no
fleet, so it skips the barrier and takes the existing-row answer (the
owner-record repair for the caller's own). For a new name CreateFleet's
atomic insert still decides; a loser gets "that name is taken".

P2: interleaving (c) parks the create before fleetFloorMu during the
publication's TryLock, so the early-unlock mutation fails on every run
(50/50).

Spec §9 and the §6 request budget follow; §7 notes the fix round (card
and seal unchanged).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 42337eb6b90853dcc36b74f92828ff996e18314d parent 2b9490a
5 files changed, +274 −123
  • docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md +25 −14
  • internal/console/fleetfloor.go +36 −30
  • internal/console/fleetfloor_test.go +135 −68
  • internal/console/fleetowner_test.go +52 −1
  • internal/console/fleets.go +26 −10

Intent

Human

<task-notification> <task-id>a37f12949b7b1e734</task-id> <tool-use-id>toolu_01RrACh9PDQj4zEtEhBGWJ4j</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/ba9fa944-a429-4788-9b3c-f2b2f42617f3/tasks/a37f12949b7b1e734.output</output-file> <status>completed</status> <summary>Agent "Implement Task 9: fleet-create barrier" 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. The concerns are notes for the reviewer; nothing is left open. **Commit:** 2b9490a9 "Fleet public routes Task 9: the fleet-create barrier and the three floor interleavings", on top of 3895bf1b. Not pushed. **Tests:** all new console tests pass, including the three interleavings, also under `-race`; the barrier tests (written first) failed against a stub, and all 14 mutations fail at least one test; root copy gate, `TestPlan9B8RecordWriteCensus`, build, vet, gofmt and the darwin/windows/linux-arm64 cross-builds pass. `make census-card` shows no unit and the seal is unchanged (`78b7e7e3...`); spec §7 records that. **Concerns:** 1. **Unreadable heartbeats also refuse.** If the heartbeats can't all be read, fleet create answers 503 FPR-C07. The brief only names an unreadable pointer, but an unread heartbeat might follow a channel the check would miss. The cost: one corrupt heartbeat blocks fleet creation until it is rewritten or ages out (24 h). Easy to remove if the reviewer disagrees. 2. **No fresh heartbeat means no check.** This follows the brief, but a deployment whose boxes are all stale passes the barrier. 3. **A refused create still uses up some of the user's fleet-create allowance.** The barrier runs after the 10-per-day create allowance is spent, because that allowance bounds the barrier's bucket reads. 4. **A repair retry gets refused too.** When a fleet create half-failed and the user retries, that retry is also refused while a channel is below the floor. It creates no new fleet, so the refusal is cautious, not needed. 5. **The mutex is held for the barrier's reads.** The heartbeat and pointer reads happen under `fleetFloorMu`, so a publication can wait behind a fleet create's bucket reads. The brief asks for exactly this, and fleet creates are rare. 6. **The channel walk is copied.** About 10 lines are copied from `regionalChannelRefusal` into `fleetfloor.go` so I didn't touch `apiplacements.go`, which isn't in this task's files. 7. **Spec changes.** §9 now names the single create door and FPR-C06/C07. §6's request budget now counts the heartbeat read on each fleet create (one listing plus a read per heartbeat); before, it counted only the pointer reads. 8. **Task 8's interleaving test is kept.** The store-read-hook version of interleaving (a) stays because it covers the reserved, unreserved and rollback paths. The new hook-based (a) goes through the real fleet-create door. Full report: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-public-routes/.superpowers/sdd/2026-10-30-fleet-public-routes/task-9-report.md`</result> <usage><subagent_tokens>183950</subagent_tokens><tool_uses>62</tool_uses><duration_ms>1048052</duration_ms></usage> </task-notification>

Human

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

Attributed to this commit: 22.7 g CO₂e (2,932,576 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/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
index d8a0dc8b0..b6e9e1742 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; 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) |
+| console floor and barrier (§9) | none | none in steady state; on each fleet create of a new name (rate-limited: the per-day create budget), one LIST of `control/system/router/` (one page per 1,000 keys, the release identities included) and one GET per published channel pointer (Task 9 R1); none on a create whose name has a row; 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
@@ -1222,6 +1222,9 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites):
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.
+ Task 9 fix round 1 (the barrier lists the pointers and reads no
+ heartbeat; the door routes an existing name around it): console code
+ only, card and seal unchanged.
Root's own row readers (adopt, capability, named units, restart, stage,
rootfs, `layoutReversalIncomplete`) change no code and select by
@@ -1437,19 +1440,27 @@ the old fleet indefinitely. The RegionalDomainsFloor pattern
- 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
- 11). Refusing on an absent pointer would block fleets on deployments
- that never publish a channel pointer, for no safety it adds. Existing
- fleets are unaffected.
+ from its check to its registry write. The check judges the published
+ system channel pointers themselves (Task 9 R1 P1, controller ruling),
+ not the channels the heartbeats say are followed: a box whose heartbeat
+ is stale or missing still follows its channel and could come back on a
+ below-floor pointer. It lists `control/system/router/` (every page; the
+ release identities under `releases/` are skipped) and reads each
+ channel pointer. It refuses (409, FPR-C06) while any pointer names a
+ release below the floor or one that does not parse and was not
+ published with the signed override (`AllowBelowFleetForwardFloor`: the
+ operator has accepted the cost for that channel); a listing or a
+ pointer that cannot be read refuses (503, FPR-C07). No heartbeat is
+ read. An absent pointer passes, and so does no pointer at all. 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 11). Refusing on an absent pointer would
+ block fleets on deployments that never publish a channel pointer, for
+ no safety it adds. Existing fleets are unaffected: a create whose name
+ already has a row creates no fleet and skips the barrier, so the
+ caller's own row still gets its owner-record repair (Task 9 R1 P2);
+ for a new name the registry's atomic insert still decides.
Refusal, override and barrier strings go to copy review.
diff --git a/internal/console/fleetfloor.go b/internal/console/fleetfloor.go
index da6c873eb..4e8cf68bd 100644
--- a/internal/console/fleetfloor.go
+++ b/internal/console/fleetfloor.go
@@ -8,7 +8,7 @@ import (
"net/http"
"os"
"sort"
- "time"
+ "strings"
"github.com/carlosframework/platform/internal/release"
)
@@ -137,16 +137,25 @@ type fleetFloorHooks struct {
// 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
+// crossing nobody judged, since it was published with no fleet, and a box
+// following it (now, or after its heartbeat has gone stale, or once it
+// comes back) would run a hub that cannot retire forward rows. 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.
+//
+// The barrier judges the published pointers themselves, every channel's,
+// not the channels the heartbeats say are followed (Task 9 R1 P1): a box
+// whose heartbeat is stale or missing still follows its channel. A pointer
+// published with the signed override (AllowBelowFleetForwardFloor) passes:
+// the operator has accepted that cost for that channel. 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, and
+// the door repairs a caller's own existing row without the barrier, since
+// a repair creates no fleet.
// consoleFleetCreateFloorRefusal (FPR-C06) takes the channel, its
// release, the floor and the floor.
@@ -156,34 +165,28 @@ const consoleFleetCreateFloorRefusal = "this deployment's %s channel is on %s, b
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.
+// listing of the router's system pointers (control/system/router/, every
+// page; the release identities under releases/ are listed with them and
+// skipped) and one GET per channel pointer found. A pointer naming a
+// release below release.FleetForwardFloor, or one that does not parse,
+// and not published with the override, is a 409 FPR-C06 naming the first
+// such channel in key order. A listing that fails, or a listed pointer
+// that cannot be read or verified, is a 503 FPR-C07. A pointer deleted
+// between the listing and its GET is absent, and passes. No pointer at all
+// passes. No heartbeat is read.
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)
+ prefix, _ := strings.CutSuffix(release.SystemPointerKey(release.SystemComponentRouter, ""), ".json")
+ keys, err := s.cfg.Releases.List(ctx, prefix)
+ if err != nil {
+ log.Printf("console: fleet create barrier: list %s: %v", prefix, 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
+ var channels []string
+ for _, key := range keys {
+ ch, ok := strings.CutSuffix(strings.TrimPrefix(key, prefix), ".json")
+ if ok && ch != "" && !strings.Contains(ch, "/") && release.SystemPointerKey(release.SystemComponentRouter, ch) == key {
+ channels = append(channels, ch)
}
- 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()
@@ -196,6 +199,9 @@ func (s *Server) fleetCreateFloorRefusal(ctx context.Context) *doorRefusal {
log.Printf("console: fleet create barrier: system pointer %s: %v", ch, err)
return &doorRefusal{http.StatusServiceUnavailable, consoleFleetCreateUnreadable}
}
+ if p.AllowBelowFleetForwardFloor {
+ continue
+ }
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)}
}
diff --git a/internal/console/fleetfloor_test.go b/internal/console/fleetfloor_test.go
index 9f810588d..974930f5d 100644
--- a/internal/console/fleetfloor_test.go
+++ b/internal/console/fleetfloor_test.go
@@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
"sync"
+ "sync/atomic"
"testing"
"time"
@@ -666,29 +667,58 @@ func TestSystemDoorsRefuseBelowTheFleetForwardFloor(t *testing.T) {
}
// 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.
+// §8 test 11. A fleet create lists every published system channel pointer
+// and reads each under fleetFloorMu, and writes its row under the same
+// mutex. No heartbeat is read: the fixtures here have none unless a test
+// says so.
// 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) {
+// fcListFault fails the listing of the router's system pointers while
+// fail is set, and runs afterList (once) after such a listing succeeds.
+type fcListFault struct {
+ release.Store
+ fail atomic.Bool
+ afterList atomic.Pointer[func()]
+}
+
+func (f *fcListFault) List(ctx context.Context, prefix string) ([]string, error) {
+ pointers := strings.HasPrefix(release.SystemPointerKey("router", "stable"), prefix)
+ if f.fail.Load() && pointers {
+ return nil, errors.New("injected list failure")
+ }
+ keys, err := f.Store.List(ctx, prefix)
+ if hook := f.afterList.Swap(nil); pointers && hook != nil {
+ (*hook)()
+ }
+ return keys, err
+}
+
+// fcFixture is a console whose owner holds a CLI token, over a store whose
+// pointer listing can be made to fail (the returned fault).
+func fcFixture(t *testing.T, code string) (*consoleFixture, string, *fcListFault) {
t.Helper()
- fx, token := fleetFixture(t, code)
- seedBox(t, fx, "box-1", "linux-arm64", "stable", "v0.32.0")
- return fx, token
+ fault := &fcListFault{}
+ fx := newConsoleFixtureWith(t, consoleFixtureOptions{WithKey: true, WrapReleases: func(s release.Store) release.Store {
+ fault.Store = s
+ return fault
+ }})
+ return fx, cliToken(t, fx, "paul@keymail.dev", code), fault
}
// 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 {
+ fcPublishWith(t, fx, channel, v, release.SystemPromoteOptions{})
+}
+
+// fcPublishWith is fcPublish with the promotion's options.
+func fcPublishWith(t *testing.T, fx *consoleFixture, channel, v string, o release.SystemPromoteOptions) {
+ t.Helper()
+ if _, err := release.PromoteSystem(t.Context(), fx.rel, release.RootSigner(fx.priv), "router", channel, fcRelease(v), o); err != nil {
t.Fatal(err)
}
}
@@ -743,13 +773,25 @@ func fcBelowWant(channel, v string) 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.
+// fcHeartbeat writes box label's heartbeat following channel, generated at.
+func fcHeartbeat(t *testing.T, fx *consoleFixture, label, channel string, at time.Time) {
+ t.Helper()
+ b := status.CollectBox(nil, status.Probes{Release: "v0.32.0", Platform: "linux-arm64", SystemChannel: channel}, at)
+ b.Label = label
+ if err := status.WriteBox(t.Context(), fx.rel, b); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// [§9, FPR-C06, FPR-C07, R2-2, Task 9 R1 P1] A fleet is not created while
+// any published system channel pointer names a release below the floor,
+// or one whose version does not parse, unless it was published with the
+// signed override (409, FPR-C06), nor while the pointers cannot be listed
+// or one cannot be read (503, FPR-C07). No fleet row is written. A pointer
+// at the floor, one published with the override, and no pointer at all
+// let the create through. The heartbeats play no part: a below-floor
+// pointer refuses with no heartbeat, with only a stale one following it,
+// and with no box following it; an unreadable heartbeat refuses nothing.
func TestFleetCreateRefusedWhileAChannelIsBelowTheFloor(t *testing.T) {
refused := func(t *testing.T, fx *consoleFixture, token string, status int, want string) {
t.Helper()
@@ -770,63 +812,74 @@ func TestFleetCreateRefusedWhileAChannelIsBelowTheFloor(t *testing.T) {
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")
+ t.Run("below-the-floor/no-heartbeat", 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("below-the-floor/every-heartbeat-stale", func(t *testing.T) {
+ fx, token, _ := fcFixture(t, "code-fpr-c06-stale")
+ fcPublish(t, fx, "stable", "v0.31.0")
+ fcHeartbeat(t, fx, "box-1", "stable", time.Now().Add(-time.Hour))
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("stable", "v0.31.0"))
+ })
+ t.Run("below-the-floor/a-channel-no-box-follows", func(t *testing.T) {
+ fx, token, _ := fcFixture(t, "code-fpr-c06-canary")
+ fcPublish(t, fx, "stable", "v0.32.0")
+ fcHeartbeat(t, fx, "box-1", "stable", time.Now())
+ fcPublish(t, fx, "canary", "v0.31.0")
+ refused(t, fx, token, http.StatusConflict, fcBelowWant("canary", "v0.31.0"))
+ })
t.Run("at-the-floor", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-c06-at")
+ fx, token, _ := fcFixture(t, "code-fpr-c06-at")
fcPublish(t, fx, "stable", "v0.32.0")
+ fcPublish(t, fx, "canary", "v0.33.1")
created(t, fx, token)
})
t.Run("no-pointer", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-c06-none")
+ fx, token, _ := fcFixture(t, "code-fpr-c06-none")
fpNoPointer(t, fx.srv, "stable")
created(t, fx, token)
})
+ t.Run("below-the-floor-with-the-override", func(t *testing.T) {
+ fx, token, _ := fcFixture(t, "code-fpr-c06-override")
+ fcPublishWith(t, fx, "stable", "v0.31.0", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: true})
+ created(t, fx, token)
+ })
t.Run("unreadable-pointer", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-c07-pointer")
+ 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("unlistable-pointers", func(t *testing.T) {
+ fx, token, fault := fcFixture(t, "code-fpr-c07-list")
+ fault.fail.Store(true)
+ refused(t, fx, token, http.StatusServiceUnavailable, consoleFleetCreateUnreadable)
+ })
+ t.Run("a-pointer-gone-after-the-listing", func(t *testing.T) {
+ fx, token, fault := fcFixture(t, "code-fpr-c06-gone")
+ fcPublish(t, fx, "stable", "v0.31.0")
+ gone := func() {
+ if err := fx.rel.Delete(context.Background(), release.SystemPointerKey("router", "stable")); err != nil {
+ t.Error(err)
+ }
+ }
+ fault.afterList.Store(&gone)
+ created(t, fx, token)
+ })
t.Run("unparseable-pointer", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-c06-unparseable")
+ 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")
+ t.Run("an-unreadable-heartbeat-refuses-nothing", 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)
})
}
@@ -835,7 +888,7 @@ func TestFleetCreateRefusedWhileAChannelIsBelowTheFloor(t *testing.T) {
// 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")
+ fx, _, _ := fcFixture(t, "code-fpr-create-mu")
s := fx.srv
hooked := false
s.fleetFloorHooks.createBeforeLock = func() {
@@ -910,13 +963,15 @@ func fcWait[T any](t *testing.T, ch <-chan T, what string) T {
// 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.
+// judgment and its write, is parked just before fleetFloorMu; in the
+// publication's last step before its write a TryLock fails, and with
+// the create parked only the publication can be holding the mutex, so
+// releasing it early fails here on every schedule; the create is then
+// let go, waits for fleetFloorMu and has written nothing 200 ms later;
+// then it 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")
+ 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 {
@@ -946,7 +1001,7 @@ func TestFleetFloorInterleavings(t *testing.T) {
}
})
t.Run("b/the-publication-first", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-order-b")
+ fx, token, _ := fcFixture(t, "code-fpr-order-b")
s := fx.srv
about := make(chan struct{}, 1)
s.fleetFloorHooks.createBeforeLock = func() { about <- struct{}{} }
@@ -974,15 +1029,35 @@ func TestFleetFloorInterleavings(t *testing.T) {
}
})
t.Run("c/through-the-write", func(t *testing.T) {
- fx, token := fcFixture(t, "code-fpr-order-c")
+ fx, token, _ := fcFixture(t, "code-fpr-order-c")
s := fx.srv
+ // The create stops just before fleetFloorMu until gate opens, so
+ // the publication's TryLock below meets no other holder.
about := make(chan struct{}, 1)
- s.fleetFloorHooks.createBeforeLock = func() { about <- struct{}{} }
+ gate := make(chan struct{})
+ s.fleetFloorHooks.createBeforeLock = func() {
+ about <- struct{}{}
+ select {
+ case <-gate:
+ case <-time.After(20 * time.Second):
+ }
+ }
var done <-chan fcResult
- var early *fcResult
s.fleetFloorHooks.locked = func() {
done = fcCreateAsync(fx, token)
fcWait(t, about, "the create to reach fleetFloorMu")
+ }
+ var early *fcResult
+ writing := false
+ s.regionalFloorHooks.locked = func() {
+ writing = true
+ // Uncontended: the create is parked before the lock, so only
+ // the publication can hold fleetFloorMu here.
+ if s.fleetFloorMu.TryLock() {
+ s.fleetFloorMu.Unlock()
+ t.Error("fleetFloorMu was free as the publication wrote its pointer")
+ }
+ close(gate)
time.Sleep(200 * time.Millisecond)
select {
case r := <-done:
@@ -994,14 +1069,6 @@ func TestFleetFloorInterleavings(t *testing.T) {
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)
diff --git a/internal/console/fleetowner_test.go b/internal/console/fleetowner_test.go
index 034756df2..cbb08d281 100644
--- a/internal/console/fleetowner_test.go
+++ b/internal/console/fleetowner_test.go
@@ -303,8 +303,19 @@ func TestBackfillWithoutAStoreOrRegistryDoesNothing(t *testing.T) {
}
// Astra R1 finding 13: the retry the 500 asks for repairs the record.
+//
+// The repair creates no fleet, so the fleet-create barrier (fleetfloor.go)
+// does not stand in its way (fleet public routes Task 9 R1 P2): with a
+// system channel below the fleet forward floor, or a pointer that cannot
+// be read, the retry still repairs.
func TestFleetCreateRetryRepairsAFailedOwnerRecord(t *testing.T) {
- fx, token, spy := fleetOwnerFixture(t, "code-owner-retry")
+ for _, barrier := range []string{"none", "below-the-floor", "unreadable-pointer"} {
+ t.Run(barrier, func(t *testing.T) { fleetCreateRetryRepairs(t, barrier) })
+ }
+}
+
+func fleetCreateRetryRepairs(t *testing.T, barrier string) {
+ fx, token, spy := fleetOwnerFixture(t, "code-owner-retry-"+barrier)
key := release.FleetOwnerKey(fx.sqid, "home")
spy.failPuts = 1
u := fleetsURL(fx, fx.sqid) + "/new"
@@ -313,6 +324,20 @@ func TestFleetCreateRetryRepairsAFailedOwnerRecord(t *testing.T) {
if status != http.StatusInternalServerError || body["error"] != "could not create the fleet — try again" {
t.Fatalf("create with a failing record write = %d %v, want 500 with the failed-create sentence", status, body)
}
+ // After the row is written, a condition that refuses a new fleet.
+ switch barrier {
+ case "below-the-floor":
+ fcPublish(t, fx, "stable", "v0.31.0")
+ case "unreadable-pointer":
+ if _, err := fx.rel.Put(t.Context(), release.SystemPointerKey("router", "stable"), []byte("not a pointer"), ""); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if barrier != "none" {
+ if st, _, err := fcCreate(fx, token, "away"); err != nil || st == http.StatusOK {
+ t.Fatalf("a new fleet under barrier %s = %d, %v; want it refused", barrier, st, err)
+ }
+ }
reg, err := openRegistry(fx.regPath)
if err != nil {
t.Fatal(err)
@@ -367,6 +392,32 @@ func TestFleetCreateRetryRepairsAFailedOwnerRecord(t *testing.T) {
}
}
+// A name with no row when the door reads it, taken by another account
+// before the door's insert (in the barrier's createBeforeLock seam): the
+// door's read only routes the request, CreateFleet's atomic insert
+// decides, and the loser gets "that name is taken" with no owner record
+// written for it (fleet public routes Task 9 R1 P2).
+func TestFleetCreateLosesANameTakenAfterItsRead(t *testing.T) {
+ fx, token, _ := fleetOwnerFixture(t, "code-owner-race")
+ fx.srv.fleetFloorHooks.createBeforeLock = func() {
+ reg, err := openRegistry(fx.regPath)
+ if err != nil {
+ t.Error(err)
+ return
+ }
+ if ok, err := reg.CreateFleet(registry.Fleet{Name: "home", Account: "k3x", Bucket: "home-data"}); !ok || err != nil {
+ t.Errorf("the rival create = %v, %v", ok, err)
+ }
+ }
+ status, body := postJSON(t, fleetsURL(fx, fx.sqid)+"/new", map[string]string{"name": "home", "bucket": "home-data"}, token)
+ if status != http.StatusConflict || body["error"] != "that name is taken" {
+ t.Fatalf("create that lost the name = %d %v, want 409 that name is taken", status, body)
+ }
+ if _, err := readFleetOwner(t, fx.rel, fx.sqid, "home"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("owner record for the loser: %v, want none", err)
+ }
+}
+
func TestFleetCreateRetryWithAnotherBucketRepairsAndStillRefuses(t *testing.T) {
fx, token, spy := fleetOwnerFixture(t, "code-owner-retry-bucket")
spy.failPuts = 1
diff --git a/internal/console/fleets.go b/internal/console/fleets.go
index a47dd7e71..da29c7c87 100644
--- a/internal/console/fleets.go
+++ b/internal/console/fleets.go
@@ -229,20 +229,36 @@ func (s *Server) handleAPIFleetNew(w http.ResponseWriter, r *http.Request) {
return
}
// 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
- }
+ // while a system channel pointer is below the floor, judged under
+ // fleetFloorMu through the write. A name that already has a row creates
+ // no fleet, so it skips the barrier and goes to the existing-row answer
+ // below (another account's: 409; the caller's own: the owner record
+ // repair, Task 9 R1 P2). This read only routes the request: for a name
+ // with no row, CreateFleet's atomic insert still decides who wins, and
+ // a loser (a row that appeared since this read) takes the same
+ // existing-row answer.
+ existing, err := reg.GetFleet(name)
if err != nil {
- log.Printf("console: fleet new %s/%s: %v", acct.Sqid, name, err)
+ log.Printf("console: fleet new %s/%s: read existing: %v", acct.Sqid, name, err)
jsonError(w, http.StatusInternalServerError, "could not create the fleet — try again")
return
}
+ created := false
+ if existing == nil {
+ var refused *doorRefusal
+ 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")
+ return
+ }
+ }
view := fleetView{Name: name, Bucket: bucket, Boxes: []fleetBoxView{}}
if created {
// The fleet owner record (rootfs apps Plan 4 D7): written before the