retire-window-415: every console record delete marks the canary-retire window
The canary-retire guard refuses for 15 minutes after a record of the app is deleted, but lifetime detach, recovery, the previous owner's cleanup and the lifetimes-off trash sweep deleted records without noting it. retirementStepsLocked notes at entry; every lifetime record delete goes through deleteRecordIfMatch (note, then delete on the ETag); the trash sweep notes before its purge; domain-detach audit rows count for a second console. A witness in every console fixture fails any console record delete without a fresh note. Record-write census: six units re-pinned, classes unchanged, approved by Astra. Astra round 1: READY AFTER FIXES, both P2s fixed. Closes #415. Squashed from retire-window-all-deletes-415 into main.
13 files changed,
+480
−13
docs/superpowers/specs/CODEX-FINDINGS-RETIRE-WINDOW-415.md+38 −0docs/superpowers/specs/CODEX-REVIEW-BRIEF-RETIRE-WINDOW-415.md+94 −0internal/console/deletion_evidence_test.go+264 −0internal/console/lifetimes_create.go+4 −6internal/console/lifetimes_create_test.go+1 −0internal/console/lifetimes_migrate.go+1 −1internal/console/lifetimes_purge.go+1 −0internal/console/lifetimes_retire.go+5 −1internal/console/remoteinstances.go+19 −4internal/console/server_test.go+1 −0internal/console/view_test.go+6 −0internal/provision/plan9_b8_census_test.go+1 −1internal/provision/retire_window_415_census_test.go+45 −0
CI passed — run details
diff --git a/docs/superpowers/specs/CODEX-FINDINGS-RETIRE-WINDOW-415.md b/docs/superpowers/specs/CODEX-FINDINGS-RETIRE-WINDOW-415.md| new file mode 100644 |
| index 000000000..a87fffec3 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-FINDINGS-RETIRE-WINDOW-415.md |
| @@ -0,0 +1,38 @@ |
| +Reviewed `origin/main...3a23d0947e5793a9167cad5fb73f133466ee385a`, round 1. |
| + |
| +The six record-write census entries are **approved**. Their fingerprints match the source; no class changes or new storage writes were introduced. |
| + |
| +| Unit | Verdict and evidence | |
| +|---|---| |
| +| `allocCleanLocked` | **Approve — key-site.** Both deletes retain their keys and ETags. Previous-owner evidence uses `plan.ownerAccount/ownerApp`. [lifetimes_create.go:324](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_create.go:324) | |
| +| `allocPrevOwnerCleanLocked` | **Approve — key-site.** Account/app come from parsing `PrevOwnerKey`; deletion retains that key and `prev.ETag`. [lifetimes_create.go:353](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_create.go:353) | |
| +| `deleteUnderRetiredSlot` | **Approve — key-site.** Same retirement-owned key, slot checks and observed ETag. [lifetimes_create.go:533](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_create.go:533) | |
| +| `migrationStepsLocked` | **Approve — key-site.** Corrupt-body deletion retains the migration’s key and `obs.ETag`; quarantine ordering is unchanged. [lifetimes_migrate.go:224](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_migrate.go:224) | |
| +| `retireStaleLocked` | **Approve — key-site.** Same account/app-derived key and conditional delete. [lifetimes_retire.go:202](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_retire.go:202) | |
| +| `retirementStepsLocked` | **Approve — record-writer.** Adds an in-memory note before dispatch; the existing tombstone `WriteRecord` and conditional removal remain unchanged. [lifetimes_retire.go:233](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_retire.go:233), [lifetimes_retire.go:314](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_retire.go:314) | |
| + |
| +Detach and normal/cleanup recovery reach the noted retirement dispatcher. Orphan recovery, allocation recovery and migration cleanup reach the noted delete helper. Every helper call passes the deleted key’s own account/app. Existing instance, sidecar, seed-finish, owner-purge and early-expiry-purge paths already note deletion. Claims are treated as shelved and inert, as the brief specifies. |
| + |
| +Adding `domain-detach` only introduces another refusal condition; it removes no existing check. The witness’s mutex and `done` flag prevent background deletes from calling `t.Errorf` after cleanup. |
| + |
| +**P1: none found.** |
| + |
| +**P2 — Coverage: the lifetimes-off hourly trash sweep still deletes records without noting them.** |
| +At [lifetimes_purge.go:231](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/lifetimes_purge.go:231), `sweepTrashedApp` calls `release.PurgeAppIfTrashedAt` directly. Unlike `purgeOne`, this path has no preceding note. The release sweep deletes every app key, including instance and sidecar records, at [trash.go:376](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/release/trash.go:376). |
| + |
| +An expired app swept with lifetimes off therefore loses records without updating deletion evidence or invalidating cached ownership facts. This is an existing omission left unresolved by the promised complete coverage. Add `noteRecordDeletion(a.Account, a.App, time.Now())` before the purge dispatch and cover the lifetimes-off hourly sweep. |
| + |
| +Fault family: every console record deletion must record evidence for its owning app before storage changes. |
| + |
| +**P2 — Witness: helper deletes bypass verification entirely.** |
| +[deletion_evidence_test.go:100](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/deletion_evidence_test.go:100) identifies `deleteRecordIfMatch` as `helper`; [deletion_evidence_test.go:43](/home/paulca/.cache/tmp/claude-1001/fu/retire-window-all-deletes-415/internal/console/deletion_evidence_test.go:43) then returns before checking evidence. |
| + |
| +Consequently, removing the helper’s note—or passing the wrong account/app during previous-owner cleanup—would escape this witness. The restart accommodation exempts these deletes even on the original server. Associate observations with the server performing the delete, including restarted servers, and remove the exemption. Verify that missing-note and wrong-owner mutations fail. |
| + |
| +Fault family: the deletion witness must independently check evidence at the storage boundary. |
| + |
| +**P3: none found.** |
| + |
| +By code tracing, the two new tests exercise the intended regression: the first clears audit evidence, while the second uses a fresh server and disables its startup hold. Main lacks the respective memory and audit evidence. Execution remains unverified: the targeted test command failed before compilation because the sandbox cannot create Go’s work directory. No full suites ran; the root-read census pass was not independently reproduced. `git diff --check` passed. No files changed. |
| + |
| +READY AFTER FIXES |
| \ No newline at end of file |
diff --git a/docs/superpowers/specs/CODEX-REVIEW-BRIEF-RETIRE-WINDOW-415.md b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-RETIRE-WINDOW-415.md| new file mode 100644 |
| index 000000000..3967d3925 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/CODEX-REVIEW-BRIEF-RETIRE-WINDOW-415.md |
| @@ -0,0 +1,94 @@ |
| +# Review brief: branch retire-window-all-deletes-415, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `retire-window-all-deletes-415`, commit named |
| +in the prompt (the tip that adds this brief). |
| +Under review: the diff `origin/main...HEAD` (console-only: internal/console). |
| +Authorities: discussion #415 (the gap), the canary-retire guard as merged on |
| +main (`retireUnsettled`, `recentRecordDeletion`, `noteRecordDeletion` in |
| +`internal/console/remoteinstances.go`; `channelHosts` and |
| +`handleRetireCanary` in `internal/console/server.go`), and the lifetime |
| +retirement protocol as merged (`internal/console/lifetimes_retire.go`, |
| +`lifetimes_create.go`, `lifetimes_recovery.go`, `lifetimes_migrate.go`). |
| +Do not review against unmerged branches; if this work needs one, say so as |
| +a P1 and stop. A sibling branch, `retire-app-lock-407`, is NOT an authority |
| +here. |
| + |
| +You are an independent reviewer. Read the diff, then the code it names, |
| +and check every claim against that code. |
| + |
| +## Fixed: do not re-argue |
| + |
| +- Paul accepted the canary-retire guard's shape and its 15-minute window |
| + (`channelSettle`) on 2026-10-25 (#280, #407). The guard refuses while any |
| + record of the app changed or was deleted within the window. Report only |
| + mechanisms that fail to honour it. |
| +- The deletion evidence is in-process memory (`deletions`) plus the audit |
| + log for another console process. "One console per deployment bucket" is |
| + the deployment assumption (`applocks.go`). Do not ask for a persisted |
| + deletion ledger. |
| +- Over-refusing a retire (holding one that had nothing to wait for) is |
| + acceptable; letting one through early is not. |
| + |
| +## What to check |
| + |
| +1. **Coverage.** Every console path that deletes an instance or sidecar |
| + record, or turns one into a tombstone, now notes the deletion for the |
| + record's own account and app before the bucket sees it. Name any path |
| + that still does not, with file:line: detach (`detachRetireLocked`), |
| + recovery (`lifetimeRecoveryIteration` and its `recover*Locked`), the |
| + allocation's previous-owner cleanup (`allocCleanLocked`, |
| + `allocPrevOwnerCleanLocked`), `deleteUnderRetiredSlot`, `retireStaleLocked`, |
| + the migration's corrupt-body delete, and anything outside the lifetime |
| + files (claims are shelved and inert; say so if you rely on that). |
| +2. **The right app.** `deleteRecordIfMatch` notes `(acct, app)` as passed. |
| + Check every call passes the key's own account and app, in particular |
| + the previous owner's (`plan.ownerAccount/ownerApp`, and the parsed |
| + `PrevOwnerKey`). |
| +3. **The audit half.** `recentRecordDeletion` now also treats a |
| + `domain-detach` audit row inside the window as a deletion. Confirm that |
| + only adds refusals and cannot let a retire through. |
| +4. **The witness** (`internal/console/deletion_evidence_test.go`, installed |
| + by `newConsoleFixtureWith`): does it really fail a test whose console |
| + code deletes a record key without a fresh note? Can its caller |
| + classification (`deletingCaller`, `isStoreMethod`) skip a console-made |
| + delete, so that a missing note would go unseen? Is it safe with |
| + background goroutines that outlive a test? |
| +5. **The record-write census (9B8).** `internal/provision/retire_window_415_census_test.go` |
| + re-pins six console units with the classes they had. You decide it (AGENTS.md, |
| + "The census", and #280 2026-10-26: the reviewer decides every class). |
| + Give a verdict per unit, approve or reject, citing the lines: same key, |
| + same ETag-conditional delete, no new write, class unchanged. The |
| + root-read census does not apply: `internal/console` is outside its |
| + scope since C2 (7c9e9d6a), and `TestPlan14RootReadCensus` passes. |
| +6. **The new tests** (`TestRetireWaitsAfterLifetimeDetach` and |
| + `...OnAnotherConsole`): do they fail on main's code for the stated |
| + reason, and pass on this branch for the right one? |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. |
| + Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. (The |
| + census, and review of any newly changed security, root, termination |
| + or production-storage behaviour, still check the fix; see AGENTS.md, |
| + "Stopping rules".) |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for |
| + another round. |
| + |
| +A P1 states its failure scenario and the evidence (file:line). Do not |
| +raise a P2 to P1 to keep the review open. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3. Each gives the section or task, the problem, |
| +the evidence (file:line, verified), the failure scenario, a concrete |
| +fix and the invariant or trust boundary it breaks (that is its fault |
| +family). End with exactly one verdict: |
| + |
| +- **READY**: no P1 and no P2. |
| +- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another |
| + round. |
| +- **NOT READY**: one or more P1s, listed. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of |
| +your own. Do not run the full test suites. |
diff --git a/internal/console/deletion_evidence_test.go b/internal/console/deletion_evidence_test.go| new file mode 100644 |
| index 000000000..a92ab097a |
| --- /dev/null |
| +++ b/internal/console/deletion_evidence_test.go |
| @@ -0,0 +1,264 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "net/http" |
| + "os" |
| + "path/filepath" |
| + "runtime" |
| + "slices" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// witnessDeletionEvidence checks, in every console fixture, the invariant |
| +// the canary-retire guard rests on (#415): the console notes the deletion |
| +// of an instance or sidecar record (noteRecordDeletion) before the delete |
| +// reaches the bucket, whichever path deletes it. A delete the test itself |
| +// makes (a frame in a _test.go file calls the store directly) is a delete |
| +// behind the console's back and is not checked. A violation fails the test |
| +// when it ends, naming the key and the console function that deleted it. |
| +func witnessDeletionEvidence(t *testing.T, srv *Server, rel release.Store) { |
| + t.Helper() |
| + ds, ok := rel.(*deletableStore) |
| + if !ok { |
| + return |
| + } |
| + var ( |
| + mu sync.Mutex |
| + done bool |
| + violations []string |
| + ) |
| + w := func(key string) { |
| + acct, app, ok := recordOwnerOfKey(key) |
| + if !ok { |
| + return |
| + } |
| + caller, console := deletingCaller() |
| + if !console || witnessNoted(ds, acct, app) { |
| + return |
| + } |
| + mu.Lock() |
| + defer mu.Unlock() |
| + if !done { |
| + violations = append(violations, key+" deleted by "+caller+" with no deletion evidence for "+acct+"/"+app) |
| + } |
| + } |
| + witnessServer(t, ds, srv) |
| + ds.witness.Store(&w) |
| + t.Cleanup(func() { |
| + mu.Lock() |
| + defer mu.Unlock() |
| + done = true |
| + for _, v := range violations { |
| + t.Errorf("deletion evidence (#415): %s", v) |
| + } |
| + }) |
| +} |
| + |
| +// recordOwnerOfKey is the account and app of an instance or sidecar record |
| +// key: apps/<acct>/<app>/{instances,sidecars}/<name>.json. |
| +func recordOwnerOfKey(key string) (acct, app string, ok bool) { |
| + parts := strings.Split(key, "/") |
| + if len(parts) != 5 || parts[0] != "apps" || (parts[3] != "instances" && parts[3] != "sidecars") || |
| + !strings.HasSuffix(parts[4], ".json") || parts[4] == ".json" { |
| + return "", "", false |
| + } |
| + return parts[1], parts[2], true |
| +} |
| + |
| +// witnessServers is every console a test built over a fixture's bucket: |
| +// the fixture's own, and a second one (ltOn.restart) over the same bucket. |
| +// A delete counts as noted when any of them noted its account and app, |
| +// since the witness cannot tell which server made the delete. |
| +var witnessServers sync.Map // *deletableStore -> *[]*Server, under witnessServersMu |
| + |
| +var witnessServersMu sync.Mutex |
| + |
| +// witnessServer adds srv to the servers rel's witness reads, until the |
| +// test ends. |
| +func witnessServer(t *testing.T, rel release.Store, srv *Server) { |
| + ds, ok := rel.(*deletableStore) |
| + if !ok { |
| + return |
| + } |
| + witnessServersMu.Lock() |
| + defer witnessServersMu.Unlock() |
| + v, _ := witnessServers.LoadOrStore(ds, &[]*Server{}) |
| + list := v.(*[]*Server) |
| + *list = append(*list, srv) |
| + t.Cleanup(func() { |
| + witnessServersMu.Lock() |
| + defer witnessServersMu.Unlock() |
| + *list = slices.DeleteFunc(*list, func(x *Server) bool { return x == srv }) |
| + }) |
| +} |
| + |
| +// witnessNoted reports whether any console over ds noted a deletion of |
| +// acct/app within the window. |
| +func witnessNoted(ds *deletableStore, acct, app string) bool { |
| + witnessServersMu.Lock() |
| + defer witnessServersMu.Unlock() |
| + v, ok := witnessServers.Load(ds) |
| + if !ok { |
| + return false |
| + } |
| + for _, srv := range *v.(*[]*Server) { |
| + if srv.recentlyDeleted(acct, app, time.Now()) { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// deletingCaller walks the delete's stack, past the store doubles and any |
| +// other package (release, provision, hostops), to the first frame in |
| +// internal/console, and reports its function and whether it is console code. |
| +// A _test.go frame reached first is the test deleting behind the console's |
| +// back; a test wrapper's own Delete or DeleteIfMatch passes the console's |
| +// delete on and is walked past. |
| +func deletingCaller() (string, bool) { |
| + pcs := make([]uintptr, 64) |
| + n := runtime.Callers(3, pcs) |
| + frames := runtime.CallersFrames(pcs[:n]) |
| + for { |
| + f, more := frames.Next() |
| + switch { |
| + case strings.HasSuffix(f.File, "/internal/console/deletion_evidence_test.go"), |
| + strings.HasSuffix(f.File, "/internal/console/view_test.go"): |
| + case strings.HasSuffix(f.File, "_test.go") && isStoreMethod(f.Function): |
| + // A test's store wrapper passing the console's delete on. |
| + case strings.HasSuffix(f.File, "_test.go"): |
| + return f.Function, false |
| + case strings.Contains(f.File, "/internal/console/"): |
| + return f.Function, true |
| + } |
| + if !more { |
| + return "", false |
| + } |
| + } |
| +} |
| + |
| +// isStoreMethod reports whether fn is a delete method of some type (a |
| +// test's wrapper around the fixture's bucket). Only the deletes: a |
| +// wrapper's Get or List that deletes something is the test's own doing. |
| +func isStoreMethod(fn string) bool { |
| + parts := strings.Split(fn[strings.LastIndex(fn, "/")+1:], ".") |
| + if len(parts) < 3 { |
| + return false // a plain function, not a method |
| + } |
| + switch parts[len(parts)-1] { |
| + case "Delete", "DeleteIfMatch": |
| + return true |
| + } |
| + return false |
| +} |
| + |
| +// lifetimeDetachedApp attaches ltDomain to shop as a first route with |
| +// lifetimes on (a record of its own), ages every record past the window, |
| +// forgets the console's deletion notes, checks the app reads as settled, |
| +// then detaches the domain through the API door. |
| +func lifetimeDetachedApp(t *testing.T) ltOn { |
| + t.Helper() |
| + l := newLtOn(t) |
| + l.fx.srv.cfg.Releases = ltModStore{l.bucket} |
| + ctx := context.Background() |
| + code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member, |
| + `{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`) |
| + if code != http.StatusOK { |
| + t.Fatalf("attach = %d %s", code, body) |
| + } |
| + root := l.fx.rel.(*deletableStore).root |
| + old := time.Now().Add(-channelSettle - time.Minute) |
| + keys, err := l.fx.rel.List(ctx, provision.RecordsPrefix("bab", ltApp)) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, k := range keys { |
| + if err := os.Chtimes(filepath.Join(root, k), old, old); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + l.fx.srv.deletionsMu.Lock() |
| + l.fx.srv.deletions = nil |
| + l.fx.srv.deletionsMu.Unlock() |
| + if _, err := l.fx.srv.channelHosts(ctx, "bab", ltApp, "canary/x"); err != nil { |
| + t.Fatalf("fixture: a still app = %v", err) |
| + } |
| + if code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, ""); code != http.StatusOK { |
| + t.Fatalf("detach = %d %s", code, body) |
| + } |
| + if raw, _ := rawOf(t, l.fx.rel, ltApp, ltDomain); raw != nil { |
| + t.Fatal("the record outlived the detach") |
| + } |
| + return l |
| +} |
| + |
| +// #415: a domain detach with lifetimes on removes its record through the |
| +// lifetime retirement steps, not retireHostRecord. The canary-retire guard |
| +// still waits out the window afterwards, with no audit row to lean on and |
| +// nothing left in the bucket to date the deletion. |
| +func TestRetireWaitsAfterLifetimeDetach(t *testing.T) { |
| + l := lifetimeDetachedApp(t) |
| + if _, err := l.fx.st.db.Exec(`DELETE FROM audit`); err != nil { |
| + t.Fatal(err) |
| + } |
| + _, err := l.fx.srv.channelHosts(context.Background(), "bab", ltApp, "canary/x") |
| + if !errorsIsUnsettled(err) || !strings.Contains(err.Error(), "deleted") { |
| + t.Fatalf("right after a lifetime detach = %v, want unsettled (deleted)", err) |
| + } |
| +} |
| + |
| +// #415: another console process over the same database has no notes in |
| +// memory; the detach's audit row dates the deletion for it. |
| +func TestRetireWaitsAfterLifetimeDetachOnAnotherConsole(t *testing.T) { |
| + l := lifetimeDetachedApp(t) |
| + srv := l.restart(t) |
| + srv.startedAt = time.Now().Add(-24 * time.Hour) |
| + _, err := srv.channelHosts(context.Background(), "bab", ltApp, "canary/x") |
| + if !errorsIsUnsettled(err) || !strings.Contains(err.Error(), "deleted") { |
| + t.Fatalf("a second console right after a lifetime detach = %v, want unsettled (deleted)", err) |
| + } |
| +} |
| + |
| +// ltModStore is the lifetimes bucket with the modification-time listing |
| +// every production store offers, which the canary-retire guard needs. |
| +type ltModStore struct{ *ltStore } |
| + |
| +func (s ltModStore) ListMod(ctx context.Context, prefix string) ([]release.KeyMod, error) { |
| + ml, ok := s.ltStore.Store.(release.ModLister) |
| + if !ok { |
| + return nil, errors.New("ltModStore: the wrapped store has no ListMod") |
| + } |
| + return ml.ListMod(ctx, prefix) |
| +} |
| + |
| +// #415 review (Astra round 1, P2 1): the hourly trash sweep with lifetimes |
| +// off purges an expired app's records through the release sweep; it notes |
| +// the deletion first, like every other path. |
| +func TestTrashSweepNotesTheRecordsItPurges(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + ctx := context.Background() |
| + now := time.Now() |
| + rec := provision.Record{Schema: 1, Host: "one.kass.example.com", Slug: "one", App: "kass", |
| + Account: release.OpsAccount, Channel: "stable", CreatedAt: now.Add(-48 * time.Hour)} |
| + if err := provision.CreateRecord(ctx, fx.rel, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := release.TrashApp(ctx, fx.rel, release.OpsAccount, "kass", "test", now.Add(-release.TrashCooloff-time.Hour)); err != nil { |
| + t.Fatal(err) |
| + } |
| + fx.srv.trashSweep(ctx, now) |
| + if _, _, err := fx.rel.Get(ctx, provision.RecordKey(release.OpsAccount, "kass", rec.Host)); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("the record after the sweep = %v, want it purged", err) |
| + } |
| + if !fx.srv.recentlyDeleted(release.OpsAccount, "kass", time.Now()) { |
| + t.Fatal("the sweep purged a record without noting the deletion") |
| + } |
| +} |
diff --git a/internal/console/lifetimes_create.go b/internal/console/lifetimes_create.go| index b7921bb0b..b615a7f0d 100644 |
| --- a/internal/console/lifetimes_create.go |
| +++ b/internal/console/lifetimes_create.go |
| @@ -10,7 +10,6 @@ import ( |
| "net/http" |
| "os" |
| "strings" |
| - "time" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -322,15 +321,14 @@ func (s *Server) allocSlotLocked(ctx context.Context, a Allocation) error { |
| // Any failure, a conflict included, leaves the allocation pending. |
| func (s *Server) allocCleanLocked(ctx context.Context, a Allocation, staleETag string, plan createPlan) error { |
| if staleETag != "" { |
| - s.noteRecordDeletion(a.Account, a.App, time.Now()) // the canary-retire guard's evidence, first |
| - if err := release.DeleteIfMatch(ctx, s.cfg.Releases, provision.RecordKey(a.Account, a.App, a.Host), staleETag); err != nil { |
| + if err := s.deleteRecordIfMatch(ctx, a.Account, a.App, provision.RecordKey(a.Account, a.App, a.Host), staleETag); err != nil { |
| log.Printf("console: lifetimes: allocation %s of %s: remove the stale record: %v (pending)", a.OpID, a.Host, err) |
| return errLifetimePending |
| } |
| } |
| if plan.ownerStaleETag != "" { |
| key := provision.RecordKey(plan.ownerAccount, plan.ownerApp, a.Host) |
| - if err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, plan.ownerStaleETag); err != nil { |
| + if err := s.deleteRecordIfMatch(ctx, plan.ownerAccount, plan.ownerApp, key, plan.ownerStaleETag); err != nil { |
| log.Printf("console: lifetimes: allocation %s of %s: remove the stale record under %s/%s: %v (pending)", |
| a.OpID, a.Host, plan.ownerAccount, plan.ownerApp, err) |
| return errLifetimePending |
| @@ -369,7 +367,7 @@ func (s *Server) allocPrevOwnerCleanLocked(ctx context.Context, a Allocation) er |
| s.lifetimeLogHourly(logKey, "console: lifetime recovery: allocation %s of %s: the slot moved while removing the previous owner's record (pending)", a.OpID, a.Host) |
| return errLifetimePending |
| } |
| - if err := release.DeleteIfMatch(ctx, s.cfg.Releases, a.PrevOwnerKey, prev.ETag); err != nil { |
| + if err := s.deleteRecordIfMatch(ctx, acct, app, a.PrevOwnerKey, prev.ETag); err != nil { |
| s.lifetimeLogHourly(logKey, "console: lifetime recovery: allocation %s of %s: remove the stale record %s: %v (pending)", a.OpID, a.Host, a.PrevOwnerKey, err) |
| return errLifetimePending |
| } |
| @@ -546,7 +544,7 @@ func (s *Server) deleteUnderRetiredSlot(ctx context.Context, r Retirement, again |
| log.Printf("console: lifetimes: retirement %s of %s: the slot moved on (%+v); the body under %s is not this retirement's to remove", r.OpID, r.Host, slot, key) |
| return nil |
| } |
| - err = release.DeleteIfMatch(ctx, s.cfg.Releases, key, obs.ETag) |
| + err = s.deleteRecordIfMatch(ctx, r.Account, r.App, key, obs.ETag) |
| switch { |
| case err == nil, !errors.Is(err, release.ErrCASConflict): |
| return err |
diff --git a/internal/console/lifetimes_create_test.go b/internal/console/lifetimes_create_test.go| index 954a6c277..d693cbcb5 100644 |
| --- a/internal/console/lifetimes_create_test.go |
| +++ b/internal/console/lifetimes_create_test.go |
| @@ -235,6 +235,7 @@ func (l ltOn) restart(t *testing.T) *Server { |
| if err != nil { |
| t.Fatal(err) |
| } |
| + witnessServer(t, l.fx.rel, srv) // its deletion notes count too (#415) |
| ctx := context.Background() |
| srv.lifetimesWatchOnce(ctx) |
| l.clock.Advance(lifetimeSettle) |
diff --git a/internal/console/lifetimes_migrate.go b/internal/console/lifetimes_migrate.go| index 100197505..fcc70d134 100644 |
| --- a/internal/console/lifetimes_migrate.go |
| +++ b/internal/console/lifetimes_migrate.go |
| @@ -221,7 +221,7 @@ func (s *Server) migrationStepsLocked(ctx context.Context, m Migration) (*provis |
| logf("quarantine the corrupt body: %v (pending)", err) |
| return migrationPending() |
| } |
| - err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, obs.ETag) |
| + err := s.deleteRecordIfMatch(ctx, m.Account, m.App, key, obs.ETag) |
| if errors.Is(err, release.ErrCASConflict) { |
| continue |
| } |
diff --git a/internal/console/lifetimes_purge.go b/internal/console/lifetimes_purge.go| index 460e858b2..68eed0704 100644 |
| --- a/internal/console/lifetimes_purge.go |
| +++ b/internal/console/lifetimes_purge.go |
| @@ -228,6 +228,7 @@ func (s *Server) sweepTrashedApp(ctx context.Context, a release.TrashedApp, now |
| if lifetimesUnit(ctx) { |
| err = s.purgeAppWithLifetimes(ctx, a.Account, a.App, tomb.DeletedAt, now) |
| } else { |
| + s.noteRecordDeletion(a.Account, a.App, time.Now()) // the canary-retire guard's evidence, first (#415) |
| err = release.PurgeAppIfTrashedAt(ctx, s.cfg.Releases, s.cfg.ReleasePub, a.Account, a.App, tomb.DeletedAt, now) |
| } |
| if err != nil { |
diff --git a/internal/console/lifetimes_retire.go b/internal/console/lifetimes_retire.go| index 8bb2c3165..d8399e549 100644 |
| --- a/internal/console/lifetimes_retire.go |
| +++ b/internal/console/lifetimes_retire.go |
| @@ -199,7 +199,7 @@ func (s *Server) retireStaleLocked(ctx context.Context, acct, app, host string, |
| } |
| return s.retirementStepsLocked(ctx, r) |
| } |
| - switch err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, obs.ETag); { |
| + switch err := s.deleteRecordIfMatch(ctx, acct, app, key, obs.ETag); { |
| case err == nil: |
| return nil |
| case errors.Is(err, release.ErrCASConflict): |
| @@ -227,6 +227,10 @@ func (s *Server) retireStaleLocked(ctx context.Context, acct, app, host string, |
| // |
| // A failed write or re-read is pending, never a terminal branch. |
| func (s *Server) retirementStepsLocked(ctx context.Context, r Retirement) error { |
| + // The canary-retire guard's evidence, first: N1 turns the record into |
| + // its tombstone, which every reader takes as gone, and recovery enters |
| + // here with no wrapper of its own (#415). |
| + s.noteRecordDeletion(r.Account, r.App, time.Now()) |
| key := provision.RecordKey(r.Account, r.App, r.Host) |
| logf := func(format string, args ...any) { |
| log.Printf("console: lifetimes: retirement %s (%s) of %s: "+format, append([]any{r.OpID, r.Kind, r.Host}, args...)...) |
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go| index d7096fdf0..129af891d 100644 |
| --- a/internal/console/remoteinstances.go |
| +++ b/internal/console/remoteinstances.go |
| @@ -563,9 +563,11 @@ var errRetireUnsettled = errors.New("the app's instances have not settled") |
| // every console path that deletes a record notes the app in memory |
| // before deleting (noteRecordDeletion: retireHostRecord, |
| // retireClaimHostRecord, deleteRead, finishSeedOnce, the owner's purge, |
| -// the claim purge and the expiry purge), |
| -// and the console refuses for channelSettle after it starts; the audit |
| -// log is read too; |
| +// the claim purge, the expiry purge, every lifetime retirement step |
| +// (retirementStepsLocked, which detach and recovery reach too) and |
| +// every lifetime delete of a stale body, the previous owner's included |
| +// (deleteRecordIfMatch)), 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 (its rollout entry) for |
| // a host no record names: a route still up after its record was |
| @@ -696,6 +698,16 @@ func (s *Server) noteRecordDeletion(acct, app string, at time.Time) { |
| s.boxReports.invalidate() |
| } |
| +// deleteRecordIfMatch is the conditional delete of an instance record |
| +// (key, a record key of acct/app) for every path that removes one: the |
| +// deletion is noted for the canary-retire guard first (noteRecordDeletion), |
| +// then the key is deleted on its ETag. A note for a delete that then fails |
| +// costs at most one refused retire for channelSettle. |
| +func (s *Server) deleteRecordIfMatch(ctx context.Context, acct, app, key, etag string) error { |
| + s.noteRecordDeletion(acct, app, time.Now()) |
| + return release.DeleteIfMatch(ctx, s.cfg.Releases, key, etag) |
| +} |
| + |
| // recentlyDeleted reports whether the console began deleting a record of |
| // acct/app within channelSettle. |
| func (s *Server) recentlyDeleted(acct, app string, now time.Time) bool { |
| @@ -737,7 +749,10 @@ func (s *Server) recentRecordDeletion(acct, app string, now time.Time) error { |
| if now.Sub(e.CreatedAt) >= channelSettle { |
| return nil // newest first: nothing older can be recent |
| } |
| - if e.Action == "instance-delete" || e.Action == "sidecar-delete" { |
| + // domain-detach: a detach of a first-route domain retires that |
| + // route's record (#415). Not every detach does, so this can hold a |
| + // retire that had nothing to wait for; it never lets one through. |
| + if e.Action == "instance-delete" || e.Action == "sidecar-delete" || e.Action == "domain-detach" { |
| return fmt.Errorf("%w: %s deleted %s ago", errRetireUnsettled, e.Target, now.Sub(e.CreatedAt).Round(time.Second)) |
| } |
| } |
diff --git a/internal/console/server_test.go b/internal/console/server_test.go| index 81cf29554..74dfa038f 100644 |
| --- a/internal/console/server_test.go |
| +++ b/internal/console/server_test.go |
| @@ -162,6 +162,7 @@ func newConsoleFixtureWith(t *testing.T, o consoleFixtureOptions) *consoleFixtur |
| if _, err := st.CreateAppIn(OpsAccountID, "kass", "paul@keymail.dev", time.Now()); err != nil { |
| t.Fatal(err) |
| } |
| + witnessDeletionEvidence(t, srv, relStore) |
| return &consoleFixture{ts: ts, srv: srv, st: st, fk: fk, rel: relStore, regPath: regPath, |
| priv: priv, pub: pub, sqid: release.OpsAccount} |
| } |
diff --git a/internal/console/view_test.go b/internal/console/view_test.go| index e1d2d7545..9336bc05c 100644 |
| --- a/internal/console/view_test.go |
| +++ b/internal/console/view_test.go |
| @@ -38,6 +38,9 @@ type deletableStore struct { |
| // returns fails the read there. Set with setGetHook, safely while the |
| // server runs. |
| getHook atomic.Pointer[func(ctx context.Context, key string) error] |
| + // witness, when set, sees each Delete and DeleteIfMatch before the hook |
| + // above: newConsoleFixtureWith's deletion-evidence check (#415). |
| + witness atomic.Pointer[func(key string)] |
| } |
| func (d *deletableStore) setGetHook(h func(ctx context.Context, key string) error) { |
| @@ -58,6 +61,9 @@ func (d *deletableStore) setDeleteHook(h func(ctx context.Context, key string) e |
| } |
| func (d *deletableStore) runDeleteHook(ctx context.Context, key string) error { |
| + if w := d.witness.Load(); w != nil && *w != nil { |
| + (*w)(key) |
| + } |
| if h := d.deleteHook.Load(); h != nil && *h != nil { |
| return (*h)(ctx, key) |
| } |
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go| index 559438935..c96e00e55 100644 |
| --- a/internal/provision/plan9_b8_census_test.go |
| +++ b/internal/provision/plan9_b8_census_test.go |
| @@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) { |
| if len(got) < 100 { |
| t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root) |
| } |
| - inventory := edgeAssetCache3WriteCensusInventory() |
| + inventory := retireWindow415WriteCensusInventory() |
| problems := append(censusDiff(inventory, got), censusPolicy(inventory)...) |
| if len(problems) > 0 { |
| t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n ")) |
diff --git a/internal/provision/retire_window_415_census_test.go b/internal/provision/retire_window_415_census_test.go| new file mode 100644 |
| index 000000000..ae262965d |
| --- /dev/null |
| +++ b/internal/provision/retire_window_415_census_test.go |
| @@ -0,0 +1,45 @@ |
| +package provision |
| + |
| +// Record-write census entries for retire-window-all-deletes-415 (#415: every |
| +// console record delete marks the canary-retire guard's window), layered on |
| +// edgeAssetCache3WriteCensusInventory (main's newest at 76bd4d3a). Reviewed by |
| +// the branch author and the cross-model reviewer (Astra) with the branch. |
| +// No record write is added and no class changes: each unit below deletes |
| +// the same key on the same ETag as before, now through |
| +// Server.deleteRecordIfMatch, which first notes the record's account and |
| +// app in the console's in-memory deletion log (noteRecordDeletion), then |
| +// calls release.DeleteIfMatch exactly as the unit did. |
| +// - Server.allocCleanLocked: both stale bodies (its own key, and the |
| +// previous owner's under plan.ownerAccount/ownerApp) through |
| +// deleteRecordIfMatch; the inline note it had is folded into it. |
| +// - Server.allocPrevOwnerCleanLocked: the previous owner's stale body, |
| +// noted under the account and app parsed from PrevOwnerKey. |
| +// - Server.deleteUnderRetiredSlot, Server.retireStaleLocked and |
| +// Server.migrationStepsLocked (the corrupt body): the same deletes, |
| +// through deleteRecordIfMatch. |
| +// - Server.retirementStepsLocked notes the deletion at entry (its N1 |
| +// tombstone write, which detach and recovery both reach); its writes |
| +// are unchanged: record-writer through WriteRecord, as before. |
| +func retireWindow415WriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), edgeAssetCache3WriteCensusInventory()...) |
| + replacements := []censusEntry{ |
| + {"internal/console/lifetimes_create.go", "Server.allocCleanLocked", "key-site", "key:RecordKey", "cc587263d87180aad2bbef56f4a4bd94fcf15e57689a56af349cc25e11d6cfd0"}, |
| + {"internal/console/lifetimes_create.go", "Server.allocPrevOwnerCleanLocked", "key-site", "key:ParseRecordKey", "a7234b19c973c64cf871b28bbb7919ea551424b02f54c2ac8ddb5fcb87ef16c3"}, |
| + {"internal/console/lifetimes_create.go", "Server.deleteUnderRetiredSlot", "key-site", "key:RecordKey", "3e98113f58a05931ad03589092b21c6950f8cb40fd2fe5797dea8d0bb7cd6305"}, |
| + {"internal/console/lifetimes_migrate.go", "Server.migrationStepsLocked", "key-site", "key:RecordKey", "4170f91be275bbc4d3d146e432636d53f28dbaf9fe6fb11c46607f9d6de1a224"}, |
| + {"internal/console/lifetimes_retire.go", "Server.retireStaleLocked", "key-site", "key:RecordKey", "3282374a0741dc30178ce64592d80484f6795890c2fb4fc3e6a84a54c7316f5a"}, |
| + {"internal/console/lifetimes_retire.go", "Server.retirementStepsLocked", "record-writer", "key:RecordKey,key:WriteRecord", "6b5e6a9f75006a111b926f8cc96c014c77a1814db7451df49c9a932c8a506d8d"}, |
| + } |
| + for _, r := range replacements { |
| + found := false |
| + for i, e := range entries { |
| + if e.File == r.File && e.Unit == r.Unit { |
| + entries[i], found = r, true |
| + } |
| + } |
| + if !found { |
| + panic("retire-window-415 replacement of an unlisted unit " + r.File + ":" + r.Unit) |
| + } |
| + } |
| + return entries |
| +} |