carlos / platform Public

fleet health: only from a report after the record (Astra R1 P2)

Astra round 1 (READY AFTER FIXES, no P1, census all APPROVE) found that
fleetHealth took a fleet box's rollout view whatever its age, so an
instance deleted and recreated at the same host, account and app could
inherit its earlier lifetime's word while the old snapshot was still
fresh. The platform-remote path already refuses a report generated
before rec.CreatedAt (appFacts.host). The rollout join now keeps each
view's snapshot GeneratedAt (rolloutView.at, not on the wire), and
fleetHealth leaves the word unknown unless that is after the record's
creation. Invariant: health observations belong to the current instance
lifetime.

Witness: TestFleetPlacedHealthComesFromItsFleetBox gains a fresh report
generated before the record (stays unknown) beside the existing reports
generated after it (Running, Asleep, Failed). Findings file committed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 770dc4a98008bd27eabdb3ac4bcdc42e0754ae8a parent ff06052
3 files changed, +65 −16
  • docs/superpowers/reviews/CODEX-FINDINGS-rootfs-fleet-followups-R1.md +30 −0
  • internal/console/apiinstances.go +15 −6
  • internal/console/fleethealth_test.go +20 −10

Intent

Attributed to this commit: 18.1 g CO₂e (2,251,355 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on rootfs-fleet-followups, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-rootfs-fleet-followups-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-rootfs-fleet-followups-R1.md
new file mode 100644
index 000000000..f6b0b2039
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-rootfs-fleet-followups-R1.md
@@ -0,0 +1,30 @@
+No P1 findings.
+
+**P2 — Fleet HEALTH can describe an earlier instance lifetime.** At [apiinstances.go:498](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/console/apiinstances.go:498), `fleetHealth` accepts the rollout view without checking when its box report was generated. The platform-remote path explicitly rejects reports generated before `rec.CreatedAt` at [remoteinstances.go:344](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/console/remoteinstances.go:344).
+
+If an instance is deleted and recreated with the same host, account and app while its previous snapshot remains fresh, the new row inherits the old instance’s `Running`, `Asleep` or `Failed` word. It should remain unknown until a report covers the new record.
+
+**Fix:** retain the snapshot’s `GeneratedAt` in the rollout join and require it to be after `rec.CreatedAt` before deriving fleet health. Add an API witness with a report predating the record and a newer-report control.
+
+**Invariant / fault family:** health observations must belong to the current instance lifetime.
+
+No P3 findings.
+
+Census verdicts for `ff0605208c91c02b86beae5fdb12136e0d10ca88`:
+
+| Unit or envelope | Verdict and evidence |
+|---|---|
+| `ExecBackend.prepareKeyedAt` | **APPROVE**, existing legacy disposition. [prepare.go:179](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/activator/prepare.go:179): adds process selection; launch gates and filesystem operations remain intact. |
+| `ExecBackend.prepareWorker` | **APPROVE**, existing legacy disposition. [prepare.go:209](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/activator/prepare.go:209): validated worker name reaches the existing listener; no additional reads. |
+| `ExecBackend.logEmitter` | **APPROVE**, existing legacy disposition. [prepare.go:325](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/activator/prepare.go:325): delegates route attribution to `appLineEmitter`. |
+| `Service.releaseAppLog` | **APPROVE**, existing legacy disposition. [rootfsrelease.go:353](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/activator/rootfsrelease.go:353): same output destination, with the release process name. |
+| `appLineEmitter` | **APPROVE**, new `legacy / accepted-legacy` disposition. [logsink.go:47](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/activator/logsink.go:47): reads route identity and invokes an in-memory sink; grants no filesystem or execution authority. |
+| `internal/activator` envelope | **APPROVE**. Changed functions preserve existing capture destinations, validation and launch boundaries. |
+| `internal/applog` envelope | **APPROVE**. [sink.go:131](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/applog/sink.go:131): process attribution overrides parsed JSON; stream and binary-instance behavior remain intact. |
+| Record-write re-pin: `Server.handleAPIInstanceList` | **APPROVE**, unchanged `key-site / lit:instances` classification. [apiinstances.go:1230](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/rootfs-fleet-followups/internal/console/apiinstances.go:1230): annotates health without changing record writes. |
+
+The five unit digests, legacy fingerprints, both envelope hashes and record-write re-pin match the source. Tenant checks remain enforced; neither change adds S3 calls per list or pass. Web generations, worker restarts and release retries reach the updated capture paths.
+
+Targeted tests and census tests could not start because the read-only sandbox prevented Go from creating its work directory. `GOCACHE` was unset. `git diff --check` passed; runtime and mutation results remain unverified.
+
+READY AFTER FIXES
\ No newline at end of file
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index cb0e63b46..4a46e84de 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -484,9 +484,12 @@ func (s *Server) instanceHealth(ctx context.Context, recs []provision.Record) ma
// names this account and app. A view whose box could not arm its scheduler
// (Unavailable, which also covers a refused view with no tenant to check)
// or whose host is starting or stopping (Transient) says nothing about the
-// host's state, and the word stays unknown. Otherwise the word is the
-// platform-remote one (instanceHealth): awake is Running, a host held down
-// after a failed hold-mode build is Failed.
+// host's state, and the word stays unknown, as it does for a view whose
+// box generated its snapshot no later than the record was created: that
+// report may be about an earlier lifetime of the same host, account and
+// app (appFacts.host's rule for a platform-remote record). Otherwise the
+// word is the platform-remote one (instanceHealth): awake is Running, a
+// host held down after a failed hold-mode build is Failed.
func fleetHealth(health map[string]string, recs []provision.Record, join boxJoin, acct, app string) {
for _, rec := range recs {
if health[rec.Host] != healthUnknown {
@@ -496,7 +499,7 @@ func fleetHealth(health map[string]string, recs []provision.Record, join boxJoin
continue
}
v := join.rollout(rec.Host, acct, app)
- if v == nil || v.Unavailable != "" || v.Transient {
+ if v == nil || v.Unavailable != "" || v.Transient || !v.at.After(rec.CreatedAt) {
continue
}
kind := rec.Kind
@@ -751,6 +754,11 @@ type rolloutView struct {
// refused marks a view built from an Unavailable box, which has no
// account or app to check (hosts are unique; the caller filtered by app).
refused bool
+ // at is when the reporting box generated its snapshot (status.Box's
+ // GeneratedAt). Not shown: fleetHealth uses a view only when it is
+ // later than the record's creation, so a report about an earlier
+ // lifetime of the same host never describes this one.
+ at time.Time
}
// workerView is one worker of a rootfs instance as a member sees it
@@ -1079,12 +1087,12 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) {
if _, held := ro.Hosts[host]; held {
continue
}
- put(host, rolloutView{Box: b.Label, Installed: v, Unavailable: ro.Unavailable, refused: true})
+ put(host, rolloutView{Box: b.Label, Installed: v, Unavailable: ro.Unavailable, refused: true, at: b.GeneratedAt})
}
for host, hr := range ro.Hosts {
put(host, rolloutView{Box: b.Label, Installed: hr.Installed, Good: hr.Good, Attempt: hr.Attempt, AttemptBuild: hr.AttemptBuild,
HeldBy: hr.HeldBy, Reason: hr.Reason, Unavailable: ro.Unavailable, Workers: workerViews(hr.Workers),
- account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV})
+ account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV, at: b.GeneratedAt})
}
return
}
@@ -1107,6 +1115,7 @@ func (j *boxJoin) foldRollout(b status.Box, override bool) {
ConfigPending: hr.ConfigPending, Transient: hr.Transient, SchedulerIdle: a.Queued == 0 && a.Running == 0 && a.Settling == 0,
Workers: workerViews(hr.Workers),
account: hr.Account, app: hr.App, heldEpoch: hr.HeldEpoch, heldBook: hr.HeldBook, retryV: hr.RetryV,
+ at: b.GeneratedAt,
})
}
}
diff --git a/internal/console/fleethealth_test.go b/internal/console/fleethealth_test.go
index 5ddff5fcb..83c9a5405 100644
--- a/internal/console/fleethealth_test.go
+++ b/internal/console/fleethealth_test.go
@@ -16,8 +16,9 @@ import (
// writeFleetRolloutBox registers fleet to owner and writes, under the
// fleet's own prefix, a box named machine reporting ro (and versions as its
-// route versions, which an Unavailable report's hosts come from).
-func writeFleetRolloutBox(t *testing.T, fx *consoleFixture, fleet, owner, machine string, ro *status.RolloutReport, versions map[string]string) {
+// route versions, which an Unavailable report's hosts come from), generated
+// at at.
+func writeFleetRolloutBox(t *testing.T, fx *consoleFixture, fleet, owner, machine string, at time.Time, ro *status.RolloutReport, versions map[string]string) {
t.Helper()
reg, err := registry.Open(fx.regPath)
if err != nil {
@@ -27,7 +28,7 @@ func writeFleetRolloutBox(t *testing.T, fx *consoleFixture, fleet, owner, machin
if err := reg.UpsertFleet(registry.Fleet{Name: fleet, Account: owner, Bucket: fleet + "-bucket"}); err != nil {
t.Fatal(err)
}
- box := status.CollectBox(nil, status.Probes{MachineID: machine}, time.Now())
+ box := status.CollectBox(nil, status.Probes{MachineID: machine}, at)
box.Metrics = &status.BoxMetrics{Rollout: ro, RouteVersions: versions}
if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/"+fleet+"/"), box); err != nil {
t.Fatal(err)
@@ -64,20 +65,25 @@ func listHealth(t *testing.T, fx *consoleFixture, token, app string) map[string]
// Asleep, a host held down is Failed. Everything the join cannot vouch for
// stays "Can't tell right now": a host starting or stopping, a report
// naming another app, a box that could not arm its scheduler, a host no
-// box reports, and another account's fleet box naming this app's host.
+// box reports, another account's fleet box naming this app's host, and a
+// report generated before the record was created (an earlier lifetime of
+// the same host, account and app; the platform-remote rule, appFacts.host).
+// Every other report here is generated after the records, the control.
func TestFleetPlacedHealthComesFromItsFleetBox(t *testing.T) {
fx := newConsoleFixture(t)
const app = "kass"
host := func(slug string) string { return slug + ".kass.carlosapp.dev" }
asleep := true
- for _, slug := range []string{"run", "nap", "down", "busy", "other", "gone", "stranger", "unavail"} {
+ now := time.Now().UTC()
+ created := now.Add(-10 * time.Second)
+ for _, slug := range []string{"run", "nap", "down", "busy", "other", "gone", "stranger", "unavail", "reborn"} {
place := registry.PlacementTarget("pi")
if slug == "stranger" {
place = registry.PlacementTarget("stranger")
}
if err := provision.CreateRecord(context.Background(), fx.rel, provision.Record{
Schema: 1, Host: host(slug), Slug: slug, App: app, Account: fx.sqid, Region: place,
- Channel: "stable", Hibernate: &asleep, CreatedAt: time.Now().UTC(), CreatedBy: "paul@keymail.dev",
+ Channel: "stable", Hibernate: &asleep, CreatedAt: created, CreatedBy: "paul@keymail.dev",
}); err != nil {
t.Fatal(err)
}
@@ -86,25 +92,29 @@ func TestFleetPlacedHealthComesFromItsFleetBox(t *testing.T) {
hr.Account, hr.App, hr.Installed = fx.sqid, app, "v1"
return hr
}
- writeFleetRolloutBox(t, fx, "pi", fx.sqid, "pi-box", &status.RolloutReport{Hosts: map[string]status.HostRollout{
+ writeFleetRolloutBox(t, fx, "pi", fx.sqid, "pi-box", now, &status.RolloutReport{Hosts: map[string]status.HostRollout{
host("run"): mine(status.HostRollout{Awake: true}),
host("nap"): mine(status.HostRollout{}),
host("down"): mine(status.HostRollout{Attempt: status.AttemptDown, AttemptBuild: "v1"}),
host("busy"): mine(status.HostRollout{Transient: true}),
host("other"): {Account: fx.sqid, App: "other", Installed: "v1", Awake: true},
}}, nil)
- writeFleetRolloutBox(t, fx, "pi", fx.sqid, "pi-box-2", &status.RolloutReport{Unavailable: "flag-off"},
+ writeFleetRolloutBox(t, fx, "pi", fx.sqid, "pi-box-2", now, &status.RolloutReport{Unavailable: "flag-off"},
map[string]string{host("unavail"): "v1"})
- writeFleetRolloutBox(t, fx, "stranger", "zzz", "stranger-box", &status.RolloutReport{Hosts: map[string]status.HostRollout{
+ writeFleetRolloutBox(t, fx, "stranger", "zzz", "stranger-box", now, &status.RolloutReport{Hosts: map[string]status.HostRollout{
host("stranger"): mine(status.HostRollout{Awake: true}),
}}, nil)
+ // Fresh (well inside the staleness window) but from before the record.
+ writeFleetRolloutBox(t, fx, "pi", fx.sqid, "pi-box-old", created.Add(-10*time.Second), &status.RolloutReport{Hosts: map[string]status.HostRollout{
+ host("reborn"): mine(status.HostRollout{Awake: true}),
+ }}, nil)
token := cliToken(t, fx, "paul@keymail.dev", "code-fleet-health")
got := listHealth(t, fx, token, app)
want := map[string]string{
host("run"): "Running", host("nap"): "Asleep", host("down"): "Failed",
host("busy"): healthUnknown, host("other"): healthUnknown, host("gone"): healthUnknown,
- host("stranger"): healthUnknown, host("unavail"): healthUnknown,
+ host("stranger"): healthUnknown, host("unavail"): healthUnknown, host("reborn"): healthUnknown,
}
for h, w := range want {
if got[h] != w {