carlos / platform Public

plan: fold in Astra plan review R1 (2 P1, 4 P2)

Hold while the release path may still compare the declaration's
identity (history completion pending, settled or not) and for the
guarded console host; guard rule on both install paths; one final
outcome per declared host; persist the fetch outcome before the
release-key gate; put/show as clireg nodes with parity rows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5c09514bde4f9500f27283bedf53dbf09eca70a7 parent 7e3bfb0
2 files changed, +96 −31
  • docs/superpowers/plans/2026-11-19-named-units-from-parameters.md +71 −31
  • docs/superpowers/reviews/CODEX-FINDINGS-named-units-param-114-plan-R1.md +25 −0
diff --git a/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md b/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md
index 761a14ce0..57ae437e4 100644
--- a/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md
+++ b/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md
@@ -145,13 +145,30 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
func installNamedUnitsLocked(dst string, raw []byte) error
```
`InstallNamedUnits(envDir, dst, raw)` keeps its signature:
- `validateForInstall`, then the lock, then `installNamedUnitsLocked`.
+ `validateForInstall`, then the box guard rule, then the lock, then
+ `installNamedUnitsLocked`.
+ ```go
+ // consoleGuardHost: the host the armed console guard names, read as
+ // proofnamed.go:126-133 does (trusted read of
+ // <opt>/system/guard/console-ready.json, matched against
+ // release.LiveLink). Extract that match into this one helper and have
+ // proofnamed.go call it too.
+ func consoleGuardHost(optDir string) (host string, ok bool)
+ // checkGuardRule: if guarded, the guarded host's entry, when present,
+ // must be console.service / app console / empty account (proofnamed.go:142).
+ func checkGuardRule(entries []namedunits.Entry, guardHost string, guarded bool) error
+ ```
+ The operator's off-box `put` (Task 7) runs `validateForInstall` only,
+ never the guard rule. (Astra plan R1 #4.)
-- [ ] **Step 1: Failing test** `TestInstallNamedUnitsRefusesWhatTheReleasePathRefuses`: a file with an unknown field, or an entry without `addr`, returns an error, and `dst` is not created.
+- [ ] **Step 1: Failing tests**
+ - `TestInstallNamedUnitsRefusesWhatTheReleasePathRefuses`: a file with an unknown field, or an entry without `addr`, returns an error, and `dst` is not created.
+ - `TestCheckGuardRuleRefusesNonConsoleForGuardedHost`: guarded `a.example.com` mapped to `shop.service` → error; the same host as console → nil; other hosts unaffected.
+ - The existing `TestPlan14NamedUnits*` tests still pass with `proofnamed.go` calling `consoleGuardHost`.
- [ ] **Step 2:** `go test ./internal/host -run 'TestInstallNamedUnits'`. Expect the new test to FAIL and `TestInstallNamedUnitsWaitsForTheConfigSyncLock` to PASS. That test must keep passing; if its fixture lacks addr/health, give it both.
- [ ] **Step 3:** Implement the split.
- [ ] **Step 4:** Run step 2 again: PASS.
-- [ ] **Step 5:** Commit: `host: named-units install takes the strict gate; split the locked write`.
+- [ ] **Step 5:** Commit: `host: named-units install takes the strict gate and guard rule`.
### Task 3: The parameter adapter (`internal/hostenv`)
@@ -195,10 +212,10 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
**Files:**
- Create: `internal/host/namedunitsfetch.go`, `internal/host/namedunitsfetch_test.go`
-- Modify: `internal/status/snapshot.go` (the record types only; Task 6 wires them into the heartbeat), `internal/host/rootrollback.go` (one helper), `internal/host/agent.go` (`runAdoptUnderRootRelease`, after the `-restart-only` return at `:6157`, before `ParsePublicKey` at `:6165`)
+- Modify: `internal/status/snapshot.go` (the record types only; Task 6 wires them into the heartbeat), `internal/host/rootrollback.go` (`declarationBindingInUse`), `internal/host/agent.go` (`runAdoptUnderRootRelease`, after the `-restart-only` return at `:6157`, before `ParsePublicKey` at `:6165`)
**Interfaces:**
-- Consumes: Tasks 1-3; `readIdentity`, `haIMDSClient`, `imdsBase`; `lockConfigSync`; `rootstate.Open`, `rootstate.OpenTrustedFile`; `readRollbackAttempt`, `rollbackMargin`, `rootRestartState`.
+- Consumes: Tasks 1-3 (including `consoleGuardHost`, `checkGuardRule` from Task 2); `readIdentity`, `haIMDSClient`, `imdsBase`; `lockConfigSync`; `rootstate.Open`, `rootstate.OpenTrustedFile`; `readRollbackAttempt`, `rollbackMargin`, `rootRestartState`; `release.RootHistory` as `roothistory.go:23-35` opens it.
- Produces:
```go
// internal/status
@@ -222,17 +239,24 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
// internal/host
const namedUnitsStatusDir = "/var/lib/carlos-named-units"
- // rollbackInFlight: an attempt exists, !Settled, and now is before
- // Deadline+rollbackMargin. No side effects (unlike loadRollback).
- func rollbackInFlight(s rootstate.Store, host string, now time.Time) (bool, error)
+ // declarationBindingInUse: the release path may still compare the
+ // declaration file's identity for host. True when the host's attempt
+ // journal (readRollbackAttempt) exists and EITHER it is !Settled and
+ // now is before Deadline+rollbackMargin, OR a.History != nil and the
+ // root history still has it pending (release.RootHistory.Pending(
+ // a.HistoryBinding) returns an attempt equal to *a.History; this is
+ // the work resumeHistoryRestart/settleHistory would still do,
+ // roothistory_recovery.go:104-143), whatever Settled says.
+ // No side effects. (Astra plan R1 #1.)
+ func declarationBindingInUse(s rootstate.Store, history *release.RootHistory, host string, now time.Time) (bool, error)
type namedUnitsFetch struct {
skip func() string // non-empty = skip reason
identity func(ctx context.Context) (iid, region string, err error)
open func(ctx context.Context, region string) (hostenv.NamedUnitsStore, error)
lock func() (func(), error)
dst string
- inFlight func(host string) (bool, error)
- guardHost func() (host string, ok bool) // console guard's host, if armed
+ inUse func(host string) (bool, error) // declarationBindingInUse, bound
+ guardHost func() (host string, ok bool) // consoleGuardHost(release.OptDir())
now func() time.Time
}
func (f namedUnitsFetch) run(ctx context.Context) status.NamedUnitsStatus
@@ -244,19 +268,24 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
2. Open and Get, under a 10 s context:
- `ErrNoParameter` → `not-found`
- any other error → `unreadable`
- 3. Gate the value with `validateForInstall`, plus the guard rule (if
- `guardHost` returns a host, that host's entry must be
- `console.service`, app `console`, empty account). Failure →
- `invalid`.
+ 3. Gate the value with `validateForInstall` and `checkGuardRule`.
+ Failure → `invalid`.
4. Then, under `lock`:
- Read `dst` with `OpenTrustedFile`. Equal bytes → `unchanged`.
- - Any host in the *current* file with `inFlight` true (or an error)
- → `held`, with the host named.
+ - The affected hosts are the hosts in the *current* file plus the
+ guarded console host when the guard is armed, even if the file
+ is absent or empty: the release path synthesises that host's
+ entry and binds the file's identity (`proofnamed.go:82-100,139`).
+ Any affected host with `inUse` true (or an error) → `held`, with
+ the host named. (Astra plan R1 #2.)
- Otherwise `installNamedUnitsLocked` → `installed`.
5. `Digest` is the sha256 of the file as it stands after the step.
- Wiring: a package var `adoptNamedUnitsStep = func(ctx context.Context) status.NamedUnitsStatus { return productionNamedUnitsFetch().run(ctx) }`.
`runAdoptUnderRootRelease` calls it, logs one line for the outcome,
- and keeps the result for Task 5 to complete and write.
+ and calls `writeNamedUnitsStatus(st)` immediately, before
+ `release.ParsePublicKey` (which can be fatal, `agent.go:6165`), so an
+ install is never left unreported. Task 5 writes again after
+ `SyncUnits` with the per-unit outcomes. (Astra plan R1 #5.)
`guardHost` reads `<opt>/system/guard/console-ready.json` with the
same trusted read and the same `release.LiveLink` match as
`proofnamed.go:126-133`. Extract that match into one helper both
@@ -269,12 +298,13 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
- `TestNamedUnitsFetchEqualBytesNoRewrite`: same bytes → `unchanged`, and the inode is the same before and after.
- `TestNamedUnitsFetchInstallsNewValue`: → `installed`, the file equals the value, mode 0644, `Version` and `Digest` set.
- `TestNamedUnitsFetchInstallsClearingValue`: `{"schema":1,"units":[]}` → `installed`.
- - `TestNamedUnitsFetchHeldWhileRollbackInFlight`: `inFlight` is true for a host in the current file → `held`, the reason names the host, the file unchanged. Flip it to false and run again → `installed`.
+ - `TestNamedUnitsFetchHeldWhileBindingInUse`: `inUse` is true for a host in the current file → `held`, the reason names the host, the file unchanged. Flip it to false and run again → `installed`.
+ - `TestNamedUnitsFetchHoldsForGuardedConsoleHost`: the current file is absent, the guard names `c.example.com`, and `inUse("c.example.com")` is true → `held`.
- `TestNamedUnitsFetchSkipsGroupAndFleetWithoutNetwork`: `skip` returns a reason → `skipped`, and the `identity` and `open` fakes are never called.
- `TestNamedUnitsFetchGuardHostMustBeConsole`: the guard names `a.example.com`, and the value maps it to `shop.service` → `invalid`.
- `TestNamedUnitsFetchWaitsForConfigSyncLock`: the shape of `TestInstallNamedUnitsWaitsForTheConfigSyncLock`, using the real `lockConfigSync`.
- - `TestRollbackInFlight` (in `rootrollback_test.go` or alongside it): no attempt → false; settled → false; past the deadline plus margin → false; open → true. Nothing is written to the store.
- - `TestAdoptRunsNamedUnitsStepBeforeConfigSync`: a source-order check over `runAdoptUnderRootRelease`, in the style of `TestRunAdoptOpensTheRegistryThroughTheHelper` (`registryowner_test.go:301`). `adoptNamedUnitsStep(` appears after the `if *restartOnly` block and before `appconfig.SyncUnits(`, and outside the `CARLOS_SECRETS_KEY` branch.
+ - `TestDeclarationBindingInUse`: no attempt → false; open within the deadline → true; past the deadline plus margin with no history → false; settled and verified with its history completion still pending → true; settled with history completed → false. Nothing is written to either store.
+ - `TestAdoptRunsNamedUnitsStepBeforeConfigSync`: a source-order check over `runAdoptUnderRootRelease`, in the style of `TestRunAdoptOpensTheRegistryThroughTheHelper` (`registryowner_test.go:301`). `adoptNamedUnitsStep(` appears after the `if *restartOnly` block, then `writeNamedUnitsStatus(` before `release.ParsePublicKey(`, then `appconfig.SyncUnits(`; the step is outside the `CARLOS_SECRETS_KEY` branch.
- `TestProductionNamedUnitsFetchIsWired`: every field of `productionNamedUnitsFetch()` is non-nil, and `dst == appconfig.DefaultNamedUnitsPath`.
- [ ] **Step 2:** `go test ./internal/host -run 'TestNamedUnitsFetch|TestRollbackInFlight|TestAdoptRunsNamedUnitsStep|TestProductionNamedUnitsFetch'`. Expect FAIL.
- [ ] **Step 3:** Implement and wire.
@@ -290,23 +320,32 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
**Interfaces:**
- Produces, on `appconfig.UnitOps`:
```go
- // Outcome, when set, is called exactly once per declared host per pass
- // that reaches planning: state "delivered" (config current, restarted
- // or not) or "refused" with the same reason the pass prints.
+ // Outcome, when set, is called exactly once per declared host per pass,
+ // after planning AND application finish, with the host's FINAL state:
+ // "delivered" (config current, whether or not anything changed or
+ // restarted), "refused" with the same reason the pass prints (the last
+ // refusal wins over an earlier success), or "no-route" (declared, but
+ // no stamped registry row selects it this pass). An unresolvable
+ // config is "refused". Implementation: accumulate a map keyed by host
+ // during the pass, emit once at the end. (Astra plan R1 #3.)
Outcome func(host, unit, state, reason string)
```
- In `runAdoptUnderRootRelease`, `productionUnitOps` gets an `Outcome`
- that appends to `st.Units`. After `SyncUnits` returns (or is skipped
- for want of a key), call `writeNamedUnitsStatus(st)` once. On a
- `-restart-only` pass, write nothing.
+ that appends to `st.Units`. After `SyncUnits` returns, call
+ `writeNamedUnitsStatus(st)` again (Task 4 already wrote the fetch
+ outcome). When `SyncUnits` is skipped for want of a key, no second
+ write. On a `-restart-only` pass, write nothing.
- [ ] **Step 1: Failing tests:**
- `TestSyncUnitsReportsOneOutcomePerDeclaredHost`. Use `newFakeUnits` with two declared hosts: one delivers, and one has an unmanaged `EnvironmentFile`. That gives exactly two calls: `delivered`, and `refused` with the same reason text the pass prints.
+ - `TestSyncUnitsOutcomeUnchangedIsDelivered`: a second pass with nothing changed → one `delivered`.
+ - `TestSyncUnitsOutcomeLaterRefusalWins`: a host whose write succeeds but whose post-reload verification refuses → one `refused`.
+ - `TestSyncUnitsOutcomeNoRouteAndUnresolved`: a declared host with no registry row → `no-route`; a host whose config cannot be resolved → `refused`.
- `TestSyncUnitsOutcomeNilIsSafe`: the existing behaviour with no hook.
- - `TestAdoptWritesNamedUnitsStatusOnce` (host, with fakes for the step and the writer): one write per full or config-only pass, none on restart-only.
-- [ ] **Step 2:** `go test ./internal/appconfig -run 'TestSyncUnitsReportsOneOutcome|TestSyncUnitsOutcomeNil'` and `go test ./internal/host -run TestAdoptWritesNamedUnitsStatus`. Expect FAIL.
-- [ ] **Step 3:** Implement. Call the hook next to the existing
- `fmt.Printf` at each site; don't change any printed text.
+ - `TestAdoptWritesNamedUnitsStatusAfterSync` (host, with fakes for the step and the writer): a full or config-only pass with a key writes twice (fetch outcome, then with units); without a key, once; restart-only, never.
+- [ ] **Step 2:** `go test ./internal/appconfig -run 'TestSyncUnitsReportsOneOutcome|TestSyncUnitsOutcome'` and `go test ./internal/host -run TestAdoptWritesNamedUnitsStatus`. Expect FAIL.
+- [ ] **Step 3:** Implement. Record state at each existing print site
+ into the per-pass map; emit at the end; don't change any printed text.
- [ ] **Step 4:** Run step 2 again, then the existing declaration tests (`go test ./internal/appconfig -run 'TestSyncUnits.*Declar'`): PASS.
- [ ] **Step 5:** Commit: `appconfig: SyncUnits reports each declared unit's outcome`.
@@ -333,7 +372,7 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
### Task 7: Operator CLI `put` / `show`, and the console status rows
**Files:**
-- Modify: `internal/host/unitops.go` (`RunSystemNamedUnits` dispatch), `internal/console/apisystemupdate.go` (`handleAPISystemStatus` rows, `:1057`), `system.go` (`systemBoxRow` `:326`; usage line `:220`), `docs/site/cli.md` (the `carlos system named-units` section, ~`:3343`)
+- Modify: `system.go:96` (replace the single `raw("named-units", box, ...)` leaf with a `named-units` group holding three `clireg` nodes: `install` (audience box-local, root), `put` and `show` (operator audience, as `host-env seed` is registered); follow AGENTS.md:526-545), `parity/parity.tsv` (rows for the new nodes), `parity/cli.tsv` and docs projection (regenerated with `make parity-doc`), `internal/host/unitops.go` (`RunSystemNamedUnits` becomes the install handler only), `internal/console/apisystemupdate.go` (`handleAPISystemStatus` rows, `:1057`), `system.go` (`systemBoxRow` `:326`; usage line `:220`), `docs/site/cli.md` (the `carlos system named-units` section, ~`:3343`). (Astra plan R1 #6.)
- Create: `internal/host/namedunitscli.go`, with its test
**Interfaces:**
@@ -362,6 +401,7 @@ per `awsssm.go:21-25`); `rootstate` public stores; systemd root units.
- `TestNamedUnitsShowNamesBothRegions`: the parameter was read in `eu-west-1`, and the box record says region `eu-west-2` with `not-found`. Both regions are printed.
- `TestNamedUnitsShowBoxNotReported`: no row matches → the output says the box hasn't reported for that instance.
- `TestAPISystemStatusRowsCarryInstanceAndNamedUnits` (console).
+ - The repo's command-tree checks pass after `make parity-doc`: `go test . -run 'TestParity'` and `go test ./internal/docsite -run TestParityPageIsCurrent`.
- [ ] **Step 2:** Run the new tests with targeted `-run` in `./internal/host`, `.` and `./internal/console`. Expect FAIL.
- [ ] **Step 3:** Implement. Write the CLI copy (the pickup line from the
spec, outcomes, the no-report line) and the docs/site/cli.md
diff --git a/docs/superpowers/reviews/CODEX-FINDINGS-named-units-param-114-plan-R1.md b/docs/superpowers/reviews/CODEX-FINDINGS-named-units-param-114-plan-R1.md
new file mode 100644
index 000000000..4382fc4d7
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-named-units-param-114-plan-R1.md
@@ -0,0 +1,25 @@
+1. **P1 — Settled restart attempts can still require the old declaration identity.**
+ Evidence: [plan:225](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:225) excludes settled attempts. However, [roothistory_recovery.go:143](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/host/roothistory_recovery.go:143) resumes history completion for settled attempts, and [line 118](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/host/roothistory_recovery.go:118) requires the original source binding. A transient history-completion failure followed by declaration replacement makes that comparison permanently fail; pending history then blocks subsequent releases.
+ **Smallest fix:** Hold replacement while source-bound history completion remains pending, regardless of `Settled` or the restart deadline. Test a settled, verified restart whose history completion fails, then retries after recovery.
+
+2. **P1 — The rollback hold misses the implicitly declared console host.**
+ Evidence: [plan:253](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:253) checks only hosts in the current declaration file. [proofnamed.go:139](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/host/proofnamed.go:139) synthesizes the guarded console’s entry when that host is absent. Its binding nevertheless incorporates the declaration file’s bytes and identity at lines 82–100. Installing declarations can therefore invalidate an outstanding console rollback that the hold never examines.
+ **Smallest fix:** Include the guarded console host in the affected-host set, including when the current file is absent or empty. Test replacement while that implicitly declared host has an outstanding rollback.
+
+3. **P2 — The specified outcome hooks cannot provide one final result per declared host.**
+ Evidence: [plan:287–309](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:287) places callbacks beside intermediate log statements. One successful delivery can hit [unitsync.go:326,329,467](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/appconfig/unitsync.go:326), producing three successes; a post-reload refusal can follow the first two. Conversely, unchanged successful delivery returns at line 312 without those messages. Declared hosts without routes and config-resolution failures also miss the specified callbacks.
+ **Smallest fix:** Accumulate one outcome per declared host and emit it after preparation and application finish. Cover unchanged success, later refusal, missing routes, and unresolved config in the tests.
+
+4. **P2 — Local installation still bypasses the console guard rule.**
+ Evidence: [plan:140–148](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:140) gives `InstallNamedUnits` only the document validators; the box-specific guard check appears solely in the fetch step at lines 247–250. A local installation can therefore accept a guarded host mapped to another app or unit, which [proofnamed.go:142](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/host/proofnamed.go:142) refuses during releases.
+ **Smallest fix:** Share the box-specific guard validation between both installation paths. Keep the operator’s off-box `put` validation independent of local guard state.
+
+5. **P2 — A successful installation can lose its status report at the next fatal gate.**
+ Evidence: [plan:198](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:198) installs before public-key parsing, but [plan:298–300](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:298) postpones the only status write until after config sync. [agent.go:6165–6167](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/internal/host/agent.go:6165) exits on an invalid release key. The file changes while the heartbeat continues reporting an older result—or none.
+ **Smallest fix:** Persist the fetch outcome before that fatal gate, then update its delivery outcomes after config sync. Add a production-path test with an invalid release key.
+
+6. **P2 — Task 7 omits command registration and parity changes.**
+ Evidence: [plan:336–357](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/docs/superpowers/plans/2026-11-19-named-units-from-parameters.md:336) adds dispatch inside `RunSystemNamedUnits`, while [system.go:96](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/named-units-param-114/system.go:96) registers the entire command as one box-local leaf. Following the plan leaves operator-facing `put` and `show` absent from the command projection and parity table, contrary to the repository’s required command structure.
+ **Smallest fix:** Register `install`, `put`, and `show` as separate `clireg` nodes with appropriate audiences; update parity rows, regenerate the projection/docs, and run their checks.
+
+NOT READY
\ No newline at end of file