carlos / platform Public

spec: data processing agreements and customer-set retention

Draft rev 1. DPA accepted in account settings with no approval step,
legal notices, statistics and log retention per account and per app
(default indefinite for statistics), and deleting a person.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 111e59db034be3e7ab44d2d6b568904b8ffb0b98 parent edaed83
1 file changed, +407 −0
  • docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md +407 −0
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
new file mode 100644
index 000000000..a8d183259
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-25-dpa-and-retention-design.md
@@ -0,0 +1,407 @@
+# Data processing agreements and customer-set retention
+
+Status: draft rev 1, 2026-11-25. Branch `dpa-and-retention`.
+Asked for by Paul, 2026-11-25 (prompts on the branch ledger).
+
+## 1. Why
+
+A customer who runs an app on the flagship processes personal data
+through it, so under GDPR Article 28 they need a data processing
+agreement (DPA) with the operator. Today the flagship's privacy policy
+says "we will sign a data processing agreement with you on request at
+privacy@carloku.com", which means a contract by email for every
+customer. The focus-group panels (docs/drafts/focus-group-20261030)
+named a DPA and a subprocessor list as blocking questions for a
+business buyer.
+
+Paul's rulings for this work:
+
+- The DPA is built into the console, not handled outside it. A
+ customer accepts the operator's standard DPA in account settings.
+ There is **no approval step**: the operator publishes one standard
+ text and every acceptance binds both sides to it (Paul's "go ahead"
+ to that proposal, 2026-11-25).
+- Every promise the privacy policy and the DPA make gets built, not
+ kept by hand.
+- Customers set their own retention. The default is **keep
+ indefinitely**, changeable in account settings for every app, or
+ per app.
+
+The platform is general-purpose: everything here is an operator
+feature. The flagship configures its own DPA text and URL; a
+self-hoster who runs no service for others never turns it on.
+
+## 2. What the promises are, and what is built
+
+The flagship privacy policy (carloku `/privacy/`, live 2026-11-11) and
+the DPA this work adds promise:
+
+| Promise | State on main edaed836 | This work |
+|---|---|---|
+| Visitor statistics kept 400 days | prune built (a3c407d4), operator-wide `CARLOS_ANALYTICS_RETENTION_DAYS`, not switched on for the flagship | replaced by the customer's setting, default indefinite (§5); policy text changes |
+| Request records up to 7 days | built (box log retention) | unchanged |
+| Mail events 30 days | built (`mailevents.go`) | unchanged |
+| Demo IP gone 7 days after the demo | built (`demo_store.go`) | unchanged |
+| Delete everything about a person, incl. the sign-in record, within 30 days of a request | **by hand only; no deletion path exists** | self-serve and operator deletion (§6) |
+| Email account owners 30 days before a policy change that matters | **not built** | legal notices (§4) |
+| DPA on request | **by email** | built in (§3) |
+| DPA: notice before a new subprocessor | n/a | legal notices (§4) |
+| DPA: delete or return customer data at the end | account delete + reap built (`ownership.go`) | the DPA states what deletion covers and when; nothing new to build |
+| DPA: help with data-subject requests | n/a | the app's data is the customer's; logs, statistics and backups are covered by §5 and §6 |
+
+## 3. Accepting the DPA
+
+### 3.1 Operator configuration
+
+A **legal document** is a row the operator publishes from the operator
+area (`/fleet/legal`, `operatorOnly`):
+
+```
+legal_documents(
+ id INTEGER PRIMARY KEY,
+ kind TEXT NOT NULL, -- 'dpa' | 'terms' | 'privacy'
+ version TEXT NOT NULL, -- operator's label, e.g. '2026-11-25'
+ url TEXT NOT NULL, -- the published text, e.g. https://carloku.com/dpa/
+ sha256 TEXT NOT NULL, -- digest of the text at url when published (§3.4)
+ summary TEXT NOT NULL, -- what changed, plain text, goes in the notice
+ published_at INTEGER NOT NULL,
+ effective_at INTEGER NOT NULL, -- >= published_at; notice period (§4)
+ published_by TEXT NOT NULL, -- operator address
+ UNIQUE(kind, version)
+)
+```
+
+Rows are append-only: never updated, never deleted. The current
+version of a kind is the newest row whose `effective_at` has passed;
+a row not yet effective is "upcoming". With no `dpa` row the feature
+is off and the settings pane does not render.
+
+`terms` and `privacy` rows exist only to drive notices (§4); nothing
+is accepted against them in this work.
+
+### 3.2 The account settings pane
+
+`/a/{sqid}/settings` gains a **Data processing** pane, rendered when a
+`dpa` document is current:
+
+- **No DPA in force:** one line saying what a DPA is for, a link to the
+ current text, and a form for the details the agreement names:
+ customer legal name, registered address, country, and the signer's
+ name and role. An **Accept** button submits it.
+- **In force:** "DPA {version} in force since {date}, accepted by
+ {signer} for {legal name}", a link to the record (§3.3), and, when a
+ newer version is upcoming, "Version {v} takes effect on {date}:
+ {summary}".
+
+Accepting is **owner-only**: binding the customer to a contract is an
+owner's decision, the same rule as billing. Gate order is the house
+order: session → CSRF → owner (byte-identical 404) → write rate limit
+→ `requireFreshAuth` last (a contract acceptance is a sensitive action,
+like a billing change).
+
+### 3.3 The record
+
+```
+dpa_acceptances(
+ id INTEGER PRIMARY KEY,
+ account_id INTEGER NOT NULL,
+ document_id INTEGER NOT NULL REFERENCES legal_documents(id),
+ legal_name TEXT NOT NULL,
+ address TEXT NOT NULL,
+ country TEXT NOT NULL, -- ISO 3166-1 alpha-2
+ signer_name TEXT NOT NULL,
+ signer_role TEXT NOT NULL,
+ accepted_by TEXT NOT NULL, -- the signed-in owner's address
+ accepted_ip TEXT NOT NULL, -- s.clientIP(r)
+ accepted_at INTEGER NOT NULL,
+ ended_at INTEGER -- set when the account is deleted
+)
+```
+
+One live row per account (`ended_at IS NULL`); a second acceptance of
+the same document is refused, and accepting after the account's row
+ended writes a new row. An accepted DPA follows later versions on their
+`effective_at` without re-acceptance, as the DPA text says (§7): the
+record keeps the version accepted, and the pane shows the version in
+force.
+
+The acceptance writes an audit row (`dpa.accept`, empty app) and emails
+the accepting owner a confirmation with the record's fields, the
+document URL and its digest, through `s.deliver`.
+
+`GET /a/{sqid}/settings/dpa` (member-readable: any member may need to
+show a customer's auditor the record) renders the record as a printable
+page: the operator's name (§3.5), the customer details, version, URL,
+digest, accepted by, at, and a "Print or save as PDF" button. A
+generated PDF is out of scope: the console has no PDF renderer of its
+own (the PDF engine is a metered tenant service), and a print
+stylesheet gives the customer the same file.
+
+### 3.4 Pinning the text
+
+The record must prove which text was accepted. When the operator
+publishes a document, the console fetches `url` once, stores the
+SHA-256 of the body, and refuses to publish on a fetch failure or a
+non-200. The record page and the confirmation email carry the digest.
+The operator keeps every version's text at a stable URL (the flagship:
+`/dpa/` for the current and `/dpa/{version}/` for each published one),
+and `url` names the versioned one.
+
+### 3.5 Operator settings
+
+Two console environment variables name the operator in the record and
+the emails: `CONSOLE_LEGAL_ENTITY` ("Team Tito Limited, Dublin,
+Ireland" on the flagship) and `CONSOLE_PRIVACY_ADDRESS`
+(privacy@carloku.com). Unset: the pane does not render even with a
+`dpa` row, and `/fleet/legal` says why.
+
+### 3.6 The operator list
+
+`/fleet/legal` lists the published documents, a form to publish a new
+one, and the accounts with a DPA in force: account, legal name,
+country, version accepted, accepted by, when. Read-only: there is
+nothing to approve. A rail entry in `opRail`.
+
+## 4. Legal notices
+
+Publishing a document with a summary schedules a notice:
+
+- `dpa`: to the owners of every account with a DPA in force.
+- `terms`, `privacy`: to the owners of every account.
+
+The publish form refuses an `effective_at` sooner than 30 days after
+`published_at` unless the operator ticks "this change doesn't need
+notice" (a typo fix), in which case no notice is sent. Thirty days is
+the policy's own promise; it is a constant, not a setting.
+
+Delivery is a background pass on the existing hourly worker, shaped
+like `notifyPlanOwners`: per account, per-delivery timeout, failures
+logged with `jobFailed`, and a mark set only after at least one
+delivery to that account succeeded, so the next pass retries.
+
+```
+legal_notices(document_id INTEGER, account_id INTEGER, notified_at INTEGER,
+ PRIMARY KEY(document_id, account_id))
+```
+
+The pass works through accounts in id order, bounded per tick so a
+large fleet doesn't send everything in one hour. An account deleted
+before its turn is skipped. The notice is plain text: the summary, the
+effective date, the URL, and for `dpa` that the customer may object by
+writing to the privacy address before that date.
+
+## 5. Retention set by the customer
+
+### 5.1 What it covers
+
+Two kinds of data the operator keeps about an app's visitors and users
+on the customer's behalf:
+
+- **Visitor statistics** (the daily analytics files).
+- **Logs and errors** (the shipped chunks each box keeps per app).
+
+Request records stay at the operator's 7 days: they are the operator's
+own security data, which the policy already bounds. An app's own
+databases, files and object store are the customer's to manage and are
+not touched.
+
+### 5.2 The settings
+
+Account settings gains a **Data retention** pane (owner-only writes,
+member-readable), and app settings a **Data retention** section with
+the same two controls, each either "Use the account's setting" or a
+value:
+
+- Visitor statistics: **Keep indefinitely** (the default) or keep N
+ days, 1 to 3660.
+- Logs and errors: **Keep as long as the platform allows** (the
+ default) or keep N days, from 1 up to the box's log retention.
+
+```
+retention_settings(
+ account_id INTEGER NOT NULL,
+ app TEXT NOT NULL DEFAULT '', -- '' = the account default
+ stats_days INTEGER, -- NULL = inherit (app) / indefinite (account)
+ log_days INTEGER, -- NULL = inherit (app) / platform limit (account)
+ updated_by TEXT NOT NULL,
+ updated_at INTEGER NOT NULL,
+ PRIMARY KEY(account_id, app)
+)
+```
+
+The effective value for an app is its own row, else the account's
+row, else the default. Every change writes an audit row
+(`retention.set`) naming the old and new values. Shortening shows the
+consequence before it saves: "Statistics older than N days will be
+deleted within a day."
+
+### 5.3 Why logs cannot be "indefinite"
+
+Logs are bounded by the box's own retention (`CARLOS_LOG_RETENTION_DAYS`
+and `_MB`, default 7 days and 50 MiB per app per box). Keeping them
+forever is a storage cost the operator pays and the plan does not
+charge for, so in this work a customer may **shorten** log retention
+but not lengthen it past the box's. Longer log retention is a plan
+feature for later (#1024's archive tier), not a setting here. This
+departs from "indefinite by default" for logs only; statistics follow
+the ruling exactly.
+
+### 5.4 Statistics: the console prune
+
+`analyticsPrunePass` today applies one operator-wide age. It becomes:
+
+- The operator setting `CARLOS_ANALYTICS_RETENTION_DAYS` stays, as a
+ **ceiling**: unset means no ceiling. The effective age for an app is
+ the shorter of the ceiling and the customer's setting; with neither,
+ nothing is pruned.
+- `analytics.PruneOptions` gains a per-app resolver,
+ `RetentionFor(account, app string) int` (0 = keep), in place of the
+ single `RetentionDays`. The walk already visits apps one at a time,
+ so the resolver is called per app with no extra listing.
+- The daily admission, cursor, limits and dry run are unchanged.
+- An app with no setting and no ceiling is still walked by nothing: the
+ pass skips listing an app whose effective age is 0.
+
+The flagship then leaves `CARLOS_ANALYTICS_RETENTION_DAYS` unset, and
+the 400-day promise is withdrawn from the policy (§8).
+
+### 5.5 Logs: the box prune
+
+The box needs each app's shorter setting. The console writes it into
+the bucket where boxes already read per-app state:
+
+```
+apps/<sqid>/<app>/retention.json {"log_days": 3, "updated_at": "..."}
+```
+
+written on every change to the app's effective `log_days` (an account
+change rewrites every app of the account that inherits it), deleted
+when the effective value returns to the platform limit, and the
+serial bumped. The box agent reads it with the rest of the app's
+records and applies `min(box retention, log_days)` to the age limit;
+the byte cap is unchanged. A missing or unparsable file means the box's
+own retention, never shorter-than-asked silently and never longer: an
+unparsable file is logged and treated as missing. Wire shape is
+additive: an old box ignores the file and keeps the box's retention,
+which is longer than asked; the pane therefore says the setting applies
+"within a day on every box that runs the app", and the release that
+carries the box change ships before the console change switches the
+control on.
+
+This changes code in the root binary's census scope (`internal/host`);
+the census card and its review apply (AGENTS.md).
+
+## 6. Deleting a person
+
+### 6.1 Self-serve
+
+`/settings` (the person's own page) gains **Delete my sign-in**. It
+refuses, naming the accounts, while the person is the only owner of an
+account: they must delete the account or make someone else an owner
+first. Otherwise, after `requireFreshAuth` and a typed confirmation of
+their address, it removes in one transaction:
+
+- the user row and sign-in methods, email sign-in codes, Keymail link;
+- sessions and CLI tokens (with their last-used IPs);
+- memberships and invitations sent to or by them;
+- DPA acceptance records naming them as `accepted_by` or signer are
+ **kept**: they are the customer's contract record, not the person's
+ account, and the DPA text says so;
+- audit rows are kept, as the policy says.
+
+The person is signed out everywhere and gets a confirmation email.
+
+### 6.2 Operator
+
+`/fleet/people/{address}` gains the same deletion for requests that
+arrive by email, under `operatorOnly` and `requireFreshAuth`, with the
+same sole-owner refusal; the operator resolves that case with the
+account first. The operator action is audited against the ops account.
+
+### 6.3 Backups
+
+The console replica and the bucket's noncurrent-version lifecycle
+(7 days) mean deleted rows leave backups within 8 days, as the policy
+already says. Nothing to build.
+
+## 7. The DPA text (flagship)
+
+A standard processor agreement, published by the flagship at
+carloku.com/dpa/, written for this work as boilerplate and to be
+checked by a lawyer before it is relied on. Its parts:
+
+1. Parties: Team Tito Limited (processor) and the customer named in the
+ acceptance (controller). Formed by acceptance in the console.
+2. Subject, duration, nature and purpose: hosting and serving the
+ customer's apps, for as long as the account exists.
+3. Data and data subjects: whatever the customer's apps process;
+ visitor statistics, logs and errors, request records, mail events.
+4. Processor duties (Art. 28(3)): documented instructions only;
+ confidentiality; security measures (Annex 2); subprocessors only as
+ listed, with 30 days' notice of a change and a right to object;
+ help with data-subject requests and with Articles 32 to 36; breach
+ notice without undue delay and within 48 hours of becoming aware;
+ deletion at the end; information and audits.
+5. Transfers: data stays in the regions the customer picks; where it
+ leaves the EU or UK, the Commission's standard contractual clauses
+ (module 2) and the UK addendum apply.
+6. Changes: new versions take effect on the date given, at least 30
+ days after notice, unless the customer objects.
+7. Liability: as in the terms.
+8. Annex 1: details of processing. Annex 2: security measures (TLS
+ everywhere, encryption at rest, per-app isolation, least-privilege
+ credentials, backups, access by named operators only). Annex 3:
+ subprocessors: Amazon Web Services (hosting, storage, backups, DNS,
+ email; Ireland, London, Virginia, Sydney), Stripe (payments; account
+ holders only, not app data).
+
+Keymail is the operator's own and not a subprocessor. Let's Encrypt
+sees only hostnames and is listed in the privacy policy, not here.
+
+The text goes through copy review before it is published.
+
+## 8. Copy changes outside the console
+
+- carloku `/dpa/` and `/dpa/{version}/`: new (§7).
+- carloku `/privacy/`: "we will sign a data processing agreement with
+ you on request" becomes "accept our data processing agreement in your
+ account settings"; the 400-day line becomes "for as long as the app's
+ owner chooses; until they choose, we keep them"; logs and errors get
+ a line ("for as long as the app's owner chooses, up to 7 days"); the
+ deletion line gains "or delete your sign-in yourself in the console".
+- Published as a new `privacy` document with a notice (§4), so owners
+ hear about it 30 days ahead.
+- `docs/site`: the console guide gains the two panes.
+
+## 9. Slices
+
+Each slice lands as its own branch merge; the first is something Paul
+can see.
+
+1. **DPA acceptance.** `legal_documents` with publish and digest,
+ `/fleet/legal`, the settings pane, `dpa_acceptances`, the record
+ page, the confirmation email, `CONSOLE_LEGAL_ENTITY` and
+ `CONSOLE_PRIVACY_ADDRESS`. Plus the carloku `/dpa/` pages. Witness:
+ on dev, publish a DPA, accept it from a test account, see it on
+ `/fleet/legal`, print the record.
+2. **Legal notices.** `legal_notices`, the 30-day rule on publish, the
+ hourly pass. Witness: on dev, publish a version with a summary and
+ see the notice arrive at a test owner.
+3. **Statistics retention.** The settings tables and panes for
+ statistics, the per-app prune. Witness: a dev app set to 1 day loses
+ its older days on the next pass (dry run first).
+4. **Log retention.** `retention.json`, the box read (census), the log
+ control. Ships in a box release before the console control turns on.
+5. **Deleting a person.** Self-serve and operator.
+6. **Flagship switch-on.** Set the two env vars, publish the DPA and
+ the changed privacy policy with 30 days' notice, update the policy
+ copy.
+
+## 10. Not in this work
+
+- An approval queue, negotiated DPAs, per-customer terms: by email,
+ outside the platform.
+- A generated PDF of the record.
+- Acceptance of terms at sign-up.
+- Lengthening log retention past the box's (#1024 archive tier).
+- Retention for request records, mail events, backups.