Skip to content

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

docs: keep Tribe graph + universe render-runs machine-local (#1724)

[._.]/ Adam Eivy407f68475135
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index b4956b7c1b..a497495269 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -17,6 +17,7 @@
## Federation
+- **[issue-1724] Decision: the Tribe relationship graph and universe render-runs stay machine-local (not federated).** Closing the last two open lines of the full-sync gap matrix (#1561) with an explicit, documented call rather than new sync wiring. The **Tribe graph** (`tribe_people` / `tribe_touchpoints` / `tribe_memory_links`) stays local because it is relationship-graph data — the same boundary PortOS already draws for the brain, where memory *nodes* federate but `memory_links` deliberately do not — and because it is coupled to machine-local domains (its memory cross-links extend the non-federated `memory_links` layer; its touchpoints carry per-machine calendar-account references). **Universe render-runs** (`universe_runs`) stay local because they are a regenerable render cache under a 200-row *global* cap that two peers would mutually evict, while the durable universe record they derive from already syncs. The decision is recorded in an ADR and pinned by a guard test so federating either later is a conscious act. No new sync categories or schema-version keys — no coverage guards touched. (`docs/decisions/2026-06-26-tribe-and-universe-runs-local.md`, `docs/STORAGE.md`, `server/services/tribe.js`, `server/services/universeBuilder/db.js`, `server/services/sharing/peerSync.test.js`)
- **[issue-1650] Completed Chief-of-Staff agent history now mirrors across full-sync peers.** Each paired machine's CoS history tab becomes a complete replica: a full-sync peer advertises its date-bucketed completed-agent archives (the metadata, transcript, and prompt for every finished agent), and the other machine receiver-pulls any it's missing on the ~60s sweep, verifies each file against its advertised hash before writing, then updates its history index so the arrivals appear. Archives are immutable once an agent finishes, so this is safe append-only replication — nothing is overwritten or merged. It runs only for peers explicitly flagged full-sync; a non-full-sync peer is unaffected. Live/running agents, their terminals, and worktrees stay machine-local as before. (Task-list and claim-metadata federation is tracked separately.) (`server/services/sharing/peerSync.js`, `server/routes/peerSync.js`, `server/services/cosAgents.js`)
- **[issue-1712] The live Chief-of-Staff task list now mirrors across full-sync peers — so two machines never both spawn the same task.** Completing the CoS federation started in #1650, each paired machine now sees the other's live backlog and, crucially, its claims: when one machine claims a task to work it, the other learns of that claim on the ~60s sweep and yields instead of spawning a duplicate agent. Because both machines edit the task files live, the backlogs are merged per task rather than copied over each other — a task you've just claimed is never clobbered by a peer's stale copy, completions converge so a finished task stops showing as in-progress on the other machine, and an expired claim (from a crashed machine) becomes freely re-claimable. It runs only for peers explicitly flagged full-sync; a non-full-sync peer is unaffected. Live terminals, in-flight spawns, and worktrees stay machine-local. (`server/services/sharing/peerSync.js`, `server/services/cosTaskMerge.js`, `server/services/cosTaskStore.js`, `server/routes/peerSync.js`)
- **[issue-1714] Chief-of-Staff task edits now converge to the most recently edited version across full-sync peers.** Building on the task-list federation in #1712: when the same task is edited on two paired machines while it stays in the same state (you re-prioritize it on one, tweak its description on the other), the machines now keep the *newest* edit instead of an arbitrary-but-stable winner. Each task carries an edit timestamp stamped whenever its content changes — but deliberately *not* on a background claim/lease heartbeat, so merely working a task can't make a stale edit win. Older tasks from a peer that predates this still converge safely (a missing timestamp counts as oldest), and task completion still always wins over an in-progress edit. (`server/services/cosTaskMerge.js`, `server/services/cosTaskStore.js`)
diff --git a/docs/STORAGE.md b/docs/STORAGE.md
index f510858086..47588f499a 100644
--- a/docs/STORAGE.md
+++ b/docs/STORAGE.md
@@ -33,7 +33,8 @@ PostgreSQL is a **required** install/runtime dependency (see [Backup & Restore](
- `memories` / `memory_links` — long-term memory + pgvector similarity.
- `creative_director_projects` — Creative Director project/treatment/scene/run state, one row per project (`id`/`status`/timestamps as columns, the full record in `data` JSONB). Migrated from the monolithic `data/creative-director-projects.json` in Phase 3 (#997); CD is local-only, so the row carries no sync cursor/tombstone. Adapter: `server/services/creativeDirector/projectsDB.js`.
- `catalog_user_types` — user-defined ingredient types (the registry that defines catalog row semantics), one row per type (`id` PK, the definition in `data` JSONB, `updated_at`/`deleted_at` mirroring the federation LWW clock + tombstone). Migrated from the `data/settings.json` `catalogUserTypes` slice in Phase 4 lead-in (#1001) so type evolution versions/syncs alongside the catalog data it governs. Federates via the catalog sync `catalogTypes` envelope block (wire shape unchanged by the move). Adapter: `server/services/catalogUserTypes/db.js`, dispatched via `store.js`.
-- `universes` / `universe_runs` — Universe Builder records (canon bibles, categories, composite sheets, locks, influences) one row per universe with the full sanitized record in `data` JSONB and `name`/`schema_version`/`ephemeral`/`updated_at`/`deleted`/`deleted_at` mirrored into columns; render-run history one row per run (local-only, capped 200, never federated). Migrated from `data/universes/{id}/index.json` (collectionStore) in Phase 3 Create slice 1 (#1014). **NO `sync_sequence`** — universes federate via the EXISTING `dataSync` snapshot/push model (LWW on the body's `updatedAt`), so the storage swap is invisible to peers (no schema-version bump). The store bumps an in-process mutation epoch on every write that `dataSync` folds into its checksum fingerprint, since a DB edit no longer changes the `data/universes/` directory the fingerprint used to watch. Adapter: `server/services/universeBuilder/db.js`, dispatched via `store.js`.
+- `universes` / `universe_runs` — Universe Builder records (canon bibles, categories, composite sheets, locks, influences) one row per universe with the full sanitized record in `data` JSONB and `name`/`schema_version`/`ephemeral`/`updated_at`/`deleted`/`deleted_at` mirrored into columns; render-run history one row per run (local-only, capped 200, never federated). Migrated from `data/universes/{id}/index.json` (collectionStore) in Phase 3 Create slice 1 (#1014). **NO `sync_sequence`** — universes federate via the EXISTING `dataSync` snapshot/push model (LWW on the body's `updatedAt`), so the storage swap is invisible to peers (no schema-version bump). The store bumps an in-process mutation epoch on every write that `dataSync` folds into its checksum fingerprint, since a DB edit no longer changes the `data/universes/` directory the fingerprint used to watch. **`universe_runs` is intentionally never federated** — a regenerable render cache under a 200-row *global* cap that two producers would mutually evict, while the durable universe record already syncs (ADR [tribe + universe-runs local](./decisions/2026-06-26-tribe-and-universe-runs-local.md), #1724). Adapter: `server/services/universeBuilder/db.js`, dispatched via `store.js`.
+- `tribe_people` / `tribe_touchpoints` / `tribe_memory_links` — the Tribe relationship/CRM graph (people + their care cadence, contact touchpoints, and cross-links into brain `memories`). **Intentionally machine-local — never federated** (ADR [tribe + universe-runs local](./decisions/2026-06-26-tribe-and-universe-runs-local.md), #1724): it is relationship-graph data, mirroring the deliberate "memory_links are instance-local" boundary in `memorySync.js` (memory *nodes* federate, the link graph does not), and is coupled to machine-local domains — `tribe_memory_links` extends the non-federated `memory_links` layer and `tribe_touchpoints` carry per-machine calendar-account refs. NO `sync_sequence`, no peer-sync record kind, no `dataSync` category. Adapter: `server/services/tribe.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-06-26-tribe-and-universe-runs-local.md b/docs/decisions/2026-06-26-tribe-and-universe-runs-local.md
new file mode 100644
index 0000000000..fc578e2ab0
--- /dev/null
+++ b/docs/decisions/2026-06-26-tribe-and-universe-runs-local.md
@@ -0,0 +1,103 @@
+# ADR: Tribe Relationship Graph + Universe Render-Runs Stay Machine-Local
+
+- **Date:** 2026-06-26
+- **Status:** Accepted
+- **Related:** issue #1724 (folded from the #1561 full-sync gap matrix),
+ [`server/services/tribe.js`](../../server/services/tribe.js),
+ [`server/services/universeBuilder/db.js`](../../server/services/universeBuilder/db.js),
+ [`server/services/memorySync.js`](../../server/services/memorySync.js),
+ [`docs/STORAGE.md`](../STORAGE.md).
+
+## Context
+
+Epic #1561 ("full-sync federated node pairs") audited every data domain for
+whether it mirrors across a federated peer pair. Two `db-primary` PostgreSQL
+domains were left undecided and folded into #1724 for a sync-vs-local call:
+
+1. **Tribe / relationship graph** — `tribe_people`, `tribe_touchpoints`,
+ `tribe_memory_links`. Not in `PEER_SUBSCRIBABLE_KINDS`
+ (`server/services/sharing/peerSync.js`) and not a `dataSync` snapshot
+ category. Local-only today.
+2. **Universe render-runs** — `universe_runs` (one row per render, capped at
+ 200 globally). Read through Postgres by `dataSync` when it loads universes,
+ but the run rows themselves are never included in any snapshot or push.
+
+The acceptance criterion is a documented decision for each, with anything that
+stays local recorded in the #1561 gap matrix as intentionally-excluded.
+
+## Decision
+
+**Both stay machine-local. Neither is federated.**
+
+### Tribe graph — local, by precedent
+
+PortOS already federates memory *nodes* (`memories`, via the `sync_sequence`
+pull-cursor in `server/services/memorySync.js`) but **deliberately keeps the
+relationship graph between them instance-local**. memorySync.js states it
+plainly:
+
+> memory_links (relationships) are not synced — only the memories table is
+> replicated. Relationship data is instance-local.
+
+The Tribe graph is the same shape — a personal relationship/CRM graph — and is
+structurally coupled to two domains PortOS holds machine-local on purpose:
+
+- **`tribe_memory_links`** is a relationship layer over `memories`, directly
+ analogous to the `memory_links` table that is already, by design, not
+ federated. Syncing tribe's memory cross-links while the brain's own
+ `memory_links` stay local would be internally inconsistent.
+- **`tribe_touchpoints`** carry `calendar_account_id` / `calendar_event_id`
+ pointing at a per-machine connected-calendar OAuth integration. Those refs do
+ not resolve on a peer that has a different (or no) calendar connection, so a
+ touchpoint synced verbatim would carry dangling, machine-specific provenance.
+
+Federating people + touchpoints while silently dropping the memory links and
+calendar refs would produce a lossy, incoherent partial mirror; federating them
+faithfully would first require federating the calendar-account integration
+layer, which is inherently machine-local. Keeping the whole Tribe graph local
+is consistent with the established "relationship data is instance-local"
+boundary.
+
+### Universe render-runs — local, regenerable cache
+
+`universe_runs` is a **regenerable render-output cache**, not durable source
+data. The durable source — the universe record itself — already federates via
+the `dataSync` snapshot/push model, so a peer reconstructs its own run history
+by rendering. Two properties make federation actively wrong rather than merely
+unnecessary:
+
+- The cap is **200 rows globally** (newest-across-all-universes, trimmed inside
+ `appendRun`), not per-universe. Two peers each generating runs would
+ continuously evict each other's rows to honor one shared cap — churn with no
+ durable value.
+- Runs are append-only outputs of a deterministic-enough render step; there is
+ nothing in a run a peer cannot reproduce locally on demand.
+
+This matches the existing classification in `docs/STORAGE.md`, which already
+describes `universe_runs` as "local-only, capped 200, never federated."
+
+## Consequences
+
+- No new `PEER_SUBSCRIBABLE_KINDS` entries, no `dataSync` categories, and no new
+ `PORTOS_SCHEMA_VERSIONS` keys — so none of the schema-version coverage guards
+ (peerSync `RECORD_KIND_SCHEMA_CATEGORIES`, dataSync, `schemaVersions`) are
+ touched.
+- The decision is pinned by a guard test
+ (`server/services/sharing/localDomains.test.js`) asserting `tribe_*` and
+ `universe_runs` are absent from the sync graph. Federating either later is a
+ conscious act: update that test and this ADR alongside the wiring.
+- If the brain `memory_links` relationship graph and the calendar-account layer
+ are ever federated, revisit Tribe — at that point the coupling argument no
+ longer holds and people + touchpoints could mirror cleanly.
+
+## Alternatives considered
+
+- **Federate the Tribe graph now (mirror the authors/artists record-kind
+ pattern).** Rejected: it crosses the deliberate "relationship data is
+ instance-local" boundary, and the memory-link + calendar-ref coupling makes a
+ faithful mirror impossible without first federating two other machine-local
+ layers.
+- **Federate `universe_runs` as append/LWW with the 200-cap honored on the
+ receiver.** Rejected: a global cap shared by two independent producers
+ guarantees mutual eviction churn, and the data is regenerable, so the mirror
+ buys nothing the universe-record sync doesn't already provide.
diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.js
index 6c5e1db234..b6bc0e4851 100644
--- a/server/services/sharing/peerSync.test.js
+++ b/server/services/sharing/peerSync.test.js
@@ -3138,6 +3138,28 @@ describe('peerSync', () => {
expect(covered.has(key)).toBe(true);
}
});
+
+ it('keeps the Tribe graph + universe render-runs intentionally OUT of the sync graph (#1724)', () => {
+ // ADR 2026-06-26: tribe_* and universe_runs are deliberately machine-local.
+ // - Tribe is relationship-graph data (mirrors the deliberate "memory_links
+ // are instance-local" policy in memorySync.js) and is coupled to
+ // machine-local calendar-account refs on touchpoints.
+ // - universe_runs is a regenerable render cache under a 200-row GLOBAL cap
+ // that two producers would mutually evict; the durable universe record
+ // already federates.
+ // This guard pins that decision: federating either later is a conscious act
+ // — wire the kind AND update this assertion + the ADR together.
+ const localOnlyKinds = ['tribe', 'tribePerson', 'tribeTouchpoint', 'tribeMemoryLink', 'universeRun'];
+ for (const kind of localOnlyKinds) {
+ expect(PEER_SUBSCRIBABLE_KINDS).not.toContain(kind);
+ expect(RECORD_KIND_SCHEMA_CATEGORIES[kind]).toBeUndefined();
+ }
+ const localOnlyCategories = ['tribe', 'tribePeople', 'tribeTouchpoints', 'tribeMemoryLinks', 'universeRuns'];
+ for (const category of localOnlyCategories) {
+ expect(PORTOS_SCHEMA_VERSIONS[category]).toBeUndefined();
+ expect(NON_RECORD_SCHEMA_CATEGORIES.has(category)).toBe(false);
+ }
+ });
});
describe('sender — pushRecordToPeer', () => {
diff --git a/server/services/tribe.js b/server/services/tribe.js
index 4b635df2eb..1557a919f2 100644
--- a/server/services/tribe.js
+++ b/server/services/tribe.js
@@ -1,3 +1,17 @@
+/**
+ * Tribe — relationship/CRM graph (PostgreSQL: tribe_people, tribe_touchpoints,
+ * tribe_memory_links).
+ *
+ * INTENTIONALLY MACHINE-LOCAL — not federated. See ADR
+ * docs/decisions/2026-06-26-tribe-and-universe-runs-local.md (#1724). It mirrors
+ * the deliberate "relationship data is instance-local" boundary already drawn by
+ * memorySync.js (memory NODES federate; memory_links do not), and is coupled to
+ * machine-local domains: tribe_memory_links extends the non-federated memory_links
+ * layer, and tribe_touchpoints carry per-machine calendar-account refs
+ * (calendar_account_id / calendar_event_id). There is no sync hook here by design;
+ * adding one is a conscious act (revisit the ADR + the guard in
+ * sharing/peerSync.test.js).
+ */
import { v4 as uuidv4 } from '../lib/uuid.js';
import { ensureSchema, query, withTransaction } from '../lib/db.js';
import { ServerError } from '../lib/errorHandler.js';
diff --git a/server/services/universeBuilder/db.js b/server/services/universeBuilder/db.js
index 5b8b03109e..a919f1d801 100644
--- a/server/services/universeBuilder/db.js
+++ b/server/services/universeBuilder/db.js
@@ -7,7 +7,11 @@
* into columns for the queries the service + federation actually run (rename
* cascade, delete-guard, list sort, snapshot ephemeral-filter, LWW staleness).
* Render-history runs live one-row-per-run in `universe_runs` (local-only,
- * capped at 200, never federated).
+ * capped at 200, never federated). Non-federation is a deliberate decision, not
+ * an oversight: runs are a regenerable render cache under a 200-row GLOBAL cap
+ * (trimmed in `appendRun`) that two peers would mutually evict, and the durable
+ * universe record already federates. See ADR
+ * docs/decisions/2026-06-26-tribe-and-universe-runs-local.md (#1724).
*
* This module is PURE leaf I/O — no in-process serialization, no sanitizing.
* The store facade (store.js) owns the per-id write queue + the mutation epoch