carlos / platform Public

console: narrow the enrollment failure comment; keep the #519 reviews

Astra r3 P3: only mode and target-read failures leave the registry as
it was; a registry add whose reply is lost leaves an active recorded
box for rotate-token. Adds the three Astra findings files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Human

Prompt

(Astra r3 P3 follow-up, no new prompt)

From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.

Summary

Comment-only fix for r3's P3; review findings filed.
claude agent, operated by paul@keymail.dev d6d7ea053edc2c169d358269ff98578aa7d88167 parent 90ab5c3
4 files changed, +176 −9
  • docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r1.md +46 −0
  • docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r2.md +56 −0
  • docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r3.md +64 −0
  • internal/console/hostsused.go +10 −9

CI passed — run details

diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r1.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r1.md
new file mode 100644
index 000000000..9cfd1e69a
--- /dev/null
+++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r1.md
@@ -0,0 +1,46 @@
+# fleet-examined-519 — review round 1 of 3
+
+Reviewed `5394c7f958e4c10f93c94f923211c0814680ff4d..c01c563008a4b92eed63982042f6045c2bac5923`. No earlier rounds were supplied. References below are to the reviewed tip. No repository files were changed.
+
+## P1 findings
+
+### 1. A new fleet identity does not establish that its storage is new or inventoried
+
+**Location:** `internal/console/hostsused.go:338–368`; the new paragraph in spec section 3.
+
+**Problem and verified evidence:** The only eligibility checks are absence from `Examined`/`Closed` and absence of a shared bucket with a recorded closed fleet. `rosterFleet` merely lists the bucket name and every non-detached box (`internal/console/hostsused_activate.go:161–175`); the caller then records all of them as examined. Fleet creation accepts a caller-supplied bucket after a name-shape check (`internal/console/fleets.go:214–259`), and `CreateFleet` inserts a registry row, not a newly provisioned empty bucket (`internal/registry/fleets.go:253–277`). Box registration also inserts or reactivates a logical identity; it does not prove that the machine or its data directory is new (`internal/registry/fleets.go:441–501`). Thus even a genuinely post-activation fleet can point at pre-existing storage absent from the activation roster.
+
+**Failure scenario:** A bucket outside the activation roster contains a current replica for a deleted, pre-history hostname H, with no surviving record or mark. After activation, create fleet F naming that bucket and add its first box. The bucket is not in `Closed`, so this change declares it examined without importing H. Creating H on F now succeeds. The reader still restores from the configured bucket and hostname prefix (`internal/activator/backend_exec.go:1001`; `internal/activator/activator.go:150–153`), so the new record can read the earlier replica. The closed-bucket exclusion does not cover this case.
+
+The stronger claim that an unrecorded fleet must itself be new is also unsupported across registry changes. For example, activation can run against an older registry snapshot that omits F, followed by restoration of a snapshot containing F and its old boxes. Activation compares its roster with the registry visible during that command (`hostsused_activate.go:349–355`), but the start-up tripwire checks records and marks, not registry continuity (`hostsused_tripwire.go:44–87`). Adding one box then records every old non-detached box too. Previously S4 kept such a fleet unavailable.
+
+**Verification:** An additional local Go-overlay witness exercised the real fleet-create, add-box, app-create and instance-create HTTP doors. With a bucket absent from the activation roster and no inventory import, the instance door returned **201** and persisted `old.go.tito.io` on `fleet/classic`. This verifies the admission path; the old-replica read consequence above was checked in source, not against a live bucket.
+
+**Concrete fix:** Keep unproven targets unexamined and require the existing offline inventory. An online exception needs positive evidence that the actual readable storage is fresh or completely inventoried, bound to the fleet and activation; absence of a fleet name, its creation timestamp, or a new box label is insufficient. Add regression cases for an existing bucket and an old fleet reintroduced by a registry restore.
+
+**Invariant / fault family:** Inventory coverage before admission: no new data-kind record over earlier data that a box can still read.
+
+### 2. A committed mode write with a lost reply permanently strands the first-box operation
+
+**Location:** `internal/console/hostsused.go:350–372`.
+
+**Problem and verified evidence:** Any error from `WriteHostsState` detaches the new box, while retaining the old cached mode and ETag. A store error does not prove the PUT failed to commit: the S3 implementation returns the client error without resolving the stored outcome (`internal/release/store.go:992–1007`). `loadHostsLocked` does not refresh an already loaded mode (`hostsused.go:104–107`).
+
+**Failure scenario:** The mode PUT commits F into `Examined`, but its response is lost or the request times out. The handler detaches F's only box and returns 503 without its token. A retry reactivates the row, attempts the mode PUT with the stale ETag, receives a CAS conflict, and detaches it again. Subsequent new-fleet recordings in this process also use that stale ETag. Restarting reloads the committed state, but now N9 refuses reactivation because F is recorded (`hostsused.go:338–339`). Token rotation cannot repair the detached status (`internal/registry/fleets.go:524`). Recovering F requires the offline invalidate/inventory cycle that this change was intended to avoid.
+
+**Verification:** An additional Go-overlay witness wrapped the real store so the first mode PUT committed and then returned `context.DeadlineExceeded`. Through the real add-box HTTP door, the initial request returned 503, retry after the transient fault cleared returned **503/CAS conflict**, and retry after a mode-cache reload returned **409/N9**. The box was detached although the persisted mode examined its fleet. The witness failed its recovery assertion as expected.
+
+**Concrete fix:** Resolve an indeterminate mode write before detaching. Read back the state and ETag under the lock; if the intended recording committed, reconcile the cache and complete the operation without detaching its box. If read-back cannot establish the outcome, retain a recoverable pending operation rather than converting uncertainty into an irreversible N9 state. Cover committed-but-error, read-back failure and subsequent retry. The existing failure test only injects an error before the PUT (`hostsused_coverage_test.go:372`; `lifetimes_create_test.go:87–93`).
+
+**Invariant / fault family:** Recoverable enrollment across the registry and mode-store writes; a transient storage response failure must not leave an examined fleet with an unusable first box.
+
+## Other checks and validation
+
+- No separate P2 or P3 findings.
+- The requested targeted tests passed: `go test ./internal/console/ -run 'TestNewFleet|TestFleetGrowth' -count=1`.
+- The mutex serializes first-box recordings with each other and with in-process invalidation. The copied `Examined` slice and replacement `FleetTargets` map avoid mutating the cached state's containers; the carried target slices are not modified here. The ordinary successful-write path updates the cached ETag.
+- A pending start-up check still blocks data-kind admission through `admitDataCreate`; recording a fleet does not itself set `verified`. Recorded fleets still receive N9. Invalidated-mode additions are not marked examined by this function.
+- The added tests exercise real add-box requests, but call `gateDataCreate` directly for data admission and manually set `verified=true` after reset; they do not exercise a real start-up tripwire. The extra HTTP witness above checked the actual instance-create path.
+- No full test suite, production access or subagents were used. Temporary overlay sources and logs were removed after recording their results here.
+
+NOT READY
diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r2.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r2.md
new file mode 100644
index 000000000..c84638a67
--- /dev/null
+++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r2.md
@@ -0,0 +1,56 @@
+Round-1 P1 1: resolved by Paul's 2026-11-02 ruling; owner-named storage and pre-activation registry restores are accepted limits, stated in the code comment and spec section 3.
+Round-1 P1 2: partly resolved; read-back handles an already committed write, but a write that commits after the read-back snapshot can still strand enrollment.
+
+# fleet-examined-519 — review round 2 of 3
+
+Reviewed `5394c7f958e4c10f93c94f923211c0814680ff4d..bc8c1e2701d619f00581182313b8a46b556b93f5`, including the round-1 fixes from `c01c5630`. References are to that tip. No repository files were changed.
+
+## P1 findings
+
+### 1. An old read-back value does not settle an outstanding mode write
+
+**Problem and verified evidence:** `internal/console/hostsused.go:380–390` treats a read-back without the fleet in `Examined` as proof that the failed write did not land, then detaches its box through `undo` at lines 362–367. A transport error can leave the remote PUT outstanding. The GET can read the old value before that PUT commits, even with strongly consistent reads. The S3 implementation returns the client error without a completion barrier (`internal/release/store.go:992–1007`); `ReadHostsState` is one GET (`internal/provision/hostsused.go:152–167`). The mutex serializes console callers, but cannot finish an outstanding remote operation.
+
+There is a related false-success path: lines 388–393 accept any active read-back containing the fleet name, without checking that its recorded targets cover the box being added. A delayed earlier enrollment can therefore be mistaken for the current enrollment.
+
+**Failure scenario:**
+
+1. Adding `classic/box-1` inserts the active box and sends the mode PUT with ETag E. The caller receives a transport error while the remote write is still outstanding.
+2. Read-back takes its snapshot of the old mode. The outstanding conditional PUT then commits, recording `box-1`; the GET returns its old snapshot.
+3. The handler caches that old snapshot, detaches `box-1`, and returns 503 without a token. Persisted state now examines the fleet but its only box is detached.
+4. After a mode-cache reload, adding `box-1` returns 409/N9 at `hostsused.go:350–351`. Rotation returns a token but cannot restore active status: `SetFleetBoxToken` updates only the token and revision (`internal/registry/fleets.go:524`). The fleet requires offline recovery again.
+
+Without a reload, adding a different label demonstrates the false success instead. The handler inserts `box-2`, loses its mode PUT against E, reads the committed recording of `box-1`, and returns 200 with `box-2`'s token because only fleet membership is checked. Coverage then refuses data-kind creation because `box-2` is absent from `FleetTargets` (`hostsused.go:261–267`).
+
+**Verification:** A temporary Go overlay added `TestReview519LateModeCommit`, exercising the real fleet-create, add-box and rotate-token HTTP doors. Its store wrapper retained the first conditional mode PUT while returning a transport error. On the following GET it read the old bytes, committed that retained PUT using its original ETag, then returned the old bytes. This models the read preceding completion of the outstanding write; it requires neither a second console nor an eventually consistent store.
+
+Both regression assertions failed as expected:
+
+- `retry-after-reload`: initial add **503**, persisted fleet examined, **no active boxes**; retry after `hosts.reset()` and `LoadHostsMode` **409/N9**; rotate **200**, still **no active boxes**.
+- `retry-different-label`: initial add **503**; adding `box-2` **200 with a token**, while persisted targets still named `box-1`; `gateDataCreate` returned **409/S4**.
+
+This verifies the application's failure under the injected transport ordering. No live S3 fault experiment was performed.
+
+**Concrete fix:** Treat an ambiguous PUT as pending even when one GET still returns the old value. Keep its box recoverable until the outstanding write is settled or prevented from committing; do not detach solely on that negative read-back. Before declaring an enrollment successful, check that the persisted targets cover the intended box and roster. Centralize this recovery invariant and guard it with delayed-commit, restart and different-label retry tests. The existing `landedButErrs` test commits before returning the error (`hostsused_coverage_test.go:401–407`); the read-back-failure case fails before the PUT commits (lines 458–487), so neither witnesses this ordering.
+
+**Invariant / fault family:** Recoverable enrollment across the registry and mode-store writes: a transient storage response failure must not leave an examined fleet with an unusable first box. This is the same family as round-1 P1 2.
+
+## P2 and P3 findings
+
+None separate from the P1 above.
+
+## Other checks and validation
+
+- The requested `go test ./internal/console/ -run 'TestNewFleet|TestFleetGrowth' -count=1` passed. `git diff --check 5394c7f9..bc8c1e27` passed.
+- Under the declared single-console/offline-activation model, activation enumerates every fleet, compares the current roster, and records each fleet as examined or closed (`hostsused_activate.go:105–141`, `349–364`, `447–461`). Adds while invalidated remain unrecorded until offline activation. Registry replacement and owner-supplied old storage were assessed under Paul's accepted limits, not raised again.
+- Closed-fleet bucket sharing and missing closed-fleet target entries leave the new fleet unrecorded (`hostsused.go:356–360`). Examined targets retain their marks; the new path does not erase any marks or activate regions. Fleet box target names include both fleet and label (`hostsused_activate.go:172`).
+- The mutex covers the registry addition, roster read and mode update. It serializes competing first-box additions with invalidation and its persistence loop. `Examined` is cloned and `FleetTargets` gets a new map; existing target slices are not modified. Successful writes and successful read-backs update the ETag. Recording a fleet does not set `verified`, so a pending start-up check continues to block data-kind admissions.
+- The handler preserves the distinction between `ErrFleetBoxActive` and registry failures (`fleets.go:429–440`). A failed rollback can leave a tokenless active row, but while the fleet remains unexamined S4 still refuses data-kind admission.
+- The added tests exercise the real add-box door and app-create door. Their data-admission assertions call `gateDataCreate` directly; their simulated restart sets `verified` manually. These are narrower witnesses than an instance-create request through a real start-up check.
+- Changed production code is confined to `internal/console`; the other changes are its tests and Markdown. No changed file is in the root-binary census scope. No full suites, production access or subagents were used. Temporary overlay sources and logs were removed after recording their results.
+
+## Stopping rule
+
+Round 1 found the storage-provenance issue, now resolved by Paul's ruling, and the enrollment-recovery defect. Round 2 still finds the enrollment-recovery defect under an outstanding-write ordering. This is two consecutive rounds in the same fault family, so repository stopping rule 2 applies: stop incremental fixes and ask Paul to choose between requiring offline inventory up front, cutting automatic first-box recording, or enforcing recoverable enrollment in one place with a guard test or simulation. I recommend the third option if online first-box recording remains required. This review does not authorize another patch-and-review cycle; the round history remains 2 of 3.
+
+NOT READY
diff --git a/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r3.md b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r3.md
new file mode 100644
index 000000000..4fc390efa
--- /dev/null
+++ b/docs/superpowers/notes/reviews/ASTRA-FINDINGS-fleet-examined-519-r3.md
@@ -0,0 +1,64 @@
+Round-1 P1 1: resolved by Paul's 2026-11-02 ruling; owner-named storage, later detach/recompletion of the first label, and pre-activation registry restores are accepted limits.
+Round-1 P1 2: resolved; the mode is written first, ambiguous mode writes clear the cache without adding or detaching a box, and the recorded first label remains completable.
+Round-2 P1 1: resolved; an old read cannot authorize adding another label, and a delayed winning write leaves its first label completable.
+
+# fleet-examined-519 — review round 3 of 3
+
+Reviewed `5394c7f958e4c10f93c94f923211c0814680ff4d..90ab5c387e14c870d2b0ebfe219d7e09a1f035ac`, including the rework from `bc8c1e27`. The amadan `origin/main` reference and a read-only remote lookup both identify the stated base. References below are to the reviewed tip. No repository files were changed.
+
+## P1
+
+None.
+
+## P2
+
+None.
+
+## P3 follow-up
+
+### 1. Qualify the comment's promise about failures
+
+**Evidence:** `internal/console/hostsused.go:324–335` says “every failure answers 503 and leaves the registry as it was,” but explicitly recognizes a committed registry add with a lost reply immediately afterward. Registry errors are returned at lines 366 and 405 and become HTTP 500 at `internal/console/fleets.go:434–440`. The fault wrapper deliberately models an add that commits before returning an error (`hostsused_coverage_test.go:463–475`).
+
+**Scenario:** The mode commits, the registry add commits, and its reply is lost. The operation reports an error with an active, recorded box present; another add receives N9, and token rotation supplies a usable credential. This is the accepted recovery path, not a production defect.
+
+**Concrete fix:** Narrow the unchanged-registry/503 statement to mode-read, roster-read and mode-write failures. State separately that a registry failure can leave an active recorded box and require token rotation. Keep the implementation's existing error distinction.
+
+**Fault family:** Documentation of enrollment recovery. Follow-up only; this does not reopen the review.
+
+## Checks against the brief
+
+- **Write ordering and recovery:** `hostsused.go:379–405` constructs the target and `FirstBox` together and writes them through the mode's existing ETag before calling `AddFleetBox`. An error clears the cached state and ETag without changing the registry. A late PUT and a retry using the same old ETag cannot commit different recordings: `WriteHostsState` forwards the precondition (`internal/provision/hostsused.go:174–184`), and the real S3 store sends `IfMatch` (`internal/release/store.go:980–1009`). If the late write wins after a GET captured the old state, the retry loses its conditional write, clears its cache, and reads the winner next time. It cannot return success for its own unrecorded label. If the earlier write never lands, the retry can record and add its box.
+- **Registry failures:** Once a recording commits, a failed-before-commit add leaves the first label eligible at `hostsused.go:364–366`, including after restart. A committed add with a lost reply leaves an active recorded box. The registry's atomic conflict guard prevents an add from replacing an active box's token (`internal/registry/fleets.go:479–501`); `SetFleetBoxToken` supplies recovery without changing status (`fleets.go:504–535`). No enrollment path detaches a box. The literal “every failure leaves the registry unchanged” is therefore too broad, as noted above, but the recovery mechanism is sound under the stated fault model.
+- **Concurrent calls:** The same history mutex covers loading, eligibility, recording and the registry add (`hostsused.go:347–405`). Concurrent add-box requests are serialized. A pending remote PUT can outlive that lock, but retains its original ETag and cannot overwrite a later successful recording. Invalidation uses the same lock and conditional writes (`hostsused.go:438–468`, `489–515`). This assessment uses the design's single-console model.
+- **Exception boundaries:** A recorded fleet passes only for its non-active first label and only when it is not closed (`hostsused.go:363–368`). HTTP input rejects an empty label (`fleets.go:406–410`), so an absent map entry cannot match. Activation creates a fresh state without `FirstBox` (`hostsused_activate.go:447–462`); activation-roster fleets therefore gain no exception. Another label remains N9. The closed-bucket and missing-target cases retain the explicitly accepted unrecorded/offline path (`hostsused.go:370–374`).
+- **Invalidation copy:** Comparing all fields of `HostsState` (`internal/provision/hostsused.go:130–151`), the new copy at `hostsused.go:454–455` preserves exactly the formerly copied fields plus `FirstBox`; mode, reason and time are still replaced. No slice or map is mutated there. It agrees with the existing retry and offline-invalidation copies (`hostsused.go:505–507`; `hostsused_activate.go:488–490`). A fresh activation drops the first-label exceptions. The latch, refusal and persistence behavior is unchanged.
+- **Simulation:** The wrappers delegate to the real fixture store and registry. Held writes retain their original bytes and ETag, including when they land after a GET has captured the old value (`hostsused_coverage_test.go:397–475`); the directory store enforces that ETag under its mutex (`internal/release/store.go:496–532`). The simulation checks successful additions against persisted targets, checks every active box of a recorded fleet, and checks recovery and data admission after faults stop (`hostsused_coverage_test.go:517–591`). It is a useful bounded witness, not an exhaustive schedule proof: it holds at most one outstanding PUT, calls additions sequentially, and simulates a restart by resetting the mode cache with the tripwire already verified. Concurrency and the real tripwire were also inspected in source.
+
+## Validation
+
+All checks of the reviewed tip passed:
+
+- `go test ./internal/console/ -run 'TestNewFleet|TestFleetGrowth' -count=1` (including the default 150 simulation seeds).
+- `go test ./internal/console -run '^Test(FailedInvalidationStillRefuses|ReactivateFromInvalidated|InvalidateOffline|TripwireInvalidatesOnUnmarkedRecord)$' -count=1`.
+- `go test ./internal/provision -run '^(TestPlan14RootReadCensus|TestCensusScopeIsTheRootBinary)$' -count=1`.
+- `git diff --check 5394c7f9..90ab5c38`.
+
+Two temporary Go-overlay checks tested whether the new tests reject the old behavior:
+
+1. Substituting round two's `hostsused.go` made `TestNewFleetLateModeWrite` fail at line 626: adding `box-2` returned **200** while the delayed write recorded `box-1`, instead of the required 503. This is the exact prior false-success ordering.
+2. The simulation initially rejected round two immediately because it has no `FirstBox`. To avoid treating that schema difference as evidence of fault coverage, a second overlay added only the new metadata to the old ordering. The simulation then failed its recovery assertion at seed 29: an active box remained on an unrecorded fleet after recovery. Thus its recovery assertion detects an actual enrollment failure beyond the missing-field mismatch.
+
+These overlays did not change the checkout. Their sources and logs were removed after the results were recorded. No full suites, production operations or subagents were used.
+
+## Census verdict
+
+**APPROVE the `internal/provision` envelope** in `internal/provision/testdata/plan14-root-reads-fleet-examined-519.tsv:3`, fingerprint `e9a018eea2b8a748db347575b5d7e5d1ec4dfc34ff5745cb3433690c9eac4a4a`, at tip `90ab5c387e14c870d2b0ebfe219d7e09a1f035ac`.
+
+The only production-source change in that package is the optional `HostsState.FirstBox` field and its comment (`internal/provision/hostsused.go:142–145`). No function body changes. I read the enclosing schema at lines 128–152 and its readers/writers at lines 154–195: the field adds JSON metadata to the existing fixed `@mode` read/write, retains old-body compatibility, and changes neither the key nor its conditional-write precondition. I also read its only behavioral consumer, `internal/console/hostsused.go:347–405`, and activation's fresh-state construction at `hostsused_activate.go:447–462`.
+
+The field does not cause root to open, run, query or follow a new tenant-, app- or agent-named input, and no root validation or refusal is weakened. There are no changed units or dispositions requiring separate verdicts. The census and root-binary scope tests pass. This file records the reviewer's approval for the author to cite on #280; no discussion post was made.
+
+The first round with no P1 ends review under stopping rule 1. The P3 goes on the branch's follow-up list; no fourth round is requested.
+
+READY
diff --git a/internal/console/hostsused.go b/internal/console/hostsused.go
index 88350190c..eb7cdf060 100644
--- a/internal/console/hostsused.go
+++ b/internal/console/hostsused.go
@@ -324,15 +324,16 @@ const msgFleetBoxNotAdded = "could not add the box — try again"
// The invariant (Paul's ruling on Astra r2, 2026-11-02): the mode is
// written before the box is added, and a box is never detached here.
// Two stores are written, the mode and the registry, and the mode write
-// can err and still land, even after a read that says it has not. So
-// every failure answers 503 and leaves the registry as it was; a mode
-// write that errs also forgets the held state, so the next caller reads
-// the store. A recorded fleet's add-box of its first-box label, while no
-// box of that label is active, completes the enrollment: the label's
-// target is already recorded. Whatever failed, the same add-box again
-// finishes it (TestNewFleetEnrollmentSimulation). An add that lands with
-// its reply lost leaves an active, recorded box; rotate-token gives it a
-// token.
+// can err and still land, even after a read that says it has not. So a
+// failure to read the mode or the fleet's targets, or to write the mode,
+// answers 503 and leaves the registry as it was; a mode write that errs
+// also forgets the held state, so the next caller reads the store. A
+// recorded fleet's add-box of its first-box label, while no box of that
+// label is active, completes the enrollment: the label's target is already
+// recorded. Whatever failed, the same add-box again finishes it
+// (TestNewFleetEnrollmentSimulation). A registry add that fails answers
+// its error: if it landed with the reply lost, the box is active and
+// recorded, and rotate-token gives it a token.
//
// It all runs under the lock every admission takes, so two add-boxes on a
// new fleet cannot both record it. A mode that cannot be read refuses.