carlos / platform Public

console: the fleet seeds door

POST /api/fleet/seeds/{account}/{app}/{host}/placed|failed|rolledback
(#1139 slice 3, plan Task 15): a customer-fleet box reports its file
seed's transitions here, since it cannot write records.

- Authenticated as the replica doors are; the record must be on the
  caller's fleet, a file seed, and owned by the caller (FleetBox, or the
  sole active box when unlabelled). Every refusal is the identical 404.
- Body grammar per op (codes only with failed, held only with
  copy-in-storage); anything else is 400. Codes map to FS-27 to FS-30.
- Under the record lock, ownership is checked again and the CAS acts only
  on the record's own seed id, bound to the region and box read there. A
  stale id or state is 409 with nothing changed; a repeat is a no-op.
- rolledback releases the lock before finishSeed (plan R1-2), so the
  lifetimes-on finish does not re-take the app mutex.
- SeedSource gains held; SeedFail(id, reason, held) sets or clears it.
- Routes, linked policy, parity row, record-write census layer 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 0fd37917e6d9357088eda2b47d331680e9c629e5 parent 772aabb
13 files changed, +864 −23
  • docs/parity.md +1 −1
  • internal/activator/seedfleet_linux_test.go +1 −1
  • internal/console/apifleetseeds.go +263 −0
  • internal/console/apifleetseeds_test.go +467 −0
  • internal/console/linkedpolicy.go +3 −0
  • internal/console/routedecls.go +7 −0
  • internal/console/seedfile_copy.go +12 −0
  • internal/provision/fleet_seeded_create_3_census_test.go +58 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/seed.go +30 −14
  • internal/provision/seed_test.go +19 −5
  • parity/parity.tsv +1 −1
  • scripts/gitleaks-gate/notscanned.go +1 −0

CI failed — run details

diff --git a/docs/parity.md b/docs/parity.md
index 1212b2fef..fe68bf72b 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -501,5 +501,5 @@ Discussion #1289.
| legacy-apps | platform | | `GET /apps`<br>`GET /apps/{app}` | Old URLs kept as redirects into the account. |
| billing-webhook | platform | | `POST /billing/webhook` | Stripe calls it. |
| ses-events | platform | | `POST /api/ses/events` | Amazon SES delivery events. |
-| box-doors | platform | | `POST /api/fleet/enrol`<br>`GET /api/box/interactive/{id}`<br>`GET /api/box/runs/{id}`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/coordinator`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/release`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/deploy` | Doors boxes and managed fleets call, not people. |
+| box-doors | platform | | `POST /api/fleet/enrol`<br>`GET /api/box/interactive/{id}`<br>`GET /api/box/runs/{id}`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/coordinator`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/release`<br>`POST /api/fleet/replicas/{account}/{app}/{host}/deploy`<br>`POST /api/fleet/seeds/{account}/{app}/{host}/placed`<br>`POST /api/fleet/seeds/{account}/{app}/{host}/failed`<br>`POST /api/fleet/seeds/{account}/{app}/{host}/rolledback` | Doors boxes and managed fleets call, not people. |
| plumbing | platform | `__demo-snapshot`<br>`__registry-child`<br>`__rootfs-check-probe`<br>`__rootfs-check-prepare`<br>`__cgexec`<br>`__cgprobe` | | Words the binary runs itself as, dispatched before the command switch. |
diff --git a/internal/activator/seedfleet_linux_test.go b/internal/activator/seedfleet_linux_test.go
index 2deebb931..e7fc1c5d9 100644
--- a/internal/activator/seedfleet_linux_test.go
+++ b/internal/activator/seedfleet_linux_test.go
@@ -738,7 +738,7 @@ func TestFleetFileSeedInterruptedPlacementHoldsHostname(t *testing.T) {
case provision.FleetSeedPlaced:
return placedErr
case provision.FleetSeedFailed:
- _, err := provision.SetRecordSeed(ctx, store, a, app, h, provision.SeedFail(id, code))
+ _, err := provision.SetRecordSeed(ctx, store, a, app, h, provision.SeedFail(id, code, held))
return err
}
return nil
diff --git a/internal/console/apifleetseeds.go b/internal/console/apifleetseeds.go
new file mode 100644
index 000000000..e55f117c0
--- /dev/null
+++ b/internal/console/apifleetseeds.go
@@ -0,0 +1,263 @@
+// The fleet seeds door (fleet seeded create design §3.5, plan Task 15).
+//
+// A customer-fleet box cannot write records: the store door refuses it
+// (ruling 4). So it reports what it did with a file seed here, and the
+// console makes the record's transition:
+//
+// POST /api/fleet/seeds/{account}/{app}/{host}/placed|failed|rolledback
+// {"id": "<seed id>", "code": "<code>", "held": "<where>"}
+//
+// The box sends codes, never text (decisions D4, D12): the console maps a
+// code to its approved sentence, and keeps held so the delete door can name
+// where the copy is from the host alone.
+//
+// This door is the only way a fleet file seed reaches rolled-back. The box
+// reports rolledback only after it has proved nothing of the seed is left
+// (provision.rollbackFleetFileSeed, design §3.6), and that is what lets the
+// finish here release the hostname.
+//
+// The gates, in order: the box's identity and its ownership of the record
+// (fleetSeedRecord), each refused with the identical 404 before anything
+// about the record is revealed; then the body (400); then, under the app's
+// record lock and with ownership checked again there, the record's own seed
+// id and state (409 when the record says otherwise, nothing changed).
+
+package console
+
+import (
+ "context"
+ "errors"
+ "log"
+ "net/http"
+ "os"
+ "strings"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/seeds"
+)
+
+// fleetSeedRecord authenticates the caller exactly as replicaFleetRecord
+// does (replicacoordinator.go): the tunnel name and bearer token are an
+// active box of a fleet the path's account owns, and the record is placed
+// on that fleet ("fleet/<fleet>") and not retired. Then the seed is a file
+// seed, and the caller owns the record: FleetBox names it, or there is no
+// FleetBox and the caller is the fleet's sole active box (a file seed's
+// record is created unlabelled, plan G1). A replica assignment grants
+// nothing here: a file seed is placed by its one owning box.
+//
+// Any failure is false, which every caller answers with the byte-identical
+// http.NotFound before anything about the record is revealed. It answers
+// the record and the caller's box label.
+func (s *Server) fleetSeedRecord(r *http.Request) (*provision.Record, string, bool) {
+ account, app, host := r.PathValue("account"), r.PathValue("app"), r.PathValue("host")
+ if !release.ValidAccount(account) || !release.ValidApp(app) || !provision.ValidHostShape(host) {
+ return nil, "", false
+ }
+ name := r.Header.Get("Carlos-Tunnel-Name")
+ fleet, box, ok := strings.Cut(name, "/")
+ if !ok {
+ return nil, "", false
+ }
+ token, bearer := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer ")
+ reg, err := openRegistry(s.cfg.Registry)
+ if err != nil || !bearer || !fleetIdentityOK(reg, name, token, fleet, account) {
+ return nil, "", false
+ }
+ rec, _, err := s.readRecord(r.Context(), account, app, host)
+ if err != nil || rec == nil || rec.Retired || rec.Region != registry.PlacementTarget(fleet) {
+ return nil, "", false
+ }
+ if rec.Seed == nil || rec.Seed.Kind != seeds.KindFile {
+ return nil, "", false
+ }
+ switch rec.FleetBox {
+ case box:
+ case "":
+ sole, ok := soleActiveFleetBox(reg, fleet)
+ if !ok || sole.Box != box {
+ return nil, "", false
+ }
+ default:
+ return nil, "", false
+ }
+ return rec, box, true
+}
+
+// fleetSeedReport is the door's body. code is only for failed; held only
+// with code copy-in-storage. replicaPayload decodes it: unknown fields
+// refused, one document, at most 8 KiB.
+type fleetSeedReport struct {
+ ID string `json:"id"`
+ Code string `json:"code,omitempty"`
+ Held string `json:"held,omitempty"`
+}
+
+// fleetSeedReason maps a failed report's code to the sentence the record
+// keeps (FS-27 to FS-30); ok is false for anything else.
+func fleetSeedReason(code string) (string, bool) {
+ switch code {
+ case provision.SeedCodeMismatch:
+ return fileSeedBoxMismatchCopy, true
+ case provision.SeedCodeNotADatabase:
+ return fileSeedBoxIntegrityCopy, true
+ case provision.SeedCodeCopyExists:
+ return fileSeedCopyExistsCopy, true
+ case provision.SeedCodeCopyInStorage:
+ return fileSeedCopyInStorageCopy, true
+ }
+ return "", false
+}
+
+// fleetSeedReportValid is the body's grammar for op (plan Task 15): a seed
+// id that passes seeds.Check; for failed, a known code, with held exactly
+// when the code is copy-in-storage and then one of the three places; for
+// placed and rolledback, neither.
+func fleetSeedReportValid(op, host string, b fleetSeedReport) bool {
+ if seeds.Check(host, b.ID) != nil {
+ return false
+ }
+ if op != provision.FleetSeedFailed {
+ return b.Code == "" && b.Held == ""
+ }
+ if _, ok := fleetSeedReason(b.Code); !ok {
+ return false
+ }
+ if b.Code != provision.SeedCodeCopyInStorage {
+ return b.Held == ""
+ }
+ switch b.Held {
+ case provision.SeedHeldReplica, provision.SeedHeldStaging, provision.SeedHeldBoth:
+ return true
+ }
+ return false
+}
+
+func (s *Server) handleFleetSeedPlaced(w http.ResponseWriter, r *http.Request) {
+ s.fleetSeedDoor(w, r, provision.FleetSeedPlaced)
+}
+
+func (s *Server) handleFleetSeedFailed(w http.ResponseWriter, r *http.Request) {
+ s.fleetSeedDoor(w, r, provision.FleetSeedFailed)
+}
+
+func (s *Server) handleFleetSeedRolledBack(w http.ResponseWriter, r *http.Request) {
+ s.fleetSeedDoor(w, r, provision.FleetSeedRolledBack)
+}
+
+// fleetSeedDoor is the three handlers' one body. The answers carry no text
+// a box could show anyone: 200 done (or already done), 400 a body outside
+// the grammar, 404 not this caller's, 409 the record says otherwise, 502
+// the write failed. The box needs only the status (seedfleetdoor.go).
+func (s *Server) fleetSeedDoor(w http.ResponseWriter, r *http.Request, op string) {
+ if _, _, ok := s.fleetSeedRecord(r); !ok {
+ http.NotFound(w, r)
+ return
+ }
+ var body fleetSeedReport
+ if !replicaPayload(r, &body) || !fleetSeedReportValid(op, r.PathValue("host"), body) {
+ http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
+ return
+ }
+ acct, app, host := r.PathValue("account"), r.PathValue("app"), r.PathValue("host")
+ unauthorized, changed := false, false
+ err := s.withRecordLock(acct, app, func() error {
+ // Ownership again, under the lock: the record and the fleet's
+ // boxes may have moved since the first look.
+ rec, _, ok := s.fleetSeedRecord(r)
+ if !ok {
+ unauthorized = true
+ return nil
+ }
+ var err error
+ changed, err = s.fleetSeedTransition(r.Context(), rec, op, body)
+ return err
+ })
+ switch {
+ case unauthorized:
+ http.NotFound(w, r)
+ return
+ case errors.Is(err, provision.ErrSeedConflict), errors.Is(err, os.ErrNotExist):
+ http.Error(w, http.StatusText(http.StatusConflict), http.StatusConflict)
+ return
+ case err != nil:
+ log.Printf("console: fleet seeds door: %s/%s/%s: seed %s %s: %v", acct, app, host, body.ID, op, err)
+ http.Error(w, http.StatusText(http.StatusBadGateway), http.StatusBadGateway)
+ return
+ }
+ if changed {
+ log.Printf("console: fleet seeds door: %s/%s/%s: seed %s %s", acct, app, host, body.ID, op)
+ }
+ if op == provision.FleetSeedRolledBack {
+ // After the record lock is released (plan R1-2): withRecordLock
+ // holds the app lock, and with lifetimes on the finish retires the
+ // record through withAppHost, which takes the same non-reentrant
+ // mutex. finishSeed checks the seed id and state itself, and its
+ // CAS protects the record; a finish that fails is the seeds sweep's
+ // to retry, and the transition the box reported stands.
+ if err := s.finishSeed(context.WithoutCancel(r.Context()), acct, app, host, body.ID); err != nil {
+ log.Printf("console: fleet seeds door: %s/%s/%s: finish seed %s: %v (the seeds sweep retries)", acct, app, host, body.ID, err)
+ }
+ }
+ w.WriteHeader(http.StatusOK)
+}
+
+// fleetSeedTransition applies op to rec's seed under the record lock, and
+// answers whether it changed the record. Only the record's own seed id is
+// acted on. A record already where op would put it (the box's answer was
+// lost, or a held copy is re-reported every pass) is a no-op: nothing is
+// written and the serial stays. Otherwise the record CAS decides
+// (provision.ErrSeedConflict when its seed is not in a state op starts
+// from), and a write that lands bumps the serial.
+func (s *Server) fleetSeedTransition(ctx context.Context, rec *provision.Record, op string, b fleetSeedReport) (bool, error) {
+ seed := rec.Seed
+ if seed.ID != b.ID {
+ return false, provision.ErrSeedConflict
+ }
+ var mut func(*provision.Record) error
+ switch op {
+ case provision.FleetSeedPlaced:
+ if seed.State == seeds.StatePlaced {
+ return false, nil
+ }
+ mut = provision.SeedPlace(b.ID)
+ case provision.FleetSeedFailed:
+ reason, _ := fleetSeedReason(b.Code)
+ if seed.State == seeds.StateAborted && seed.Reason == reason && seed.Held == b.Held {
+ return false, nil
+ }
+ mut = provision.SeedFail(b.ID, reason, b.Held)
+ case provision.FleetSeedRolledBack:
+ if seed.State == seeds.StateRolledBack {
+ return false, nil
+ }
+ mut = provision.SeedRolledBack(b.ID)
+ default:
+ return false, provision.ErrSeedConflict
+ }
+ // The CAS is bound to the ownership the caller was checked against
+ // under the lock: a record that moved fleet or box, or retired, since
+ // that read is refused like any other record that says otherwise.
+ region, box := rec.Region, rec.FleetBox
+ owned := func(cur *provision.Record) error {
+ if cur.Retired || cur.Region != region || cur.FleetBox != box {
+ return provision.ErrSeedConflict
+ }
+ return mut(cur)
+ }
+ if _, err := provision.SetRecordSeed(ctx, s.cfg.Releases, rec.Account, rec.App, rec.Host, owned); err != nil {
+ return false, err
+ }
+ if op != provision.FleetSeedFailed {
+ // Placed or rolled back, the seed's snapshot is spent. Absent is
+ // fine; a delete that fails is the seeds sweep's to retry, which
+ // deletes a placed or abandoned seed's snapshot.
+ key := seeds.FleetSnapshotKey(rec.Account, rec.App, rec.Host, b.ID)
+ if err := s.cfg.Releases.Delete(ctx, key); err != nil && !errors.Is(err, os.ErrNotExist) {
+ log.Printf("console: fleet seeds door: %s: delete the snapshot of seed %s: %v (the seeds sweep retries)", rec.Host, b.ID, err)
+ }
+ }
+ s.bumpSerial(ctx)
+ return true, nil
+}
diff --git a/internal/console/apifleetseeds_test.go b/internal/console/apifleetseeds_test.go
new file mode 100644
index 000000000..4bda6a5eb
--- /dev/null
+++ b/internal/console/apifleetseeds_test.go
@@ -0,0 +1,467 @@
+package console
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "io"
+ "net/http"
+ "os"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/seeds"
+)
+
+// The fleet seeds door (plan Task 15): a customer-fleet box reports its
+// file seed's placed, failed and rolledback here, because it cannot write
+// records itself.
+
+const fsHost = "seeded.shop.example.com"
+
+// fleetSeedFx is the interactive world's fleets (home: b1 active, b2
+// detached; away: a1), with a data bucket for the finish, and lifetimes
+// on or off.
+type fleetSeedFx struct {
+ fx *interactiveFx
+ b1, b2, a1 string
+ on bool
+}
+
+func newFleetSeedFx(t *testing.T, lifetimesOn bool) fleetSeedFx {
+ t.Helper()
+ clock := useLifetimesClock(t)
+ fx := newIxFx(t, "code-fleet-seeds")
+ b1, b2, a1 := ixFleetWorld(t, fx, fx.acct)
+ fx.srv.cfg.SeedData = release.NewDirStore(t.TempDir())
+ if lifetimesOn {
+ turnLifetimesOn(t, fx.srv, clock)
+ }
+ return fleetSeedFx{fx: fx, b1: b1, b2: b2, a1: a1, on: lifetimesOn}
+}
+
+// ctx is a record context as a request admitted now has it.
+func (f fleetSeedFx) ctx(t *testing.T) context.Context {
+ t.Helper()
+ if f.on {
+ return onCtx(t, f.fx.srv)
+ }
+ return context.Background()
+}
+
+// seed creates host's record through the seed doors' own create, on region,
+// with a seed of kind in state, labelled box ("" for none), and puts its
+// fleet snapshot. It answers the seed id.
+func (f fleetSeedFx) seed(t *testing.T, host, region, box, kind, state string) string {
+ t.Helper()
+ id := newSeedID(t)
+ now := time.Now().UTC()
+ rec := provision.Record{Schema: 1, Host: host, Slug: strings.SplitN(host, ".", 2)[0], App: "shop", Account: f.fx.acct,
+ Channel: "stable", Region: region, FleetBox: box, CreatedAt: now,
+ Seed: &provision.SeedSource{ID: id, Kind: kind, State: state, SHA256: strings.Repeat("a", 64), Bytes: 4,
+ By: "alice@keymail.dev", At: now}}
+ life, err := f.fx.st.AppLife(f.fx.acctID, "shop")
+ if err != nil || life == nil {
+ t.Fatalf("app life: %v %v", life, err)
+ }
+ ctx := f.ctx(t)
+ if err := f.fx.srv.createSeedRecord(ctx, seedCreate{lifetime: life.Lifetime}, rec); err != nil {
+ t.Fatal(err)
+ }
+ f.putSnapshot(t, host, id)
+ return id
+}
+
+func (f fleetSeedFx) putSnapshot(t *testing.T, host, id string) {
+ t.Helper()
+ if _, err := f.fx.rel.Put(context.Background(), seeds.FleetSnapshotKey(f.fx.acct, "shop", host, id), []byte("snap"), ""); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// serial is the serial object's etag: it moves with every bump.
+func (f fleetSeedFx) serial(t *testing.T) string {
+ t.Helper()
+ _, etag, err := f.fx.rel.Get(context.Background(), release.SerialKey)
+ if err != nil && !errors.Is(err, os.ErrNotExist) {
+ t.Fatal(err)
+ }
+ return etag
+}
+
+func (f fleetSeedFx) hasSnapshot(t *testing.T, host, id string) bool {
+ t.Helper()
+ _, _, err := f.fx.rel.Get(context.Background(), seeds.FleetSnapshotKey(f.fx.acct, "shop", host, id))
+ if err != nil && !errors.Is(err, os.ErrNotExist) {
+ t.Fatal(err)
+ }
+ return err == nil
+}
+
+// raw is host's record bytes, nil when there is none.
+func (f fleetSeedFx) raw(t *testing.T, host string) []byte {
+ t.Helper()
+ raw, _, err := f.fx.rel.Get(context.Background(), provision.RecordKey(f.fx.acct, "shop", host))
+ if errors.Is(err, os.ErrNotExist) {
+ return nil
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ return raw
+}
+
+func (f fleetSeedFx) record(t *testing.T, host string) *provision.Record {
+ t.Helper()
+ rec, _, err := f.fx.srv.readRecord(f.ctx(t), f.fx.acct, "shop", host)
+ if errors.Is(err, os.ErrNotExist) {
+ return nil
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ return rec
+}
+
+// post calls the door as the box name with token, bounded so a deadlock
+// fails the test instead of hanging it.
+func (f fleetSeedFx) post(t *testing.T, host, op, name, token string, body any) (int, []byte) {
+ t.Helper()
+ return f.postPath(t, "/api/fleet/seeds/"+f.fx.acct+"/shop/"+host+"/"+op, name, token, body)
+}
+
+func (f fleetSeedFx) postPath(t *testing.T, path, name, token string, body any) (int, []byte) {
+ t.Helper()
+ raw, err := json.Marshal(body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ req, err := http.NewRequest(http.MethodPost, f.fx.ts.URL+path, bytes.NewReader(raw))
+ if err != nil {
+ t.Fatal(err)
+ }
+ req.Header.Set("Authorization", "Bearer "+token)
+ req.Header.Set("Carlos-Tunnel-Name", name)
+ res, err := (&http.Client{Timeout: 30 * time.Second}).Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer res.Body.Close()
+ out, err := io.ReadAll(res.Body)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return res.StatusCode, out
+}
+
+type fsBody map[string]string
+
+// opBody is a well-formed body for op.
+func opBody(op, id string) fsBody {
+ if op == provision.FleetSeedFailed {
+ return fsBody{"id": id, "code": provision.SeedCodeMismatch}
+ }
+ return fsBody{"id": id}
+}
+
+var fleetSeedOps = []string{provision.FleetSeedPlaced, provision.FleetSeedFailed, provision.FleetSeedRolledBack}
+
+func TestFleetSeedDoorRefusals(t *testing.T) {
+ f := newFleetSeedFx(t, false)
+ id := f.seed(t, fsHost, "fleet/home", "", seeds.KindFile, seeds.StateReady)
+ region := f.seed(t, "region.shop.example.com", "uk", "", seeds.KindFile, seeds.StateReady)
+ imp := f.seed(t, "imported.shop.example.com", "fleet/home", "", seeds.KindImport, seeds.StateReady)
+ from := f.seed(t, "copied.shop.example.com", "fleet/home", "", seeds.KindReplica, seeds.StateReady)
+ notFound := func(t *testing.T, what, path, name, token string, body fsBody, host string) {
+ t.Helper()
+ before := f.raw(t, host)
+ code, raw := f.postPath(t, path, name, token, body)
+ if code != http.StatusNotFound || string(raw) != "404 page not found\n" {
+ t.Errorf("%s: %d %q, want the identical 404", what, code, raw)
+ }
+ if after := f.raw(t, host); !bytes.Equal(before, after) {
+ t.Errorf("%s: the record changed:\n%s\n%s", what, before, after)
+ }
+ }
+ base := func(host string) string { return "/api/fleet/seeds/" + f.fx.acct + "/shop/" + host + "/" }
+ for _, op := range fleetSeedOps {
+ for _, c := range []struct {
+ what, host, id, name, token string
+ path string
+ }{
+ {"another fleet's box", fsHost, id, "away/a1", f.a1, ""},
+ {"another fleet's token", fsHost, id, "home/b1", f.a1, ""},
+ {"a detached box", fsHost, id, "home/b2", f.b2, ""},
+ {"no bearer", fsHost, id, "home/b1", "", ""},
+ {"a region record", "region.shop.example.com", region, "home/b1", f.b1, ""},
+ {"an import seed", "imported.shop.example.com", imp, "home/b1", f.b1, ""},
+ {"a --from seed", "copied.shop.example.com", from, "home/b1", f.b1, ""},
+ {"a malformed host", fsHost, id, "home/b1", f.b1, base("bad!host") + op},
+ {"another account", fsHost, id, "home/b1", f.b1, strings.Replace(base(fsHost), f.fx.acct, "baj", 1) + op},
+ {"no record", "absent.shop.example.com", id, "home/b1", f.b1, ""},
+ } {
+ path := c.path
+ if path == "" {
+ path = base(c.host) + op
+ }
+ notFound(t, op+": "+c.what, path, c.name, c.token, opBody(op, c.id), c.host)
+ }
+ }
+
+ // Ownership: a labelled record answers only its box, and an unlabelled
+ // one only the fleet's sole active box.
+ reg, err := openRegistry(f.fx.regPath)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.SetFleetBoxStatus("home", "b2", "active"); err != nil {
+ t.Fatal(err)
+ }
+ onB1 := f.seed(t, "one.shop.example.com", "fleet/home", "b1", seeds.KindFile, seeds.StateReady)
+ onB2 := f.seed(t, "two.shop.example.com", "fleet/home", "b2", seeds.KindFile, seeds.StateReady)
+ for _, op := range fleetSeedOps {
+ notFound(t, op+": another box", base("one.shop.example.com")+op, "home/b2", f.b2, opBody(op, onB1), "one.shop.example.com")
+ notFound(t, op+": a record labelled for another box", base("two.shop.example.com")+op, "home/b1", f.b1, opBody(op, onB2), "two.shop.example.com")
+ notFound(t, op+": unlabelled, two active boxes", base(fsHost)+op, "home/b1", f.b1, opBody(op, id), fsHost)
+ }
+ if err := reg.SetFleetBoxStatus("home", "b2", "detached"); err != nil {
+ t.Fatal(err)
+ }
+
+ // A stale seed id is the owner's, so it is told: 409, nothing changed.
+ stale := newSeedID(t)
+ for _, op := range fleetSeedOps {
+ before := f.raw(t, fsHost)
+ if code, raw := f.post(t, fsHost, op, "home/b1", f.b1, opBody(op, stale)); code != http.StatusConflict {
+ t.Errorf("%s with a stale id: %d %s, want 409", op, code, raw)
+ }
+ if !bytes.Equal(before, f.raw(t, fsHost)) {
+ t.Errorf("%s with a stale id changed the record", op)
+ }
+ }
+ if !f.hasSnapshot(t, fsHost, id) {
+ t.Fatal("a refused call deleted the snapshot")
+ }
+}
+
+func TestFleetSeedDoorPlacedDeletesSnapshotOnce(t *testing.T) {
+ f := newFleetSeedFx(t, false)
+ id := f.seed(t, fsHost, "fleet/home", "", seeds.KindFile, seeds.StateReady)
+ serial := f.serial(t)
+ if code, raw := f.post(t, fsHost, "placed", "home/b1", f.b1, fsBody{"id": id}); code != http.StatusOK {
+ t.Fatalf("placed: %d %s", code, raw)
+ }
+ if rec := f.record(t, fsHost); rec.Seed.State != seeds.StatePlaced {
+ t.Fatalf("seed %+v, want placed", rec.Seed)
+ }
+ if f.hasSnapshot(t, fsHost, id) {
+ t.Fatal("the snapshot of a placed seed is still there")
+ }
+ if f.serial(t) == serial {
+ t.Fatal("placed did not bump the serial")
+ }
+ // A repeat (the box's answer was lost) is a no-op: the record, the
+ // serial and anything at the snapshot's key stay as they are.
+ f.putSnapshot(t, fsHost, id)
+ before, serial := f.raw(t, fsHost), f.serial(t)
+ if code, raw := f.post(t, fsHost, "placed", "home/b1", f.b1, fsBody{"id": id}); code != http.StatusOK {
+ t.Fatalf("placed again: %d %s", code, raw)
+ }
+ if !bytes.Equal(before, f.raw(t, fsHost)) || !f.hasSnapshot(t, fsHost, id) || f.serial(t) != serial {
+ t.Fatal("a repeated placed changed something")
+ }
+ // A labelled record answers its own box the same way.
+ labelled := f.seed(t, "one.shop.example.com", "fleet/home", "b1", seeds.KindFile, seeds.StateReady)
+ if code, raw := f.post(t, "one.shop.example.com", "placed", "home/b1", f.b1, fsBody{"id": labelled}); code != http.StatusOK {
+ t.Fatalf("placed, labelled: %d %s", code, raw)
+ }
+ // placed from aborted is the record saying otherwise.
+ aborted := f.seed(t, "two.shop.example.com", "fleet/home", "", seeds.KindFile, seeds.StateAborted)
+ before = f.raw(t, "two.shop.example.com")
+ if code, _ := f.post(t, "two.shop.example.com", "placed", "home/b1", f.b1, fsBody{"id": aborted}); code != http.StatusConflict {
+ t.Fatalf("placed from aborted: %d, want 409", code)
+ }
+ if !bytes.Equal(before, f.raw(t, "two.shop.example.com")) || !f.hasSnapshot(t, "two.shop.example.com", aborted) {
+ t.Fatal("a refused placed changed something")
+ }
+}
+
+func TestFleetSeedDoorFailedMapsCodes(t *testing.T) {
+ f := newFleetSeedFx(t, false)
+ n := 0
+ fresh := func(t *testing.T, state string) (string, string) {
+ t.Helper()
+ n++
+ host := "s" + string(rune('a'+n)) + ".shop.example.com"
+ return host, f.seed(t, host, "fleet/home", "", seeds.KindFile, state)
+ }
+ for _, c := range []struct{ code, held, reason string }{
+ {provision.SeedCodeMismatch, "", "the seed file on the box did not match the upload"},
+ {provision.SeedCodeNotADatabase, "", "the seed file on the box failed its integrity check"},
+ {provision.SeedCodeCopyExists, "", "a copy of data already exists for this hostname"},
+ {provision.SeedCodeCopyInStorage, provision.SeedHeldReplica, "a copy of its data is still in the fleet’s storage"},
+ {provision.SeedCodeCopyInStorage, provision.SeedHeldStaging, "a copy of its data is still in the fleet’s storage"},
+ {provision.SeedCodeCopyInStorage, provision.SeedHeldBoth, "a copy of its data is still in the fleet’s storage"},
+ } {
+ host, id := fresh(t, seeds.StateReady)
+ body := fsBody{"id": id, "code": c.code}
+ if c.held != "" {
+ body["held"] = c.held
+ }
+ if code, raw := f.post(t, host, "failed", "home/b1", f.b1, body); code != http.StatusOK {
+ t.Fatalf("%s %s: %d %s", c.code, c.held, code, raw)
+ }
+ rec := f.record(t, host)
+ if rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != c.reason || rec.Seed.Held != c.held {
+ t.Errorf("%s %s: seed %+v", c.code, c.held, rec.Seed)
+ }
+ }
+
+ // The rollback's re-report while a copy is held: an aborted seed takes
+ // the reason and held; the same report again writes nothing.
+ host, id := fresh(t, seeds.StateAborted)
+ held := fsBody{"id": id, "code": provision.SeedCodeCopyInStorage, "held": provision.SeedHeldBoth}
+ if code, raw := f.post(t, host, "failed", "home/b1", f.b1, held); code != http.StatusOK {
+ t.Fatalf("copy-in-storage on aborted: %d %s", code, raw)
+ }
+ if rec := f.record(t, host); rec.Seed.State != seeds.StateAborted || rec.Seed.Held != provision.SeedHeldBoth {
+ t.Fatalf("seed %+v", rec.Seed)
+ }
+ before, serial := f.raw(t, host), f.serial(t)
+ if code, raw := f.post(t, host, "failed", "home/b1", f.b1, held); code != http.StatusOK {
+ t.Fatalf("the same report again: %d %s", code, raw)
+ }
+ if !bytes.Equal(before, f.raw(t, host)) || f.serial(t) != serial {
+ t.Fatal("a repeated copy-in-storage report wrote something")
+ }
+ // A different place is recorded.
+ held["held"] = provision.SeedHeldReplica
+ if code, raw := f.post(t, host, "failed", "home/b1", f.b1, held); code != http.StatusOK {
+ t.Fatalf("copy-in-storage, replica: %d %s", code, raw)
+ }
+ if rec := f.record(t, host); rec.Seed.Held != provision.SeedHeldReplica {
+ t.Fatalf("seed %+v, want held replica", rec.Seed)
+ }
+
+ // Outside the door's vocabulary: 400, nothing changed.
+ host, id = fresh(t, seeds.StateReady)
+ for _, c := range []struct {
+ what, op string
+ body any
+ }{
+ {"an unknown code", "failed", fsBody{"id": id, "code": "melted"}},
+ {"no code", "failed", fsBody{"id": id}},
+ {"copy-in-storage without held", "failed", fsBody{"id": id, "code": provision.SeedCodeCopyInStorage}},
+ {"copy-in-storage held elsewhere", "failed", fsBody{"id": id, "code": provision.SeedCodeCopyInStorage, "held": "elsewhere"}},
+ {"held with mismatch", "failed", fsBody{"id": id, "code": provision.SeedCodeMismatch, "held": provision.SeedHeldReplica}},
+ {"held on placed", "placed", fsBody{"id": id, "held": provision.SeedHeldReplica}},
+ {"held on rolledback", "rolledback", fsBody{"id": id, "held": provision.SeedHeldReplica}},
+ {"a code on placed", "placed", fsBody{"id": id, "code": provision.SeedCodeMismatch}},
+ {"a code on rolledback", "rolledback", fsBody{"id": id, "code": provision.SeedCodeMismatch}},
+ {"text from the box", "failed", fsBody{"id": id, "code": provision.SeedCodeMismatch, "reason": "it broke"}},
+ {"a malformed id", "failed", fsBody{"id": "../x", "code": provision.SeedCodeMismatch}},
+ {"not an object", "failed", "failed"},
+ {"two documents", "failed", nil},
+ } {
+ before := f.raw(t, host)
+ var code int
+ var raw []byte
+ if c.body == nil {
+ code, raw = f.postRaw(t, host, c.op, `{"id":"`+id+`","code":"mismatch"}{}`)
+ } else {
+ code, raw = f.post(t, host, c.op, "home/b1", f.b1, c.body)
+ }
+ if code != http.StatusBadRequest {
+ t.Errorf("%s: %d %s, want 400", c.what, code, raw)
+ }
+ if !bytes.Equal(before, f.raw(t, host)) {
+ t.Errorf("%s: the record changed", c.what)
+ }
+ }
+}
+
+// postRaw sends body verbatim as home/b1.
+func (f fleetSeedFx) postRaw(t *testing.T, host, op, body string) (int, []byte) {
+ t.Helper()
+ req, err := http.NewRequest(http.MethodPost, f.fx.ts.URL+"/api/fleet/seeds/"+f.fx.acct+"/shop/"+host+"/"+op, strings.NewReader(body))
+ if err != nil {
+ t.Fatal(err)
+ }
+ req.Header.Set("Authorization", "Bearer "+f.b1)
+ req.Header.Set("Carlos-Tunnel-Name", "home/b1")
+ res, err := (&http.Client{Timeout: 30 * time.Second}).Do(req)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer res.Body.Close()
+ out, _ := io.ReadAll(res.Body)
+ return res.StatusCode, out
+}
+
+func TestFleetSeedDoorRolledBackFinishes(t *testing.T) {
+ for _, on := range []bool{false, true} {
+ name := "lifetimes off"
+ if on {
+ name = "lifetimes on"
+ }
+ t.Run(name, func(t *testing.T) {
+ f := newFleetSeedFx(t, on)
+ id := f.seed(t, fsHost, "fleet/home", "", seeds.KindFile, seeds.StateAborted)
+ if code, raw := f.post(t, fsHost, "rolledback", "home/b1", f.b1, fsBody{"id": id}); code != http.StatusOK {
+ t.Fatalf("rolledback: %d %s", code, raw)
+ }
+ if raw := f.raw(t, fsHost); raw != nil {
+ t.Fatalf("the record is still there: %s", raw)
+ }
+ if f.hasSnapshot(t, fsHost, id) {
+ t.Fatal("the snapshot is still there")
+ }
+ // The hostname is free: it can be created again.
+ again := f.seed(t, fsHost, "fleet/home", "", seeds.KindFile, seeds.StateReady)
+ if rec := f.record(t, fsHost); rec == nil || rec.Seed.ID != again {
+ t.Fatalf("the hostname was not created again: %+v", rec)
+ }
+ // The app's lock was released: a second mutation does not block.
+ done := make(chan error, 1)
+ go func() {
+ done <- f.fx.srv.withRecordLock(f.fx.acct, "shop", func() error { return nil })
+ }()
+ select {
+ case err := <-done:
+ if err != nil {
+ t.Fatal(err)
+ }
+ case <-time.After(10 * time.Second):
+ t.Fatal("the app lock is still held after the door answered")
+ }
+ // The door answers only for the record's own seed: the old id
+ // is now stale against the new record.
+ before := f.raw(t, fsHost)
+ if code, _ := f.post(t, fsHost, "rolledback", "home/b1", f.b1, fsBody{"id": id}); code != http.StatusConflict {
+ t.Fatalf("rolledback with the finished seed's id: %d, want 409", code)
+ }
+ if !bytes.Equal(before, f.raw(t, fsHost)) {
+ t.Fatal("the new record changed")
+ }
+ })
+ }
+}
+
+func TestFleetSeedDoorRolledBackOnlyFromAborted(t *testing.T) {
+ f := newFleetSeedFx(t, false)
+ for _, state := range []string{seeds.StateReserving, seeds.StateReady, seeds.StatePlaced} {
+ host := state + ".shop.example.com"
+ id := f.seed(t, host, "fleet/home", "", seeds.KindFile, state)
+ before := f.raw(t, host)
+ if code, raw := f.post(t, host, "rolledback", "home/b1", f.b1, fsBody{"id": id}); code != http.StatusConflict {
+ t.Errorf("rolledback from %s: %d %s, want 409", state, code, raw)
+ }
+ if !bytes.Equal(before, f.raw(t, host)) || !f.hasSnapshot(t, host, id) {
+ t.Errorf("rolledback from %s changed something", state)
+ }
+ }
+}
diff --git a/internal/console/linkedpolicy.go b/internal/console/linkedpolicy.go
index 91d0293dc..dee00a86f 100644
--- a/internal/console/linkedpolicy.go
+++ b/internal/console/linkedpolicy.go
@@ -302,6 +302,9 @@ var linkedPolicies = map[string]linkedPolicy{
"POST /api/fleet/replicas/{account}/{app}/{host}/coordinator": linkedRefuse,
"POST /api/fleet/replicas/{account}/{app}/{host}/release": linkedRefuse,
"POST /api/fleet/replicas/{account}/{app}/{host}/deploy": linkedRefuse,
+ "POST /api/fleet/seeds/{account}/{app}/{host}/placed": linkedRefuse,
+ "POST /api/fleet/seeds/{account}/{app}/{host}/failed": linkedRefuse,
+ "POST /api/fleet/seeds/{account}/{app}/{host}/rolledback": linkedRefuse,
}
// refuseLinkedJSON answers an API door's linked refusal, if any, and
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go
index faed3a3c7..27b800b18 100644
--- a/internal/console/routedecls.go
+++ b/internal/console/routedecls.go
@@ -465,6 +465,13 @@ var routeDecls = []routeDecl{
{Pattern: "POST /api/fleet/replicas/{account}/{app}/{host}/coordinator", Handler: (*Server).handleReplicaCoordinator},
{Pattern: "POST /api/fleet/replicas/{account}/{app}/{host}/release", Handler: (*Server).handleReplicaRelease},
{Pattern: "POST /api/fleet/replicas/{account}/{app}/{host}/deploy", Handler: (*Server).handleReplicaDeploy},
+ // The fleet seeds door (apifleetseeds.go, fleet seeded create design
+ // §3.5): a customer-fleet box reports its file seed's placement,
+ // failure and rollback, authenticated as the replica doors are. Every
+ // refusal of the caller is the same 404.
+ {Pattern: "POST /api/fleet/seeds/{account}/{app}/{host}/placed", Handler: (*Server).handleFleetSeedPlaced},
+ {Pattern: "POST /api/fleet/seeds/{account}/{app}/{host}/failed", Handler: (*Server).handleFleetSeedFailed},
+ {Pattern: "POST /api/fleet/seeds/{account}/{app}/{host}/rolledback", Handler: (*Server).handleFleetSeedRolledBack},
{Pattern: "POST /auth/cli/start", Handler: (*Server).handleCLIStart},
{Pattern: "POST /auth/cli/poll", Handler: (*Server).handleCLIPoll},
{Pattern: "GET /auth/cli", Handler: (*Server).handleCLIApprovePage},
diff --git a/internal/console/seedfile_copy.go b/internal/console/seedfile_copy.go
index c921b57f1..92508f6d8 100644
--- a/internal/console/seedfile_copy.go
+++ b/internal/console/seedfile_copy.go
@@ -21,6 +21,18 @@ const (
// FS-25: capital T, as its sibling SD-N3.
fileSeedFloorCopy = "This deployment’s seeds floor does not allow seed files yet. An operator publishes it again with carlos system seeds-floor publish."
+ // FS-27 to FS-30: the reason a fleet file seed's record keeps, mapped
+ // from the code its box reports to the fleet seeds door
+ // (apifleetseeds.go; the box sends no text, decision D4).
+ // FS-27, code mismatch.
+ fileSeedBoxMismatchCopy = "the seed file on the box did not match the upload"
+ // FS-28, code not-a-database.
+ fileSeedBoxIntegrityCopy = "the seed file on the box failed its integrity check"
+ // FS-29, code copy-exists.
+ fileSeedCopyExistsCopy = "a copy of data already exists for this hostname"
+ // FS-30, code copy-in-storage; the record keeps where (held) beside it.
+ fileSeedCopyInStorageCopy = "a copy of its data is still in the fleet’s storage"
+
// FS-41: an import object whose kind is neither absent nor "file". Only a hand-written API call reaches it; the CLI sends one or
// the other.
fileSeedKindCopy = "kind must be file, or left out for an import"
diff --git a/internal/provision/fleet_seeded_create_3_census_test.go b/internal/provision/fleet_seeded_create_3_census_test.go
new file mode 100644
index 000000000..e27489b4d
--- /dev/null
+++ b/internal/provision/fleet_seeded_create_3_census_test.go
@@ -0,0 +1,58 @@
+package provision
+
+// fleetSeededCreate3WriteCensusInventory is the record-write census for
+// slice 3 of seeded instances on a customer fleet (#1139, branch
+// fleet-seeded-create-3: the console's fleet path), layered on
+// fleetSeededCreate2WriteCensusInventory (main's newest at origin/main
+// 772aabbb0, the slice 2 merge).
+// Reviewed by the branch author against the source. No class or site kind
+// changes; one unit is new, and two tables are re-pinned.
+//
+// New (Task 15, the fleet seeds door):
+//
+// - Server.fleetSeedTransition (internal/console/apifleetseeds.go): the
+// one record write behind the door's three handlers
+// (handleFleetSeedPlaced, handleFleetSeedFailed,
+// handleFleetSeedRolledBack, through fleetSeedDoor, which hold no site
+// of their own). Under the app's record lock, after the caller's
+// ownership is checked again there, it moves the record's own file seed
+// by provision.SetRecordSeed: SeedPlace, SeedFail (with the reason the
+// code maps to and held) or SeedRolledBack, each bound to the record's
+// region and box as read under the lock. A record already where the op
+// would put it is not written. It then deletes the seed's fleet
+// snapshot (placed, rolled back) and bumps the serial. The finish that
+// follows rolled-back runs after the lock is released, through
+// finishSeed, whose own entry (finishSeedOnce) is unchanged.
+// record-writer / key:SetRecordSeed, as the other seed doors' writers.
+//
+// Re-pinned (route tables, no record write):
+// - var routeDecls: the door's three POST routes beside the replica doors.
+// - var linkedPolicies: the same three as linkedRefuse, beside the replica
+// doors' rows.
+//
+// provision.SeedFail gains held (decision D12); it is a transition passed
+// to SetRecordSeed, not a census unit, and SetRecordSeed's digest stands.
+func fleetSeededCreate3WriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), fleetSeededCreate2WriteCensusInventory()...)
+ for _, r := range []censusEntry{
+ {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "e25fb0d3dbac6d7886d05636ae0a3fc09180e3ed699e1a9b2a7dc7b1c8e8d328"},
+ {"internal/console/linkedpolicy.go", "var linkedPolicies", "key-site", "lit:instances,lit:sidecars", "c4139a1a2795e47d76f3c49bb761c15a849035942a4dcfa5a9ea631be61708b9"},
+ } {
+ replaced := false
+ for i, e := range entries {
+ if e.File == r.File && e.Unit == r.Unit {
+ if e.Class != r.Class || e.Kinds != r.Kinds {
+ panic("fleet-seeded-create-3 census: classification changed for " + r.File + ":" + r.Unit)
+ }
+ entries[i], replaced = r, true
+ break
+ }
+ }
+ if !replaced {
+ panic("fleet-seeded-create-3 census: re-pin of an unlisted unit " + r.File + ":" + r.Unit)
+ }
+ }
+ return append(entries,
+ censusEntry{"internal/console/apifleetseeds.go", "Server.fleetSeedTransition", "record-writer", "key:SetRecordSeed", "15987d1343dee7ce732f193d757ef7853376c0a666c9bb2a87b6ea1be2a4ab51"},
+ )
+}
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index 359db1a97..f91fcf000 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := fleetSeededCreate2WriteCensusInventory()
+ inventory := fleetSeededCreate3WriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/seed.go b/internal/provision/seed.go
index d48289422..cda366afa 100644
--- a/internal/provision/seed.go
+++ b/internal/provision/seed.go
@@ -14,17 +14,23 @@ import (
// SeedSource is a record's seed (seeded-instances spec §3.2). The run series
// declared its Kind and State; those keep their json tags.
type SeedSource struct {
- ClaimID string `json:"claim_id,omitempty"`
- ID string `json:"id"` // random, minted with the seed; never reused
- Kind string `json:"kind"` // seeds.KindReplica | seeds.KindImport | seeds.KindDemoClaim
- From string `json:"from,omitempty"` // replica: the source host
- TXID string `json:"txid,omitempty"` // replica: the TXID actually restored
- SHA256 string `json:"sha256"` // of snapshot.db
- Bytes int64 `json:"bytes"`
- State string `json:"state"` // seeds.State*
- Reason string `json:"reason,omitempty"` // set with refused, and with aborted when the abort names why
- By string `json:"by"` // the caller
- At time.Time `json:"at"`
+ ClaimID string `json:"claim_id,omitempty"`
+ ID string `json:"id"` // random, minted with the seed; never reused
+ Kind string `json:"kind"` // seeds.KindReplica | seeds.KindImport | seeds.KindDemoClaim
+ From string `json:"from,omitempty"` // replica: the source host
+ TXID string `json:"txid,omitempty"` // replica: the TXID actually restored
+ SHA256 string `json:"sha256"` // of snapshot.db
+ Bytes int64 `json:"bytes"`
+ State string `json:"state"` // seeds.State*
+ Reason string `json:"reason,omitempty"` // set with refused, and with aborted when the abort names why
+ // Held is where a fleet file seed's copy still is, when its box could
+ // not prove it gone (decision D12): SeedHeldReplica, SeedHeldStaging
+ // or SeedHeldBoth, set only beside the copy-in-storage reason. The
+ // console builds the location a member reads from it and the host,
+ // never from text a box sent.
+ Held string `json:"held,omitempty"`
+ By string `json:"by"` // the caller
+ At time.Time `json:"at"`
// Replaces is import-only. VerifyHash also gates a fresh demo claim.
Replaces string `json:"replaces,omitempty"` // the addr the swap replaces
VerifyHash string `json:"verify_hash,omitempty"` // sha256 of the verify token (§5.4)
@@ -188,15 +194,25 @@ func SeedAbortFileUploadBecause(id, reason string) func(*Record) error {
// SeedFail is a box's terminal placement failure (design §3.6): a file seed
// from ready to aborted, with Reason. Never an import (SeedRefuse is
-// unchanged). It also accepts an aborted file seed and sets only Reason
-// (Decision D6), so a rollback that finds a copy can say so.
-func SeedFail(id, reason string) func(*Record) error {
+// unchanged). It also accepts an aborted file seed and sets only Reason and
+// Held (Decision D6), so a rollback that finds a copy can say so. held is
+// "", "replica", "staging" or "both" (Decision D12): which of the host's
+// two storage locations still holds a copy. It is set, or cleared, on every
+// call; only copy-in-storage passes a non-empty one. Any other held is
+// refused and changes nothing.
+func SeedFail(id, reason, held string) func(*Record) error {
return func(rec *Record) error {
+ switch held {
+ case "", SeedHeldReplica, SeedHeldStaging, SeedHeldBoth:
+ default:
+ return fmt.Errorf("provision: seed %s: held %q is not a place", id, held)
+ }
if err := seedIn(rec, id, seeds.KindFile, seeds.StateReady, seeds.StateAborted); err != nil {
return err
}
rec.Seed.State = seeds.StateAborted
rec.Seed.Reason = reason
+ rec.Seed.Held = held
return nil
}
}
diff --git a/internal/provision/seed_test.go b/internal/provision/seed_test.go
index 9da835c01..7ee290c0f 100644
--- a/internal/provision/seed_test.go
+++ b/internal/provision/seed_test.go
@@ -311,7 +311,7 @@ func TestSeedTransitionTable(t *testing.T) {
{seeds.KindFile, seeds.StateReady}: seeds.StatePlaced,
{seeds.KindImport, seeds.StateSwapped}: seeds.StatePlaced}},
"publish file": {SeedPublishFile, map[cell]string{{seeds.KindFile, seeds.StateReserving}: seeds.StateReady}},
- "fail": {func(id string) func(*Record) error { return SeedFail(id, "x") }, map[cell]string{
+ "fail": {func(id string) func(*Record) error { return SeedFail(id, "x", "") }, map[cell]string{
{seeds.KindFile, seeds.StateReady}: seeds.StateAborted,
{seeds.KindFile, seeds.StateAborted}: seeds.StateAborted}},
"abort file upload": {func(id string) func(*Record) error { return SeedAbortFileUploadBecause(id, "no") },
@@ -767,22 +767,36 @@ func TestUnfinishedFilePlacedIsFinished(t *testing.T) {
func TestSeedFailFileOnly(t *testing.T) {
seed := testSeed(t, seeds.KindFile, seeds.StateReady)
rec := Record{Seed: seed}
- if err := SeedFail(seed.ID, "placing-failed")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "placing-failed" {
+ if err := SeedFail(seed.ID, "placing-failed", "")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "placing-failed" || rec.Seed.Held != "" {
t.Fatalf("ready: %v %+v", err, rec.Seed)
}
- if err := SeedFail(seed.ID, "copy-in-storage")(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "copy-in-storage" {
+ // An aborted file seed keeps its state and takes the new Reason and
+ // Held (decisions D6, D12).
+ if err := SeedFail(seed.ID, "copy-in-storage", SeedHeldBoth)(&rec); err != nil || rec.Seed.State != seeds.StateAborted || rec.Seed.Reason != "copy-in-storage" || rec.Seed.Held != SeedHeldBoth {
t.Fatalf("aborted: %v %+v", err, rec.Seed)
}
+ // Held is set, or cleared, on every call.
+ if err := SeedFail(seed.ID, "copy-in-storage", SeedHeldReplica)(&rec); err != nil || rec.Seed.Held != SeedHeldReplica {
+ t.Fatalf("held replica: %v %+v", err, rec.Seed)
+ }
+ if err := SeedFail(seed.ID, "not-kept", "")(&rec); err != nil || rec.Seed.Held != "" || rec.Seed.Reason != "not-kept" {
+ t.Fatalf("held cleared: %v %+v", err, rec.Seed)
+ }
+ // A held outside the four values is refused, and changes nothing.
+ before := *rec.Seed
+ if err := SeedFail(seed.ID, "copy-in-storage", "elsewhere")(&rec); err == nil || *rec.Seed != before {
+ t.Fatalf("held elsewhere: %v %+v", err, rec.Seed)
+ }
for _, c := range []struct{ kind, state string }{
{seeds.KindImport, seeds.StateReady}, {seeds.KindImport, seeds.StateAborted},
{seeds.KindFile, seeds.StateReserving}, {seeds.KindFile, seeds.StatePlaced},
} {
other := testSeed(t, c.kind, c.state)
- if err := SeedFail(other.ID, "x")(&Record{Seed: other}); !errors.Is(err, ErrSeedConflict) {
+ if err := SeedFail(other.ID, "x", "")(&Record{Seed: other}); !errors.Is(err, ErrSeedConflict) {
t.Errorf("%s %s: %v", c.kind, c.state, err)
}
}
- if err := SeedFail("sd_other", "x")(&Record{Seed: testSeed(t, seeds.KindFile, seeds.StateReady)}); !errors.Is(err, ErrSeedConflict) {
+ if err := SeedFail("sd_other", "x", "")(&Record{Seed: testSeed(t, seeds.KindFile, seeds.StateReady)}); !errors.Is(err, ErrSeedConflict) {
t.Errorf("another id: %v", err)
}
}
diff --git a/parity/parity.tsv b/parity/parity.tsv
index c9c4bb66b..4c33283a1 100644
--- a/parity/parity.tsv
+++ b/parity/parity.tsv
@@ -268,5 +268,5 @@ alert-signing-key platform internal GET /alerts/signing-key The public key al
legacy-apps platform internal GET /apps ; GET /apps/{app} Old URLs kept as redirects into the account.
billing-webhook platform internal POST /billing/webhook Stripe calls it.
ses-events platform internal POST /api/ses/events Amazon SES delivery events.
-box-doors platform internal POST /api/fleet/enrol ; GET /api/box/interactive/{id} ; GET /api/box/runs/{id} ; POST /api/fleet/replicas/{account}/{app}/{host}/coordinator ; POST /api/fleet/replicas/{account}/{app}/{host}/release ; POST /api/fleet/replicas/{account}/{app}/{host}/deploy Doors boxes and managed fleets call, not people.
+box-doors platform internal POST /api/fleet/enrol ; GET /api/box/interactive/{id} ; GET /api/box/runs/{id} ; POST /api/fleet/replicas/{account}/{app}/{host}/coordinator ; POST /api/fleet/replicas/{account}/{app}/{host}/release ; POST /api/fleet/replicas/{account}/{app}/{host}/deploy ; POST /api/fleet/seeds/{account}/{app}/{host}/placed ; POST /api/fleet/seeds/{account}/{app}/{host}/failed ; POST /api/fleet/seeds/{account}/{app}/{host}/rolledback Doors boxes and managed fleets call, not people.
plumbing platform internal __demo-snapshot ; __registry-child ; __rootfs-check-probe ; __rootfs-check-prepare ; __cgexec ; __cgprobe Words the binary runs itself as, dispatched before the command switch.
diff --git a/scripts/gitleaks-gate/notscanned.go b/scripts/gitleaks-gate/notscanned.go
index 20d1efbd7..7050970e6 100644
--- a/scripts/gitleaks-gate/notscanned.go
+++ b/scripts/gitleaks-gate/notscanned.go
@@ -30,6 +30,7 @@ var notScanned = []string{
"internal/provision/fleet_public_routes_census_test.go",
"internal/provision/fleet_seeded_create_1_census_test.go",
"internal/provision/fleet_seeded_create_2_census_test.go",
+ "internal/provision/fleet_seeded_create_3_census_test.go",
"internal/provision/instance_egress_sizes_census_test.go",
"internal/provision/instance_restore_658_census_test.go",
"internal/provision/linked_deployments_slice1_census_test.go",