rootfs apps plan 3: Task 4 fix round 1, seeded records refused over runtime rows, seed guard keyed on the row, reverse runtime mismatch unapplied
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+155
−12
internal/provision/reconcile.go+35 −12internal/provision/reconcile_rootfs_test.go+120 −0
CI failed — run details
diff --git a/internal/provision/reconcile.go b/internal/provision/reconcile.go| index 5a3bfde87..ca1408e33 100644 |
| --- a/internal/provision/reconcile.go |
| +++ b/internal/provision/reconcile.go |
| @@ -1391,6 +1391,18 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg |
| // clobber, and a later pass converges it once the manifest reads. |
| seed, seedIsKnown := seedFor(rec.Account, rec.App) |
| existing, ok := byHost[rec.Host] |
| + // A row with a runtime takes no seed (D5), so a seeded record over |
| + // one is refused before seed dispatch: an aborted replica seed would |
| + // otherwise retire the row (retireAbortedSeedRow), and a ready one |
| + // would converge SeedSource onto it, which a wake's seeded restore |
| + // reads. Only a record that lost its runtime (or a bucket write) can |
| + // get here, since ValidateShape refuses a seed on a rootfs record. |
| + // The row is left as it is and the record is not applied. |
| + if rec.Seed != nil && ok && existing.Runtime != "" { |
| + log.Printf("provision: %s: record carries seed %s but the row has runtime %q, which takes no seed; leaving the row alone", |
| + rec.Host, rec.Seed.ID, existing.Runtime) |
| + continue |
| + } |
| // A seed is dispatched before anything else (seeded-instances spec |
| // §3.2, codex 13): an aborted one is finished, an unready one is |
| // skipped, and a seeded row never carries the manifest's seed |
| @@ -1426,14 +1438,6 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg |
| } |
| seed, seedIsKnown = "", true |
| } |
| - // Nor does a record or row with a runtime (D5): the manifest's seed |
| - // is a binary's argv, and RouteFor mints a rootfs row without it, so |
| - // the owned arm's seed converge must not write it on a later pass. |
| - // Keyed on the row too, so a record that lost its runtime does not |
| - // seed the rootfs row it still describes. |
| - if rec.Runtime != "" || (ok && existing.Runtime != "") { |
| - seed, seedIsKnown = "", true |
| - } |
| // Existing rows across lifetimes (self-serve moves plan 1 Task 7), |
| // rule (0): a predecessor's row held by an op this record does not |
| // carry is retired by that op first, whatever the record asks; the |
| @@ -1444,6 +1448,16 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg |
| } |
| ok, existing = false, registry.Route{} |
| } |
| + // Nor does a row with a runtime take the manifest's seed (D5): it is |
| + // a binary's argv, and RouteFor mints a rootfs row without it, so |
| + // the owned arm's seed converge must not write it on a later pass. |
| + // The row decides when there is one (the runtime is fixed at mint), |
| + // so a record that lost its runtime does not seed the rootfs row it |
| + // still describes, and a binary row under a record claiming a |
| + // runtime keeps its seed. With no row, the record decides. |
| + if (!ok && rec.Runtime != "") || (ok && existing.Runtime != "") { |
| + seed, seedIsKnown = "", true |
| + } |
| // A move's hold is judged first (moves spec §9.6). A missing row is |
| // minted held by mintHeld, which has a ready mint's refusals and |
| // the same claim hook (below) around its write, so the hold and the |
| @@ -1597,14 +1611,23 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg |
| // skip keys on any runtime on either side, as |
| // registry.SetHibernate's refusal does (an unknown runtime is |
| // fixed and inert). An older console's rewrite that drops |
| - // "runtime" therefore never changes what the box runs. The |
| - // disagreement is logged and leaves applied alone: the box's |
| - // answer is final, and a record counted unapplied for it would |
| - // keep the app's report incomplete for good. |
| + // "runtime" therefore never changes what the box runs. That |
| + // disagreement, and a rootfs hibernation one, is logged and |
| + // leaves applied alone: the box's answer is final, and a |
| + // record counted unapplied for it would keep the app's report |
| + // incomplete for good. |
| if existing.Runtime != "" || rec.Runtime != "" { |
| if existing.Runtime != rec.Runtime { |
| log.Printf("provision: %s: record runtime %q, row %q: the runtime is fixed at mint; leaving the row's runtime and hibernation alone", |
| rec.Host, rec.Runtime, existing.Runtime) |
| + // A record that claims a runtime its row does not |
| + // run is not applied: no writer of this series |
| + // produces it. The other direction, a record that |
| + // lost its runtime (an older console's rewrite), |
| + // stays applied, as above. |
| + if rec.Runtime != "" { |
| + applied = false |
| + } |
| } else if rec.Hibernate != nil && existing.Hibernate != *rec.Hibernate { |
| log.Printf("provision: %s: record hibernate %v, row %v: a rootfs row's hibernation is fixed at mint; leaving it alone", |
| rec.Host, *rec.Hibernate, existing.Hibernate) |
diff --git a/internal/provision/reconcile_rootfs_test.go b/internal/provision/reconcile_rootfs_test.go| index a4a8f0402..caaae304d 100644 |
| --- a/internal/provision/reconcile_rootfs_test.go |
| +++ b/internal/provision/reconcile_rootfs_test.go |
| @@ -2,6 +2,7 @@ package provision |
| import ( |
| "bytes" |
| + "context" |
| "encoding/json" |
| "strings" |
| "testing" |
| @@ -9,6 +10,7 @@ import ( |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/seeds" |
| ) |
| // Rootfs apps Plan 3 Task 4: reconcile materializes a record's runtime. A |
| @@ -375,3 +377,121 @@ func TestRootfsRecordIsHomeBoxed(t *testing.T) { |
| t.Fatal("a rootfs record is not home-boxed") |
| } |
| } |
| + |
| +// A seeded record over a row with a runtime is refused before seed dispatch |
| +// (fix round 1, Astra): an aborted replica seed would retire the row, and a |
| +// ready one would converge SeedSource onto it for a wake's seeded restore. |
| +// The record is one that lost its runtime (ValidateShape refuses a seed on |
| +// a rootfs record); seed hooks are on. A binary row is the control: its |
| +// seed behaviour is unchanged. |
| +func TestSeededRecordOverRuntimeRowIsRefused(t *testing.T) { |
| + for _, runtime := range []string{registry.RuntimeRootfsV1, "rootfs-v2", ""} { |
| + for _, state := range []string{seeds.StateAborted, seeds.StateReady} { |
| + t.Run(runtime+"/"+state, func(t *testing.T) { |
| + s, sqid := rootfsSetup(t) |
| + on := true |
| + id, _ := seeds.NewID() |
| + rec := Record{Schema: 1, Host: rootfsHost, Slug: "bab", App: "shop", Account: sqid, |
| + Region: "ie", Channel: "stable", Hibernate: &on, CreatedAt: time.Now(), |
| + Seed: &SeedSource{ID: id, Kind: seeds.KindReplica, State: state, SHA256: "a", Bytes: 1, By: "t", At: time.Now()}} |
| + if err := CreateRecord(ctx, s, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + row := registry.Route{Host: rootfsHost, Slug: "bab", Kind: "instance", |
| + Socket: NestedSocket(rootfsHost), DBPath: NestedDBPath("/data", rootfsHost), |
| + App: "shop", Account: sqid, Region: "ie", Channel: "stable", |
| + Hibernate: runtime == "", Provisioned: true, Runtime: runtime} |
| + reg := regWith(t, row) |
| + before := *mustGet(t, reg, rootfsHost) |
| + cfg := rootfsCfg(nil) |
| + cfg.Layout = func(context.Context, release.Store) (string, error) { return release.LayoutModeNested, nil } |
| + cfg.Seeds = &SeedHooks{Data: dirStore(t)} |
| + var rep ReconcileReport |
| + cfg.Report = &rep |
| + logged := captureLog(t) |
| + reconcileOnce(t, s, reg, cfg) |
| + got, err := reg.Get(rootfsHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + stored, err := GetRecord(ctx, s, sqid, "shop", rootfsHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if runtime == "" { |
| + // The control: today's seed behaviour. |
| + switch state { |
| + case seeds.StateAborted: |
| + if got != nil { |
| + t.Fatalf("binary row under an aborted replica seed was kept: %+v", *got) |
| + } |
| + case seeds.StateReady: |
| + if got == nil || got.SeedSource != SeedColumn(rec) { |
| + t.Fatalf("binary row under a ready seed: %+v, want SeedSource %q", got, SeedColumn(rec)) |
| + } |
| + } |
| + return |
| + } |
| + if got == nil { |
| + t.Fatalf("the seed retired the %s row:\n%s", runtime, logged.String()) |
| + } |
| + if *got != before { |
| + t.Fatalf("the seed touched the %s row:\n before %+v\n after %+v", runtime, before, *got) |
| + } |
| + if stored.Seed == nil || stored.Seed.State != state { |
| + t.Fatalf("the seed was acted on: %+v", stored.Seed) |
| + } |
| + line := "record carries seed " + id + ` but the row has runtime "` + runtime + `"` |
| + if n := strings.Count(logged.String(), line); n != 1 { |
| + t.Fatalf("want the refusal once, got %d:\n%s", n, logged.String()) |
| + } |
| + if rep.Complete[sqid+"/shop"] { |
| + t.Fatal("a refused seeded record left its app complete") |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// A binary row under a record that claims a runtime it does not run (no |
| +// writer of this series produces one; a bucket write can): the row keeps |
| +// its seed command (the row decides the seed guard), its runtime, and the |
| +// record is not applied. |
| +func TestRecordClaimingRuntimeOverBinaryRow(t *testing.T) { |
| + s, sqid := rootfsSetup(t) |
| + on := true |
| + rec := Record{Schema: 1, Host: rootfsHost, Slug: "bab", App: "shop", Account: sqid, |
| + Region: "ie", Channel: "stable", Hibernate: &on, CreatedAt: time.Now()} |
| + if err := CreateRecord(ctx, s, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + // Minted nested, so the paths agree with a rootfs record's and only |
| + // the runtime differs. |
| + cfg := rootfsCfg(nil) |
| + cfg.Layout = func(context.Context, release.Store) (string, error) { return release.LayoutModeNested, nil } |
| + reg := regWith(t) |
| + reconcileOnce(t, s, reg, cfg) |
| + before := *mustGet(t, reg, rootfsHost) |
| + if before.Seed != `["seed"]` || before.Runtime != "" || before.Socket != NestedSocket(rootfsHost) { |
| + t.Fatalf("fixture row = %+v", before) |
| + } |
| + rewriteRecord(t, s, RecordKey(sqid, "shop", rootfsHost), func(m map[string]any) { |
| + m["runtime"] = registry.RuntimeRootfsV1 |
| + }) |
| + for pass := 1; pass <= 2; pass++ { |
| + logged := captureLog(t) |
| + var rep ReconcileReport |
| + cfg.Report = &rep |
| + reconcileOnce(t, s, reg, cfg) |
| + got := *mustGet(t, reg, rootfsHost) |
| + if got != before { |
| + t.Fatalf("pass %d: row changed:\n before %+v\n after %+v", pass, before, got) |
| + } |
| + if !strings.Contains(logged.String(), `record runtime "rootfs-v1", row ""`) { |
| + t.Fatalf("pass %d: no runtime line:\n%s", pass, logged.String()) |
| + } |
| + if rep.Complete[sqid+"/shop"] { |
| + t.Fatalf("pass %d: a record claiming a runtime its row does not run was applied", pass) |
| + } |
| + } |
| +} |