carlos / platform Public

Managed fleets 1b: whole-branch Astra review R1 findings (NOT READY, 3 P1, 2 P2; census approved)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c10e6d40bf410c9e20b244691466e2b6073ec7b8 parent d52fa9a
1 file changed, +186 −0
  • docs/superpowers/plans/CODEX-FINDINGS-MANAGED-FLEETS-1B-BRANCH-R1.md +186 −0

CI failed — run details

diff --git a/docs/superpowers/plans/CODEX-FINDINGS-MANAGED-FLEETS-1B-BRANCH-R1.md b/docs/superpowers/plans/CODEX-FINDINGS-MANAGED-FLEETS-1B-BRANCH-R1.md
new file mode 100644
index 000000000..05ba6edb4
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-MANAGED-FLEETS-1B-BRANCH-R1.md
@@ -0,0 +1,186 @@
+Reviewed `c24e7a04b1..d52fa9a16b45b481e7099398a944035b74f51c0d`, branch review round 1 of 3. **Three P1 findings and two P2 findings.**
+
+These are findings from code inspection. The targeted test command could not start because Go could not create its work directory in the read-only sandbox. No test results are claimed. `git diff --check` passed; the checkout remains unchanged.
+
+**P1 — A wake already in progress can boot the previous assignment’s stale database.**
+
+Evidence: [backend_exec.go:901](internal/activator/backend_exec.go:901), [startrule.go:190](internal/activator/startrule.go:190), [activator.go:2548](internal/activator/activator.go:2548), [activator.go:5680](internal/activator/activator.go:5680).
+
+`doWake` reads the route before acquiring the lease. After acquisition, its check at line 2571 tests cancellation and `wakeAllowed`; the latter checks only the explicit fence map. `RetireExcept` does not cancel or fence an `actWaking` entry. It waits for that wake to finish and then stops it.
+
+A concrete execution is:
+
+1. A has a sleeping binary instance, local database, and marker matching assignment A. A wake reads that route, then stalls before acquiring its lease.
+2. The record moves to B. A reconciles the removal; retirement waits for its pending wake.
+3. B acquires the lease, restores, writes newer data, and sleeps, releasing the lease.
+4. A’s pending acquisition resumes and succeeds. `reconcileAssignment` compares its marker with the **old route value** and keeps the stale database. `startAllowed` accepts the same comparison, and the warm-cache path returns without restoring B’s newer replica.
+
+There need never be two concurrent lease holders. The instance can still boot stale data. The production before-exec hook does not close this case: [buildstate.go:619](internal/host/buildstate.go:619) permits an absent route.
+
+**Fix:** make retirement invalidate pending wakes, and revalidate the route’s ownership and assignment under the acquired lease before accepting a local copy. Add a service-level interleaving test that delays A’s acquisition, retires A, lets B write and release, then resumes A; A must not boot its old copy.
+
+**Fault family:** assignment freshness across wake and retirement. This is an implementation gap in the accepted marker rule, rather than an objection to that rule.
+
+**P1 — A drain heartbeat can combine old zero lease counts with a newer empty route list.**
+
+Evidence: [agent.go:4404](internal/host/agent.go:4404), [agent.go:4504](internal/host/agent.go:4504), [drainreport.go:184](internal/activator/drainreport.go:184), [fleetrelabel.go:382](internal/console/fleetrelabel.go:382).
+
+`statusLoop` captures `LeasesHeld` and `ReplicationFailures` through `drainReport`. After further probes, `statusTick` independently reads the routes and assigns the heartbeat’s timestamp. The resulting report does not establish that its zero counts held together.
+
+For example, more than two minutes after draining began:
+
+1. A delayed source reconcile still has a sleeping route. `drainReport` reads zero leases and zero replication failures.
+2. A request wakes that route and acquires its lease.
+3. Reconcile removes the route and starts asynchronous retirement.
+4. `statusTick` reads zero routes and publishes them with the earlier zero counts and a fresh timestamp.
+
+`drainDone` accepts this report while the process, lease, or final replication is still active. Both detach doors use the predicate correctly under the fleet lock, but that lock cannot repair inconsistent evidence produced on the box. No clock skew is required.
+
+**Fix:** collect a conservative drain snapshot that covers route removal, pending wakes, held leases, and unfinished replication together. At minimum, avoid combining a later route list with earlier drain facts; also ensure a pending acquisition cannot escape the snapshot. Add a deterministic test injecting wake and retirement between collection stages and verify that neither detach door accepts the report.
+
+**Fault family:** drain completion requires consistent evidence of quiescence.
+
+**P1 — A failed replication initialization can be reported as successful final replication.**
+
+Evidence: [lease.go:572](internal/lease/lease.go:572), [drainreport.go:494](internal/activator/drainreport.go:494), and the pinned Litestream dependency’s [db.go:775](gomod:github.com/benbjohnson/litestream@v0.5.14/db.go:775) and [db.go:967](gomod:github.com/benbjohnson/litestream@v0.5.14/db.go:967).
+
+`Replicator.Close` discards the error from `SyncAndWait`, then classifies only `store.Close` as a possible `FinalSyncError`. The assumption in its comment—that the first call has initialized the database—is not guaranteed.
+
+Litestream initialization can return an error before assigning `db.db`, including a filesystem error while inspecting the database or its parent. Its `Close` skips both final database sync and replica sync when `db.db == nil`, and can return nil.
+
+A newly started replicator whose database has not initialized can therefore encounter an initialization I/O error during the final checkpoint, release its lease, and return success without uploading the local data. The new `noteFinalReplication` handling then removes the durable unsynced/failure records. Once the route disappears, the heartbeat can falsely establish drain completion.
+
+Although the discarded error predates this branch, using that outcome to clear the new drain-safety evidence makes this a branch defect.
+
+**Fix:** preserve a failed prerequisite sync as a final replication failure unless a subsequent flush positively establishes success. Add coverage for an uninitialized replicator whose initialization fails; the existing initialized-replica upload-failure case does not exercise this path.
+
+**Fault family:** drain completion requires positive evidence of final replication.
+
+**P2 — A registered box with no heartbeat is displayed as “not paused” instead of “unknown.”**
+
+Evidence: [fleetrelabel.go:576](internal/console/fleetrelabel.go:576), [fleetrelabel.go:325](internal/console/fleetrelabel.go:325), and [fleetbox.go:293](internal/console/fleetbox.go:293).
+
+`labelsPausedFor` discards `joinBeats`’s `unheard` result. `labelsPausedBy` skips a box with no heartbeat, and a successful listing can be complete while containing no report for a registered box. The function then returns the ordinary empty value.
+
+This occurs when an active box has never reported or its report has left the listing horizon. Activation correctly treats this as missing version evidence, but `LABELS PAUSED` does not communicate that uncertainty.
+
+**Fix:** retain `unheard` and return `fleetLabelsUnknown` when a registered active box lacks a report, while retaining the existing precedence for a positively observed below-floor box. Add a missing-key test alongside the unreadable-report tests.
+
+**Fault family:** mixed-version observability. This need not change the accepted lost-box relabelling policy.
+
+**P2 — The required rollback alert disappears after a labelled fleet shrinks to one box.**
+
+Evidence: [fleetbox.go:274](internal/console/fleetbox.go:274) and [fleetrelabel.go:145](internal/console/fleetrelabel.go:145).
+
+`loadFleetViewAt` returns before loading heartbeats whenever fewer than two active boxes remain. After a labelled fleet drains and detaches down to one box, that remaining box can still hold labelled records. If it rolls back below the floor, the worker sees no `LastSeen`, so `labelsPausedBy` produces no result and the required ERROR alert is never emitted.
+
+**Fix:** continue collecting version evidence for an already-labelled fleet with one active box. Keep the two-box requirement for new activation separate. Test rollback after shrinking a labelled fleet to one box.
+
+**Fault family:** mixed-version gate and alert coverage.
+
+No additional P3 findings beyond the deferred minors below.
+
+**Census verdicts**
+
+These verdicts apply to the card’s root-authority question and recorded dispositions at the reviewed tip. They do **not** approve the storage and termination behavior identified above. The census tests could not execute in this sandbox, so these are source-review verdicts, not a claim that the generated overlay passes mechanically.
+
+| Existing body/site unit | Verdict and evidence |
+|---|---|
+| `Service.finishStop` | **APPROVE** — [activator.go:4831](internal/activator/activator.go:4831). Agent-side outcome recording; no additional root authority. |
+| `ExecBackend.acquireClassified` | **APPROVE** — [hawake.go:298](internal/activator/hawake.go:298). Production defaults preserve the acquire path and admission checks. |
+| `Service.reapUnprovenWake` | **APPROVE** — [opset.go:890](internal/activator/opset.go:890). Existing stop proof remains; outcome recording runs as the agent. |
+| `provisionTickConfig` | **APPROVE** — [agent.go:3504](internal/host/agent.go:3504). Existing environment supplies a narrower ownership scope. |
+| `statusLoop` | **APPROVE** — [agent.go:4218](internal/host/agent.go:4218). Private agent heartbeat additions; no new root consumer. |
+| `Reconcile` | **APPROVE** — [reconcile.go:1061](internal/provision/reconcile.go:1061). Ownership restricts admission; existing retirement mechanisms remain. |
+| `RouteFor` | **APPROVE** — [reconcile.go:558](internal/provision/reconcile.go:558). Copies assignment metadata without extending root’s accepted authority fields. |
+| `retireAbortedSeedRow` | **APPROVE** — [seedreconcile.go:180](internal/provision/seedreconcile.go:180). Additional ownership refusal narrows retirement. |
+| `Registry.AddFleetBox` | **APPROVE** — [fleets.go:441](internal/registry/fleets.go:441). Lifecycle fields remain registry data. |
+| `Registry.SetFleetBoxIf` | **APPROVE** — [forward.go:34](internal/registry/forward.go:34). Authoritative labels restrict binding updates. |
+| `Registry.Fingerprint` | **APPROVE** — [registry.go:3878](internal/registry/registry.go:3878). Label hashing changes reload detection only. |
+| `Registry.SnapshotFingerprint` | **APPROVE** — [registry.go:4240](internal/registry/registry.go:4240). Same label-aware fingerprint behavior. |
+| `upsertRoute` | **APPROVE** — [registry.go:1543](internal/registry/registry.go:1543). Added columns retain the existing write and normalization boundary. |
+| `CollectBox` | **APPROVE** — [snapshot.go:980](internal/status/snapshot.go:980). Serializes private observations; introduces no root action. |
+| `Service.doWake` | **APPROVE** — [activator.go:2327](internal/activator/activator.go:2327). Durable unsynced recording adds an agent-side refusal without expanding root execution authority. |
+| `ExecBackend.Acquire` | **APPROVE** — [backend_exec.go:776](internal/activator/backend_exec.go:776). Configuration admission remains before acquisition; tracking adds no root input. |
+| `ExecBackend.restorePlain` | **APPROVE** — [backend_exec.go:881](internal/activator/backend_exec.go:881). Assignment operations stay within the agent’s data handling. |
+| `Service.cleanupFailedWake` | **APPROVE** — [maintenance.go:364](internal/activator/maintenance.go:364). Existing stop/release proofs remain; adds outcome recording. |
+| `Edge.Reload` | **APPROVE** — [edge.go:729](internal/edge/edge.go:729). Labelled dispatch narrows destinations and retains the merged forward-row refusals. |
+| `Registry.migrateFleets` | **APPROVE** — [fleets.go:130](internal/registry/fleets.go:130). Fixed additive SQL; no new interpreted input. |
+
+| New unit | Verdict and evidence |
+|---|---|
+| `ExecBackend.knownHA` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:217](internal/activator/drainreport.go:217). Agent-local classification. |
+| `ExecBackend.noteUnsynced` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:279](internal/activator/drainreport.go:279). Validated host record in agent-owned storage. |
+| `Service.noteUnsynced` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:478](internal/activator/drainreport.go:478). Agent-side dispatch with HA exclusion. |
+| `SplitBackend.execFacts` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:379](internal/activator/drainreport.go:379). Backend selection only. |
+| `SplitBackend.noteUnsynced` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:403](internal/activator/drainreport.go:403). Delegates within the existing backend boundary. |
+| `readRecordHosts` | **APPROVE**, `legacy/accepted-legacy` — [drainreport.go:235](internal/activator/drainreport.go:235). Agent record-directory enumeration. |
+| `ExecBackend.establishAssignment` | **APPROVE**, `legacy/accepted-legacy` — [startrule.go:352](internal/activator/startrule.go:352). Agent marker write; no new root reader. |
+| `ExecBackend.reconcileAssignment` | **APPROVE**, `legacy/accepted-legacy` — [startrule.go:173](internal/activator/startrule.go:173). Agent-local inspection and set-aside operations. |
+| `ExecBackend.startAllowed` | **APPROVE**, `legacy/accepted-legacy` — [startrule.go:302](internal/activator/startrule.go:302). Additional agent storage checks, with no expanded root execution input. |
+| `ExecBackend.supersededEntries` | **APPROVE**, `legacy/accepted-legacy` — [startrule.go:101](internal/activator/startrule.go:101). Reads the agent’s superseded-copy inventory. |
+| `localCopyNames` | **APPROVE**, `legacy/accepted-legacy` — [startrule.go:139](internal/activator/startrule.go:139). Local file enumeration, not a root action. |
+| `fleetBoxOf` | **APPROVE**, `legacy/accepted-legacy` — [edge.go:3249](internal/edge/edge.go:3249). Authoritative label takes precedence over binding. |
+| `Registry.MarkFleetBoxLabelled` | **APPROVE**, `legacy/accepted-legacy` — [fleets.go:645](internal/registry/fleets.go:645). Fixed registry operation. |
+| `Registry.SetFleetBoxDraining` | **APPROVE**, `legacy/accepted-legacy` — [fleets.go:609](internal/registry/fleets.go:609). Fixed registry operation. |
+| `Registry.SetFleetAssignment` | **APPROVE**, `legacy/accepted-legacy` — [registry.go:2668](internal/registry/registry.go:2668). Assignment metadata update without new root authority. |
+
+| Changed-read unit / schema | Verdict and evidence |
+|---|---|
+| `ExecBackend.seededRestore` | **APPROVE**, retains `legacy/accepted-legacy` — [seedplace.go:97](internal/activator/seedplace.go:97). Assignment checks remain agent-side. |
+| `forwardCurrent` | **APPROVE**, retains `legacy/accepted-legacy` — [forward.go:51](internal/provision/forward.go:51). Label-aware comparison preserves authoritative routing. |
+| `convergeOwned` | **APPROVE**, retains `legacy/accepted-legacy` — [reconcile.go:873](internal/provision/reconcile.go:873). Converges assignment metadata through existing ownership handling. |
+| `Registry.ListFleetBoxes` | **APPROVE**, retains `legacy/accepted-legacy` — [fleets.go:674](internal/registry/fleets.go:674). Reads additive lifecycle columns. |
+| `Registry.PutForward` | **APPROVE**, retains `legacy/accepted-legacy` — [forward.go:350](internal/registry/forward.go:350). Inert forward-row restrictions survive the merge and label additions. |
+| `Route.InertForward` | **APPROVE**, retains `legacy/accepted-legacy` — [forward.go:201](internal/registry/forward.go:201). Assignment fields cannot grant local execution to forward rows. |
+| `normalizeRoute` | **APPROVE**, retains `authority/E3` — [registry.go:1624](internal/registry/registry.go:1624). Existing normalization boundary covers the label addition. |
+| `routeArgs` | **APPROVE**, retains `authority/E3` — [registry.go:1665](internal/registry/registry.go:1665). Parameterized serialization adds only the declared columns. |
+| `scanRoute` | **APPROVE**, retains `legacy/accepted-legacy` — [registry.go:1097](internal/registry/registry.go:1097). Matching additive deserialization. |
+| `Registry.dispatchRemote` | **APPROVE**, retains `hint/E2` — [remote_dispatch.go:143](internal/registry/remote_dispatch.go:143). Dispatch reaches typed registry operations without promoting hints into root authority. |
+| Changed registry schema | **APPROVE** — [registry.go:738](internal/registry/registry.go:738), [fleets.go:161](internal/registry/fleets.go:161). Declared route assignment fields and fleet-box lifecycle columns account for this schema change. |
+
+The package-envelope verdicts include the changed functions and their reached code, beyond the individually inventoried units:
+
+| Re-pinned envelope | Verdict |
+|---|---|
+| `.` | **APPROVE** — CLI/API client additions introduce no new root-consumed path or execution authority. |
+| `internal/activator` | **APPROVE** — agent-side marker, replication-record, and lease-tracking changes; root invocation authority remains unchanged. Functional blockers are listed above. |
+| `internal/edge` | **APPROVE** — authoritative labels narrow routing; merged forward-row eligibility and refusal behavior remain. |
+| `internal/host` | **APPROVE** — ownership configuration and private heartbeat reporting do not expand root inputs. |
+| `internal/lease` | **APPROVE** — error classification and test identity seams do not expand root authority. Final-sync correctness is separately blocked above. |
+| `internal/provision` | **APPROVE** — ownership and conditional writes preserve the existing root trust boundary; copied assignment fields grant no new root operation. |
+| `internal/registry` | **APPROVE** — additive schema, typed operations, normalization, fingerprints, and inert-forward handling preserve the recorded authority boundaries. |
+| `internal/release` | **APPROVE** — release-floor declaration introduces no new root input. |
+| `internal/status` | **APPROVE** — private heartbeat additions introduce no new root action. |
+
+Record-write census:
+
+| Unit | Verdict |
+|---|---|
+| `SetRecordRegion` | **APPROVE** — [provision.go:1033](internal/provision/provision.go:1033). Same guarded writer; placement change clears label/time and preserves the moved flag. |
+| `SetRecordFleetBox` | **APPROVE** — [fleetbox.go:47](internal/provision/fleetbox.go:47). Expected region, label, and lifetime are checked inside the retrying mutation; import refusal precedes changes. |
+| `fleetInventory.readRecords` | **APPROVE** — [fleetbox.go:486](internal/console/fleetbox.go:486). Read-only key site; cached record bodies still receive fresh lifetime judgments. |
+| `fleetInventory.readSidecars` | **APPROVE** — [fleetbox.go:558](internal/console/fleetbox.go:558). Read-only sidecar inventory. |
+| `Reconcile` | **APPROVE** — [reconcile.go:1061](internal/provision/reconcile.go:1061). Same record key sites; ownership restricts admission and determines existing retirement handling. |
+| `Server.registerCLIRoutes` — Task 6b | **APPROVE** — [authcli.go:505](internal/console/authcli.go:505). Drain registration uses the same service-role restriction as neighboring fleet mutations; no direct record write. |
+| `Server.writeRelabels` — Task 6b | **APPROVE** — [fleetrelabel.go:218](internal/console/fleetrelabel.go:218). Uses the typed conditional setter; import-in-flight and changed-expectation refusals are handled separately. |
+
+**Deferred minors**
+
+None of the ledger’s deferred minors independently needs to become a merge blocker based on this review.
+
+| Deferred item | Triage |
+|---|---|
+| Task 1: conflict-injection test for changed expectations | Keep as a test-strengthening follow-up. The expectation check is inside the retrying mutation. |
+| Task 2: rootfs/sidecar tests located in `fleetbox_test.go` | Organization only; leave deferred. |
+| Task 3: missing registry cleanup in two tests | Add `t.Cleanup` in a follow-up. |
+| Task 4: pre-existing seed-marker directory fsync gap | Separate durability follow-up; do not broaden this branch’s assignment-marker work. |
+| Task 5: write-count helper missing `rows.Err()` | Test-helper follow-up. |
+| Task 6a: lease-loss timing flake and `packed-refs.lock` warning | Retain the tracked investigation. Neither was reproduced here. A red required gate still cannot be waived as “known.” |
+| Task 6a: records retained after a host becomes HA | Accepted conservative behavior; no merge fix required. |
+| Task 6b: assert both CLI rows before inspecting columns | Test-strengthening follow-up. |
+| Task 7: explicitly assert acquisition occurred after recorded expiry | Strengthen the test separately. The pending-wake test required by the first P1 is a distinct missing case. |
+| Task 7: Litestream diagnostics in test output | Output cleanup only. |
+| Task 7: Darwin vet failure involving `claimsOnEnv` | The referenced code is present in the review base; not introduced here. Track separately. This review did not run Darwin vet. |
+
+**NOT READY**
\ No newline at end of file