carlos / platform Public

console remote instances: canary-retire guard weighs every report of the host

Codex census review of 050a3a7e: reports.pick chose one box, so during a
move a fresher report of the new build could hide another fresh,
same-tenant report still running the retiring build. unsettledFollowers
now takes every fresh tenant-named report (fleetReports.tenantReports):
any one on the retiring build holds the retire whatever the record's
age, and convergence within the window needs every one on the new
channel's build. Two tests fail first on 050a3a7e; three mutants killed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 18b5884b34e447ada2942189ac5d2ad9875dc3da parent 050a3a7
4 files changed, +106 −17
  • internal/console/remoteinstances.go +41 −15
  • internal/console/remoteinstances_round2_test.go +63 −0
  • internal/provision/console_remote_instances_census_test.go +1 −1
  • internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv +1 −1

CI passed — run details

diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go
index e9a654ada..9a8bd3f98 100644
--- a/internal/console/remoteinstances.go
+++ b/internal/console/remoteinstances.go
@@ -240,6 +240,19 @@ func (f fleetReports) pick(host, acct, app string) *hostReport {
return best
}
+// tenantReports is every fresh report of host whose rollout names acct and
+// app: the evidence a safety check weighs, all of it, where pick chooses one
+// report to show.
+func (f fleetReports) tenantReports(host, acct, app string) []hostReport {
+ var out []hostReport
+ for _, r := range f.byHost[host] {
+ if r.tenantKnown && r.account == acct && r.app == app {
+ out = append(out, r)
+ }
+ }
+ return out
+}
+
func betterReport(a, b *hostReport) bool {
if a.tenantKnown != b.tenantKnown {
return a.tenantKnown
@@ -445,14 +458,15 @@ type settleCandidate struct{ host, channel string }
// that has not done so in channelSettle (three status snapshot periods,
// the fleet's staleness rule, status.BoxStale) is one the fleet already
// treats as dark;
-// - a record modified within it is settled only when a fresh report of its
-// box, naming this account and app, shows the host on its new channel's
+// - a record modified within it is settled only when every fresh report
+// naming this account and app shows the host on its new channel's
// build, and that build differs from the retiring channel's (otherwise
-// the report cannot tell the two channels apart).
+// the reports cannot tell the two channels apart).
//
-// Whatever a record's age, a fresh tenant-named report showing its host on
-// the retiring channel's build, which its new channel does not point at, is
-// evidence it has not converged, and holds the retire too. (When the two
+// Whatever a record's age, any fresh tenant-named report showing its host
+// on the retiring channel's build, which its new channel does not point at,
+// is evidence it has not converged, and holds the retire too. Every such
+// report counts, not only the one the pages show (a move in flight has two). (When the two
// channels point at one build, no report can tell them apart; then only
// the window decides.) Everything else is settled. Only hosts on other
// boxes are candidates: a host with a row in the console box's registry has
@@ -506,22 +520,34 @@ func (s *Server) unsettledFollowers(ctx context.Context, acct, app, channel stri
reports := foldFleetReports(boxes, complete, now)
var out []string
for key, c := range others {
- runs := ""
- if rep := reports.pick(c.host, acct, app); rep != nil && rep.tenantKnown {
- runs = rep.version
- }
moved := version(c.channel)
+ // Every fresh report naming this tenant counts: during a move two
+ // boxes may report the host, and the one still on the old channel
+ // is the one that matters.
+ stillOld, converged := false, false
+ if moved != retiring.Version {
+ reps := reports.tenantReports(c.host, acct, app)
+ converged = len(reps) > 0
+ for _, r := range reps {
+ if r.version == retiring.Version {
+ stillOld = true
+ }
+ if r.version == "" || r.version != moved {
+ converged = false
+ }
+ }
+ }
mod, listed := mods[key]
recent := !listed || now.Sub(mod) < channelSettle
switch {
- case runs != "" && runs == retiring.Version && moved != retiring.Version:
- // Its box still runs the retiring channel's build, which its new
+ case stillOld:
+ // A box still runs the retiring channel's build, which the new
// channel does not point at: whatever the record's age, it has
// not converged.
out = append(out, c.host)
- case recent && !(runs != "" && runs == moved && moved != retiring.Version):
- // Changed (or of unknown age) within the window, with no report
- // showing it on its new channel's own build yet.
+ case recent && !converged:
+ // Changed (or of unknown age) within the window, and not every
+ // report shows it on its new channel's own build yet.
out = append(out, c.host)
}
}
diff --git a/internal/console/remoteinstances_round2_test.go b/internal/console/remoteinstances_round2_test.go
index d4c2686d2..8c3940304 100644
--- a/internal/console/remoteinstances_round2_test.go
+++ b/internal/console/remoteinstances_round2_test.go
@@ -16,6 +16,7 @@ import (
"github.com/carlosframework/platform/internal/metrics"
"github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/status"
)
@@ -414,3 +415,65 @@ func TestRetireGuardUnknownsFailClosed(t *testing.T) {
t.Fatalf("an unreadable retiring pointer = %v, nil error", hosts)
}
}
+
+// Codex census review of 050a3a7e, P1: during a move two fresh boxes report
+// the host for this account. The fresher shows the new channel's build;
+// the other still runs the retiring one. Every matching report counts, so
+// the retire is refused whatever the record's age.
+func TestRetireGuardConsidersEveryReport(t *testing.T) {
+ tb := newTwoBoxes(t)
+ ds := tb.fx.rel.(*deletableStore)
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v4", "canary/rc")
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v5", "canary/next")
+ tb.create(t, tb.token, tb.sqid, "shop", remoteHost, "uk", "canary/next")
+ tb.reconcile(t, "v5")
+ old := time.Now().Add(-channelSettle - time.Minute)
+ if err := os.Chtimes(filepath.Join(ds.root, provision.RecordKey(tb.sqid, "shop", remoteHost)), old, old); err != nil {
+ t.Fatal(err)
+ }
+ // Box C still carries the host on canary/rc at v4 (the source of a move
+ // that has not let go of it), reporting a little earlier than B.
+ regC, err := registry.Open(filepath.Join(t.TempDir(), "registry-c.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { regC.Close() })
+ if err := regC.Upsert(registry.Route{Host: remoteHost, Kind: "instance", App: "shop", Account: tb.sqid,
+ Channel: "canary/rc", Version: "v4", Provisioned: true, Status: "ready"}); err != nil {
+ t.Fatal(err)
+ }
+ report(t, tb.fx.rel, regC, "box-c", "uk", time.Now().Add(-time.Minute), nil, 4096)
+ report(t, tb.fx.rel, tb.regB, "box-b", "uk", time.Now(), nil, 4096)
+ tb.fx.srv.boxReports.expire()
+ hosts, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc")
+ if err != nil || len(hosts) != 1 || hosts[0] != remoteHost {
+ t.Fatalf("followers of canary/rc = %v %v, want the host box C still runs on rc's build", hosts, err)
+ }
+}
+
+// Within the window, convergence needs every matching report on the new
+// channel's build: one box on it and another on some third build is not
+// settled.
+func TestRetireGuardConvergenceNeedsEveryReport(t *testing.T) {
+ tb := newTwoBoxes(t)
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v4", "canary/rc")
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v5", "canary/next")
+ tb.create(t, tb.token, tb.sqid, "shop", remoteHost, "uk", "canary/next")
+ tb.reconcile(t, "v5")
+ regC, err := registry.Open(filepath.Join(t.TempDir(), "registry-c.db"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { regC.Close() })
+ if err := regC.Upsert(registry.Route{Host: remoteHost, Kind: "instance", App: "shop", Account: tb.sqid,
+ Channel: "stable", Version: "v3", Provisioned: true, Status: "ready"}); err != nil {
+ t.Fatal(err)
+ }
+ report(t, tb.fx.rel, regC, "box-c", "uk", time.Now().Add(-time.Minute), nil, 4096)
+ report(t, tb.fx.rel, tb.regB, "box-b", "uk", time.Now(), nil, 4096)
+ tb.fx.srv.boxReports.expire()
+ hosts, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc")
+ if err != nil || len(hosts) != 1 || hosts[0] != remoteHost {
+ t.Fatalf("followers of canary/rc = %v %v, want the host not every report shows converged", hosts, err)
+ }
+}
diff --git a/internal/provision/console_remote_instances_census_test.go b/internal/provision/console_remote_instances_census_test.go
index 9f3f6c332..16cd38429 100644
--- a/internal/provision/console_remote_instances_census_test.go
+++ b/internal/provision/console_remote_instances_census_test.go
@@ -33,7 +33,7 @@ func consoleRemoteInstancesWriteCensusInventory() []censusEntry {
replacements := []censusEntry{
{"internal/console/instancepage.go", "Server.handleAppInstance", "key-site", "lit:instances", "07f5c01659b0d453d5996abb6a6e9493f74c7df97e3cddfe0f765b6f316de4a7"},
{"internal/console/server.go", "Server.channelHosts", "key-site", "key:RecordKey,key:SidecarsPrefix", "56baa86331ca8e5e19b7a765bcca5fbd9250319a4eaf25b1ee4d71c5bca0fbed"},
- {"internal/console/remoteinstances.go", "Server.unsettledFollowers", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "48cbc6a4c86ebb8a71842049cd97a2ac9eed42ba3beecc0a76e4cead6a7ba833"},
+ {"internal/console/remoteinstances.go", "Server.unsettledFollowers", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "70b3ee51e7810e0f180a99ed9c7de463ca418d80881b2abe102858d85902be77"},
{"internal/console/remoteinstances.go", "Server.pageRecords", "key-site", "key:RecordsPrefix", "b03ec08af6e2eedc5b2fa269751b5fa3465c2e728c93a6c97964ebabb15362a4"},
}
for _, r := range replacements {
diff --git a/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv b/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv
index d68c1d38a..3fc49122d 100644
--- a/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv
+++ b/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv
@@ -19,5 +19,5 @@ internal/console/templates/app_overview.html external legacy accepted-legacy acc
internal/console/apiinstances.go Server.instanceHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-console-remote-instances;basis=Records with no local registry row get health only from a box report naming the record's own account and app (held down: Failed; transient or no tenant: Can't tell right now), readings pinned to that box and bounded by each record's created_at. Builds registry.Route literals from the record; reads no registry for them. registry:Account@1987,registry:Account@2007,registry:App@1948,registry:App@1964,registry:Host@839,registry:Unit@2117,registry:Unit@2159,whole:Route@1151,whole:Route@2054,whole:Route@2075,whole:Route@2854,whole:Route@3654,whole:Route@4134,whole:Route@4187,whole:Route@4302,whole:Route@792,whole:Route@821,whole:Route@832,whole:Route@850 e69364d7fdaa2f8606a32c5587b4f31293695dba9d920ae75246556b8d281941
internal/console/server.go Server.channelHosts legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-console-remote-instances;basis=Canary-retire guard also counts the account's instance records (ListRecordsStrict) and sidecar records (listed, then each read with GetSidecarRecord; any read error refuses), and records on other boxes that changed within channelSettle (or have no modification time) unless their box report shows the new channel's build, or whose box report still shows the retiring channel's build at any age (unsettledFollowers); it notes which hosts have a local registry row (rt.Host) so only remote hosts are candidates. Fails closed, including on an unreadable retiring pointer. registry:App@493,registry:Channel@510,registry:Host@472,registry:Host@541,whole:Route@324,whole:Route@455 56baa86331ca8e5e19b7a765bcca5fbd9250319a4eaf25b1ee4d71c5bca0fbed
internal/console/view.go Assemble legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-console-remote-instances;basis=Collects the set of local registry hosts (rt.Host) so a record host the registry has gets no remote row (its record's created_at bounds the local row's metrics history); adds rows from the account's records and box reports when given a remote source. registry:App@1716,registry:App@1739,registry:App@2117,registry:App@2147,registry:Backing@2017,registry:Caps@1385,registry:Channel@960,registry:Environment@1942,registry:Hibernate@1859,registry:Host@1768,registry:Host@861,registry:Kind@1783,registry:Platform@1889,registry:Provisioned@2042,registry:Status@1800,registry:Unit@1999,registry:Version@1823,whole:Route@2092,whole:Route@2167,whole:Route@810,whole:Route@839,whole:Route@910 120ae8c042523f872fd1c19357b8bb830e4afe9da1e38ad202df2ada3ad52ada
-@coverage internal/console efa83979663b313cee864276db19a6df18c0224f220fa8fbc4eef400c82acfa3
+@coverage internal/console 591c443ab2c56397233812d1f8f987efe934b603c1701ba8fc682e76b8bb8378
@coverage internal/console/templates d953013575663fbd275b663ac3d9b46e99eb830b223b9e545ddec7580468d5db