spec: config versions, digests and receipts (#522), plan 1 draft
Plan 2 (proof of delivery) section is a placeholder pending the box-side map.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+437
−0
docs/superpowers/specs/2026-11-02-config-receipts-design.md+437 −0
CI cancelled — superseded by a newer push — run details
Intent
Attributed to this commit: 29.7 g CO₂e (2,858,395 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-config-receipts-522, 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/specs/2026-11-02-config-receipts-design.md b/docs/superpowers/specs/2026-11-02-config-receipts-design.md| new file mode 100644 |
| index 000000000..94f4c2272 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-02-config-receipts-design.md |
| @@ -0,0 +1,437 @@ |
| +# Config versions, digests and receipts: proving what a config change touched |
| + |
| +Status: DRAFT rev 1, 2026-11-02. Discussion: amadan carlos/platform #522 |
| +(filed by the Oficina Home agent; its consumer is oficina/home #103). |
| +Branch `design-config-receipts-522`, cut from main `5394c7f9`. Every |
| +file:line below is on that commit. |
| + |
| +## 0. Status and shape |
| + |
| +One spec, built as two plans: |
| + |
| +- **Plan 1, versions, digests and conditional writes** (§4). Console and |
| + `internal/appconfig` only. No box change. |
| +- **Plan 2, proof of delivery** (§5). Box-side: what the running process on |
| + each route actually has. Touches the root binary's packages, so it carries a |
| + census section and Astra's census verdict (#280). |
| + |
| +Oficina's production activation needs both. Plan 1 lands first because it is |
| +small, self-contained, and lets the adoption runner be written and tested |
| +against real doors while Plan 2 is built. |
| + |
| +## 1. Intent |
| + |
| +An agent adopting an existing app has to add two settings (`AGENT_ISSUER`, |
| +`AGENT_TEAM`) to six live apps and then show, with evidence the platform |
| +supports, that it changed those two and nothing else. Today it cannot: |
| + |
| +- `GET /api/cli/apps/{account}/{app}/config` returns only `key` and `kind` |
| + for a secret (`internal/console/apiconfig.go:184`). A list of names does not |
| + show that a value is unchanged. |
| +- `PUT` on the same path is a per-key read-modify-write behind a CAS on the |
| + bucket object (`applyAt`, `internal/appconfig/store.go:162`), but the |
| + version it compared against is never shown to the caller, the caller cannot |
| + supply one, and the answer is `{"result":"ok","removed":n}`: no record of |
| + what moved. |
| +- A stored bundle that is correct does not mean the process has it (#516: |
| + months of undelivered config behind healthy listings; #490: a release that |
| + started before its config arrived). |
| + |
| +Paul's ruling, 2026-11-02: the per-key question is **"has this changed since |
| +I last looked"**, not "does this equal a value I hold". Nobody needs to check |
| +a stored secret against a plaintext copy. That ruling is what lets secrets be |
| +covered without any risk of revealing or confirming a value. |
| + |
| +Both people and agents use this (Paul, 2026-11-02). People see it as a |
| +receipt after `carlos env set` / `carlos secrets set` and a version in |
| +`list`; agents use the conditional write and the digests to make scripted |
| +changes that refuse to land on top of something they did not expect. |
| + |
| +## 2. Goals, non-goals, anti-goals |
| + |
| +Goals: |
| + |
| +1. Every config layer read through the console carries a **version** that |
| + changes when, and only when, the stored object changes. |
| +2. Every var read through the console carries a **digest** that changes when |
| + its stored value changes, for secrets as well as plain vars, and reveals |
| + nothing about a secret's plaintext. |
| +3. A write can carry a **precondition** (the version the caller last saw) and |
| + is refused, with nothing written, when the layer has moved. |
| +4. Every successful write returns a **receipt**: the layer, its version before |
| + and after, and the exact names set, removed and asked-to-remove-but-absent. |
| +5. An owner can see, for one instance, which layer each key's value comes |
| + from (shadowing). |
| +6. (Plan 2) An owner can see, per route, whether the running process has the |
| + config now stored, with honest pending, blocked and unknown answers. |
| + |
| +Non-goals: |
| + |
| +- Checking a stored secret against a plaintext value (ruled out above). |
| +- Cross-layer transactions. Layers are separate bucket objects; this spec |
| + reports what moved around a write rather than pretending several objects |
| + changed atomically (§4.6). |
| +- Receipts for writes that do not pass through the console: a CLI in bucket |
| + mode writes the store directly (`appconfig_cli.go:415`). Its writes still |
| + move versions and digests, so an observer still sees them. |
| +- Changing who may read config. The doors keep their existing gates (§4.8). |
| + |
| +Anti-goals (a failure even if it works): |
| + |
| +- A digest from which a short or guessable secret could be recovered, or that |
| + confirms a guess. A plain hash of the plaintext would be exactly that. |
| +- Any envelope, plaintext or plaintext-derived hash in a log line, audit row, |
| + error or report. |
| +- A version that reads as current when it is not, or "delivered" when the box |
| + does not know. |
| +- A team credential learning anything about the default bundle or instance |
| + overlays (#449's boundary). |
| + |
| +## 3. What exists today |
| + |
| +### 3.1 Storage |
| + |
| +Three layers, each one JSON bucket object of the same `Manifest` shape |
| +(`internal/appconfig/appconfig.go:26`): |
| + |
| +| Layer | Key | Written by | |
| +|---|---|---| |
| +| default | `apps/<acct>/<app>/config.json` | owner via console or bucket-mode CLI; platform features | |
| +| named environment | `apps/<acct>/<app>/environments/<name>.json` | owner; team credential (owned environments) | |
| +| instance overlay | `apps/<acct>/<app>/instances-config/<host>.json` | platform only (`ApplyInstance`, `instances.go:386`) | |
| + |
| +Resolution for a route: default, then its environment on top, then its |
| +host's overlay on top (`LoadMergedHostVersions`, `instances.go:223`). An |
| +**owned** environment is standalone and never folds the default in |
| +(`OwnerScope`, `appconfig.go:102`). |
| + |
| +Every write is a read, an in-memory change and a `Put` at the read's etag |
| +(`putManifestAt`, `store.go:212`); a lost race is `release.ErrCASConflict`, |
| +answered 409 by the door. Every write also bumps the app's generation object |
| +(`generation.go`) so boxes notice within seconds. The store's etag is not a |
| +safe public version on its own: `getForWriteAt`'s comment (`store.go:91`) |
| +notes a store may return an empty etag for an object that exists, and the |
| +etag's derivation differs by backend (content hash in DirStore; S3's own). |
| + |
| +### 3.2 Writers other than the owner |
| + |
| +Platform features write into the same bundles: mail senders |
| +(`internal/console/apimail.go`, `internal/mail/walk*.go`), relay |
| +(`relayenv.go`, `relayops.go`), scanning (`apiscan.go`, `scankeysync.go`), |
| +object storage (`internal/objstore/walk.go`), swap and interactive settings |
| +(`apiswap.go`, `appswap.go`, `apiinteractivesetting.go`). Their writes move |
| +versions like any other. That is correct: a preservation check must see them. |
| + |
| +### 3.3 Doors |
| + |
| +`internal/console/authcli.go:723-725`: GET, PUT and `POST .../config/sync`, |
| +all `svcrole.Allow(svcrole.Operate)`; team credentials reach GET and PUT for |
| +owned environments only, and never the default bundle (`apiconfig.go:197`, |
| +`:385`). |
| + |
| +### 3.4 Prior art for delivery |
| + |
| +`ConfigAck` (`internal/appconfig/configack.go`): after config sync converges |
| +a route, the box writes an acknowledgement naming what it delivered, including |
| +the instance overlay's etag. Today only `carlos relay status` reads it. |
| +`RenderHeld` / `CheckRenderedIdentity` (`renderheld.go`) are internal to moves. |
| +§5 builds on these. |
| + |
| +## 4. Plan 1: versions, digests, conditional writes |
| + |
| +### 4.1 In one paragraph |
| + |
| +The console computes a layer's **version** as a SHA-256 of the stored |
| +object's bytes, and each var's **digest** as a SHA-256 over its stored form |
| +(plain value for an env var, sealed envelope for a secret). Reads return both. |
| +A write may send `if_version`; the console reads the layer, compares, refuses |
| +with 412 on a mismatch, otherwise applies and writes at the read's etag, so a |
| +race between the compare and the write is still caught by the existing CAS. |
| +The answer to every successful write is a receipt. A new read, |
| +`GET .../config/effective?host=<host>`, shows for one instance which layer |
| +each key comes from. |
| + |
| +### 4.2 Version |
| + |
| +``` |
| +version = "cv1:" + lowercase hex SHA-256(raw object bytes as stored) |
| +``` |
| + |
| +- Computed by the console from the bytes it read, never from the store's etag |
| + (§3.1). Two reads of unchanged bytes give the same version on every backend. |
| +- An absent layer has version `"none"`. It is distinct from an existing empty |
| + manifest, which has a real version: by `applyAt`'s contract |
| + (`store.go:153`) "configured, then fully unset" and "never configured" are |
| + different states and render differently on the box. |
| +- Content-derived, so A, then B, then A again gives the first version back. |
| + That is the right answer for "has this changed": the bytes are identical. |
| + Secrets cannot return to an earlier version by accident, because sealing is |
| + randomised (§4.3). |
| +- Manifests marshal deterministically (`json.MarshalIndent` of a struct with a |
| + map; Go sorts map keys), so a version does not move without a content change. |
| + A write that changes nothing (setting a var to its current plain value) |
| + still rewrites the object; with identical bytes the version stays the same, |
| + and the receipt says so (`changed: false`). |
| + |
| +### 4.3 Digest |
| + |
| +``` |
| +digest = "vd1:" + lowercase hex SHA-256( |
| + "carlos.config.var.v1" 0x00 kind 0x00 value 0x00 envelope 0x00 sealed_to) |
| +``` |
| + |
| +over the four stored fields of `Var` (`appconfig.go:174`), empty strings where |
| +a field is absent. |
| + |
| +- **Secrets.** The input is the envelope, which is randomised at seal time, so |
| + the digest is unrelated to the plaintext. Nobody can test a guess against it |
| + without the box's private key. Setting a secret again to the same plaintext |
| + gives a new digest: it reads as changed, which is accurate (somebody wrote |
| + it). |
| +- **Plain vars.** The input includes the plaintext value. Whoever can read the |
| + digest can already read that value from the same response, so the digest |
| + reveals nothing new to its reader. It does make a plain value guessable from |
| + the digest alone, so **digests of plain vars are not to be put in reports** |
| + that travel wider than the value would; §4.10 says so in the docs. (My call; |
| + the alternative, a per-app keyed MAC, needs a stored key and buys nothing for |
| + a reader who can already see the value.) |
| +- A client can compute the digest of what it sent: the plain value, or the |
| + envelope it sealed. That is what makes retry-without-rebaselining work |
| + (§4.7). The CLI exposes this as a helper (§4.9). |
| + |
| +### 4.4 Reads |
| + |
| +`GET /api/cli/apps/{account}/{app}/config[?environment=<name>]` gains, without |
| +removing anything: |
| + |
| +```json |
| +{ |
| + "bundle": "default", |
| + "version": "cv1:…", |
| + "vars": [ |
| + {"key": "DATABASE_URL", "kind": "secret", "digest": "vd1:…"}, |
| + {"key": "LOG_LEVEL", "kind": "env", "value": "info", "digest": "vd1:…"} |
| + ], |
| + …existing fields… |
| +} |
| +``` |
| + |
| +Additive JSON; an older CLI ignores the new fields. The rule that a secret's |
| +envelope never comes back out (`apiconfig.go:171`) is unchanged: the digest |
| +is computed from the envelope, and the envelope is still structurally absent. |
| + |
| +New: `GET /api/cli/apps/{account}/{app}/config/effective?host=<host>`. |
| +`host` must be a route of this app (refused with the gate's own 404 |
| +otherwise). Answer: |
| + |
| +```json |
| +{ |
| + "host": "shop.example.com", |
| + "environment": "prod", |
| + "owned": false, |
| + "layers": { |
| + "default": {"version": "cv1:…"}, |
| + "environment": {"name": "prod", "version": "cv1:…"}, |
| + "overlay": {"version": "none"} |
| + }, |
| + "vars": [ |
| + {"key": "DATABASE_URL", "kind": "secret", "digest": "vd1:…", "from": "environment", |
| + "shadows": ["default"]} |
| + ] |
| +} |
| +``` |
| + |
| +- `from` is the layer whose value the route gets; `shadows` lists lower layers |
| + that also set the key. This is how an observer sees a key it added to the |
| + default bundle being overridden by the environment or by a platform overlay. |
| +- For an owned environment, `owned: true`, `layers.default` is absent, and no |
| + var reports `from: "default"` (it is standalone). |
| +- Plain vars carry `value` only when it comes from the default or environment |
| + layer. An overlay is platform-written; its plain values are shown as they are |
| + in the owner's other reads today (decided by the builder from what |
| + `instances.go` already exposes; if nothing exposes them, digest only). |
| +- Read with the same loader boxes render from (`LoadMergedHostVersions`), so |
| + the answer cannot disagree with what a box would build. |
| + |
| +### 4.5 Conditional writes |
| + |
| +`PUT` gains one optional body field, `if_version`. When present: |
| + |
| +1. Refused with 400 if the request also carries `exec_delivery`. That half is |
| + a second CAS write (`apiconfig.go:590`) and cannot share one precondition. |
| + A caller sends two requests. |
| +2. All existing refusals run first, unchanged (nothing written). |
| +3. The door reads the target layer (raw bytes and etag), computes its version, |
| + and compares. Mismatch: **412**, nothing written, body |
| + `{"error": "...", "version": "<current>"}`. `if_version: "none"` means |
| + "only if this layer does not exist yet". |
| +4. Applies sets and unsets in memory and writes at the read's etag. A CAS |
| + conflict here means the layer moved between step 3 and the write: also 412, |
| + nothing written. |
| +5. Answers with a receipt (§4.6). |
| + |
| +Without `if_version`, behaviour is today's (409 on a CAS conflict), plus the |
| +receipt. That keeps every existing caller working. |
| + |
| +Header vs body: the field is in the body because the CLI's door client sends |
| +JSON bodies everywhere and a body field shows up in the request log the |
| +console already keeps. An `If-Match` header is accepted as a synonym if the |
| +builder finds it cheap; the body field wins if both are sent and differ (400). |
| +(My call.) |
| + |
| +This needs `applyAt` to accept a caller-supplied expected version. The builder |
| +adds that as a parameter on the internal path, not a second write path, so the |
| +platform writers in §3.2 keep using the same function. |
| + |
| +### 4.6 Receipts |
| + |
| +Every successful PUT answers (existing fields kept): |
| + |
| +```json |
| +{ |
| + "result": "ok", |
| + "removed": 1, |
| + "receipt": { |
| + "bundle": "default", |
| + "version_before": "cv1:…", |
| + "version_after": "cv1:…", |
| + "changed": true, |
| + "set": ["AGENT_ISSUER", "AGENT_TEAM"], |
| + "unset": ["OLD_FLAG"], |
| + "unset_absent": ["NEVER_THERE"], |
| + "digests": {"AGENT_ISSUER": "vd1:…", "AGENT_TEAM": "vd1:…"}, |
| + "others": { |
| + "default": {"before": "cv1:…", "after": "cv1:…"} |
| + } |
| + } |
| +} |
| +``` |
| + |
| +- `set`, `unset` and `unset_absent` are sorted and exact. `unset` is what was |
| + present and removed; `unset_absent` is what was asked for and not there. |
| +- `digests` covers the keys just set, so the caller can check what it sent. |
| +- `others` is present for a write to a named (non-owned) environment and names |
| + the default bundle's version read just before and just after the write. The |
| + two layers are separate objects with no shared transaction: if `before` and |
| + `after` differ, somebody wrote the default bundle during this request, and |
| + the caller decides what that means. Instance overlays are not listed; there |
| + is one per host, and `config/effective` is the per-host view. |
| +- The audit row keeps its rule of counts, never names (`apiconfig.go:570`), |
| + and adds the two versions. A version is a hash over the whole object, which |
| + includes envelopes; it reveals nothing a row reader could use. (My call.) |
| + |
| +### 4.7 Retries and the adoption recipe |
| + |
| +The facility is designed so that this procedure is sound: |
| + |
| +1. **Baseline.** Read the layer: keep its version and the digest of every key |
| + the runner must preserve. |
| +2. **Write.** PUT with `if_version` = baseline version, setting only the new |
| + keys. For a secret, keep the envelope sent. |
| +3. **Receipt.** On 200, check `set` is exactly the new keys, `unset` is empty, |
| + and each digest in `digests` equals the digest of what was sent. |
| +4. **Lost answer or 412.** Read again. Then: |
| + - every preserved key's digest equals the baseline, and every new key's |
| + digest equals what was sent: the write landed. Done. |
| + - every preserved key equals the baseline and the new keys are absent: the |
| + write did not land and nothing the runner cares about moved. Retry with |
| + `if_version` = the version just read. |
| + - any preserved key differs from the baseline, or is gone: stop. Something |
| + else changed what the runner promised to preserve. |
| + |
| +The baseline is the per-key digests, not the version, so a write to some |
| +unrelated key between attempts does not force a new baseline, and a change to |
| +a preserved key is never absorbed into one. A secret's digest cannot collide |
| +with a resealed copy of the same plaintext, so "preserved" really means |
| +"nobody wrote it". |
| + |
| +The receipt describes the stored layer only. Whether the process got it is §5. |
| + |
| +### 4.8 Who may read what |
| + |
| +- The GET and PUT doors keep their gates: `Operate` or `Admin`, the app's |
| + account only; every other account is the gate's byte-identical 404. |
| +- `config/effective` is registered with the same gate and is **not** reachable |
| + by team credentials. A team reads its owned environment through the existing |
| + GET, which now carries its version and digests; it never sees default or |
| + overlay versions, digests or names. (#449.) |
| +- #522 asks for "owner-only". Here that means: the app's own account, through |
| + the roles that can already read its config today. A digest says less than |
| + the plain values those roles already read, and a secret's digest says only |
| + "changed since". If the reviewer reads #522 as needing a narrower gate, the |
| + narrowing is to register `config/effective` with `Admin` only; this is the |
| + one open question for review. (My call.) |
| + |
| +### 4.9 Command line |
| + |
| +- `carlos env list` / `carlos secrets list`: print the layer's version in the |
| + header line; `--digests` adds a digest column. `--json` carries both always. |
| +- `carlos env set` / `unset`, `carlos secrets set` / `unset`: print the |
| + receipt's names and, when `changed` is false, say nothing changed. A new |
| + `--if-version <v>` flag passes the precondition; a 412 prints the current |
| + version and exits non-zero with its own code so a script can tell it from |
| + other failures. |
| +- `carlos env effective --app <a> --host <h>`: the effective view, table or |
| + `--json`. |
| +- `carlos env digest --kind env|secret …`: computes a digest locally from a |
| + value or a saved envelope, for scripts doing §4.7 step 3. |
| + |
| +All new strings go through copy review at plan time. |
| + |
| +### 4.10 Docs |
| + |
| +One page section on config versions and digests, the §4.7 recipe as a worked |
| +example, and the line that a plain var's digest is as sensitive as its value. |
| + |
| +### 4.11 Plan 1 tests |
| + |
| +The negative checks #522 lists, each a test through the real doors: |
| + |
| +| Case | Expected | |
| +|---|---| |
| +| secret changed (resealed, same plaintext) | its digest moves; version moves | |
| +| plain value changed | its digest moves | |
| +| key added to the default bundle shadowed by the environment | `effective` shows `from: environment`, `shadows: [default]` | |
| +| key shadowed by a platform overlay | `from: overlay` | |
| +| stale `if_version` | 412, layer bytes unchanged | |
| +| concurrent write between compare and put | 412, nothing written (test hook at the existing `configPutBeforeApply` seam) | |
| +| `if_version` with `exec_delivery` | 400 | |
| +| `if_version: none` on an existing layer | 412 | |
| +| wrong instance (`host` of another app or account) | 404, same bytes as unknown app | |
| +| cross-account | 404 | |
| +| team credential on `effective` | 404 | |
| +| team credential on its owned environment | version and digests, no default info | |
| +| receipt names | exact `set` / `unset` / `unset_absent` | |
| +| no envelope, plaintext or plaintext hash in any log line or audit row | asserted over captured logs and rows | |
| +| version stable across reads; changes only with bytes | both stores (DirStore and the S3 store's test double) | |
| + |
| +Undelivered config and wrong-storage cases belong to Plan 2. |
| + |
| +### 4.12 Plan 1 census |
| + |
| +The console is outside census scope. `internal/appconfig` is inside it (the |
| +root `carlos` binary's package set includes it). Plan 1 adds pure functions |
| +(version, digest) and a parameter to `applyAt`; the root binary gains no new |
| +read of tenant input and no new authority. The census card is still run and |
| +the verdict recorded on #280. |
| + |
| +## 5. Plan 2: proof of delivery |
| + |
| +(Being written: depends on the box-side map of config acks, held renders and |
| +blocked-delivery paths.) |
| + |
| +## 6. Rollout |
| + |
| +Plan 1 is additive and needs no switch: new response fields, a new optional |
| +request field, a new read door. Older CLIs are unaffected. Release with the |
| +next platform release; no roll ordering beyond the usual dev first. |
| + |
| +## 7. Calls made in this draft (for Paul to check) |
| + |
| +1. Version is a hash of the stored bytes, not the store's etag (§4.2). |
| +2. Plain vars' digests include the value; documented as being as sensitive as |
| + the value (§4.3). |
| +3. "Owner-only" means the existing config read gate, not a new Admin-only |
| + gate; flagged for review (§4.8). |
| +4. Precondition in the JSON body, header as optional synonym (§4.5). |
| +5. Audit rows gain versions, still never names (§4.6). |