carlos / platform Public

console remote instances: deletion evidence that cannot fail; zero mod times refuse

Codex census review of ba69fcc1: the audit row the guard read for
deletions is best-effort and written after the delete, so a failed audit
write hid a deletion; and a listed record with a zero modification time
counted as old. retireHostRecord, the one door every instance and
sidecar deletion goes through, now notes the app in memory before
deleting anything; the guard refuses while that note is within
channelSettle, and for channelSettle after the console starts (memory
does not survive a restart). A zero modification time refuses. Test
fixtures start the console a day ago. Tests fail first; four mutants
killed. Census re-proposed; retireUnsettled digest.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ce50a820cc04d639468deb1037f0eb3a0855a5fa parent ba69fcc
8 files changed, +127 −15
  • docs/superpowers/notes/console-remote-instances.md +13 −7
  • internal/console/hostclaimops.go +5 −0
  • internal/console/remoteinstances.go +41 −6
  • internal/console/remoteinstances_round3_test.go +54 −0
  • internal/console/server.go +9 −0
  • internal/console/server_test.go +3 −0
  • internal/provision/console_remote_instances_census_test.go +1 −1
  • internal/provision/testdata/plan14-root-reads-console-remote-instances.tsv +1 −1

CI failed — run details

diff --git a/docs/superpowers/notes/console-remote-instances.md b/docs/superpowers/notes/console-remote-instances.md
index 118375003..c2d391204 100644
--- a/docs/superpowers/notes/console-remote-instances.md
+++ b/docs/superpowers/notes/console-remote-instances.md
@@ -265,12 +265,16 @@ conservative rule.
console's box and no instance or sidecar record names C, and the app has
settled:
- no record was created or changed in the last `channelSettle` (15
- minutes), and none is missing from the modification-time listing;
+ minutes), and none is missing from the modification-time listing or
+ listed with no modification time;
- no record was deleted in that time. The change index carries no
- times, so deletions are dated by the console's own audit log: every
- member deletion goes through the instance and sidecar delete doors,
- which audit it. An unreadable audit log, or one too busy to look back
- that far, counts as a recent deletion;
+ times, so deletions are dated by the console itself: every member
+ deletion goes through `retireHostRecord`, which notes the app in
+ memory before deleting anything (a note that cannot fail to be
+ written, unlike the best-effort audit row). Memory does not survive a
+ restart, so a console refuses every retire for `channelSettle` after
+ it starts. The audit log is read as well, and an unreadable one, or
+ one too busy to look back that far, counts as a recent deletion;
- every box report was read; and
- no fresh box report names this account and app for a host that no
record names. That covers a deletion made behind the console's back,
@@ -282,6 +286,8 @@ conservative rule.
local route never stands in for a remote copy. The refusal is the
existing "Could not verify no hosts follow this channel — try again."
sentence, shown as a flash. A clearer sentence that names the wait would
- be new copy, for Luna. The cost: a retire right after any record change
- waits up to 15 minutes.
+ be new copy, for Luna. The cost: a retire right after any record change,
+ or in the first 15 minutes after a console restart, waits up to 15
+ minutes. A record deleted directly from the bucket, behind every
+ console door, is caught only while a box still reports its host.
diff --git a/internal/console/hostclaimops.go b/internal/console/hostclaimops.go
index 152aa34c4..c5ba7b6de 100644
--- a/internal/console/hostclaimops.go
+++ b/internal/console/hostclaimops.go
@@ -13,6 +13,11 @@ import (
)
func (s *Server) retireHostRecord(ctx context.Context, ref provision.RetireRef) error {
+ // Before anything is deleted, and in memory, where it cannot fail: the
+ // canary-retire guard's evidence that this app lost a record just now
+ // (recentRecordDeletion). A delete that then fails costs at most a
+ // retire held back for channelSettle.
+ s.noteRecordDeletion(ref.Account, ref.App, time.Now())
if s.cfg.HostClaim {
return s.retireClaimHostRecord(ctx, ref)
}
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go
index 785f249cb..42a23b6e9 100644
--- a/internal/console/remoteinstances.go
+++ b/internal/console/remoteinstances.go
@@ -459,10 +459,10 @@ var errRetireUnsettled = errors.New("the app's instances have not settled")
// - any instance or sidecar record of the app was created or changed in
// the last channelSettle, or is missing from the modification-time
// listing (deleted since it was read);
-// - any was deleted in the last channelSettle: every member deletion goes
-// through the console's instance and sidecar delete doors, which audit
-// it, so the console's own audit log dates it (an unreadable log, or
-// one too busy to look back that far, counts as a recent deletion);
+// - any was deleted in the last channelSettle (recentRecordDeletion):
+// every member deletion goes through retireHostRecord, which notes it
+// in memory before deleting, and the console refuses for channelSettle
+// after it starts; the audit log is read too;
// - the box reports cannot all be read; or
// - a fresh box report names this account and app for a host no record
// names: a route still up after its record was deleted, or a hand route
@@ -491,6 +491,9 @@ func (s *Server) retireUnsettled(ctx context.Context, acct, app string, keys, ho
continue
}
listed[o.Key] = true
+ if o.Mod.IsZero() {
+ return unsettled("%s has no modification time", o.Key)
+ }
if now.Sub(o.Mod) < channelSettle {
return unsettled("%s changed %s ago", o.Key, now.Sub(o.Mod).Round(time.Second))
}
@@ -527,9 +530,41 @@ func (s *Server) retireUnsettled(ctx context.Context, acct, app string, keys, ho
// see past them, and says the app has not settled.
const retireAuditWindow = 500
-// recentRecordDeletion is errRetireUnsettled when the console's audit log
-// shows an instance or sidecar of acct/app deleted within channelSettle.
+// processStart is when this console process started.
+var processStart = time.Now()
+
+// noteRecordDeletion records that an instance or sidecar record of
+// acct/app is being deleted now (retireHostRecord calls it first).
+func (s *Server) noteRecordDeletion(acct, app string, at time.Time) {
+ s.deletionsMu.Lock()
+ defer s.deletionsMu.Unlock()
+ if s.deletions == nil {
+ s.deletions = map[string]time.Time{}
+ }
+ s.deletions[acct+"/"+app] = at
+}
+
+// recentRecordDeletion is errRetireUnsettled when an instance or sidecar of
+// acct/app may have been deleted within channelSettle. Every member
+// deletion goes through retireHostRecord, which notes it in memory before
+// deleting; a console that started within channelSettle cannot vouch for
+// the time before it started, so it refuses until it has been up that
+// long. The audit log is read as well, for a deletion another console
+// process sharing this database made.
func (s *Server) recentRecordDeletion(acct, app string, now time.Time) error {
+ s.deletionsMu.Lock()
+ at, deleted := s.deletions[acct+"/"+app]
+ s.deletionsMu.Unlock()
+ if deleted && now.Sub(at) < channelSettle {
+ return fmt.Errorf("%w: a record of %s/%s was deleted %s ago", errRetireUnsettled, acct, app, now.Sub(at).Round(time.Second))
+ }
+ started := s.startedAt
+ if started.IsZero() {
+ started = processStart
+ }
+ if now.Sub(started) < channelSettle {
+ return fmt.Errorf("%w: the console started %s ago and cannot vouch for deletions before that", errRetireUnsettled, now.Sub(started).Round(time.Second))
+ }
a, err := s.store.AccountBySqid(acct)
if err != nil || a == nil {
return fmt.Errorf("%w: the account's audit log cannot be read: %v", errRetireUnsettled, err)
diff --git a/internal/console/remoteinstances_round3_test.go b/internal/console/remoteinstances_round3_test.go
index 6ac0192cc..f6509d4bc 100644
--- a/internal/console/remoteinstances_round3_test.go
+++ b/internal/console/remoteinstances_round3_test.go
@@ -269,3 +269,57 @@ func TestRetireRefusedOnRecordWithoutModTime(t *testing.T) {
}
func errorsIsUnsettled(err error) bool { return errors.Is(err, errRetireUnsettled) }
+
+// Codex census review of ba69fcc1: deletion evidence that cannot fail. A
+// record deleted through retireHostRecord with no audit row at all (the
+// audit write is best-effort) still holds the retire; a console that has
+// just started cannot vouch for deletions before it, so it holds every
+// retire for the window; and a listed record with a zero modification time
+// is not settled.
+func TestRetireDeletionEvidenceCannotFail(t *testing.T) {
+ tb := newTwoBoxes(t)
+ tb.create(t, tb.token, tb.sqid, "shop", remoteHost, "uk", "stable")
+ tb.create(t, tb.token, tb.sqid, "shop", localHost, "ie", "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()
+ if _, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc"); err != nil {
+ t.Fatalf("fixture: a still app = %v", err)
+ }
+
+ // Zero modification time.
+ ds := tb.fx.rel.(*deletableStore)
+ tb.fx.srv.cfg.Releases = zeroModStore{ds}
+ if _, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc"); !errorsIsUnsettled(err) {
+ t.Fatalf("a zero modification time = %v, want unsettled", err)
+ }
+ tb.fx.srv.cfg.Releases = ds
+
+ // Just started.
+ started := tb.fx.srv.startedAt
+ tb.fx.srv.startedAt = time.Now().Add(-time.Minute)
+ if _, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc"); !errorsIsUnsettled(err) {
+ t.Fatalf("a console up for a minute = %v, want unsettled", err)
+ }
+ tb.fx.srv.startedAt = started
+
+ // A deletion with no audit row: retireHostRecord itself, not the door.
+ if err := tb.fx.srv.retireInstanceRecord(context.Background(), tb.sqid, "shop", localHost, "test", ""); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := tb.fx.srv.channelHosts(context.Background(), tb.sqid, "shop", "canary/rc"); !errorsIsUnsettled(err) || !strings.Contains(err.Error(), "deleted") {
+ t.Fatalf("after an unaudited deletion = %v, want unsettled", err)
+ }
+}
+
+// zeroModStore lists every record with a zero modification time.
+type zeroModStore struct{ *deletableStore }
+
+func (s zeroModStore) ListMod(ctx context.Context, prefix string) ([]release.KeyMod, error) {
+ objs, err := s.deletableStore.ListMod(ctx, prefix)
+ for i := range objs {
+ objs[i].Mod = time.Time{}
+ }
+ return objs, err
+}
diff --git a/internal/console/server.go b/internal/console/server.go
index dc3c82b99..75604a211 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1192,6 +1192,15 @@ type Server struct {
// (remoteinstances.go), held for boxReportTTL so the app pages ask the
// bucket at most once a minute however many people browse.
boxReports boxReportCache
+ // 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 + "/"
+ // + app): the canary-retire guard's deletion evidence
+ // (recentRecordDeletion). Memory, so it cannot fail to be written; the
+ // guard does not vouch for the channelSettle before the start.
+ startedAt time.Time
+ deletionsMu sync.Mutex
+ deletions map[string]time.Time
// viewUse is the last recordWalkStore outcome, so a switch between the
// view and the bucket is logged once, not on every pass.
viewUse atomic.Int32
diff --git a/internal/console/server_test.go b/internal/console/server_test.go
index cfad24697..b707cad42 100644
--- a/internal/console/server_test.go
+++ b/internal/console/server_test.go
@@ -91,6 +91,9 @@ func newConsoleFixtureOn(t *testing.T, withKey bool, rel release.Store) *console
}
// Fixture route hosts don't resolve; keep the not-reporting verdict quick.
srv.instances.timeout = 100 * time.Millisecond
+ // A console that has been up a while: the canary-retire guard does not
+ // vouch for the window before a console started (recentRecordDeletion).
+ srv.startedAt = time.Now().Add(-24 * time.Hour)
// paul owns the built-in ops account (created by NewServer's backfill),
// which claims kass — the shape a deployment is in once the pre-accounts
// grants have been mapped onto memberships.
diff --git a/internal/provision/console_remote_instances_census_test.go b/internal/provision/console_remote_instances_census_test.go
index 34492136d..5aa826611 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", "966e1fb668d3910ccb102845f1c5c91a1aa2cfa857bbf0ca11d850945259c682"},
- {"internal/console/remoteinstances.go", "Server.retireUnsettled", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "622db1c4651b4a4ce4d5eef89e2734982db7ea61fe6a7ad4129b364ee30fb071"},
+ {"internal/console/remoteinstances.go", "Server.retireUnsettled", "key-site", "key:RecordsPrefix,key:SidecarsPrefix", "8aa2e4063634cd4d643fc22982baa79845b73410eeef500e228ffa29b00d6c3f"},
{"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 dc7989785..ad93b7537 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/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 naming the record's own account and app (held down: Failed; transient, unidentified or unread: 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@3646,whole:Route@4126,whole:Route@4179,whole:Route@4294,whole:Route@792,whole:Route@821,whole:Route@832,whole:Route@850 f2b042a95c77b07f0bcd1c11f099769a7ad3c1a230c521af71c6bf5cb7685897
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 09ddeb704f9055eb14c84f59d57e871521a4e90df7c8f2ee9d2c8205c0b971b5
+@coverage internal/console f862afd341c843335fa1c8b4d5f09952b59bc5e1e567a5b6023546d3ed693df3
@coverage internal/console/templates 6e272e30e00be5785b3f364a947ea4ab86b2d96a0e8d21821b7812c45f0a636f