console: slice 3 review fixes
- P2-1: an app holding an unfinished fleet file seed is not moved to the trash (API and browser doors, and the expiry pass): its box skips a trashed app's records, so the seed could never be rolled back and the purge would refuse for ever. FS-39 (pending) names the hosts. - P2-2: a region listing failure costs only the region half of the seeds sweep; the fleet half carries on. - P3-1: the retirement primitives ask the hold of the stored body's region and seed, so a body the full decode rejects is still held, and a seed the hold cannot read is refused. - P3-2: a placed or aborted fleet file seed's snapshot is condemned by its record's key when its app is no longer listed on a fleet. - P3-3: the demo-expiry purge asks fleetSeedPurgeRefusal too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
12 files changed,
+355
−44
docs/superpowers/plans/2026-11-20-fleet-seeded-create.md+1 −0internal/console/apicli.go+10 −0internal/console/appsettings.go+10 −0internal/console/demo_expiry.go+9 −0internal/console/expirypass.go+10 −0internal/console/hostclaimops.go+4 −13internal/console/lifetimes_retire.go+3 −1internal/console/seedfile.go+57 −2internal/console/seedfile_copy.go+7 −0internal/console/seedslice3review_test.go+180 −0internal/console/seedsweep.go+58 −26internal/provision/fleet_seeded_create_3_census_test.go+6 −2
CI failed — run details
diff --git a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md| index 1cf27542b..600264cd4 100644 |
| --- a/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md |
| +++ b/docs/superpowers/plans/2026-11-20-fleet-seeded-create.md |
| @@ -854,6 +854,7 @@ House rules applied: no em dashes; curly apostrophes; placeholders in their orde |
| | FS-37 | (FS-34's location, `held` staging) moves/%s/ | new | approved (Paul, 2026-11-20) (Decision D12) | |
| | FS-38 | (FS-34's location, `held` both: FS-36, then FS-37) %s and %s | new | approved (Paul, 2026-11-20) (Decision D12) | |
| | FS-35 | %s can’t be deleted permanently until its fleet box has cleaned up %s. | %s can’t be purged yet: %s still hold their hostnames until their fleet box has cleaned up. | approved (Paul, 2026-11-20) (the Trash page's "Delete now", and the trash sweep's log) | |
| +| FS-39 | %s can’t be moved to the trash until its fleet box has cleaned up %s. Delete each with carlos instances delete, then try again. | new | **pending** (slice 3 review P2-1: the trash doors' 409 and the expiry pass's log while an app holds an unfinished fleet file seed; %s is the app, then the hosts) | |
| | FS-41 | kind must be file, or left out for an import | new | approved (Paul, 2026-11-20) (an import object whose kind is neither absent nor `file`; 400, as the sibling shape sentences SD-N48 and the sha256 rule; only a hand-written API call reaches it) | |
| | FS-42 | began seeding %s from a file (%s, %d bytes) | new | approved (Paul, 2026-11-20) (the begin's `instance-seed` activity row: host, first 12 of the sha256, length; as the import's "began an import of …") | |
| | FS-43 | uploaded the seed file for %s | new | approved (Paul, 2026-11-20) (the upload's `seed-file-uploaded` activity row; as the import's "uploaded the snapshot for %s") | |
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index 034a81841..a0f6390dd 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -1787,6 +1787,16 @@ func (s *Server) handleAPITrashApp(w http.ResponseWriter, r *http.Request) { |
| }) |
| return |
| } |
| + // A fleet file seed its box has not proved gone (fleetSeedTrashRefusal): |
| + // refused before the marker, so nothing changes. |
| + if msg, err := s.fleetSeedTrashRefusal(ctx, acct.Sqid, app); err != nil { |
| + log.Printf("console: api trash %s/%s: fleet seeds: %v", acct.Sqid, app, err) |
| + jsonError(w, http.StatusBadGateway, "could not write the trash marker — nothing was deleted; try again") |
| + return |
| + } else if msg != "" { |
| + jsonError(w, http.StatusConflict, msg) |
| + return |
| + } |
| now := time.Now() |
| if err := release.TrashApp(ctx, s.cfg.Releases, acct.Sqid, app, addr, now); err != nil { |
| log.Printf("console: api trash %s/%s: %v", acct.Sqid, app, err) |
diff --git a/internal/console/appsettings.go b/internal/console/appsettings.go| index ccd7b9315..2214bc653 100644 |
| --- a/internal/console/appsettings.go |
| +++ b/internal/console/appsettings.go |
| @@ -1450,6 +1450,16 @@ func (s *Server) handleAppDelete(w http.ResponseWriter, r *http.Request) { |
| back("err", app+" is marked as production, so deleting is refused. Turn the safety delay off first (owner + passkey, on the Releases page; it takes effect after ~72h), then try again.") |
| return |
| } |
| + // A fleet file seed its box has not proved gone (fleetSeedTrashRefusal): |
| + // refused before the marker, so nothing changes. |
| + if msg, err := s.fleetSeedTrashRefusal(ctx, acct.Sqid, app); err != nil { |
| + log.Printf("console: trash %s/%s: fleet seeds: %v", acct.Sqid, app, err) |
| + back("err", "Could not confirm the trash marker. Nothing was changed. Try again.") |
| + return |
| + } else if msg != "" { |
| + back("err", msg) |
| + return |
| + } |
| now := time.Now() |
| if err := release.TrashApp(ctx, s.cfg.Releases, acct.Sqid, app, addr, now); err != nil { |
| log.Printf("console: trash %s/%s: %v", acct.Sqid, app, err) |
diff --git a/internal/console/demo_expiry.go b/internal/console/demo_expiry.go| index 0989c7399..a2e02d3e4 100644 |
| --- a/internal/console/demo_expiry.go |
| +++ b/internal/console/demo_expiry.go |
| @@ -325,6 +325,15 @@ func (s *Server) retireDemoLocked(ctx context.Context, d DemoRow, now time.Time, |
| } else if estate { |
| return demo.ErrPolicy |
| } |
| + // The fleet seed hold's purge check, as every purge entrance asks it |
| + // (fleetSeedPurgeRefusal). A demo app cannot hold a fleet file seed |
| + // today (a file seed's begin refuses a demo record, seedPlacementRefusal), |
| + // so this never refuses; it is asked so the rule has no exception. |
| + if msg, err := s.fleetSeedPurgeRefusal(ctx, d.AccountSqid, d.App); err != nil { |
| + return err |
| + } else if msg != "" { |
| + return errors.New(msg) |
| + } |
| if err = release.PurgeAppGuards(ctx, s.cfg.Releases, s.cfg.ReleasePub, d.AccountSqid, d.App, at, now); err != nil { |
| return err |
| } |
diff --git a/internal/console/expirypass.go b/internal/console/expirypass.go| index 8b03e7336..84f072399 100644 |
| --- a/internal/console/expirypass.go |
| +++ b/internal/console/expirypass.go |
| @@ -184,6 +184,16 @@ func (s *Server) expireOne(ctx context.Context, r AppRow, now time.Time, ev evid |
| s.audit(acct, r.App, expiryActor, "expire-refused", "did not move "+r.App+" to the trash: it is marked as the control plane") |
| return |
| } |
| + // A fleet file seed its box has not proved gone (fleetSeedTrashRefusal): |
| + // not trashed this pass; the next asks again. |
| + if msg, err := s.fleetSeedTrashRefusal(ctx, r.Sqid, r.App); err != nil || msg != "" { |
| + if err != nil { |
| + msg = err.Error() |
| + jobFailed(ctx, fmt.Errorf("expiry pass: %s/%s: fleet seeds: %w; not trashing", r.Sqid, r.App, err)) |
| + } |
| + log.Printf("console: expiry pass: %s/%s: %s Not moving it to the trash this pass.", r.Sqid, r.App, msg) |
| + return |
| + } |
| if err := release.TrashApp(ctx, s.cfg.Releases, r.Sqid, r.App, expiryActor, now); err != nil { |
| log.Printf("console: expiry pass: trash %s/%s: %v", r.Sqid, r.App, err) |
| jobFailed(ctx, fmt.Errorf("expiry pass: trash %s/%s: %w", r.Sqid, r.App, err)) |
diff --git a/internal/console/hostclaimops.go b/internal/console/hostclaimops.go| index 9f2940939..a48137cb8 100644 |
| --- a/internal/console/hostclaimops.go |
| +++ b/internal/console/hostclaimops.go |
| @@ -2,7 +2,6 @@ package console |
| import ( |
| "context" |
| - "encoding/json" |
| "errors" |
| "log" |
| "os" |
| @@ -55,8 +54,8 @@ func (s *Server) retireHostRecord(ctx context.Context, ref provision.RetireRef) |
| // deletes only the body the hold saw: a record written since answers |
| // release.ErrCASConflict, which every caller's failure branch answers as |
| // "try again", and the next try asks the hold of it. An absent key is |
| -// done, as lifetimes on answers it. A body that will not decode is no seed |
| -// and is deleted as before, bound the same way. |
| +// done, as lifetimes on answers it. A body whose region and seed cannot be |
| +// read is refused (fleetSeedHoldRaw fails closed, slice 3 review P3-1). |
| func (s *Server) retireLegacyInstanceRecord(ctx context.Context, ref provision.RetireRef) error { |
| key := provision.RecordKey(ref.Account, ref.App, ref.Host) |
| raw, etag, err := s.cfg.Releases.Get(ctx, key) |
| @@ -66,16 +65,8 @@ func (s *Server) retireLegacyInstanceRecord(ctx context.Context, ref provision.R |
| if err != nil { |
| return err |
| } |
| - // Only the fields the hold reads: the record's own decode is the |
| - // readers', and this is no copy of it. |
| - var body struct { |
| - Region string `json:"region"` |
| - Seed *provision.SeedSource `json:"seed"` |
| - } |
| - if json.Unmarshal(raw, &body) == nil { |
| - if err := fleetSeedHoldOf(ref.Host, body.Region, body.Seed); err != nil { |
| - return err |
| - } |
| + if err := fleetSeedHoldRaw(ref.Host, raw); err != nil { |
| + return err |
| } |
| if err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, etag); err != nil && !errors.Is(err, os.ErrNotExist) { |
| return err |
diff --git a/internal/console/lifetimes_retire.go b/internal/console/lifetimes_retire.go| index 2613f2dcd..955f81d23 100644 |
| --- a/internal/console/lifetimes_retire.go |
| +++ b/internal/console/lifetimes_retire.go |
| @@ -128,8 +128,10 @@ func (s *Server) retireRecordWithLifetimeLocked(ctx context.Context, acct, app, |
| // The fleet seed hold (Task 16 review P1-1): a fleet file seed whose box |
| // has not proved it gone is never retired, whichever entrance asked. |
| // Read under both locks, before anything is persisted. |
| + // Asked of the stored body, not obs.Rec: a stale or corrupt body has |
| + // no Rec, and is held all the same (fleetSeedHoldRaw). |
| if obs.Present { |
| - if err := fleetSeedHold(obs.Rec); err != nil { |
| + if err := fleetSeedHoldRaw(host, obs.Raw); err != nil { |
| return err |
| } |
| } |
diff --git a/internal/console/seedfile.go b/internal/console/seedfile.go| index 4f97dbdad..7a0b9977b 100644 |
| --- a/internal/console/seedfile.go |
| +++ b/internal/console/seedfile.go |
| @@ -13,7 +13,9 @@ |
| package console |
| import ( |
| + "bytes" |
| "context" |
| + "encoding/json" |
| "errors" |
| "fmt" |
| "log" |
| @@ -626,8 +628,37 @@ func fleetSeedHold(rec *provision.Record) error { |
| return fleetSeedHoldOf(rec.Host, rec.Region, rec.Seed) |
| } |
| -// fleetSeedHoldOf is fleetSeedHold asked of a record's three fields, for a |
| -// caller holding only its body (retireLegacyInstanceRecord). |
| +// fleetSeedHoldRaw is fleetSeedHold asked of a record's body as stored, |
| +// for the retirement primitives (retireRecordWithLifetimeLocked, |
| +// retireLegacyInstanceRecord), which must hold even a body the record's |
| +// own decode rejects (slice 3 review P3-1). It decodes only the two fields |
| +// the hold reads, so a body that is otherwise stale or corrupt is still |
| +// classified. One that will not decode even that far is refused |
| +// (errFleetSeedUnclassified, fail closed) unless it plainly carries no |
| +// seed: every record with a seed is written with a "seed" member (its json |
| +// tag), so a body with no such text is no seed's, and the lifetimes' |
| +// cleanup of a corrupt body (lifetimes_retire.go, cases (d) and (g)) goes |
| +// on as before. |
| +func fleetSeedHoldRaw(host string, raw []byte) error { |
| + var body struct { |
| + Region string `json:"region"` |
| + Seed *provision.SeedSource `json:"seed"` |
| + } |
| + if err := json.Unmarshal(raw, &body); err != nil { |
| + if !bytes.Contains(raw, []byte(`"seed"`)) { |
| + return nil |
| + } |
| + return fmt.Errorf("%w: %s: %v", errFleetSeedUnclassified, host, err) |
| + } |
| + return fleetSeedHoldOf(host, body.Region, body.Seed) |
| +} |
| + |
| +// errFleetSeedUnclassified is a retirement refused because the record's |
| +// body could not be read far enough to tell whether a fleet file seed holds |
| +// the hostname. Each door answers it as its ordinary failure. |
| +var errFleetSeedUnclassified = errors.New("console: the record could not be read to check for a fleet file seed") |
| + |
| +// fleetSeedHoldOf is fleetSeedHold asked of a record's three fields. |
| func fleetSeedHoldOf(host, region string, seed *provision.SeedSource) error { |
| if _, fleet := registry.FleetPlacement(region); !fleet || seed == nil || seed.Kind != seeds.KindFile || |
| seed.State == seeds.StatePlaced || seed.State == seeds.StateRolledBack { |
| @@ -689,3 +720,27 @@ func fleetSeedHoldRefusal(err error) (*doorRefusal, bool) { |
| } |
| return &doorRefusal{Status: http.StatusConflict, Msg: held.Msg}, true |
| } |
| + |
| +// fleetSeedTrashRefusal is the trash entrances' check (slice 3 review |
| +// P2-1), under the app lock and before anything is written: "" to go |
| +// ahead, else FS-39 naming the hosts whose fleet file seed is unfinished. |
| +// A box skips every record of a trashed app (provision reconcile), so a |
| +// seed trashed before its box proved it gone would never be rolled back, |
| +// and the app's purge would refuse it (FS-35) for ever. The member deletes |
| +// the instance first: that aborts it, the box rolls it back, the finish |
| +// frees it, and then the trash goes through. An error reading the records |
| +// refuses too, with err set. |
| +// |
| +// A trashed app that already holds one cannot exist: fleet file seeds |
| +// first ship with this check (#1139 slice 3), so no app was trashed |
| +// holding one before it. |
| +func (s *Server) fleetSeedTrashRefusal(ctx context.Context, sqid, app string) (string, error) { |
| + hosts, err := s.unfinishedFleetFileSeeds(ctx, sqid, app) |
| + if err != nil { |
| + return "", err |
| + } |
| + if len(hosts) == 0 { |
| + return "", nil |
| + } |
| + return fmt.Sprintf(fileSeedTrashHeldCopy, app, strings.Join(hosts, ", ")), nil |
| +} |
diff --git a/internal/console/seedfile_copy.go b/internal/console/seedfile_copy.go| index a30facbbc..a9461b1b9 100644 |
| --- a/internal/console/seedfile_copy.go |
| +++ b/internal/console/seedfile_copy.go |
| @@ -63,6 +63,13 @@ const ( |
| // and the trash sweeps' log, while a fleet file seed holds a hostname. |
| fileSeedPurgeHeldCopy = "%s can’t be deleted permanently until its fleet box has cleaned up %s." |
| + // FS-39 (PENDING Paul's approval; slice 3 review P2-1): %s is the app, |
| + // then the hosts. The trash doors' refusal, and the expiry pass's log, |
| + // while a fleet file seed holds a hostname: a trashed app's records are |
| + // skipped by its box, so a seed trashed unfinished could never be |
| + // rolled back, and the app never purged. |
| + fileSeedTrashHeldCopy = "%s can’t be moved to the trash until its fleet box has cleaned up %s. Delete each with carlos instances delete, then try again." |
| + |
| // 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/console/seedslice3review_test.go b/internal/console/seedslice3review_test.go| new file mode 100644 |
| index 000000000..b48bd5e26 |
| --- /dev/null |
| +++ b/internal/console/seedslice3review_test.go |
| @@ -0,0 +1,180 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "net/http" |
| + "os" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/seeds" |
| +) |
| + |
| +// Slice 3's whole-branch review fixes. |
| + |
| +// P2-1: an app holding an unfinished fleet file seed is not trashed (its |
| +// box skips a trashed app's records, so the seed could never be rolled |
| +// back and the app never purged). Deleting the instance first, then the |
| +// box's rollback and the finish, lets the trash through. |
| +func TestTrashAppRefusesHeldFleetFileSeed(t *testing.T) { |
| + f := newFleetFileFixture(t) |
| + ctx := context.Background() |
| + id := f.fleetSeedRecord(t, fileHost, seeds.StateAborted, "", "", time.Now()) |
| + trash := func() (int, string) { |
| + code, _, out := rawReq(t, http.MethodPost, f.fx.ts.URL+"/api/cli/apps/bab/"+fromApp+"/delete", f.token, "") |
| + return code, out |
| + } |
| + want := fmt.Sprintf(fileSeedTrashHeldCopy, fromApp, fileHost) |
| + if want != "shop can’t be moved to the trash until its fleet box has cleaned up push.shop.example.com. Delete each with carlos instances delete, then try again." { |
| + t.Fatalf("FS-39 = %q", want) |
| + } |
| + if code, out := trash(); code != http.StatusConflict || errorOf(t, out) != want { |
| + t.Fatalf("trash = %d %s, want 409 FS-39", code, out) |
| + } |
| + if tomb, err := release.ReadAppTombstone(ctx, f.fx.rel, "bab", fromApp); err != nil || tomb != nil { |
| + t.Fatalf("marker = %+v %v, want none", tomb, err) |
| + } |
| + if life, _ := f.fx.st.AppLife(OpsAccountID, fromApp); life == nil || life.Trashed() { |
| + t.Fatalf("app row = %+v, want it live", life) |
| + } |
| + // The expiry pass's trash asks the same. |
| + if _, err := f.fx.st.db.Exec(`UPDATE apps SET expires_at = ? WHERE app = ?`, time.Now().Add(-time.Hour).Unix(), fromApp); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.fx.srv.expiryPass(ctx, time.Now()) |
| + if tomb, _ := release.ReadAppTombstone(ctx, f.fx.rel, "bab", fromApp); tomb != nil { |
| + t.Fatal("the expiry pass trashed an app holding a fleet file seed") |
| + } |
| + if _, err := f.fx.st.db.Exec(`UPDATE apps SET expires_at = 0 WHERE app = ?`, fromApp); err != nil { |
| + t.Fatal(err) |
| + } |
| + // The box rolls it back (through the seeds door), and the finish frees |
| + // the host: the trash goes through. |
| + if _, err := provision.SetRecordSeed(ctx, f.fx.rel, "bab", fromApp, fileHost, provision.SeedRolledBack(id)); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := f.fx.srv.finishSeed(ctx, "bab", fromApp, fileHost, id); err != nil { |
| + t.Fatal(err) |
| + } |
| + if code, out := trash(); code != http.StatusOK { |
| + t.Fatalf("trash after the finish = %d %s", code, out) |
| + } |
| + if tomb, err := release.ReadAppTombstone(ctx, f.fx.rel, "bab", fromApp); err != nil || tomb == nil { |
| + t.Fatalf("marker = %+v %v, want it written", tomb, err) |
| + } |
| +} |
| + |
| +// failingDataList is a data bucket whose listing fails. |
| +type failingDataList struct{ release.Store } |
| + |
| +func (failingDataList) ListMod(context.Context, string) ([]release.KeyMod, error) { |
| + return nil, errors.New("listing unavailable") |
| +} |
| + |
| +// P2-2: a region listing that fails costs only the region half. |
| +func TestSeedsPassFleetHalfSurvivesRegionListingFailure(t *testing.T) { |
| + f := newFleetFileFixture(t) |
| + f.sweepable() |
| + f.fx.srv.cfg.SeedData = failingDataList{Store: f.data} |
| + fleetID := f.fleetSeedRecord(t, fileHost, seeds.StateAborted, "", "", time.Now()) |
| + now := time.Now() |
| + // A region reservation long stale: with the region half off it is left. |
| + if err := provision.CreateRecord(context.Background(), f.fx.rel, provision.Record{Schema: 1, Host: "stuck.other.example.com", Slug: "stuck", |
| + App: "other", Account: "bab", Channel: "stable", CreatedAt: now.UTC(), |
| + Seed: &provision.SeedSource{ID: newSeedID(t), Kind: seeds.KindFile, State: seeds.StateReserving, By: "bob@example.com", At: now.Add(-seedFileReserveTTL - time.Minute)}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + ctx, run := jobCtx() |
| + f.fx.srv.seedsPass(ctx, now) |
| + if f.hasKey(t, fleetSnapshotOf(fileHost, fleetID)) { |
| + t.Fatal("the fleet half did not run past a region listing failure") |
| + } |
| + if run.err == nil || !strings.Contains(run.err.Error(), "list snapshots") { |
| + t.Fatalf("job error = %v, want the region listing's", run.err) |
| + } |
| + rec, err := provision.GetRecord(context.Background(), f.fx.rel, "bab", "other", "stuck.other.example.com") |
| + if err != nil || rec.Seed.State != seeds.StateReserving { |
| + t.Fatalf("region reservation = %+v %v, want it left reserving", rec, err) |
| + } |
| +} |
| + |
| +// P3-2: a placed or aborted fleet file seed's snapshot is deleted by its |
| +// record's own key even when its app is no longer listed on a fleet. |
| +func TestSeedsPassCondemnsFleetSnapshotByRecord(t *testing.T) { |
| + f := newFleetFileFixture(t) |
| + f.sweepable() |
| + ctx := context.Background() |
| + put := func(host, state string) string { |
| + t.Helper() |
| + id := newSeedID(t) |
| + if err := provision.CreateRecord(ctx, f.fx.rel, provision.Record{Schema: 1, Host: host, Slug: "x", App: "other", Account: "bab", |
| + Channel: "stable", Region: "fleet/" + seedFleet, CreatedAt: time.Now().UTC(), |
| + Seed: &provision.SeedSource{ID: id, Kind: seeds.KindFile, State: state, By: "bob@example.com", At: time.Now()}}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := f.fx.rel.Put(ctx, seeds.FleetSnapshotKey("bab", "other", host, id), []byte("snap"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + return id |
| + } |
| + placed := put("placed.other.example.com", seeds.StatePlaced) |
| + aborted := put("aborted.other.example.com", seeds.StateAborted) |
| + ready := put("ready.other.example.com", seeds.StateReady) |
| + f.fx.srv.seedsPass(ctx, time.Now()) |
| + for host, c := range map[string]struct { |
| + id string |
| + gone bool |
| + }{"placed.other.example.com": {placed, true}, "aborted.other.example.com": {aborted, true}, "ready.other.example.com": {ready, false}} { |
| + _, _, err := f.fx.rel.Get(ctx, seeds.FleetSnapshotKey("bab", "other", host, c.id)) |
| + if gone := errors.Is(err, os.ErrNotExist); gone != c.gone { |
| + t.Errorf("%s: snapshot gone %v, want %v (%v)", host, gone, c.gone, err) |
| + } |
| + } |
| +} |
| + |
| +// P3-1: the hold is asked of the stored body, so a body the record's own |
| +// decode rejects is still held; one the hold cannot classify while it |
| +// carries a seed is refused, and one with no seed at all is not. |
| +func TestRetireHoldsAnUndecodableSeedRecord(t *testing.T) { |
| + for _, on := range []bool{false, true} { |
| + t.Run(map[bool]string{false: "lifetimes off", true: "lifetimes on"}[on], func(t *testing.T) { |
| + fx, _, ctxOf := holdWorld(t, on) |
| + key := provision.RecordKey("bab", "titogo", holdHost) |
| + put := func(body string) { |
| + t.Helper() |
| + _, etag, err := fx.rel.Get(context.Background(), key) |
| + if err != nil && !errors.Is(err, os.ErrNotExist) { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.rel.Put(context.Background(), key, []byte(body), etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // A held seed in a body the full decode rejects (schema 0, no |
| + // account) is still the hold's. |
| + put(`{"host":"` + holdHost + `","region":"fleet/pi","seed":{"id":"sd_x","kind":"file","state":"aborted"}}`) |
| + var held *fleetSeedHoldError |
| + if err := fx.srv.retireInstanceRecord(ctxOf(t), "bab", "titogo", holdHost, "test", "", retireAny); !errors.As(err, &held) { |
| + t.Fatalf("an undecodable held seed = %v, want the hold", err) |
| + } |
| + // A seed the hold cannot read: refused. |
| + put(`{"host":"` + holdHost + `","seed":"garbled"}`) |
| + if err := fx.srv.retireInstanceRecord(ctxOf(t), "bab", "titogo", holdHost, "test", "", retireAny); !errors.Is(err, errFleetSeedUnclassified) { |
| + t.Fatalf("an unclassifiable seed = %v, want errFleetSeedUnclassified", err) |
| + } |
| + if holdRecord(t, fx) == nil { |
| + t.Fatal("a refused retirement removed the record") |
| + } |
| + // No seed at all: corrupt, and retired as before. |
| + put(`not json`) |
| + if err := fx.srv.retireInstanceRecord(ctxOf(t), "bab", "titogo", holdHost, "test", "", retireAny); err != nil { |
| + t.Fatalf("a corrupt body with no seed = %v, want it retired", err) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/console/seedsweep.go b/internal/console/seedsweep.go| index 35cee7149..699b8b67d 100644 |
| --- a/internal/console/seedsweep.go |
| +++ b/internal/console/seedsweep.go |
| @@ -168,12 +168,20 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| } |
| }() |
| var snaps []seedSnapshot |
| - if ml, walk := s.cfg.SeedData.(release.ModLister); s.cfg.SeedData != nil && walk { |
| + // The two halves are independent: a console with no data bucket runs the |
| + // fleet half alone (Task 16 review P3-1), and a listing that fails costs |
| + // only its own half this pass (Task 16 review P2-1, slice 3 review |
| + // P2-2). With the region half off, no region snapshot is decided on, |
| + // and steps 4 and 6 leave region seeds alone: their abandonment and |
| + // finish need that bucket and that listing. |
| + regionHalf := s.cfg.SeedData != nil |
| + if ml, walk := s.cfg.SeedData.(release.ModLister); regionHalf && walk { |
| listed, err := ml.ListMod(ctx, seeds.Prefix) |
| if err != nil { |
| - log.Printf("console: seeds pass: list snapshots: %v (nothing swept this pass)", err) |
| - jobFailed(ctx, fmt.Errorf("seeds pass: list snapshots: %w (nothing swept this pass)", err)) |
| - return |
| + log.Printf("console: seeds pass: list snapshots: %v (no region seed swept this pass)", err) |
| + jobFailed(ctx, fmt.Errorf("seeds pass: list snapshots: %w (no region seed swept this pass)", err)) |
| + regionHalf = false |
| + listed = nil |
| } |
| for _, o := range listed { |
| if host, id, ok := seeds.ParseSnapshotKey(o.Key); ok { |
| @@ -181,20 +189,14 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| } |
| } |
| } |
| - // The fleet half's listing is its own (Task 16 review P2-1): one that |
| - // fails leaves this pass with no fleet snapshot to decide on, so none |
| - // is deleted, and the region half carries on. |
| - fleet, err := s.fleetSeedSnapshots(ctx) |
| - if err != nil { |
| + fleet, fleetApps, err := s.fleetSeedSnapshots(ctx) |
| + fleetListed := err == nil |
| + if err != nil && !errors.Is(err, errNoFleetListing) { |
| log.Printf("console: seeds pass: list fleet seed snapshots: %v (no fleet seed's snapshot swept this pass)", err) |
| jobFailed(ctx, fmt.Errorf("seeds pass: list fleet seed snapshots: %w (no fleet seed's snapshot swept this pass)", err)) |
| fleet = nil |
| } |
| snaps = append(snaps, fleet...) |
| - // A console with no data bucket runs the fleet half alone (review |
| - // P3-1): a region seed's abandonment and finish need that bucket, and |
| - // would fail every pass, so steps 4 and 6 leave region seeds alone. |
| - regionHalf := s.cfg.SeedData != nil |
| if seedsPassBetweenListings != nil { |
| seedsPassBetweenListings() |
| } |
| @@ -257,6 +259,26 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| } |
| } |
| + // Step 3, by record (slice 3 review P3-2): a placed or aborted fleet |
| + // file seed's record names its own snapshot's exact key, so that key is |
| + // deleted even when the listing above did not reach it (the app is no |
| + // longer placed on that fleet, or no longer on any). Only for an app the |
| + // listing did not cover, and only after a listing that did not fail, so |
| + // a pass never re-deletes what it listed or guesses on a partial one. |
| + if fleetListed { |
| + for i := range recs { |
| + rec := &recs[i] |
| + if !seedOnFleet(rec) || fleetApps[rec.Account+"/"+rec.App] || held(rec.Host) || |
| + seeds.Check(rec.Host, rec.Seed.ID) != nil || |
| + (rec.Seed.State != seeds.StatePlaced && rec.Seed.State != seeds.StateAborted) { |
| + continue |
| + } |
| + condemned = append(condemned, seedSnapshot{store: s.cfg.Releases, |
| + key: seeds.FleetSnapshotKey(rec.Account, rec.App, rec.Host, rec.Seed.ID), |
| + acct: rec.Account, app: rec.App, host: rec.Host, id: rec.Seed.ID}) |
| + } |
| + } |
| + |
| // Step 4: the abandonments. |
| for _, rec := range recs { |
| if ctx.Err() != nil { |
| @@ -278,7 +300,9 @@ func (s *Server) seedsPass(ctx context.Context, now time.Time) { |
| if ctx.Err() != nil { |
| return |
| } |
| - if err := o.store.Delete(ctx, o.key); err != nil && !errors.Is(err, os.ErrNotExist) { |
| + if err := o.store.Delete(ctx, o.key); errors.Is(err, os.ErrNotExist) { |
| + continue // gone already (a by-record key, or another pass) |
| + } else if err != nil { |
| log.Printf("console: seeds pass: delete %s: %v", o.key, err) |
| jobFailed(ctx, fmt.Errorf("seeds pass: delete %s: %w", o.key, err)) |
| continue |
| @@ -312,6 +336,11 @@ type seedSnapshot struct { |
| host, id string |
| } |
| +// errNoFleetListing is fleetSeedSnapshots on a deployment bucket that |
| +// cannot list last-modified times: no fleet half this pass, and nothing to |
| +// report each pass (StartSeedsPass logged it once). |
| +var errNoFleetListing = errors.New("console: the deployment bucket cannot list last-modified times") |
| + |
| // fleetSeedSnapshots lists every fleet file seed's snapshot in the |
| // deployment bucket: for each customer fleet, each app of its owning |
| // account placed on it, trashed apps included (plan R1-4: a trashed app's |
| @@ -319,20 +348,22 @@ type seedSnapshot struct { |
| // seeds.FleetSnapshotsPrefix. A key that does not parse as that app's is |
| // skipped. Any error is the whole listing's: the pass decides nothing on a |
| // partial set. A deployment bucket that cannot list last-modified times |
| -// gives none (StartSeedsPass logged it), so nothing of the fleet half is |
| -// deleted. |
| -func (s *Server) fleetSeedSnapshots(ctx context.Context) ([]seedSnapshot, error) { |
| +// answers errNoFleetListing, so nothing of the fleet half is deleted. It |
| +// also answers the "<sqid>/<app>" of every app it listed, so the pass can |
| +// condemn by record only what the listing did not cover. |
| +func (s *Server) fleetSeedSnapshots(ctx context.Context) ([]seedSnapshot, map[string]bool, error) { |
| + listed := map[string]bool{} // "<sqid>/<app>" for every app listed |
| ml, ok := s.cfg.Releases.(release.ModLister) |
| if !ok { |
| - return nil, nil |
| + return nil, nil, errNoFleetListing |
| } |
| reg, err := openRegistry(s.cfg.Registry) |
| if err != nil { |
| - return nil, fmt.Errorf("open the registry: %w", err) |
| + return nil, nil, fmt.Errorf("open the registry: %w", err) |
| } |
| owners, err := reg.FleetOwners() |
| if err != nil { |
| - return nil, fmt.Errorf("list the fleets: %w", err) |
| + return nil, nil, fmt.Errorf("list the fleets: %w", err) |
| } |
| fleets := make([]string, 0, len(owners)) |
| for f := range owners { |
| @@ -344,21 +375,22 @@ func (s *Server) fleetSeedSnapshots(ctx context.Context) ([]seedSnapshot, error) |
| sqid := owners[fleet] |
| acct, err := s.store.AccountBySqid(sqid) |
| if err != nil { |
| - return nil, fmt.Errorf("fleet %s: account %s: %w", fleet, sqid, err) |
| + return nil, nil, fmt.Errorf("fleet %s: account %s: %w", fleet, sqid, err) |
| } |
| if acct == nil { |
| continue // an account this console does not hold: no app of it to list |
| } |
| apps, err := s.fleetPlacedAppsIn(acct, fleet, true) |
| if err != nil { |
| - return nil, fmt.Errorf("fleet %s: its apps: %w", fleet, err) |
| + return nil, nil, fmt.Errorf("fleet %s: its apps: %w", fleet, err) |
| } |
| for _, app := range apps { |
| - listed, err := ml.ListMod(ctx, seeds.FleetSnapshotsPrefix(sqid, app)) |
| + objs, err := ml.ListMod(ctx, seeds.FleetSnapshotsPrefix(sqid, app)) |
| if err != nil { |
| - return nil, fmt.Errorf("fleet %s: %s/%s: %w", fleet, sqid, app, err) |
| + return nil, nil, fmt.Errorf("fleet %s: %s/%s: %w", fleet, sqid, app, err) |
| } |
| - for _, o := range listed { |
| + listed[sqid+"/"+app] = true |
| + for _, o := range objs { |
| a, ap, host, id, ok := seeds.ParseFleetSnapshotKey(o.Key) |
| if !ok || a != sqid || ap != app { |
| continue |
| @@ -367,7 +399,7 @@ func (s *Server) fleetSeedSnapshots(ctx context.Context) ([]seedSnapshot, error) |
| } |
| } |
| } |
| - return out, nil |
| + return out, listed, nil |
| } |
| type snapshotVerdict int |
diff --git a/internal/provision/fleet_seeded_create_3_census_test.go b/internal/provision/fleet_seeded_create_3_census_test.go| index 250744f6b..edb85cd18 100644 |
| --- a/internal/provision/fleet_seeded_create_3_census_test.go |
| +++ b/internal/provision/fleet_seeded_create_3_census_test.go |
| @@ -67,6 +67,10 @@ package provision |
| // round 2, P2-A): a record written since answers ErrCASConflict, an |
| // absent key is done. key-site / key:RecordKey, as deleteRead, its |
| // sibling delete bound to a read. |
| +// - Slice 3 review P3-1, both re-pinned again: the hold is asked of the |
| +// stored body (fleetSeedHoldRaw: its region and seed alone), so a body |
| +// the full decode rejects is still held, and one carrying a seed the |
| +// hold cannot read is refused. No site changes. |
| // |
| // Not in the inventory, because they write no record: seedFleetReady, |
| // fleetSeedSnapshots (the sweep's fleet listing; the sweep's own record |
| @@ -86,7 +90,7 @@ func fleetSeededCreate3WriteCensusInventory() []censusEntry { |
| {"internal/console/apiinstanceimport.go", "Server.runImportUpload", "record-writer", "key:SetRecordSeed", "051483202bca1a0af137b0181cf5c7e59c71c0c79511ef501e0f35ea1428e805"}, |
| {"internal/console/seedfile.go", "Server.fileSeedDeleteRule", "record-writer", "key:SetRecordSeed", "c3872951d6f0f0a469eb93828843153c023a408df8672a7e11c08cb1c8937d6b"}, |
| {"internal/console/seedfinish.go", "Server.finishSeedOnce", "key-site", "key:RecordKey", "f5da4e619ec229aef9ae9559cf347b62dbd6e0556b325d5ca6ad8f56c09f859d"}, |
| - {"internal/console/lifetimes_retire.go", "Server.retireRecordWithLifetimeLocked", "key-site", "key:RecordKey", "16ba61287735836465c84ef20a36b43ec6896faccaa985cfe5b09388cce0ae57"}, |
| + {"internal/console/lifetimes_retire.go", "Server.retireRecordWithLifetimeLocked", "key-site", "key:RecordKey", "c3e439af5d9b34811cba7b3576f86f734e6741e4e3aad20ec0665f893e84b1d4"}, |
| } { |
| replaced := false |
| for i, e := range entries { |
| @@ -103,7 +107,7 @@ func fleetSeededCreate3WriteCensusInventory() []censusEntry { |
| } |
| } |
| return append(entries, |
| - censusEntry{"internal/console/hostclaimops.go", "Server.retireLegacyInstanceRecord", "key-site", "key:RecordKey", "0b8733784111dc645f84a88163c4e8c1ad82c5b94a514abd3f3d944b516a717c"}, |
| + censusEntry{"internal/console/hostclaimops.go", "Server.retireLegacyInstanceRecord", "key-site", "key:RecordKey", "75be7b7a2b460bb3edf1f4b5e94b9a67475690d9a7c7f7e64c9044f6c3b4b649"}, |
| censusEntry{"internal/console/apifleetseeds.go", "Server.fleetSeedTransition", "record-writer", "key:SetRecordSeed", "44b66548aa5c3cafd85d240edbd4bd48e7f3ccd66dfce76facd5d20561738265"}, |
| ) |
| } |