carlos / platform Public

console remote instances: close the Codex census escalations on 55706243

- The retire guard counts either source (rollout report, edges file)
  naming the app for a host no record names; a disagreement only stops
  the host joining a page row.
- An edges-file identity is dated by the box report's generation, not
  the console's read, so a stale edges file cannot extend the window.
- Retire: after deleting the pointer the record stamps are compared once
  more; on any change the pointer's own bytes are put back (create-only)
  and the retire refused.
- Box-report invalidation counts generations, so a load in flight when a
  deletion invalidates the cache cannot publish its older result as held.

Tests fail first; four mutants killed. Census re-proposed; record-write:
handleRetireCanary (nonrecord, sel:Put), retireUnsettled re-digested.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev cadd9fe9165450cb343807e90835a061a5710a5d parent 5570624
6 files changed, +183 −19
  • docs/superpowers/notes/console-remote-instances.md +14 −8
  • internal/console/remoteinstances.go +30 −7
  • internal/console/remoteinstances_round4_test.go +104 −0
  • internal/console/server.go +28 −2
  • internal/provision/console_remote_instances_census_test.go +6 −1
  • internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv +1 −1

CI passed — run details

diff --git a/docs/superpowers/notes/console-remote-instances.md b/docs/superpowers/notes/console-remote-instances.md
index 5cb3785b7..265baec7a 100644
--- a/docs/superpowers/notes/console-remote-instances.md
+++ b/docs/superpowers/notes/console-remote-instances.md
@@ -298,30 +298,36 @@ conservative rule.
1. **Successor samples.** A remote row's readings are now bounded on both
sides: from the record's `created_at` up to when the box report it joined
- observed the host as this account's. That is the report's generation for
- a rollout entry, or the console's read for an edges-file entry. A
+ observed the host as this account's: the box report's generation, for a
+ rollout entry and an edges-file entry alike (the box rewrites its edges
+ file when a host changes hands, and the report beside it is the latest
+ moment the console knows the box still named this owner). A
hostname can change hands on the same box while the console still holds
the old ownership, and a newer sample may then be the successor's. The
current reading is the newest sample inside the window, and nothing at
all if that sample is older than the metrics fresh window (8 minutes). A
remote row's reading therefore lags by up to one status snapshot period
- (5 minutes) for rollout-managed hosts, or one cache age (60 seconds) for
- edges-file identities. A report generated before the record existed
+ (5 minutes). A report generated before the record existed
joins nothing. Every console deletion also invalidates the held box
- reports and makes the pages read that app's records from the bucket, not
+ reports (a load already in flight cannot put its older result back) and makes the pages read that app's records from the bucket, not
the record view's snapshot, for `channelSettle`.
2. **Records created between the retire listings.** The modification-time
listing refuses any record key the follower read did not see. There is
no lock that record writes take (the app-mutation runner is a claim-mode
admission, not a lock), so the retire door takes the app's record keys
- and modification times before its check and again just before deleting
- the pointer, inside the app mutation, and refuses on any difference.
+ and modification times before its check, again just before deleting the
+ pointer, and once more right after: a change seen after the delete puts
+ the pointer back (its own signed bytes, create-only) and refuses. A
+ record written after that last listing meets a channel with no pointer,
+ which is no different from creating one on a channel nobody promoted.
3. **Identity for every route kind.** The rollout report covers only the
routes the rollout manages (never statics, non-hibernating instances or
unit-backed routes). Each box's edges file publishes the account and app
that own every host it serves. It is read with the box reports, in the
same cached load, and identifies the hosts the rollout does not cover.
- Where both sources speak and disagree, the host has no identity.
+ Where both sources speak and disagree, the host has no identity to join,
+ but the retire guard still counts either source naming the app as a
+ possible follower.
Reports with no identity still contribute nothing. The test helper now
writes rollout entries by production's `rollout.Managed` rule, and
writes an edges file in the producer's shape.
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go
index 1041c311f..e9292486e 100644
--- a/internal/console/remoteinstances.go
+++ b/internal/console/remoteinstances.go
@@ -64,7 +64,10 @@ type boxReportCache struct {
complete bool
// owners is every box's edges file's word on who owns each host it
// serves: box label -> host -> {account, app}, read with the reports.
- owners map[string]map[string][2]string
+ owners map[string]map[string][2]string
+ // gen counts invalidations: a load that began before one publishes its
+ // result to its own caller but does not hold it for later views.
+ gen uint64
loading chan struct{}
// now is the cache's clock; nil is time.Now. Tests set it.
now func() time.Time
@@ -111,6 +114,7 @@ func (c *boxReportCache) invalidate() {
c.mu.Lock()
defer c.mu.Unlock()
c.valid = false
+ c.gen++
}
// pageFleet is pageBoxReports with the edges-file owners and the read's
@@ -143,6 +147,7 @@ func (s *Server) pageFleet(ctx context.Context) fleetRead {
}
done := make(chan struct{})
c.loading = done
+ gen := c.gen
c.mu.Unlock()
loadCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), instanceStoreTimeout)
@@ -154,7 +159,7 @@ func (s *Server) pageFleet(ctx context.Context) fleetRead {
owners := edgesOwners(loadCtx, s.cfg.Releases)
cancel()
c.mu.Lock()
- c.at, c.valid, c.failed, c.boxes, c.complete, c.owners = c.clock(), true, err != nil || !complete, boxes, complete, owners
+ c.at, c.valid, c.failed, c.boxes, c.complete, c.owners = c.clock(), c.gen == gen, err != nil || !complete, boxes, complete, owners
r := fleetRead{boxes: boxes, complete: complete, owners: owners, at: c.at}
c.loading = nil
close(done)
@@ -219,7 +224,10 @@ type hostReport struct {
tenantKnown bool
account, app string
obsAt time.Time
- awake bool
+ // claims is every tenant either source names for the host, agreeing
+ // or not: the canary-retire guard's evidence of a possible follower.
+ claims [][2]string
+ awake bool
// down is a failed hold-mode build that left the host with nothing
// serving it (status.AttemptDown): its wakes are refused. transient is
// a process mid-start or mid-stop: neither awake nor asleep.
@@ -292,13 +300,26 @@ func foldFleet(read fleetRead, now time.Time) fleetReports {
}
// The edges file names owners for every route kind. It identifies a
// host the rollout does not manage; where both speak, they must
- // agree, or the host has no identity.
+ // agree, or the host has no identity to join. Either source's word is
+ // kept (claims) for the canary-retire guard, which must count a
+ // possible follower whatever the other source says.
+ //
+ // An edges-file identity is dated by this box's report, not by the
+ // console's read: the box rewrites its edges file when a host
+ // changes hands, and the report generated alongside is the latest
+ // moment the console knows the box still said this owner.
for host, r := range reps {
+ if r.tenantKnown {
+ r.claims = append(r.claims, [2]string{r.account, r.app})
+ }
o, ok := read.owners[b.Label][host]
+ if ok {
+ r.claims = append(r.claims, o)
+ }
switch {
case !ok:
case !r.tenantKnown && r.account == "" && r.app == "":
- r.tenantKnown, r.account, r.app, r.obsAt = true, o[0], o[1], read.at
+ r.tenantKnown, r.account, r.app, r.obsAt = true, o[0], o[1], b.GeneratedAt
case r.account != o[0] || r.app != o[1]:
r.tenantKnown = false
r.account, r.app = "conflict", "conflict"
@@ -621,8 +642,10 @@ func (s *Server) retireUnsettled(ctx context.Context, acct, app string, keys, ho
continue
}
for _, r := range reps {
- if r.tenantKnown && r.account == acct && r.app == app {
- return unsettled("box %s still serves %s, which no record names", r.box, host)
+ for _, c := range r.claims {
+ if c[0] == acct && c[1] == app {
+ return unsettled("box %s still serves %s, which no record names", r.box, host)
+ }
}
}
}
diff --git a/internal/console/remoteinstances_round4_test.go b/internal/console/remoteinstances_round4_test.go
index 05f43ef6b..720867d87 100644
--- a/internal/console/remoteinstances_round4_test.go
+++ b/internal/console/remoteinstances_round4_test.go
@@ -4,6 +4,7 @@ package console
import (
"context"
+ "encoding/json"
"net/http"
"strings"
"sync"
@@ -12,6 +13,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/rollout"
"github.com/carlosframework/platform/internal/status"
@@ -231,3 +233,105 @@ func TestRemoteInstancesListIgnoresSuccessorSample(t *testing.T) {
t.Fatalf("instances list = %d %s: a successor's sample made it Running", code, out)
}
}
+
+// Codex census review of 55706243: a follower created after the last
+// comparison, as the pointer is deleted, puts the pointer back and refuses.
+func TestRetireRestoresPointerOnRecordCreatedDuringDelete(t *testing.T) {
+ tb := newTwoBoxes(t)
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v4", "canary/rc")
+ tb.create(t, tb.token, tb.sqid, "shop", remoteHost, "uk", "stable")
+ tb.reconcile(t, "v3")
+ report(t, tb.fx.rel, tb.regB, "box-b", "uk", time.Now(), nil, 4096)
+ ageRecords(t, tb)
+ tb.fx.srv.boxReports.expire()
+ before, _, err := tb.fx.rel.Get(context.Background(), release.ChannelKey(tb.sqid, "shop", "canary/rc"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ tb.fx.srv.retireAfterDeleteHook = followerRecord(t, tb, "late.shop.example.com")
+ if page := retireRC(t, tb); !strings.Contains(page, notSettled) {
+ t.Fatalf("retire with a follower created during the delete:\n%s", page)
+ }
+ after, _, err := tb.fx.rel.Get(context.Background(), release.ChannelKey(tb.sqid, "shop", "canary/rc"))
+ if err != nil || string(after) != string(before) {
+ t.Fatalf("the pointer was not put back as it was: %v", err)
+ }
+}
+
+// Codex census review of 55706243: where the rollout report and the edges
+// file disagree about a host no record names, the host has no identity to
+// join, but either source naming this app still holds a retire.
+func TestRetireKeepsConflictingEvidence(t *testing.T) {
+ tb := newTwoBoxes(t)
+ shipAndPromote(t, tb.fx, tb.sqid, "shop", "v4", "canary/rc")
+ if err := tb.regB.Upsert(registry.Route{Host: "hand.shop.example.com", Kind: "instance", App: "shop", Account: tb.sqid,
+ Channel: "canary/rc", Version: "v4", Provisioned: true, Hibernate: true, Status: "ready",
+ Socket: "/run/carlos/hand.sock"}); err != nil {
+ t.Fatal(err)
+ }
+ label := report(t, tb.fx.rel, tb.regB, "box-b", "uk", time.Now(), nil, 4096)
+ rt, _ := tb.regB.Get("hand.shop.example.com")
+ if !rollout.Managed(*rt) {
+ t.Fatalf("fixture: the hand route is not rollout-managed: %+v", rt)
+ }
+ writeEdgesOwners(t, tb.fx.rel, label, map[string][2]string{"hand.shop.example.com": {"other", "shop"}})
+ tb.fx.srv.boxReports.expire()
+ if _, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc"); !errorsIsUnsettled(err) {
+ t.Fatalf("a box naming this app for a host no record names (edges disagreeing) = %v, want unsettled", err)
+ }
+}
+
+func writeEdgesOwners(t *testing.T, rel release.Store, label string, owners map[string][2]string) {
+ t.Helper()
+ hosts := map[string]any{}
+ for h, o := range owners {
+ hosts[h] = map[string]any{"role": "home", "account": o[0], "app": o[1]}
+ }
+ body, _ := json.Marshal(map[string]any{"v": 1, "box": label, "hosts": hosts, "generation": time.Now().UTC().Format(time.RFC3339)})
+ key := "control/edges/" + label + ".json"
+ _, etag, _ := rel.Get(context.Background(), key)
+ if _, err := rel.Put(context.Background(), key, body, etag); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// Codex census review of 55706243: an edges-file identity is dated by the
+// box's report, not by when the console read the file.
+func TestEdgesIdentityDatedByReport(t *testing.T) {
+ gen := time.Now().Add(-4 * time.Minute)
+ boxes := []status.Box{{GeneratedAt: gen, Label: "b", Metrics: &status.BoxMetrics{
+ RouteVersions: map[string]string{"s.example.com": "v2"}}}}
+ owners := map[string]map[string][2]string{"b": {"s.example.com": {"a", "shop"}}}
+ f := foldFleet(fleetRead{boxes: boxes, complete: true, owners: owners, at: time.Now()}, time.Now())
+ if rep := f.pick("s.example.com", "a", "shop", time.Time{}); rep == nil || !rep.obsAt.Equal(gen) {
+ t.Fatalf("edges identity observed at %+v, want the report's generation %v", rep, gen)
+ }
+}
+
+// Codex census review of 55706243: an invalidation during a load is not
+// overwritten by that load's (older) result.
+func TestBoxReportInvalidationDuringLoad(t *testing.T) {
+ release1 := make(chan struct{})
+ started := make(chan struct{}, 1)
+ rs := &reportStore{Store: release.NewDirStore(t.TempDir())}
+ first := true
+ rs.onList = func() error {
+ if first {
+ first = false
+ started <- struct{}{}
+ <-release1
+ }
+ return nil
+ }
+ s, _ := cacheServer(t, rs)
+ done := make(chan struct{})
+ go func() { s.pageBoxReports(context.Background()); close(done) }()
+ <-started
+ s.boxReports.invalidate()
+ close(release1)
+ <-done
+ s.pageBoxReports(context.Background())
+ if n := rs.listCount(); n != 2 {
+ t.Fatalf("box report listings = %d, want 2: the load that began before the invalidation was held", n)
+ }
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index 7f8027da5..a1e9c7fc6 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1196,6 +1196,9 @@ type Server struct {
// retireBeforeDeleteHook, when set, runs in the canary retire between
// the follower check and the final record comparison. Tests only.
retireBeforeDeleteHook func()
+ // retireAfterDeleteHook, when set, runs right after the pointer's
+ // delete, before the last record comparison. Tests only.
+ retireAfterDeleteHook func()
// startedAt overrides when this console started (zero: the process
// start, processStart; tests set it), and deletions is when it last
// began deleting an instance or sidecar record of each app (acct + "/"
@@ -5496,7 +5499,8 @@ func (s *Server) handleRetireCanary(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second)
defer cancel()
key := release.ChannelKey(acct.Sqid, app, channel)
- if _, _, err := s.cfg.Releases.Get(ctx, key); errors.Is(err, os.ErrNotExist) {
+ pointer, _, err := s.cfg.Releases.Get(ctx, key)
+ if errors.Is(err, os.ErrNotExist) {
back("err", "No canary named "+name+" here.")
return
} else if err != nil {
@@ -5518,7 +5522,29 @@ func (s *Server) handleRetireCanary(w http.ResponseWriter, r *http.Request) {
if !maps.Equal(before, after) {
return fmt.Errorf("%w: the app's records changed during the check", errRetireUnsettled)
}
- return s.cfg.Releases.Delete(ctx, key)
+ if err := s.cfg.Releases.Delete(ctx, key); err != nil {
+ return err
+ }
+ if h := s.retireAfterDeleteHook; h != nil {
+ h()
+ }
+ // No lock covers record writes, so a follower can still land between
+ // that comparison and the delete. Compare once more after it: on any
+ // change, put the pointer back (its signed bytes, as read) and
+ // refuse. A record written after this listing meets a channel with no
+ // pointer, which is no different from creating one on a channel
+ // nobody has promoted yet.
+ final, ferr := s.recordStamps(ctx, acct.Sqid, app)
+ if ferr != nil || !maps.Equal(before, final) {
+ if _, perr := s.cfg.Releases.Put(ctx, key, pointer, ""); perr != nil {
+ log.Printf("console: retire %s %s: RESTORING THE POINTER FAILED after a concurrent record change: %v", app, channel, perr)
+ }
+ if ferr != nil {
+ return ferr
+ }
+ return fmt.Errorf("%w: the app's records changed while retiring; the pointer was put back", errRetireUnsettled)
+ }
+ return nil
})
if errors.Is(err, errRetireUnsettled) {
log.Printf("console: retire %s %s: %v", app, channel, err)
diff --git a/internal/provision/console_remote_instances_census_test.go b/internal/provision/console_remote_instances_census_test.go
index 0393864eb..301b6c5f5 100644
--- a/internal/provision/console_remote_instances_census_test.go
+++ b/internal/provision/console_remote_instances_census_test.go
@@ -34,6 +34,10 @@ package provision
// follower read did not see; Server.pageRecords reads the bucket, not
// the record view, for an app the console just deleted a record of.
// None writes anything: key-site.
+// - Server.handleRetireCanary gains one Put: after deleting the canary's
+// channel pointer, if the app's records changed meanwhile, it puts the
+// pointer back (its own signed bytes, read a moment before, create-only)
+// and refuses. A channel pointer, never a record: nonrecord.
// - Server.pageRecords is new (round 1 review): the app pages' record
// reader. It lists RecordsPrefix for the viewed account's app and reads
// each record not already a local row with GetRecord, through the
@@ -47,8 +51,9 @@ func consoleRemoteInstancesWriteCensusInventory() []censusEntry {
{"internal/console/apiinstanceimport.go", "Server.deleteRead", "key-site", "key:RecordKey", "10452daaaf26912a51748001af6d1c801726b80c1167b22815e70f41c04c9552"},
{"internal/console/seedfinish.go", "Server.finishSeedOnce", "key-site", "key:RecordKey", "55c0cd69496dbc7c5339ea9374d90da70864d5c6f8a33e613351e290988c1e72"},
{"internal/console/claim_retire.go", "Server.retireClaimHostRecord", "key-site", "key:claimRetireRecordKey", "3c30cfcad8f2edb3c38b7dd9e56697cd3e17ce3a7fa0e76eb815adf3dad7bd4d"},
- {"internal/console/remoteinstances.go", "Server.retireUnsettled", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "46f74063782140e59d2acf3c57cd32784b1b2fca069e23a3c00bf961a324da5d"},
+ {"internal/console/remoteinstances.go", "Server.retireUnsettled", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "f8060eaf63710c2326b3bcb10b545b15f21d91c52d540b0245d0dc5b83548ab6"},
{"internal/console/remoteinstances.go", "Server.pageRecords", "key-site", "key:RecordsPrefix", "5298e5713404c168fdc4cfdc9995f57a5d3d61893d4b6c17f985877de59f8896"},
+ {"internal/console/server.go", "Server.handleRetireCanary", "nonrecord", "sel:Put", "70c248a329b475c574abeda7714933219e8cb7f6b5c881cbfe387e0390f7caaa"},
{"internal/console/remoteinstances.go", "Server.recordStamps", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "c38f120e5be0e8c883b6da7d86df23a5b6b495a31732732e6cbe6efe5821ff43"},
}
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 b56cb38d0..3736fafa4 100644
--- a/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv
+++ b/internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv
@@ -21,5 +21,5 @@ internal/console/server.go Server.channelHosts legacy accepted-legacy accepted-l
internal/console/templates/app_overview.html external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-console-remote-instances;basis=Running tile does not claim Served when a route's state is unknown and reads the existing 'no data right now' when every instance's state is unknown; Web addresses tile reads 'no data right now' instead of 'DNS & certs OK' for a domain with no reading; display only. file:external@0 2a112ff768c300894881b858e61465841c87810ca7cb1d98a0fe2a54155a0ca1
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 (rollout entry or edges-file owner) naming the record's own account and app and generated after the record existed (held down: Failed; transient, unidentified or unread: Can't tell right now), readings pinned to that box and bounded by the record's created_at and the report's observation. 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@2893,whole:Route@3649,whole:Route@4166,whole:Route@4219,whole:Route@4334,whole:Route@792,whole:Route@821,whole:Route@832,whole:Route@850 5824a71a58f5869ec8f0f90878b939d5a900399f42a504d6cc4c33210d55be6c
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 tenant-named 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 c73257bab5d1ed70783d0a5dd5aa5c2af5b1197f38c79295b53577f7be25204a
+@coverage internal/console 864a523d52ff3db9c0587d1fbf6e47d8749d96bd318c5196196648d3699b5791
@coverage internal/console/templates 6e272e30e00be5785b3f364a947ea4ab86b2d96a0e8d21821b7812c45f0a636f