carlos / platform Public

Fleet secrets key plan: Astra plan round 2 fixes (relay readiness per app, guard covers Sealer literals, apiSession method, pending copy status); round 3 brief

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev b955f4a55c3a853a7b5ac545e6f1dd20fea728aa parent f3d406d
3 files changed, +44 −4
  • docs/superpowers/plans/2026-10-29-fleet-secrets-key.md +5 −4
  • docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R2.md +26 −0
  • docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R3.md +13 −0

CI cancelled — superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>b3j344emc</task-id> <tool-use-id>toolu_01VAwBfqxPF7mU57SWjZzBr5</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2d812478-ae68-44f2-8075-b2330abd5939/tasks/b3j344emc.output</output-file> <status>completed</status> <summary>Background command "Run Astra plan review round 2" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 13.3 g CO₂e (1,659,657 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-secrets-key, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md b/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md
index 68b2af393..003713639 100644
--- a/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md
+++ b/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md
@@ -49,7 +49,7 @@
**Interfaces:**
- Produces: row ids `FSK-C01`... referenced by every later task; the gate's `fleetSecretsCopyBuilt` list, which each later task extends in the commit that writes a row.
-- [ ] **Step 1: Write the deck** with one row per string, columns as `2026-10-28-console-budget-copy.md` (id, file, text, status `draft`). Rows: the `fleets secrets-key` help line in `fleetsUsage` and its output (registered, fingerprint, the stale-apps list and its fix line, already registered no-op); the door's refusals (unknown fleet, unparseable key, the deployment's own key, key used by another fleet, replacement while sealed values exist naming the apps, not an owner); `fleets ls`'s `SECRETS KEY` column header and `-`; `secrets fingerprint` help and output; the config GET-less refusal (`errFleetNoSecretsKey`: run `carlos fleets secrets-key <f>`); the PUT refusals (missing `sealed_to` on a fleet app: upgrade the CLI; wrong key: unset `CARLOS_SECRETS_PUBKEY` in the terminal; not v2); the store/mail/relay keyless-fleet refusal; the placement refusal listing vars and the order that works; the two direct-mode refusals; the REASON cells for `no_key`, `cannot_open`, and the capped report; the BYO page line; the docs paragraphs (Task 10). Draft text from the spec's sections verbatim where it gives words.
+- [ ] **Step 1: Write the deck** with one row per string, columns as `2026-10-28-console-budget-copy.md` (id, file, text, status `pending`, which the reused gate accepts beside `approved` and `struck`, `approved_rootfs_copy_test.go:155`). Rows: the `fleets secrets-key` help line in `fleetsUsage` and its output (registered, fingerprint, the stale-apps list and its fix line, already registered no-op); the door's refusals (unknown fleet, unparseable key, the deployment's own key, key used by another fleet, replacement while sealed values exist naming the apps, not an owner); `fleets ls`'s `SECRETS KEY` column header and `-`; `secrets fingerprint` help and output; the config GET-less refusal (`errFleetNoSecretsKey`: run `carlos fleets secrets-key <f>`); the PUT refusals (missing `sealed_to` on a fleet app: upgrade the CLI; wrong key: unset `CARLOS_SECRETS_PUBKEY` in the terminal; not v2); the store/mail/relay keyless-fleet refusal; the placement refusal listing vars and the order that works; the two direct-mode refusals; the REASON cells for `no_key`, `cannot_open`, and the capped report; the BYO page line; the docs paragraphs (Task 10). Draft text from the spec's sections verbatim where it gives words.
- [ ] **Step 2: Write `approved_fleet_secrets_copy_test.go`** by copying `approved_rootfs_copy_test.go`'s four tests with this deck's path, its id prefix `FSK-C` and an empty `fleetSecretsCopyBuilt`.
- [ ] **Step 3: Run** `nice -n 19 go test . -run 'TestFleetSecretsCopy' -count=1`. Expected: PASS (deck complete, no em dashes, nothing built yet).
- [ ] **Step 4: Copy review.** The controller sends the deck through copy review (a Luna pass by delegation is acceptable for a deck this size). Rows come back `approved` with their final text. No later task writes a row until it is approved.
@@ -133,7 +133,7 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount
- Consumes: Task 3's door and answer shape.
- Produces:
- `carlos fleets secrets-key <fleet> <pubkey>` and `--file <path>` (accepts a `CARLOS_SECRETS_PUBKEY=` line or a bare key); parses locally first and prints the fingerprint, then the `stale` list.
- - `func setFleetSecretsKey(ctx context.Context, a apiAcct, fleet, pub string) (fleetKeyAnswer, error)`
+ - `func (s *apiSession) setFleetSecretsKey(ctx context.Context, a apiAcct, fleet, pub string) (fleetKeyAnswer, error)`, a method like the existing fleet calls (`apimode.go:4944-4970`), using the CLI's resolved session
- `fleets ls` header `FLEET\tBUCKET\tSECRETS KEY\tSTALE\tBOX\tSTATUS\tTAGS`, key shown as the first 12 hex characters after `sha256:` or `-`, STALE the count of stale sealed values (`-` when zero), from the list view's `stale_secrets`.
- `carlos secrets fingerprint [--file <path>]` (default `/etc/carlos/host.env`): reads `CARLOS_SECRETS_KEY`, prints `KeyFingerprint` of its public half, never the key; no console call.
@@ -175,12 +175,13 @@ Order inside the handler, every refusal before the first write: `apiOwnerAccount
- Consumes: Task 5's `sealKeyFor`; Task 1's `Sealer`.
- Produces:
- Every `sealPub *ecdh.PublicKey` parameter in `objstore` and `mail` becomes `seal appconfig.Sealer`; they call `seal.Seal(appconfig.Binding{acct, app}, ...)` and store the returned Var (with `SealedTo`).
+ - Relay (plan review R2 #1): `relayReady()` (`relayops.go:477`) drops its `s.cfg.SecretsPub == ""` arm (`errRelayNoSealKey`); its callers `relayEnable` (`:979`), the rotate path (`:1347`) and owned-environment delivery (`relayenv.go:207`) call `sealKeyFor(ctx, sqid, app)` right after `relayReady` and before the first mutation, mapping `errNoDeploymentKey` to the existing `errRelayNoSealKey` answer and `errFleetNoSecretsKey` to the keyless-fleet row; `relayApplyConfig`/`relayApplyConfigIn` take the `appconfig.Sealer` instead of parsing the key.
- Selection is context-based: `sealKeyFor(ctx, sqid, app)` returns typed errors (`errFleetNoSecretsKey`, `errNoDeploymentKey`, `errUnknownApp`). HTTP doors wrap it: `func (s *Server) storeSealKey(w http.ResponseWriter, ctx context.Context, acct *Account, app string) (appconfig.Sealer, bool)` and the mail twin map each error to its approved refusal before any backend call. `instanceStorePreflight(ctx, w, acct, app)` returns `(appconfig.Sealer, bool)`; its detached seed caller (`apiinstanceseed.go:446`) calls `sealKeyFor` directly and records the error as the seed's failure.
- `rotateWebhookBudget(ctx)` and `convergeCallbackKey(ctx, acct *Account, app string)` take no key; each app's sealer comes from `sealKeyFor(ctx, target.acct, target.app)`. Background walks (plan storage, team credentials, webhook rotation) skip an app whose `sealKeyFor` fails, with a log line, and retry next pass.
- Lock ownership (plan review R1 #2). `lockAccount` is a non-reentrant keyed mutex, so it is taken only at entry points, never inside `sealKeyFor`, the package sealers or any helper. Entry points that take it (before any app lock): the config PUT (`handleAPIConfigPut`, before `teamApplyEnvironment`'s app lock, `apiconfig.go:682-715`), the key door, `handleAPIEnvironmentFork`, `placeAppTarget`'s callers, `handleAPIStoreGrant`/`Rotate`/`Provision`, `handleAPIEmailEnable`/`Rotate`, the scan doors, `handleAPISystemWebhookRotate` (per app inside `rotateWebhookBudget`), and each background walk per app. Entry points that ALREADY hold it and must not take it again: app creation (`apicli.go:497`, around `claimAppWith`), instance creation (`apiinstances.go:2009`, `:2083`, around private-store provisioning), and anything under `planLock` when plans are enabled (`plancaps.go:227`). Where an entry point holds it only when plans are enabled, the seal runs unlocked with plans off: an accepted I2 gap (§2.1), noted in a comment. The implementer lists every entry point in the commit message with which arm it is.
-- Guard (`TestOnlySealKeyForBuildsSealers`): load every non-test package of the module with `golang.org/x/tools/go/packages` (types and syntax), and collect by OBJECT IDENTITY (`types.Info.Uses` resolving to the `*types.Func`, so import aliases and same-package calls count): calls to `appconfig.Seal`, `appconfig.SealBound`, `appconfig.SealUnbound`, `appconfig.NewSealer`, the method `(appconfig.Sealer).Seal`, and `archive.Seal`. A `Sealer` composite literal outside `internal/appconfig` cannot compile (unexported fields); the test also asserts the struct has no exported field. Inside `internal/appconfig`, calls from `Sealer.Seal` to `SealBound`/`SealUnbound` and from `Seal` to them are allowed. Method calls `(Sealer).Seal` are allowed anywhere (a sealer can only come from an allowed constructor). If `x/tools` is not already a module dependency, use `go/types` with `go/importer.ForCompiler(fset, "source", nil)` instead; no new dependency. Allowlist, by enclosing function: `appconfig.(Sealer).Seal`; `console.(*Server).sealKeyFor`; `main.sealSecretAPI`; `main.runSecretsSet` (direct mode, after Task 8's checks); `archive.Seal` and its callers `buildArchive` and `offlineArchive` in `internal/host` (platform moves, deployment key; fleet instances are not moved). Any other call fails the test naming file:line. Negative fixtures as testdata packages: a new site with an arbitrary key, the same through an aliased import (`ac "…/internal/appconfig"`), a second `NewSealer` inside `sealkey.go` outside `sealKeyFor`, and a sealer for `bab/shop` used on `bab/other` (fails at runtime with `ErrSealerBinding`).
+- Guard (`TestOnlySealKeyForBuildsSealers`): load every non-test package of the module with `golang.org/x/tools/go/packages` (types and syntax), and collect by OBJECT IDENTITY (`types.Info.Uses` resolving to the `*types.Func`, so import aliases and same-package calls count): calls to `appconfig.Seal`, `appconfig.SealBound`, `appconfig.SealUnbound`, `appconfig.NewSealer`, the method `(appconfig.Sealer).Seal`, and `archive.Seal`. Constructions too (plan review R2 #2): the guard also collects every composite literal whose type is `appconfig.Sealer` (via `types.Info.Types`), anywhere in the module, and allows exactly one, inside `NewSealer`; outside `internal/appconfig` a literal cannot compile (unexported fields), and the test asserts the struct has no exported field. Inside `internal/appconfig`, calls from `Sealer.Seal` to `SealBound`/`SealUnbound` and from `Seal` to them are allowed. Method calls `(Sealer).Seal` are allowed anywhere (a sealer can only come from an allowed constructor). If `x/tools` is not already a module dependency, use `go/types` with `go/importer.ForCompiler(fset, "source", nil)` instead; no new dependency. Allowlist, by enclosing function: `appconfig.(Sealer).Seal`; `console.(*Server).sealKeyFor`; `main.sealSecretAPI`; `main.runSecretsSet` (direct mode, after Task 8's checks); `archive.Seal` and its callers `buildArchive` and `offlineArchive` in `internal/host` (platform moves, deployment key; fleet instances are not moved). Any other call fails the test naming file:line. Negative fixtures as testdata packages: a new site with an arbitrary key, the same through an aliased import (`ac "…/internal/appconfig"`), a second `NewSealer` inside `sealkey.go` outside `sealKeyFor`, a second constructor inside `internal/appconfig` that returns `Sealer{...}`, and a sealer for `bab/shop` used on `bab/other` (fails at runtime with `ErrSealerBinding`).
-- [ ] **Step 1: Write failing tests**: `TestOnlySealKeyForBuildsSealers` with its three negative fixtures; `TestStoreGrantOnKeylessFleetRefusesBeforeBackend` (the fake provisioner records no call); `TestStoreGrantOnFleetSealsToTheFleetKey` (the delivered Var opens with the fleet private key and has `SealedTo`); `TestMailEnableOnFleetSealsToTheFleetKey`; `TestRelayApplyOnFleet`; `TestWebhookRotateUsesEachAppsKey` (two apps, one platform and one fleet, sqid-only targets); `TestPlanStorageSkipsKeylessFleet`; lock tests through HTTP with plans enabled AND disabled: `TestAppCreateAdoptingFleetAppDoesNotDeadlock`, `TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock`, `TestTeamEnvironmentCreateOnFleetDoesNotDeadlock` (each with a 5 s deadline).
+- [ ] **Step 1: Write failing tests**: `TestOnlySealKeyForBuildsSealers` with its three negative fixtures; `TestStoreGrantOnKeylessFleetRefusesBeforeBackend` (the fake provisioner records no call); `TestStoreGrantOnFleetSealsToTheFleetKey` (the delivered Var opens with the fleet private key and has `SealedTo`); `TestMailEnableOnFleetSealsToTheFleetKey`; `TestRelayApplyOnFleet`; `TestWebhookRotateUsesEachAppsKey` (two apps, one platform and one fleet, sqid-only targets); `TestPlanStorageSkipsKeylessFleet`; `TestRelayEnableOnFleetWithNoDeploymentKey` (console with empty `SecretsPub`, fleet key registered: enable succeeds and seals to the fleet key) and `TestRelayEnableOnKeylessFleetRefusesBeforeMutation` (no relay record written); lock tests through HTTP with plans enabled AND disabled: `TestAppCreateAdoptingFleetAppDoesNotDeadlock`, `TestInstanceCreatePrivateStoreOnFleetDoesNotDeadlock`, `TestTeamEnvironmentCreateOnFleetDoesNotDeadlock` (each with a 5 s deadline).
- [ ] **Step 2: Run** `nice -n 19 go test ./internal/console/ ./internal/objstore/ ./internal/mail/ -run 'TestOnlySealKeyForBuildsSealers|TestStoreGrantOn|TestMailEnableOnFleet|TestRelayApplyOnFleet|TestWebhookRotateUsesEachAppsKey|TestPlanStorageSkipsKeylessFleet' -count=1`. Expected: FAIL.
- [ ] **Step 3: Implement**, approved rows only.
- [ ] **Step 4: Run** the same, plus `-run 'Store|Mail|Relay|Scan|Webhook|Plan|Team'` over the three packages. Expected: PASS. Mutation: add `appconfig.SealBound` to `apimail.go`; the guard fails naming it.
diff --git a/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R2.md b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R2.md
new file mode 100644
index 000000000..7d842caf4
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-FINDINGS-fleet-secrets-key-plan-R2.md
@@ -0,0 +1,26 @@
+- R1 #1: resolved — append-only fingerprints preserve exclusion after failed replacement.
+- R1 #2: resolved — entry-point ownership avoids reacquiring the account lock.
+- R1 #3: resolved — replacement uses a separate “any sealed values” query.
+- R1 #4: resolved — public-key encoding and context-based selection are specified.
+- R1 #5: resolved — remote sentinel encoding is included.
+- R1 #6: partly resolved — identity-based calls are covered; sealer constructions remain incomplete.
+- R1 #7: resolved — CLI stale counts and their repair test are specified.
+- R1 #8: resolved — mutations now distinguish successful rendering from refusal witnesses.
+
+1. **P1 — Task 6: relay readiness still requires the deployment key. Invariant: fleet credential delivery uses the app’s selected key.**
+ The migration names `relayApplyConfig` and `relayApplyConfigIn` ([plan:171](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:171)), but omits `relayReady`, which refuses when `s.cfg.SecretsPub` is empty ([relayops.go:484](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/relayops.go:484)). `relayEnable` calls this before reaching the migrated sealer ([relayops.go:979](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/internal/console/relayops.go:979)); rotation and owned-environment delivery also call it. Consequently, a fleet with a registered key still cannot receive relay credentials when the console has no deployment public key.
+ **Fix:** separate general relay readiness from per-app key selection; use `sealKeyFor` before each app’s mutation. Add HTTP witnesses with a registered fleet key and empty deployment key, plus a keyless-fleet refusal before mutation.
+
+2. **P2 — Task 6, carried from R1 #6: the guard still misses sealer construction. Invariant: I1 sealing-boundary coverage.**
+ [Plan:181](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:181) scans calls but specifies no check for composite literals inside `internal/appconfig`. A second function there can construct a fully populated `Sealer` from an arbitrary key; its callers and subsequent `Sealer.Seal` calls pass the proposed guard. Unexported fields do not prevent that. This remains short of the requirement to inventory **every construction** ([spec:245](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/specs/2026-10-29-fleet-secrets-key-design.md:245)).
+ **Fix:** enforce construction in `NewSealer` alone, inspect typed composite literals throughout the package, and add a negative fixture for another constructor. This is the second round in the same fault family; stopping rule 2 applies.
+
+3. **P2 — Task 4: the registration client has no session. Invariant: interface completeness.**
+ The declared free function receives only context, account, fleet and key ([plan:136](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:136)). `apiAcct` contains only `Seg` and `Exact` ([apimode.go:437](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/apimode.go:437)); the authenticated client belongs to `apiSession`.
+ **Fix:** declare `func (s *apiSession) setFleetSecretsKey(...)`, following the existing fleet methods, and use the CLI’s resolved session.
+
+4. **P2 — Task 0: draft status disagrees with the prescribed gate. Invariant: validation instructions match the reused parser.**
+ [Plan:52](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/docs/superpowers/plans/2026-10-29-fleet-secrets-key.md:52) requires `draft` rows and then copies the rootfs gate expecting PASS. That gate accepts `pending`, `approved` and `struck` ([approved_rootfs_copy_test.go:155](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-secrets-key/approved_rootfs_copy_test.go:155)).
+ **Fix:** use `pending`, or explicitly specify a fleet-specific parser status list accepting `draft`.
+
+NOT READY
\ No newline at end of file
diff --git a/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R3.md b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R3.md
new file mode 100644
index 000000000..f3b1f1282
--- /dev/null
+++ b/docs/superpowers/plans/CODEX-REVIEW-BRIEF-fleet-secrets-key-plan-R3.md
@@ -0,0 +1,13 @@
+# Review brief: fleet secrets key implementation plan, round 3 of 3 (LAST)
+
+Repo carlos/platform, branch `design-fleet-secrets-key`, commit named in your prompt.
+Under review: `docs/superpowers/plans/2026-10-29-fleet-secrets-key.md`. Authorities as in `CODEX-REVIEW-BRIEF-fleet-secrets-key-plan.md` (same directory); the same "Fixed: do not re-argue" list applies. Do not edit files.
+
+This is the last round allowed (AGENTS.md "Stopping rules"). Scope: the diff from round 2's commit to this one (`git diff f3d406dedbe97405623f2ed5ce74048b45776dd9 <this commit> -- docs/superpowers/plans/2026-10-29-fleet-secrets-key.md`), plus anything that diff breaks elsewhere in the plan.
+
+1. One line per round 2 finding (`CODEX-FINDINGS-fleet-secrets-key-plan-R2.md`): resolved, partly, or not.
+2. New findings only where the round 2 fixes introduce a would-not-work, an I1 break, or a wrong file:line or signature. Name the invariant beside each.
+
+Severity: P1 unsafe (I1), would not compile, a test fails, or would not work; P2 wrong or missing, fixed without reopening; P3 polish. A P1 states the failure and file:line evidence.
+
+Output: dispositions, findings ranked, then one verdict line: READY, READY AFTER FIXES (no P1), or NOT READY. A P1 here goes to Paul.