Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
docs([issue-2148]): record privacy records as never-federated and guard it
[._.]/ Adam Eivy421f2cbaa046
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex d1afd87c4c..e2565e1785 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -34,3 +34,7 @@- **CoS tasks filed for PortOS's own work now actually run.** Two producers used `metadata.app` as a feature tag when it is workspace routing — it has to name a record in `data/apps.json`. The Series Pipeline autopilot filed every gap it found (unparseable script, stalled verify, failed render, run-ending error) at `app: pipeline`, and the auto-fixer filed its AI-provider investigations at `app: portos`, which matches neither the seeded app id (`portos-default`) nor its name. Both were harmless until the wrong-repo guard (#3180) closed the silent fall-through to the PortOS root: since then each of these tasks was filed and then rejected at every spawn attempt, so the one mechanism that surfaces an autopilot capability gap never reached an agent. Both now file with no app — which resolves to the PortOS workspace they were always meant to run in — and migration 234 un-routes the ones already queued on existing installs (re-stamping them so the fix wins the sync merge against a peer that hasn't upgraded).- A CoS task naming an app that doesn't resolve to a repository directory is now **parked as blocked** instead of retried forever. The spawn guard refused to start the agent (correctly — it would otherwise commit into the PortOS checkout) but left the task `pending`, so the scheduler re-dequeued it every tick and reprinted the same error, while the fix was only visible in that task's own log. It now lands in the Blocked list, and the message covers both ways an app resolves to nothing: no Repository Path set, or nothing in Apps matching that id/name at all (in which case the fix is to clear the app from the task, not to register a path).++## Privacy Center++- **Your PII vault stays on one machine — permanently, by decision.** The Privacy Center's vault, organization registry, change-of-address inventory and broker opt-out ledger were always machine-local, but that was recorded as a feature not yet built, which left the door open to syncing them to your other PortOS machines later. It is now a documented guarantee: none of it federates, and none of it ever will without a new decision record superseding this one. The reasoning is written up in full — chiefly that PortOS's peer-sync was built for creative work rather than identity data, that the display masks (`••••1234`, `j•••@example.com`) are readable even when the underlying values are encrypted, and that copying one encryption key to several machines would widen the exposure of every one of them. If you want the vault on a second machine, restore a backup and copy the key by hand — a deliberate act, rather than something that happens quietly in the background. Managing PII for other household members is unaffected and remains planned.diff --git a/CLAUDE.md b/CLAUDE.mdindex 5681010d71..4030524290 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -18,7 +18,13 @@ npm run test:db # DB-backed suites → portos_test ONLY (see Se## Security Model-**Trust model (within one install).** Each PortOS install serves exactly one human user, on a private network behind Tailscale VPN, never exposed to the public internet. Within an install there is one server process and one user — so concurrent *request* races, mutex locking on file I/O, and atomic write patterns are unnecessary as defenses against competing actors and should not be added or flagged as concerns. Simple re-entrancy guards (per-account sync locks to prevent duplicate in-flight operations; serializing two write paths that mutate the same record) are fine and expected. PortOS intentionally omits authentication, CORS restrictions, rate limiting, HTTPS, and full concurrency controls — these are non-issues for a single-user private-network deployment. Do not add them or flag their absence as security concerns. **"Single-user" means: do not defend against multiple competing humans inside one install. It does NOT mean "assume only one install exists."**+**Trust model (within one install).** Each PortOS install serves exactly one human user, on a private network behind Tailscale VPN, never exposed to the public internet. Within an install there is one server process and one user — so concurrent *request* races, mutex locking on file I/O, and atomic write patterns are unnecessary as defenses against competing actors and should not be added or flagged as concerns. Simple re-entrancy guards (per-account sync locks to prevent duplicate in-flight operations; serializing two write paths that mutate the same record) are fine and expected. PortOS intentionally omits CORS restrictions, rate limiting, and full concurrency controls by default — these are non-issues for a single-user private-network deployment. Do not add them or flag their absence as security concerns. **"Single-user" means: do not defend against multiple competing humans inside one install. It does NOT mean "assume only one install exists."**++**Authentication and HTTPS exist, but are OPT-IN and OFF by default.** Do not assume they are absent:+- **Auth** — an optional instance password (`server/services/auth.js`, enforced by `server/lib/authGate.js`) gates all of `/api/*` and `/data/*` when set, with a small always-public set (`/api/auth/status`, `/api/system/health`). Peers reach a password-gated instance via a per-peer Basic credential stored on the peer record, attached to every outbound hop by `peerFetch` (`server/lib/peerHttpClient.js`).+- **HTTPS** — provisioned by `npm run setup:cert`; `:5555` flips to TLS with a loopback-only HTTP mirror on `:5553`. Peer hops set `rejectUnauthorized: false` ("Tailnet is the trust boundary") — between two tailnet nodes WireGuard already supplies mutual auth, but a non-tailnet peer (plain LAN IP / non-`.ts.net` host, see `peerRequiresTailscale()`) gets no server authentication.++Because both are off by default, **never treat "the password is set" as an available guarantee** when designing a feature — gate on it explicitly, or design for the default posture. **PII must not ride the federation layer at all** — see ADR [privacy records machine-local](docs/decisions/2026-08-08-privacy-records-machine-local.md).**Distribution model (across installs).** PortOS is distributed software: many independent people each run their own install, on their own machine(s), each upgrading on their own schedule — and a single user commonly runs **several machines federated as sync peers**. So backward/forward compatibility across installs and versions is first-class, NOT optional:diff --git a/docs/STORAGE.md b/docs/STORAGE.mdindex 068355d1fb..381eccc7f6 100644--- a/docs/STORAGE.md+++ b/docs/STORAGE.md@@ -38,6 +38,7 @@ PostgreSQL is a **required** install/runtime dependency (see [Backup & Restore](- `creative_commissions` — Creative Commissions (Autonomous Creation Engine Phase 1, #2657): standing recurring creative briefs that fire on a cron cadence and drive the Creative Director directive pipeline unattended. One row per commission, the full sanitized record (brief / schedule / generation / feedback / capped `runs[]`) in `data` JSONB with `name`/`enabled`/`created_at`/`updated_at` mirrored into columns for the scheduler's "arm every enabled commission" query. **Intentionally machine-local — never federated** (a synced schedule would double-run on every peer, same rationale as `seriesAutopilotScheduler`): NO `sync_sequence` and NO `deleted`/`deleted_at` tombstone — deletes are hard deletes, mirroring `tribe`. Phase 2 will split the machine-local *schedule* from a federatable *brief/feedback* record before adding any sync hook. Adapter: `server/services/creativeCommissions/db.js`, selected pg-vs-file by `server/services/creativeCommissions/store.js` (file backend is the `NODE_ENV=test`/`MEMORY_BACKEND=file` escape hatch only).- `games` — Game studio workspaces (#3177): one row per managed-app asset plan, with the full reusable sprite/music binding set, current compiled-manifest pointer, compile history, and user-requested AI feedback history in `data` JSONB; `app_id`/`name`/`updated_at` are mirrored for list and relationship queries. The record is **machine-local** because managed-app registration, sprite atlases, and music-library bytes are machine-local; there is no peer-sync cursor or tombstone, and deletes are hard deletes. Compiled manifests are immutable, SHA-256-addressed artifacts under `data/games/{id}/manifests/`; their pointers and hashes live in the DB record. Adapter: `server/services/games/db.js`, selected pg-vs-collectionStore by `server/services/games/store.js` (collectionStore is test/unsupported file escape hatch only).- `threejs_models` — generated procedural 3D-model workspaces: one row per model with gallery-image lineage, provider/model attribution, generation/refinement status, and the validated declarative scene spec in `data` JSONB. The referenced image bytes remain under `data/images/`; deterministic Three.js source is derived from the stored spec rather than persisted as a second mutable artifact. The table is local-only in this first slice, with soft-delete columns retained so federation can be added without a record-shape migration.+- `privacy_vault_records` / `privacy_consents` / `privacy_orgs` / `privacy_org_holdings` / `privacy_change_events` / `privacy_brokers` / `privacy_broker_cases` — the Privacy Center (epic #2138): the encrypted PII vault, the trusted-organization registry with per-field holdings, the change-of-address inventory, and the data-broker opt-out ledger. Relational by nature (org ↔ holdings ↔ vault records ↔ change events ↔ broker cases), which is why they are `db-primary`. Vault *values* are AES-256-GCM ciphertext (`v1:<iv>:<tag>:<ct>`, key from `PRIVACY_VAULT_KEY`) — the DB holds bytes of ciphertext, never plaintext PII, and plaintext never appears in logs (`server/lib/vaultCrypto.js`). **Intentionally machine-local — never federated**, and this is a product *guarantee*, not a deferred feature (ADR [privacy records machine-local](./decisions/2026-08-08-privacy-records-machine-local.md), #2148). NO `sync_sequence`, NO peer-sync record kind, NO `dataSync` category, NO `PORTOS_SCHEMA_VERSIONS` entry, and no `deleted`/`deleted_at` tombstones — deletes are hard deletes, mirroring `tribe`. The reasoning is the same class as the Tribe graph but stronger: the peer-sync **pull** path (`GET /api/peer-sync/record`) carries no peer identity, `masked_value` is plaintext by design so even ciphertext-only sync would leak a PII fingerprint, and a shared `PRIVACY_VAULT_KEY` would widen the at-rest blast radius to every peer's `.env`. A second machine gets the vault by restoring a backup and copying the key by hand — a deliberate act, not continuous replication. Enforced by `server/services/sharing/privacyNeverFederates.test.js`. Adapters: `server/services/privacyVault.js`, `privacyOrgs.js`, `privacyChanges.js`, `privacyBrokers.js`, `privacyOptOut.js`.**Postgres-First target.** Pipeline series/issues, Story Builder sessions, and searchable media metadata are still `db-primary` targets — they currently live in `data/` JSON but carry relationships and status that belong in the DB. The schema for the Create domains is designed in [`docs/plans/2026-06-07-create-relational-schema-design.md`](./plans/2026-06-07-create-relational-schema-design.md) (#999), with implementation tracked as #1014–#1018. (Creative Director project/scene/run state moved to Postgres in Phase 3 / #997; catalog user-defined types moved in Phase 4 lead-in / #1001; **universes moved in Phase 3 Create slice 1 / #1014** — see the `universes` entry above. Pipeline series/issues #1015, Story Builder #1016, Writers Room #1017, and the catalog ref resolver #1018 are the remaining slices.)diff --git a/docs/decisions/2026-08-08-privacy-records-machine-local.md b/docs/decisions/2026-08-08-privacy-records-machine-local.mdnew file mode 100644index 0000000000..0a4f37f0af--- /dev/null+++ b/docs/decisions/2026-08-08-privacy-records-machine-local.md@@ -0,0 +1,150 @@+# ADR: Privacy Center Records Stay Machine-Local — Never Federated++- **Date:** 2026-08-08+- **Status:** Accepted+- **Related:** issue #2148 (closes the federation half; household subjects split+ out), epic #2138,+ [design record](../plans/2026-07-04-privacy-center-pii-vault-broker-optout.md),+ [`server/lib/vaultCrypto.js`](../../server/lib/vaultCrypto.js),+ [`server/services/sharing/peerSync.js`](../../server/services/sharing/peerSync.js),+ [`docs/STORAGE.md`](../STORAGE.md),+ ADR [tribe + universe-runs local](./2026-06-26-tribe-and-universe-runs-local.md) (#1724).++## Context++The Privacy Center (epic #2138) shipped Phases 1–8: an AES-256-GCM encrypted PII+vault, a trusted-organization registry with per-field holdings, a+change-of-address inventory, and an unbroker-style data-broker opt-out engine.+All eight tables (`privacy_vault_records`, `privacy_consents`, `privacy_orgs`,+`privacy_org_holdings`, `privacy_change_events`, `privacy_brokers`,+`privacy_broker_cases`) are `db-primary` PostgreSQL and machine-local.++Federation was deliberately excluded from v1 and parked in #2148, whose proposal+was: copy the same `PRIVACY_VAULT_KEY` to every peer, sync+`privacy_vault_records` with the ciphertext travelling as-is, and sync orgs ++holdings as **plain** records. This ADR resolves that parked question.++## What federating them would actually mean today++Three properties of the current federation layer make the parked proposal unsafe+as written:++1. **The pull path carries no peer identity.**+ `GET /api/peer-sync/record?kind=&id=` calls `getRecordPayloadForPeer(kind, id)`+ with no notion of *who* is asking. The `peerAllowsOutbound` / `peerHasCategory`+ checks gate only the **push** direction+ (`server/services/sharing/peerSyncPush.js`). Adding a privacy kind to+ `PEER_SUBSCRIBABLE_KINDS` would therefore not create a *subscription* — it+ would create a read anyone who can reach the port can perform. When the+ optional instance password is off (the default posture), that is every host+ on the tailnet.++2. **Everything federated today is creative work.** `PEER_SUBSCRIBABLE_KINDS` is+ `universe, series, mediaCollection, author, artist, album, track,+ creativeDirectorProject, moodBoard, writersRoomWork, writersRoomFolder,+ writersRoomExercise, musicVideoProject, commissionFeedback,+ creativeCommission` — zero PII, zero credentials. The transport's trust+ posture (`peerHttpClient.js` sets `rejectUnauthorized: false`, commented+ "Tailnet is the trust boundary") was chosen for that data class. Between two+ tailnet nodes WireGuard already provides mutual authentication and+ confidentiality, so the un-validated TLS layer is redundant rather than+ dangerous — but `peerRequiresTailscale()` (`server/services/instances.js`)+ shows a peer may equally be a plain LAN IP or a non-tailnet DNS host, where+ nothing authenticates the far end.++3. **Ciphertext-only sync still leaks a PII fingerprint.** `masked_value` is a+ precomputed **plaintext** column by design (`•••, Portland, OR`,+ `j•••@example.com`, `••••1234`). A "ciphertext travels as-is" sync ships the+ whole mask set. Separately, `privacy_orgs` is the user's banks, employers,+ medical providers and insurers, and `privacy_broker_cases.evidence`+ holds `listing_urls` — the map of where the user is exposed. The parked+ proposal would have synced those as plain records.++A shared `PRIVACY_VAULT_KEY` also converts the at-rest guarantee from "one+machine's `.env`" to "N machines' `.env` files," which is precisely the blast+radius the encryption layer exists to bound.++## Decision++**No Privacy Center record federates. All eight tables are machine-local, and+that is an intentional product guarantee — not a missing feature.**++Concretely, and permanently unless this ADR is superseded:++- No privacy kind is added to `PEER_SUBSCRIBABLE_KINDS`.+- No privacy category is added to `dataSync`'s `CATEGORIES`.+- No privacy table gains a `sync_sequence` cursor or `deleted`/`deleted_at`+ tombstone. Deletes stay hard deletes.+- No privacy category is added to `PORTOS_SCHEMA_VERSIONS` — there is no wire+ contract to version, because there is no wire.++A guard test (`server/services/sharing/privacyNeverFederates.test.js`) enforces+the first two so the boundary fails loudly rather than eroding.++### Why not "federate, but gate it on HTTPS + the instance password"++This was seriously considered, and the machinery for it already exists: the+optional instance password (`server/services/auth.js` + `server/lib/authGate.js`)+gates all of `/api/*` including `/api/peer-sync/*`; per-peer Basic credentials+are stored on the peer record and attached to every outbound hop by+`peerFetch` (`server/lib/peerHttpClient.js`); and `GET /api/auth/status` is+always-public, so a peer probe can *detect* whether the far end requires auth+and refuse to send otherwise.++It was rejected for the vault because the cost/benefit is poor, not because it+is unimplementable:++- **The benefit is thin.** Durability is already covered — the DB is in the+ backup, and `PRIVACY_VAULT_KEY` lives in `.env`. The opt-out ledger is+ single-writer by design (#2148 flagged this itself); replicating it invites+ two peers to double-submit opt-outs against the same broker, which is worse+ than not syncing. The genuine multi-machine want — "see my vault on the+ laptop" — is satisfied by restoring a backup and copying one key, a+ deliberate, auditable, one-time act.+- **The cost is a permanent widening of the highest-value target in the+ install.** The instance password is a single credential granting the *entire*+ API (shell, agents, providers), not a scoped capability. Making an SSN vault+ reachable over any network path, behind any single shared secret, trades a+ hard guarantee ("this data has never left this machine") for a soft one+ ("this data is protected as well as our weakest peer's password"). For PII+ specifically, the hard guarantee is worth more than the convenience.+- **Precedent.** `tribe_people` — a personal relationship/CRM graph — is already+ intentionally machine-local (ADR #1724), mirroring `memorySync.js`'s+ "relationship data is instance-local" boundary. An identity vault holding+ SSN, passport, driver's licence and financial-account numbers is a strictly+ stronger case than the one already decided.++The transport-hardening idea is worth keeping on its own merits, independent of+privacy data: adding per-peer identity + category authorization to the pull path+benefits **every** federated kind. That is tracked separately (see Consequences)+and is explicitly *not* a precondition for revisiting this decision — it is a+fix for the creative-data federation that already exists.++## Consequences++- The Privacy Center is single-machine. The UI and docs should state this as a+ guarantee, so users understand the vault's contents have never traversed a+ network from PortOS.+- A user wanting the vault on a second machine restores from backup and copies+ `PRIVACY_VAULT_KEY` by hand. This is documented, not automated — a manual key+ copy is a moment of deliberate consent, which continuous replication is not.+- Household subjects (the other half of #2148) is unaffected: it is a+ same-machine, multi-subject feature with no federation dependency, and is+ split into **#3658**.+- Per-peer authorization on the peer-sync pull path is filed separately as+ **#3659** — a general federation fix benefiting every federated kind, not a+ privacy prerequisite. It is version-gated so an older peer that does not+ present identity degrades gracefully rather than losing sync.+- `CLAUDE.md`'s Security Model previously stated that PortOS "intentionally+ omits authentication … HTTPS." Both exist as opt-in, off-by-default features,+ and the stale wording actively misleads anyone reasoning about what a peer+ channel can guarantee. Corrected as part of this change.++## Revisiting++Superseding this ADR requires more than "the transport got safer." It requires a+concrete user need that a backup restore genuinely cannot serve, plus, at+minimum: per-peer identity and category authorization on the pull path, an+explicit per-category opt-in that defaults off, a hard refusal to transmit when+the far end reports auth disabled, and a resolution for `masked_value` (it must+not travel in plaintext). Absent all of those, the answer stays no.diff --git a/docs/plans/2026-07-04-privacy-center-pii-vault-broker-optout.md b/docs/plans/2026-07-04-privacy-center-pii-vault-broker-optout.mdindex daf0ebafd4..e485246432 100644--- a/docs/plans/2026-07-04-privacy-center-pii-vault-broker-optout.md+++ b/docs/plans/2026-07-04-privacy-center-pii-vault-broker-optout.md@@ -108,7 +108,7 @@ Epic: #2138## Deferred / open questions-- **Federation**: encrypted vault sync across peers (void/null/NaN/undefined) needs a key-distribution decision (shared `PRIVACY_VAULT_KEY` via user, or per-peer re-encryption). Parked in issue 9.+- **Federation**: ~~encrypted vault sync across peers needs a key-distribution decision~~ — **RESOLVED 2026-08-08: privacy records never federate.** Machine-local is a product guarantee, not a deferred feature. See ADR [privacy records machine-local](../decisions/2026-08-08-privacy-records-machine-local.md) (#2148) for the reasoning — chiefly that the peer-sync *pull* path carries no peer identity, `masked_value` is plaintext by design, and a shared `PRIVACY_VAULT_KEY` would widen the at-rest blast radius to every peer. A second machine gets the vault via backup restore + a manual key copy.- **Household subjects**: unbroker manages multiple consenting people; schema leaves room (`privacy_consents.subject`) but v1 is self-only.- **Cloud/residential browser** for antibot brokers (unbroker's Browserbase lane): out of scope; `blocked` cases stay in the digest with the broker's rights-request email as the rescue lane.- **Key rotation**: ciphertext format is versioned (`v1:`); a rotation script is trivial to add later, not in v1.diff --git a/server/lib/db/schema/privacy.js b/server/lib/db/schema/privacy.jsindex 796210875c..e95d4733f9 100644--- a/server/lib/db/schema/privacy.js+++ b/server/lib/db/schema/privacy.js@@ -6,7 +6,10 @@ export const privacyDdl = [// Encrypted-at-rest identity facts. `value_enc` is AES-256-GCM ciphertext// (`v1:<iv>:<tag>:<ct>`, key from PRIVACY_VAULT_KEY — lib/vaultCrypto.js);// plaintext is NEVER stored, `masked_value` is the display form. Machine-- // local: no federation, no tombstones (deferred, #2148) — a delete is a+ // local: no federation, no tombstones — NEVER federated by decision, not+ // deferral (ADR docs/decisions/2026-08-08-privacy-records-machine-local.md,+ // #2148); adding a sync cursor here trips+ // services/sharing/privacyNeverFederates.test.js. A delete is a// hard DELETE. `use_for_scans` gates which facts the broker scan engine// may disclose (hard-false for ssn/passport/drivers_license/// financial_account — enforced app-side). Mirrors the privacy blocks in@@ -44,8 +47,9 @@ export const privacyDdl = [// stance and per-org holdings linking to the exact vault records each org// holds. Data backbone for the change-of-address inventory (Phase 4) and// the "who has my PII" view. Machine-local: no federation, no tombstones- // (same deferred scope as the vault, #2148). Mirrors the privacy blocks- // in init-db.sql.+ // — NEVER federated, same guarantee as the vault (ADR+ // docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148).+ // Mirrors the privacy blocks in init-db.sql.`CREATE TABLE IF NOT EXISTS privacy_orgs (id UUID PRIMARY KEY,name TEXT NOT NULL,@@ -85,8 +89,10 @@ export const privacyDdl = [// (field_verified/documented) are never clobbered by an auto refresh.// `cluster_parent` groups sibling brands under one suppression;// `disclosure_fields` caps what the engine may ever submit to that broker.- // Machine-local — no federation, no tombstones (same deferred scope as the- // vault, #2148). Mirrors the privacy blocks in init-db.sql.+ // Machine-local — no federation, no tombstones; NEVER federated, same+ // guarantee as the vault (ADR+ // docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148).+ // Mirrors the privacy blocks in init-db.sql.`CREATE TABLE IF NOT EXISTS privacy_brokers (id TEXT PRIMARY KEY,name TEXT NOT NULL,@@ -138,8 +144,10 @@ export const privacyDdl = [// is the NEW one (nullable for a removal-only change). Declaring an event// flips every `current` holding of the old record to `update_pending` (see// privacyChanges.js). Both FKs cascade so removing a vault record cleans up- // its change events. Machine-local — no federation, no tombstones (same- // deferred scope as the vault, #2148). Mirrors the block in init-db.sql.+ // its change events. Machine-local — no federation, no tombstones; NEVER+ // federated, same guarantee as the vault (ADR+ // docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148).+ // Mirrors the block in init-db.sql.`CREATE TABLE IF NOT EXISTS privacy_change_events (id UUID PRIMARY KEY,vault_record_id UUID NOT NULL REFERENCES privacy_vault_records (id) ON DELETE CASCADE,diff --git a/server/lib/privacyValidation.js b/server/lib/privacyValidation.jsindex 91f6791e2b..4338b90acb 100644--- a/server/lib/privacyValidation.js+++ b/server/lib/privacyValidation.js@@ -102,7 +102,8 @@ export const privacyVaultIdParamsSchema = z.object({// TRUSTED ORGANIZATIONS REGISTRY SCHEMAS (issue #2141, epic #2138)// =============================================================================// Zod schemas for `privacy_orgs` / `privacy_org_holdings` — db-primary Postgres,-// machine-local (same federation-deferred scope as the vault, #2148).+// machine-local and NEVER federated (same guarantee as the vault — ADR+// docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148).export const PRIVACY_ORG_CATEGORIES = Object.freeze(['bank', 'utility', 'government', 'employer', 'subscription',@@ -172,7 +173,8 @@ export const privacyOrgHoldingsSetSchema = z.object({// CHANGE-OF-ADDRESS EVENTS + INVENTORY SCHEMAS (issue #2143, epic #2138)// =============================================================================// Zod schemas for `privacy_change_events` — db-primary Postgres, machine-local-// (same federation-deferred scope as the vault, #2148). Declaring a change flips+// and NEVER federated (same guarantee as the vault — ADR+// docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148). Declaring a change flips// every `current` holding of the old vault record to `update_pending`; the// Changes tab then works that per-org checklist.@@ -222,7 +224,8 @@ export const privacyChangeOrgParamsSchema = z.object({// DATA-BROKER DATABASE + CASE LEDGER SCHEMAS (issue #2144, epic #2138)// =============================================================================// Zod schemas for `privacy_brokers` / `privacy_broker_cases` — db-primary-// Postgres, machine-local (same federation-deferred scope as the vault, #2148).+// Postgres, machine-local and NEVER federated (same guarantee as the vault —+// ADR docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148).// The broker rows themselves are curated seed / auto-refresh, not user-created,// so there is no broker create/update input schema — only read filters and the// scan/refresh action bodies.diff --git a/server/scripts/init-db.sql b/server/scripts/init-db.sqlindex a05a7b3d02..818ad0a275 100644--- a/server/scripts/init-db.sql+++ b/server/scripts/init-db.sql@@ -1132,7 +1132,10 @@ CREATE INDEX IF NOT EXISTS idx_lora_training_runs_character ON lora_training_run-- identity facts — `value_enc` is AES-256-GCM ciphertext (`v1:<iv>:<tag>:<ct>`,-- key from PRIVACY_VAULT_KEY; see server/lib/vaultCrypto.js). Plaintext is-- NEVER stored; `masked_value` is the display form. Machine-local — no--- federation, no tombstones (deferred, #2148); a delete is a hard DELETE.+-- federation, no tombstones. NEVER federated by decision, not deferral (ADR+-- docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148); adding a+-- sync cursor trips services/sharing/privacyNeverFederates.test.js.+-- A delete is a hard DELETE.-- `use_for_scans` gates which facts the broker scan engine may disclose-- (hard-false for ssn/passport/drivers_license/financial_account — enforced-- app-side). Mirrors the privacy blocks in server/lib/db.js ensureSchema().@@ -1168,8 +1171,9 @@ CREATE TABLE IF NOT EXISTS privacy_consents (-- and per-org holdings linking to the exact vault records each org holds.-- Data backbone for the change-of-address inventory (Phase 4) and the "who-- has my PII" view. Machine-local — no federation, no tombstones (same--- deferred scope as the vault, #2148). Mirrors the privacy blocks in--- server/lib/db.js ensureSchema().+-- guarantee as the vault — NEVER federated; ADR+-- docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148). Mirrors+-- the privacy blocks in server/lib/db.js ensureSchema().CREATE TABLE IF NOT EXISTS privacy_orgs (id UUID PRIMARY KEY,name TEXT NOT NULL,@@ -1207,8 +1211,9 @@ CREATE INDEX IF NOT EXISTS idx_privacy_org_holdings_vault_record ON privacy_org_-- at boot). `source`/`confidence` gate the refresh: curated rows are never-- clobbered by an auto refresh. `cluster_parent` groups sibling brands under one-- suppression; `disclosure_fields` caps what the engine may submit. Machine-local--- — no federation, no tombstones (#2148). Mirrors the privacy blocks in--- server/lib/db.js ensureSchema().+-- — no federation, no tombstones; NEVER federated (ADR+-- docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148). Mirrors+-- the privacy blocks in server/lib/db.js ensureSchema().CREATE TABLE IF NOT EXISTS privacy_brokers (id TEXT PRIMARY KEY,name TEXT NOT NULL,@@ -1258,8 +1263,10 @@ CREATE INDEX IF NOT EXISTS idx_privacy_broker_cases_recheck ON privacy_broker_ca-- (nullable for a removal-only change). Declaring an event flips every `current`-- holding of the old record to `update_pending` (see privacyChanges.js). Both-- FKs cascade-delete so removing a vault record cleans up its change events.--- Machine-local — no federation, no tombstones (same deferred scope as the--- vault, #2148). Mirrors the block in server/lib/db.js ensureSchema().+-- Machine-local — no federation, no tombstones; NEVER federated, same+-- guarantee as the vault (ADR+-- docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148). Mirrors+-- the block in server/lib/db.js ensureSchema().CREATE TABLE IF NOT EXISTS privacy_change_events (id UUID PRIMARY KEY,vault_record_id UUID NOT NULL REFERENCES privacy_vault_records (id) ON DELETE CASCADE,diff --git a/server/services/privacyBrokers.js b/server/services/privacyBrokers.jsindex 1951ba010d..988c26cfae 100644--- a/server/services/privacyBrokers.js+++ b/server/services/privacyBrokers.js@@ -5,7 +5,10 @@* (+ later BADBOOL / CA-registry) database of people-search brokers the* exposure-scan / opt-out engine works; `privacy_broker_cases` is the per-broker* ledger with a SERVICE-ENFORCED state machine. Machine-local — no federation,- * no tombstones (same deferred scope as the vault, #2148).+ * no tombstones. NEVER federated, by decision rather than deferral: ADR+ * docs/decisions/2026-08-08-privacy-records-machine-local.md (#2148). The case+ * ledger is additionally single-writer — two peers working the same broker+ * would double-submit opt-outs against it.** Boot policy (CLAUDE.md — no cold-bootstrap network/LLM): NOTHING here runs at* server boot. The curated seed is loaded LAZILY fromdiff --git a/server/services/privacyChanges.js b/server/services/privacyChanges.jsindex 34f1bb3006..c33f0b4d0c 100644--- a/server/services/privacyChanges.js+++ b/server/services/privacyChanges.js@@ -8,8 +8,9 @@* record flips to `update_pending`. The Changes tab then works that per-org* checklist to done (zero `update_pending`).*- * Machine-local: NO federation, NO tombstones (same deferred scope as the- * vault, #2148). Plaintext PII is NEVER stored here and NEVER logged — the+ * Machine-local: NO federation, NO tombstones — NEVER federated, by decision+ * rather than deferral (ADR+ * docs/decisions/2026-08-08-privacy-records-machine-local.md, #2148). Plaintext PII is NEVER stored here and NEVER logged — the* inventory joins masked vault values only. The ONE place plaintext surfaces is* `draftUpdateEmail`, which decrypts the NEW value into an email draft the user* explicitly requested and must still approve before it sends (never auto-senddiff --git a/server/services/privacyOrgs.js b/server/services/privacyOrgs.jsindex 34fa4d7e9e..8a34fd39cc 100644--- a/server/services/privacyOrgs.js+++ b/server/services/privacyOrgs.js@@ -4,8 +4,9 @@* db-primary Postgres per docs/STORAGE.md: `privacy_orgs` (one row per* organization that has or had the user's PII) and `privacy_org_holdings`* (which vault records each org holds, with a per-holding status). Machine-- * local: NO federation, NO tombstones (same deferred scope as the vault,- * #2148) — deletes are hard DELETEs with cascading holdings cleanup.+ * local: NO federation, NO tombstones — NEVER federated, by decision rather+ * than deferral (ADR docs/decisions/2026-08-08-privacy-records-machine-local.md,+ * #2148). Deletes are hard DELETEs with cascading holdings cleanup.** Holdings responses join masked vault values ONLY — never plaintext. The* one decrypt path stays `revealValue()` in privacyVault.js; this servicediff --git a/server/services/privacyVault.js b/server/services/privacyVault.jsindex 51470fe2aa..7d268ae532 100644--- a/server/services/privacyVault.js+++ b/server/services/privacyVault.js@@ -4,7 +4,10 @@* db-primary Postgres per docs/STORAGE.md: one row per identity fact in* `privacy_vault_records` (dedicated columns — the records are relational and* queried by type), consent audit rows in `privacy_consents`. Machine-local:- * NO federation, NO tombstones (deferred child issue #2148).+ * NO federation, NO tombstones. This is a product GUARANTEE, not a deferred+ * feature — the vault's contents have never traversed a network from PortOS.+ * See ADR docs/decisions/2026-08-08-privacy-records-machine-local.md (#2148);+ * a second machine gets the vault via backup restore + a manual key copy.** Encryption contract:* - plaintext is NEVER stored — every write computes `value_enc` (AES-256-GCMdiff --git a/server/services/sharing/privacyNeverFederates.test.js b/server/services/sharing/privacyNeverFederates.test.jsnew file mode 100644index 0000000000..190c985c6f--- /dev/null+++ b/server/services/sharing/privacyNeverFederates.test.js@@ -0,0 +1,75 @@+/**+ * Guard: Privacy Center records must NEVER federate.+ *+ * This is a product guarantee, not a deferred feature — see ADR+ * `docs/decisions/2026-08-08-privacy-records-machine-local.md` (#2148). The+ * vault holds SSN / passport / driver's-licence / financial-account facts, and+ * the peer-sync PULL path (`GET /api/peer-sync/record`) carries no peer+ * identity, so adding a privacy kind to the federation surface would publish+ * that data to anything that can reach the port — not merely subscribe it.+ *+ * These assertions are cheap and blunt on purpose: they match the string+ * `privacy` BROADLY across each federation surface and subtract nothing, so a+ * future `privacyVault`, `privacy_orgs`, or `privacyCases` entry trips the+ * guard no matter what it is called. If you are here because this test failed,+ * the answer is almost certainly "don't add it" — read the ADR's "Revisiting"+ * section before changing this file.+ */++import { describe, it, expect } from 'vitest';+import { PEER_SUBSCRIBABLE_KINDS } from './peerSyncShared.js';+import { PORTOS_SCHEMA_VERSIONS, NON_RECORD_SCHEMA_CATEGORIES } from '../../lib/schemaVersions.js';+import { privacyDdl } from '../../lib/db/schema/privacy.js';++const mentionsPrivacy = (value) => /privacy/i.test(String(value));++// Columns that only exist to support cross-instance sync. A privacy table that+// grows one is either federating already or is being prepared to — both are+// the thing this ADR forbids.+const FEDERATION_COLUMNS = ['sync_sequence', 'deleted_at'];++/** The `CREATE TABLE privacy_*` statements, each a complete balanced string. */+const privacyCreateTableStatements = privacyDdl.filter(+ (stmt) => /CREATE TABLE IF NOT EXISTS privacy_/i.test(stmt),+);++describe('privacy records never federate (ADR 2026-08-08, #2148)', () => {+ it('exposes no privacy kind to peer-sync subscriptions', () => {+ expect(PEER_SUBSCRIBABLE_KINDS.filter(mentionsPrivacy)).toEqual([]);+ });++ it('declares no privacy wire-schema category', () => {+ expect(Object.keys(PORTOS_SCHEMA_VERSIONS).filter(mentionsPrivacy)).toEqual([]);+ expect([...NON_RECORD_SCHEMA_CATEGORIES].filter(mentionsPrivacy)).toEqual([]);+ });++ it('declares no privacy dataSync snapshot category', async () => {+ // Imported lazily: dataSync pulls a broad service graph, and the two+ // assertions above must still run if that import ever gets heavier.+ const { getSupportedCategories } = await import('../dataSync.js');+ expect(getSupportedCategories().filter(mentionsPrivacy)).toEqual([]);+ });++ it('gives no privacy table a sync cursor or tombstone column', () => {+ // Sanity: if the filter ever matches nothing the assertions below are+ // vacuous, so pin the table count we expect to be guarding.+ expect(privacyCreateTableStatements).toHaveLength(7);+ for (const stmt of privacyCreateTableStatements) {+ const table = stmt.match(/privacy_[a-z_]+/i)?.[0];+ for (const column of FEDERATION_COLUMNS) {+ expect(`${table}:${stmt.includes(column)}`).toBe(`${table}:false`);+ }+ }+ });++ // Bypass probe — proves the assertions above actually fire. Without this, a+ // predicate that silently stopped matching (a renamed export, a filter that+ // returns undefined) would keep the suite green while guarding nothing.+ it('the guard predicates reject a planted violation', () => {+ expect(['universe', 'privacyVault'].filter(mentionsPrivacy)).toEqual(['privacyVault']);+ expect(+ ['CREATE TABLE IF NOT EXISTS privacy_vault_records (id UUID, sync_sequence BIGINT)']+ .filter((s) => FEDERATION_COLUMNS.some((c) => s.includes(c))),+ ).toHaveLength(1);+ });+});