console: read back an erring mode write at a new fleet's box (#519)
Astra r1 P1 2: a mode write whose reply was lost could commit the fleet and still detach its only box, leaving it N9. The state is now read back: landed keeps the box, not landed detaches it, and a failed read-back leaves the box and re-reads the mode next time. Astra r1 P1 1 (storage the owner names is taken as new) is accepted by Paul, 2026-11-02, and stated in the code and spec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Human
Prompt
Accept, document (Recommended) — Paul's answer on Astra r1 P1 1 for #519
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
Read-back after an erring mode write; the trust limit documented.
3 files changed,
+126
−6
docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md+1 −1internal/console/hostsused.go+28 −5internal/console/hostsused_coverage_test.go+97 −0
CI passed — run details
diff --git a/docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md b/docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md| index 2e01c894f..572815438 100644 |
| --- a/docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md |
| +++ b/docs/superpowers/specs/2026-10-26-nearest-region-without-claims-design.md |
| @@ -54,7 +54,7 @@ Deleted history and noncurrent versions are not sources, because they are harmle |
| **After completion, unexamined targets are refused.** A region, pool or fleet that was not in the roster gets S4 for data-kind creates, and the nearest-region picker skips it, until its own inventory is imported. |
| -**A fleet created after completion is recorded at its first box (#519, 2026-11-02).** Activation records every fleet on its roster, so a fleet the history has not recorded was created since. No box of it existed before completion, so none holds its old data. Its first add-box, with the console serving, adds the box and records the fleet as examined, its targets being its bucket and that box. Its next add-box is N9 like any recorded fleet's. A bucket that a closed fleet also uses was never scanned: such a fleet is left unrecorded and completes offline, as before. A failed write of the mode detaches the box again; its token was never shown. |
| +**A fleet created after completion is recorded at its first box (#519, 2026-11-02).** Activation records every fleet on its roster, so a fleet the history has not recorded was created since. No box of it existed before completion, so none holds its old data. Its first add-box, with the console serving, adds the box and records the fleet as examined, its targets being its bucket and that box. Its next add-box is N9 like any recorded fleet's. A bucket that a closed fleet also uses was never scanned: such a fleet is left unrecorded and completes offline, as before. A write of the mode that errs is read back: if it landed the add succeeds, if not the box is detached again (its token was never shown). **What this takes on trust (Paul, 2026-11-02, on Astra r1 P1 1):** the console never reads a fleet's bucket or boxes, so storage the owner names is examined as new, as anything they copy into an examined fleet's storage later would be. A registry restored to a snapshot from before activation is outside it too. |
| ## 3a. The activation window (accepted 2026-10-26) |
diff --git a/internal/console/hostsused.go b/internal/console/hostsused.go| index 947958ccc..c2fab1357 100644 |
| --- a/internal/console/hostsused.go |
| +++ b/internal/console/hostsused.go |
| @@ -320,10 +320,22 @@ const msgFleetBoxNotAdded = "could not add the box — try again" |
| // before #519, to be completed offline. |
| // |
| // It all runs under the lock every admission takes, so two add-boxes on a |
| -// new fleet cannot both record it. A write of the mode that fails detaches |
| -// the box again (its token was never shown, so nothing has dialled in with |
| -// it), and the retry reactivates it. A mode that cannot be read refuses. |
| -// err is AddFleetBox's, for the door to tell a duplicate from a failure. |
| +// new fleet cannot both record it. A write of the mode that errs may still |
| +// have landed (Astra r1, P1 2), so the state is read back: landed, the box |
| +// stays and the add succeeds; not landed, the box is detached again (its |
| +// token was never shown, so nothing has dialled in with it) and the retry |
| +// reactivates it. A read-back that fails too leaves the box and forgets the |
| +// held state, so the next caller reads the store: if the write landed, the |
| +// box is recorded and rotate-token gives it a token; if not, detaching it |
| +// and adding it again records the fleet. A mode that cannot be read |
| +// refuses. err is AddFleetBox's, for the door to tell a duplicate from a |
| +// failure. |
| +// |
| +// What examining at the first box takes on trust (#519, Paul's ruling |
| +// 2026-11-02 on Astra r1, P1 1): the console never reads a fleet's bucket |
| +// or boxes, so storage the owner names is examined as new, as anything |
| +// they copy into an examined fleet's storage later would be. A registry |
| +// restored to a snapshot from before activation is outside it too. |
| func (s *Server) addFleetBoxRecorded(ctx context.Context, reg consoleRegistry, fl registry.Fleet, box registry.FleetBox) (*doorRefusal, error) { |
| s.hosts.mu.Lock() |
| defer s.hosts.mu.Unlock() |
| @@ -367,7 +379,18 @@ func (s *Server) addFleetBoxRecorded(ctx context.Context, reg consoleRegistry, f |
| next.FleetTargets[key] = sortedUnique(targets) |
| etag, err := provision.WriteHostsState(ctx, s.cfg.Releases, next, s.hosts.etag) |
| if err != nil { |
| - return undo("write the mode", err), nil |
| + back, backTag, rerr := provision.ReadHostsState(ctx, s.cfg.Releases) |
| + if rerr != nil { |
| + log.Printf("console: hosts used: record new fleet %s: write the mode: %v; read it back: %v (box %s left active; the next caller reads the mode again)", fl.Name, err, rerr, box.Label) |
| + s.hosts.state, s.hosts.etag = provision.HostsState{}, "" |
| + return &doorRefusal{http.StatusServiceUnavailable, msgFleetBoxNotAdded}, nil |
| + } |
| + s.hosts.state, s.hosts.etag = back, backTag |
| + if back.Mode != provision.HostsModeActive || !slices.Contains(back.Examined, key) { |
| + return undo("write the mode", err), nil |
| + } |
| + log.Printf("console: hosts used: record new fleet %s: write the mode: %v, but it landed", fl.Name, err) |
| + etag, next = backTag, back |
| } |
| s.hosts.state, s.hosts.etag = next, etag |
| log.Printf("console: hosts used: fleet %s recorded at its first box, targets %v", fl.Name, next.FleetTargets[key]) |
diff --git a/internal/console/hostsused_coverage_test.go b/internal/console/hostsused_coverage_test.go| index 082802ef4..082c70c94 100644 |
| --- a/internal/console/hostsused_coverage_test.go |
| +++ b/internal/console/hostsused_coverage_test.go |
| @@ -389,3 +389,100 @@ func TestNewFleetNotRecorded(t *testing.T) { |
| } |
| }) |
| } |
| + |
| +// landedButErrs commits the first Put of key and answers an error anyway, |
| +// as a write whose reply is lost would. |
| +type landedButErrs struct { |
| + release.Store |
| + key string |
| + done bool |
| +} |
| + |
| +func (s *landedButErrs) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + etag, err := s.Store.Put(ctx, key, body, ifMatch) |
| + if err == nil && key == s.key && !s.done { |
| + s.done = true |
| + return "", errBucketDown |
| + } |
| + return etag, err |
| +} |
| + |
| +// TestNewFleetModeWriteAmbiguous (Astra r1, P1 2): a write of the mode that |
| +// errs is read back. Landed, the first box stays and the add succeeds, and |
| +// the next add-box is N9. Not landed and the read-back failing too, the box |
| +// is left active and the state is read again, so the next add-box records |
| +// the fleet with both boxes. |
| +func TestNewFleetModeWriteAmbiguous(t *testing.T) { |
| + setup := func(t *testing.T, code string) (*consoleFixture, func(string) (int, map[string]any)) { |
| + fx, token := placeFixture(t, code) |
| + if status, body := postJSON(t, fleetsURL(fx, fx.sqid)+"/new", map[string]string{"name": "classic", "bucket": "classic-data"}, token); status != http.StatusOK { |
| + t.Fatalf("create fleet = %d %v", status, body) |
| + } |
| + st, err := HostsActivation{Releases: fx.srv.cfg.Releases, Registry: fx.srv.cfg.Registry}.Roster(context.Background()) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + delete(st.Fleets, "fleet:classic") |
| + forceHostsState(t, fx.srv, provision.HostsState{Mode: provision.HostsModeActive, Examined: []string{"fleet:pi"}, FleetTargets: st.Fleets, RegionTargets: []string{}}) |
| + return fx, func(label string) (int, map[string]any) { |
| + return postJSON(t, fleetsURL(fx, fx.sqid)+"/classic/boxes", map[string]string{"label": label}, token) |
| + } |
| + } |
| + targets := func(t *testing.T, fx *consoleFixture) []string { |
| + t.Helper() |
| + st, _, err := provision.ReadHostsState(context.Background(), fx.srv.cfg.Releases) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return st.FleetTargets["fleet:classic"] |
| + } |
| + t.Run("landed", func(t *testing.T) { |
| + fx, add := setup(t, "code-new-fleet-landed") |
| + fx.srv.cfg.Releases = &landedButErrs{Store: fx.srv.cfg.Releases, key: provision.HostsModeKey} |
| + if status, out := add("box-1"); status != http.StatusOK || out["token"] == nil { |
| + t.Fatalf("add-box whose mode write landed but erred = %d %v, want 200 with a token", status, out) |
| + } |
| + if got := activeFleetBoxes(t, fx, "classic"); !slices.Equal(got, []string{"box-1"}) { |
| + t.Fatalf("active boxes = %v, want [box-1]", got) |
| + } |
| + if got, want := targets(t, fx), []string{"box:fleet/classic/box-1", "bucket:classic-data"}; !slices.Equal(got, want) { |
| + t.Fatalf("classic's targets = %v, want %v", got, want) |
| + } |
| + if status, out := add("box-2"); status != http.StatusConflict || out["error"] != msgFleetInventoried("classic") { |
| + t.Fatalf("next add-box = %d %v, want 409 N9", status, out) |
| + } |
| + if ref := fx.srv.gateDataCreate(context.Background(), "x.go.tito.io", "fleet/classic"); ref != nil { |
| + t.Fatalf("a data-kind create on the recorded fleet = %+v, want admitted", ref) |
| + } |
| + }) |
| + t.Run("read-back fails", func(t *testing.T) { |
| + fx, add := setup(t, "code-new-fleet-unread") |
| + bucket := wrapBucket(fx) |
| + put, get := failNth("put", provision.HostsModeKey, 1, false), failNth("get", provision.HostsModeKey, 1, false) |
| + bucket.setHook(func(op, key string) error { |
| + if err := put(op, key); err != nil { |
| + return err |
| + } |
| + return get(op, key) |
| + }) |
| + if status, out := add("box-1"); status != http.StatusServiceUnavailable || out["error"] != msgFleetBoxNotAdded { |
| + t.Fatalf("add-box with the write and read-back failing = %d %v, want 503", status, out) |
| + } |
| + bucket.setHook(nil) |
| + if got := activeFleetBoxes(t, fx, "classic"); !slices.Equal(got, []string{"box-1"}) { |
| + t.Fatalf("active boxes = %v, want box-1 left active", got) |
| + } |
| + if got := targets(t, fx); got != nil { |
| + t.Fatalf("classic recorded after a failed write: %v", got) |
| + } |
| + fx.srv.hosts.mu.Lock() |
| + fx.srv.hosts.verified = true // the start-up check had passed before |
| + fx.srv.hosts.mu.Unlock() |
| + if status, out := add("box-2"); status != http.StatusOK { |
| + t.Fatalf("next add-box = %d %v, want 200", status, out) |
| + } |
| + if got, want := targets(t, fx), []string{"box:fleet/classic/box-1", "box:fleet/classic/box-2", "bucket:classic-data"}; !slices.Equal(got, want) { |
| + t.Fatalf("classic's targets = %v, want %v", got, want) |
| + } |
| + }) |
| +} |