status: the heartbeat carries the seeds floor
seedsFloorFields runs the edges file's own seeds-floor writers over the box identity and the moves-floor context, so the heartbeat and the edges file cannot disagree. Seven fields, set from claimReport so agent.go does not grow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+229
−1
internal/host/claimreport.go+4 −0internal/host/seedsfloorprobe.go+49 −0internal/host/seedsfloorprobe_test.go+135 −0internal/status/snapshot.go+23 −1internal/status/snapshot_test.go+18 −0
CI cancelled — superseded by a newer push — run details
diff --git a/internal/host/claimreport.go b/internal/host/claimreport.go| index b15b53cc6..1e10e07f7 100644 |
| --- a/internal/host/claimreport.go |
| +++ b/internal/host/claimreport.go |
| @@ -12,6 +12,10 @@ import ( |
| ) |
| func claimReport(p *status.Probes) { |
| + // First, ahead of the early returns below: a box with no host-claim |
| + // floor still reports its seeds floor (seeded-create Task 11). The call |
| + // lives here so agent.go, at its line ceiling, does not grow. |
| + fillSeedsFloorProbe(p) |
| d, err := floorDisk(release.OptDir()) |
| if err != nil { |
| return |
diff --git a/internal/host/seedsfloorprobe.go b/internal/host/seedsfloorprobe.go| new file mode 100644 |
| index 000000000..ff24f0b15 |
| --- /dev/null |
| +++ b/internal/host/seedsfloorprobe.go |
| @@ -0,0 +1,49 @@ |
| +package host |
| + |
| +import ( |
| + "os" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +// movesFloorContext is the part of the moves floor the seeds floor's writer |
| +// depends on: withSeedsFields picks the root path from a non-empty state |
| +// (seedsfloor.go:58) and the report carries both fields. It is filled first, |
| +// exactly as the edges file's loop fills it (withMovesFields, then |
| +// withSeedsFields), never left zero by a caller that only wants the seeds |
| +// half. |
| +type movesFloorContext struct { |
| + State string |
| + Generation uint64 |
| +} |
| + |
| +// seedsFloorFields is withSeedsFields' (and withRootSeedsFields') logic as |
| +// one value, so the edges file and the heartbeat are filled by the same |
| +// code. box is the identity withRootSeedsFields compares the root |
| +// projection's box against, and moves is the moves-floor context; both are |
| +// inputs the writers depend on, so the report is never derived from an |
| +// empty edgesFile (plan R3-2). |
| +func seedsFloorFields(dataDir, optDir, box string, moves movesFloorContext) status.SeedsFloorReport { |
| + f := withSeedsFields(edgesFile{Box: box, MovesFloorState: moves.State, MovesFloorGeneration: moves.Generation}, dataDir, optDir) |
| + return status.SeedsFloorReport{ |
| + Protocol: f.SeedsProtocol, |
| + MinRelease: f.SeedsFloorMinRelease, |
| + PrevAllowedFor: f.PrevSeedsAllowedFor, |
| + FloorState: f.SeedsFloorState, |
| + FloorGeneration: f.SeedsFloorGeneration, |
| + MovesFloorState: f.MovesFloorState, |
| + MovesFloorGeneration: f.MovesFloorGeneration, |
| + } |
| +} |
| + |
| +// fillSeedsFloorProbe sets the status tick's seeds-floor block from this |
| +// box's own files. The moves context is read the way the edges file loop |
| +// reads it (withMovesFields first), under the same box label the loop uses. |
| +func fillSeedsFloorProbe(p *status.Probes) { |
| + dd, opt := dataDir(), release.OptDir() |
| + box := metricsBoxLabel(os.Getenv, readMachineID()) |
| + m := withMovesFields(edgesFile{Box: box}, dd, opt) |
| + r := seedsFloorFields(dd, opt, box, movesFloorContext{State: m.MovesFloorState, Generation: m.MovesFloorGeneration}) |
| + p.SeedsFloor = &r |
| +} |
diff --git a/internal/host/seedsfloorprobe_test.go b/internal/host/seedsfloorprobe_test.go| new file mode 100644 |
| index 000000000..bb7ab72c0 |
| --- /dev/null |
| +++ b/internal/host/seedsfloorprobe_test.go |
| @@ -0,0 +1,135 @@ |
| +package host |
| + |
| +import ( |
| + "encoding/json" |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/seeds" |
| +) |
| + |
| +// armSeedsProbeFloor writes a local seeds floor and carlos.prev's verdict |
| +// (legacy path). |
| +func armSeedsProbeFloor(t *testing.T, dd, opt, rel string) { |
| + t.Helper() |
| + // Written directly, not through the floor lock (linux-only): the reader |
| + // is what the writers under test call. |
| + body, _ := json.Marshal(seeds.Floor{Min: seeds.RequiredProtocol, MinRelease: rel}) |
| + if err := os.MkdirAll(filepath.Join(dd, filepath.Dir(seeds.FloorFile)), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(filepath.Join(dd, seeds.FloorFile), body, 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := os.WriteFile(seedsPrevAllowedPath(opt), []byte(rel+"\n"), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// TestSeedsFloorFieldsSameForEdgesFileAndHeartbeat: the edges file's writer |
| +// and the heartbeat's report are one code path, armed and not, and with the |
| +// root guard directory present. |
| +func TestSeedsFloorFieldsSameForEdgesFileAndHeartbeat(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + arm bool |
| + root bool |
| + moves movesFloorContext |
| + }{ |
| + {name: "unarmed"}, |
| + {name: "armed", arm: true}, |
| + {name: "root guard armed", root: true}, |
| + {name: "root guard and moves state", root: true, moves: movesFloorContext{State: "accepted", Generation: 5}}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + dd, opt := t.TempDir(), t.TempDir() |
| + if tc.arm { |
| + armSeedsProbeFloor(t, dd, opt, "v0.27.0") |
| + } |
| + if tc.root { |
| + if err := os.MkdirAll(rootSeedsFloorDir(opt), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + f := withSeedsFields(edgesFile{Box: "kass-1", MovesFloorState: tc.moves.State, MovesFloorGeneration: tc.moves.Generation}, dd, opt) |
| + got := seedsFloorFields(dd, opt, "kass-1", tc.moves) |
| + if got.Protocol != f.SeedsProtocol || got.MinRelease != f.SeedsFloorMinRelease || got.PrevAllowedFor != f.PrevSeedsAllowedFor || |
| + got.FloorState != f.SeedsFloorState || got.FloorGeneration != f.SeedsFloorGeneration || |
| + got.MovesFloorState != f.MovesFloorState || got.MovesFloorGeneration != f.MovesFloorGeneration { |
| + t.Fatalf("heartbeat %+v differs from edges file %+v", got, f) |
| + } |
| + if got.Protocol != seeds.ProtocolVersion { |
| + t.Fatalf("protocol = %d", got.Protocol) |
| + } |
| + if tc.arm && (got.MinRelease != "v0.27.0" || got.PrevAllowedFor != "v0.27.0") { |
| + t.Fatalf("armed floor not reported: %+v", got) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestSeedsFloorFieldsBoxIdentity: the box identity reaches the writer that |
| +// compares it (withRootSeedsFields checks the projection's box against |
| +// f.Box), so the heartbeat can never be filled from an anonymous edgesFile. |
| +// A root box with no projection that names it is quarantined whatever the |
| +// name; the identity itself is pinned at the source. |
| +func TestSeedsFloorFieldsBoxIdentity(t *testing.T) { |
| + dd, opt := t.TempDir(), t.TempDir() |
| + if err := os.MkdirAll(rootSeedsFloorDir(opt), 0o755); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, box := range []string{"kass-1", "other-box"} { |
| + got := seedsFloorFields(dd, opt, box, movesFloorContext{}) |
| + if got.FloorState != "quarantined" || got.MinRelease != "" || got.PrevAllowedFor != "" { |
| + t.Fatalf("%s: a root box without its projection = %+v, want quarantined", box, got) |
| + } |
| + } |
| + src := funcSource(t, "seedsfloorprobe.go", "seedsFloorFields") |
| + if !strings.Contains(src, "Box: box") { |
| + t.Fatalf("seedsFloorFields does not pass its box identity on:\n%s", src) |
| + } |
| + if strings.Contains(src, "edgesFile{}") { |
| + t.Fatal("seedsFloorFields derives from an empty edgesFile") |
| + } |
| +} |
| + |
| +// TestSeedsFloorFieldsRootMovesGuardWithoutSeedsProjection: the root moves |
| +// guard is present, the seeds projection is absent. The root path is chosen |
| +// (through the moves context) and reads not-ready, never the legacy path, |
| +// which would report the local floor as if root had accepted it. |
| +func TestSeedsFloorFieldsRootMovesGuardWithoutSeedsProjection(t *testing.T) { |
| + dd, opt := t.TempDir(), t.TempDir() |
| + armSeedsProbeFloor(t, dd, opt, "v0.27.0") |
| + got := seedsFloorFields(dd, opt, "kass-1", movesFloorContext{State: "accepted", Generation: 2}) |
| + if got.FloorState != "quarantined" || got.MinRelease != "" || got.PrevAllowedFor != "" { |
| + t.Fatalf("root moves guard without a seeds projection = %+v, want quarantined and no floor", got) |
| + } |
| + if got.MovesFloorState != "accepted" || got.MovesFloorGeneration != 2 { |
| + t.Fatalf("moves context not carried: %+v", got) |
| + } |
| + // With no moves context at all the legacy path is right: nothing on this |
| + // box has opted in to root floors. |
| + if legacy := seedsFloorFields(dd, opt, "kass-1", movesFloorContext{}); legacy.MinRelease != "v0.27.0" { |
| + t.Fatalf("legacy = %+v", legacy) |
| + } |
| +} |
| + |
| +// TestStatusLoopSetsSeedsFloor reads source, as the named-units order test |
| +// does: the heartbeat's probe is set by claimReport, which statusLoop calls |
| +// once per tick, so agent.go does not grow. |
| +func TestStatusLoopSetsSeedsFloor(t *testing.T) { |
| + if n := strings.Count(funcSource(t, "agent.go", "statusLoop"), "claimReport(&p)"); n != 1 { |
| + t.Fatalf("statusLoop calls claimReport %d times, want once", n) |
| + } |
| + body := funcSource(t, "claimreport.go", "claimReport") |
| + if n := strings.Count(body, "fillSeedsFloorProbe(p)"); n != 1 { |
| + t.Fatalf("claimReport sets the seeds floor probe %d times, want once", n) |
| + } |
| + // Before the first early return, so a box with no host-claim floor still |
| + // reports its seeds floor. |
| + if strings.Index(body, "fillSeedsFloorProbe(p)") > strings.Index(body, "return\n") { |
| + t.Fatal("the seeds floor probe is set after an early return") |
| + } |
| +} |
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go| index 34fd93a49..c6580a0a6 100644 |
| --- a/internal/status/snapshot.go |
| +++ b/internal/status/snapshot.go |
| @@ -240,6 +240,24 @@ type Probes struct { |
| // NamedUnits is root's last named-units record, read by the agent from |
| // the public root store; nil when root has written none. |
| NamedUnits *NamedUnitsStatus |
| + // SeedsFloor is the box's seeds protocol floor as it advertises it in |
| + // the edges file, so the console can read the same facts for a fleet |
| + // (seeded-create D3). nil when the box did not say. |
| + SeedsFloor *SeedsFloorReport |
| +} |
| + |
| +// SeedsFloorReport is the seven facts the console's region seeds check reads |
| +// (internal/console/seedfloor.go), carried in the heartbeat so the fleet |
| +// check can apply the same rule. Written by host.seedsFloorFields, the same |
| +// code that fills the edges file. |
| +type SeedsFloorReport struct { |
| + Protocol int `json:"protocol"` // the build's seeds.ProtocolVersion |
| + MinRelease string `json:"min_release,omitempty"` // armed floor; "" = none armed |
| + PrevAllowedFor string `json:"prev_allowed_for,omitempty"` // carlos.prev's verdict |
| + FloorState string `json:"floor_state,omitempty"` // root floor guard |
| + FloorGeneration uint64 `json:"floor_generation,omitempty"` |
| + MovesFloorState string `json:"moves_floor_state,omitempty"` |
| + MovesFloorGeneration uint64 `json:"moves_floor_generation,omitempty"` |
| } |
| // OfflineMoveFacts is what a box that can take part in an offline move |
| @@ -860,6 +878,9 @@ type BoxMetrics struct { |
| // carried in the heartbeat the agent already publishes. Omitted when root |
| // has written none. |
| NamedUnits *NamedUnitsStatus `json:"named_units,omitempty"` |
| + // SeedsFloor is Probes.SeedsFloor: the seeds protocol floor facts a |
| + // fleet's seed door reads. Omitted when the box did not say. |
| + SeedsFloor *SeedsFloorReport `json:"seeds_floor,omitempty"` |
| } |
| // UpdateSettingsProtocol is the BoxMetrics.UpdateSettings a binary reports |
| @@ -1302,7 +1323,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| len(routeDBBytes) > 0 || p.Layout != nil || len(p.ConfigRefusals) > 0 || len(p.ReleaseRefusals) > 0 || len(p.ProofWaits) > 0 || p.Rollout != nil || p.ConfigGuard != "" || |
| p.Alerts != nil || p.GeoIP != nil || p.HeldStreams != nil || len(p.BuildStates) > 0 || p.BuildStatesErr != "" || |
| p.DemoClaimSeedReady || p.DemoMovedReady || p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil || |
| - p.MailerArmed || p.OfflineMove != nil || p.NamedUnits != nil { |
| + p.MailerArmed || p.OfflineMove != nil || p.NamedUnits != nil || p.SeedsFloor != nil { |
| var capabilities []string |
| if p.DemoClaimSeedReady { |
| capabilities = append(capabilities, seeds.DemoClaimCapability) |
| @@ -1363,6 +1384,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box { |
| MailerArmed: p.MailerArmed, |
| OfflineMove: p.OfflineMove, |
| NamedUnits: p.NamedUnits, |
| + SeedsFloor: p.SeedsFloor, |
| } |
| } |
diff --git a/internal/status/snapshot_test.go b/internal/status/snapshot_test.go| index 5cf4bebaf..500b33c42 100644 |
| --- a/internal/status/snapshot_test.go |
| +++ b/internal/status/snapshot_test.go |
| @@ -490,3 +490,21 @@ func TestCollectBoxCarriesOfflineMoveFacts(t *testing.T) { |
| t.Fatalf("no facts and nothing else known must mean no metrics block: %+v", b.Metrics) |
| } |
| } |
| + |
| +// TestCollectBoxCarriesSeedsFloor: the seeds-floor block reaches the private |
| +// Metrics block, counts as something known, and a box without it publishes |
| +// what it did before. |
| +func TestCollectBoxCarriesSeedsFloor(t *testing.T) { |
| + want := SeedsFloorReport{Protocol: 4, MinRelease: "v1.2.3", PrevAllowedFor: "v1.2.3", FloorState: "accepted", FloorGeneration: 7, MovesFloorState: "accepted", MovesFloorGeneration: 3} |
| + b := CollectBox(nil, Probes{MachineID: "m", SeedsFloor: &want}, time.Now()) |
| + if b.Metrics == nil || b.Metrics.SeedsFloor == nil || *b.Metrics.SeedsFloor != want { |
| + t.Fatalf("Metrics = %+v", b.Metrics) |
| + } |
| + raw, _ := json.Marshal(b.Metrics) |
| + if !strings.Contains(string(raw), `"seeds_floor":{"protocol":4,"min_release":"v1.2.3"`) { |
| + t.Fatalf("wire = %s", raw) |
| + } |
| + if b := CollectBox(nil, Probes{MachineID: "m"}, time.Now()); b.Metrics != nil { |
| + t.Fatalf("an all-unknown probe attached Metrics: %+v", b.Metrics) |
| + } |
| +} |