carlos / platform Public

spec rev 5: round 4 fixes; spec review closed by Paul

Server-side single-use OAuth state, backup inventory written before
ownership is lost, stalled-replicator alert, measurements split.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 125ba48e4445c3ac254ed53e4d2085a09c269a80 parent 12a744b
2 files changed, +111 −17
  • docs/superpowers/reviews/CODEX-FINDINGS-dpa-and-retention-R4.md +54 −0
  • docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md +57 −17

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-RhoENo
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/aws/smithy-go v1.28.1
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading golang.org/x/sys v0.49.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading golang.org/x/mod v0.41.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading github.com/oschwald/maxminddb-golang v1.13.1
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/pion/randutil v0.1.0
go: downloading github.com/prometheus/common v0.45.0
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/klauspost/compress v1.20.2
go: downloading modernc.org/sqlite v1.55.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading github.com/google/uuid v1.6.0
go: downloading modernc.org/mathutil v1.7.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec

amadan: job cancelled — a newer push superseded it

Intent

Human

<task-notification> <task-id>bom443pzs</task-id> <tool-use-id>toolu_017z82ZF1jiTxTtLGJTk356J</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/260ddc60-0dfc-4cf8-8857-7688d6275097/tasks/bom443pzs.output</output-file> <status>completed</status> <summary>Background command "Run Astra targeted round 4 in background" completed (exit code 0)</summary> </task-notification>

Attributed to this commit: 120 g CO₂e (13,869,180 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on dpa-and-retention, 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/reviews/CODEX-FINDINGS-dpa-and-retention-R4.md b/docs/superpowers/reviews/CODEX-FINDINGS-dpa-and-retention-R4.md
new file mode 100644
index 000000000..a9b440715
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-FINDINGS-dpa-and-retention-R4.md
@@ -0,0 +1,54 @@
+- **R3-1 — Partly resolved:** the persistent marker is specified, but the cooldown relies on an attempt lifetime Keymail does not enforce server-side.
+- **R3-2 — Resolved:** the first terms/privacy row records the policy already in force.
+- **R3-3 — Partly resolved:** the scope and promise follow Paul’s ruling; the operator action still lacks reliable backup ownership evidence.
+- **R3-4 — Partly resolved:** inactive replicas are reported, but their fifteen-day erasure deadline remains unenforced.
+- **R3-5 — Resolved:** initial recipients are snapshotted transactionally, with durable cohort membership.
+- **R3-6 — Resolved:** the effective date now respects both the emailed lower bound and actual deliveries.
+- **R3-7 — Resolved:** acceptance binds the letterhead and stored agreement; sanitization must preserve the fetched bytes.
+- **R3-8 — Resolved:** UX and copy review precede implementation.
+
+Reviewed commit `12a744b681673e15e2647b7fc7c79d3fbbdc9cb7`, limited to round 4’s scope. No files changed, subagents spawned, or test suites run.
+
+1. **P1 — §6.2: the cooldown assumes a server-enforced Keymail attempt expiry that does not exist.**
+
+ **Evidence:** [§6.2:581](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md:581) claims every attempt expires within fifteen minutes. Keymail’s state and verifier are stored in a cookie at [server.go:3860](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/server.go:3860); the ten-minute lifetime is only cookie `MaxAge` ([server.go:3009](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/server.go:3009)). The callback checks cookie contents and exchanges the code without checking the attempt’s age ([server.go:3905](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/server.go:3905)).
+
+ **Failure scenario:** a client retains the cookie and authorization URL from before deletion, then completes authorization after the cooldown. With a valid authorization code, the callback accepts the old state; the deletion gate now permits identity and session creation. Comparing lifetime constants cannot detect this missing enforcement.
+
+ **Fix:** retain the one-hour cooldown, but enforce Keymail state expiry server-side—for example, through a single-use state record expiring after ten minutes. This needs no comparison between attempt-start and deletion timestamps. Test a retained cookie after the cooldown, using a valid provider response, and require refusal.
+
+ **Fault family:** R1-2/R2-1/R3-1 — deletion must revoke outstanding authority to recreate an identity or issue credentials.
+
+2. **P1 — §6.6: historical hostname use does not establish ownership of the backup being deleted.**
+
+ **Evidence:** [§6.6:672](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md:672) selects hosts from audit history and trashed records, then deletes their replica prefixes unless a live record holds the host. Those prefixes are explicitly keyed by hostname alone ([createleftovers.go:4](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/createleftovers.go:4)). Audit writes are best effort ([server.go:5218](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/server.go:5218)), and purge removes the app’s records ([lifetimes_purge.go:86](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/internal/console/lifetimes_purge.go:86)).
+
+ **Failure scenario:** app A’s backup is deleted, freeing its hostname. App B subsequently uses that hostname and is later deleted, leaving B’s backup. Repeating A’s cleanup finds A’s historical hostname and no live record, so the specified action deletes B’s backup. Separately, a missing audit entry followed by record removal can leave a backup undiscoverable through the proposed inputs.
+
+ **Fix:** preserve a durable cleanup inventory before removing ownership records, identifying the app incarnation, storage location and backup generation or exact object versions. Record completed cleanup so retries cannot target a successor’s data. Require ownership and writer-exclusion proof throughout deletion; refuse ambiguous legacy prefixes. This can support the operator action without implementing #199’s automatic cleanup.
+
+ **Fault family:** backup deletion must identify all—and only—the requesting app’s data; historical hostname association is insufficient deletion authority.
+
+3. **P2 — §6.4: reporting inactive replicas does not enforce fifteen-day erasure.**
+
+ **Evidence:** [§6.4:623](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md:623) adds an alert and manual deletion action, excludes the live prefix, and retains the unconditional fifteen-day promise. The bucket explicitly never expires current objects ([main.tf:137](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/infra/modules/deployment-buckets/main.tf:137)).
+
+ **Failure scenario:** an abandoned replica remains after an operator misses the alert. A stopped replicator belonging to the current console is worse: its prefix is excluded from both reporting and deletion. Either can retain deleted rows beyond fifteen days.
+
+ **Fix:** specify a deadline-enforcing cleanup workflow for authoritatively retired replicas, with retries and completion verification. Detect stalled current replication separately and require recovery or safe retirement before the deadline. Include both cases in the measurement; an alert alone is insufficient.
+
+ **Fault family:** R1-9/R2-4/R3-4 — backup erasure deadlines must cover inactive and stalled replicas.
+
+4. **P2 — §6.6 measurement: the acceptance criterion still assumes automatic database-backup purge.**
+
+ **Evidence:** [§6.6:660](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md:660) correctly states that app purge leaves database backups. Yet [§6.6:682](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/dpa-and-retention/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md:682) still says the measured purge deletes the whole replica prefix, including snapshots.
+
+ **Failure scenario:** the prescribed measurement either fails against the intended implementation or counts operator cleanup as automatic purge, leaving the actual on-request promise unverified.
+
+ **Fix:** measure automatic app-data cleanup separately from database-backup cleanup. For backups, start the thirty-day clock at the request and verify the operator action’s completion, retries and deletion of every version.
+
+ **Fault family:** acceptance measurements must verify the promised deletion workflow and its actual starting event.
+
+No P3 findings.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md b/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md
index f9fe87974..181cbac37 100644
--- a/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md
+++ b/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md
@@ -1,6 +1,6 @@
# Data processing agreements and customer-set retention
-Status: draft rev 4, 2026-11-25. Branch `dpa-and-retention`.
+Status: rev 5, 2026-11-25. Spec review closed by Paul after round 4. Branch `dpa-and-retention`.
Asked for by Paul, 2026-11-25 (prompts on the branch ledger).
Review history:
@@ -27,6 +27,11 @@ Review history:
no attempt timestamps (§6.2);
- the live policy: **record a baseline first** (§3.1);
- a **short targeted round 4** on the sections rev 4 changes.
+- Round 4 (Astra, `CODEX-FINDINGS-dpa-and-retention-R4.md`, 12a744b6):
+ NOT READY, 2 P1, 2 P2, marked **(R4-n)**. Paul, 2026-11-25: apply the
+ fixes and **stop reviewing the spec**; go to the plan. The tasks on
+ sign-in, deletion and storage get their own Astra review when built
+ (stopping rule 3), and the branch gets one before merge.
## 1. Why
@@ -586,6 +591,18 @@ dispositions known now:
and the cost is that a person who deletes their login waits an hour
to sign up again. A test reads every attempt-lifetime constant and
fails if any reaches the cooldown.
+- **Keymail and social state lives on the server (R4-1).** Today the
+ OAuth state and verifier sit only in a cookie whose 10-minute life is
+ its `MaxAge` (`server.go:3009`, `:3860`), and the callback never checks
+ the attempt's age (`server.go:3905`). A client that keeps the cookie
+ can finish an old sign-in at any time. The sign-in start writes a
+ single-use `auth_attempts(state_hmac, created_at, consumed_at)` row;
+ the callback consumes it in a transaction and refuses one that is
+ missing, consumed, or older than `authFlowTTL`. The cookie keeps the
+ verifier and the state; the row is what makes the lifetime real. A
+ test keeps the cookie past the cooldown, completes with a valid
+ provider response, and requires refusal. This also closes stale
+ sign-ins for everyone, deleted or not.
- **The marker.** Deletion writes `identity_deletions(subject_hmac,
deleted_at)`: the address, and each linked sign-in subject (Keymail,
social), under an HMAC keyed by the console's persistent signing key
@@ -629,7 +646,15 @@ replica: an operator alert, and a row on `/fleet/legal` with a
**Delete** action (`operatorOnly` + `requireFreshAuth`, refusing the
live prefix, deleting every version). It reports rather than deletes on
its own, because deleting a console backup is not something to automate
-on a guess. Slice 4
+on a guess.
+
+The 15 days therefore rests on two operator responses, which this spec
+states rather than hides (R4-3): the alert fires at day 2, leaving 13
+days to delete a retired prefix; and a **stalled live replicator**
+(the live prefix's newest object older than 2 days) raises its own
+alert, since its snapshots stop being pruned too. Recovering the
+replicator resumes pruning. Both cases are in the slice 5
+measurement. Slice 4
measures it on dev before the policy changes. The policy says 15 days;
nothing in the platform changes.
@@ -669,23 +694,38 @@ Until it lands:
- The DPA promises an app's **database backups** are deleted **on
request, within 30 days**, and everything else on its own.
-- `/fleet/legal` has an operator action: given an account and a
- deleted app, list the hosts its records held (from the audit log and
- the trashed records) and the replica and staging prefixes still
- holding objects in this console's data bucket, then delete every
- version of them (`operatorOnly` + `requireFreshAuth`, audited). It
- refuses a host that a live record holds now. Prefixes in another
- region's bucket, on a customer fleet or in a pool are listed as "not
- reachable from this console" and handled by hand.
+- **An inventory, written before ownership is lost (R4-2).** When the
+ purge (§6.5) retires an app's records, in the same step and before
+ any record is removed, it writes one `backup_inventory` row per
+ record: account, app, the record's incarnation id, host, the bucket
+ and the exact `instances/<host>` and `moves/<host>/` prefixes, the
+ newest LTX object's key and version id at that moment, and
+ `state = 'pending'`. Hostnames alone are never deletion authority: the
+ create doors already refuse a new record on a host whose prefix holds
+ an LTX file (`createleftovers.go`), and the action re-checks that the
+ newest object is still the inventoried one, so a successor's data is
+ never touched.
+- `/fleet/legal` has an operator action over those rows
+ (`operatorOnly` + `requireFreshAuth`, audited): delete every version
+ under the inventoried prefixes, verify the prefixes are empty
+ (current and noncurrent), and mark the row `done` with the time. A
+ `done` row is never acted on again. It refuses a row whose host a
+ live record holds now, or whose newest object no longer matches.
+ Prefixes in another region's bucket, on a customer fleet or in a pool
+ are listed as "not reachable from this console" and handled by hand.
+ Apps deleted before the inventory existed have no row: those
+ requests are handled by hand, and the action says so.
- When #199 lands, the DPA's deletion clause changes with notice.
-**Measurement.** Slice 4 measures the worst case on dev for an app with
-a database, an object store and an email service: the trash period,
-the purge, every object becoming noncurrent, and the 7-day noncurrent
-expiry. Litestream's snapshot retention applies only while a
-replicator runs; the purge deletes the whole replica prefix, snapshots
-included. If the measured worst case exceeds 30 days, the DPA's number
-changes before publishing, not the other way round.
+**Measurement (R4-4).** Two measurements on dev, separately. The
+automatic one, for an app with an object store and an email service:
+the trash period, the purge, every deleted object becoming
+noncurrent, and the 7-day noncurrent expiry, with the database
+backups expected to remain. The on-request one: from the request, the
+operator action over the inventory row, its verification that every
+version is gone, and a retry after an injected failure part-way. If
+either worst case exceeds 30 days, the DPA's number changes before
+publishing, not the other way round.
## 7. The DPA text (flagship)