Federation

Beta in docs/STATUS.md. Mnemosyne is alpha, on the 3.6.x line, and the API can still change within 3.x.

Federation is signed synchronization between Mnemosyne servers. One server pulls items from a peer it trusts into a workspace, keeps them apart from the workspace’s own memory, and returns them in recall marked with their source. This page gives the model; the setup steps are in Operations: federation.

Three tiers of access

Routes live under /memory/federation/ (packages/server/src/routes/federation.ts).

TierRoutesRequires
Peer adminGET /peers, POST /peers, GET /peers/pending, POST /peers/{id}/approve, POST /peers/{id}/approve-key, DELETE /peers/{id}A key with the federation:admin scope
Peer callsGET /items, POST /resolveThe memory:federation scope and the peer gate: an mk_fed_ key this server issued, the pinned public key, a service JWT signed with the peer’s key, and workspace binding
Local syncPOST /sync, GET /sync/{jobId}The memory:federation scope from a local key; a peer’s mk_fed_ key is refused

A federation:admin key cannot be minted from the dashboard or through MCP. An operator provisions it.

A peer exists only after an operator adds it with POST /memory/federation/peers. Peers are kept in Postgres, and their pull key and symmetric key are sealed with MNEMO_MASTER_KEY and never returned by the API.

What the server enforces

These hold whatever a peer sends (packages/federation/src/SyncEngine.ts):

  • Attribution is capped. An incoming memory is stored as federation_received, the lowest trust score (20), whatever attribution the peer claims.
  • Trust weights are local. A peer’s weight comes from this server’s own peer configuration, never from the peer.
  • The origin is local. Each item is stored under the id this server registered the peer with, whatever the peer claims. Only that peer can update the item or send a tombstone for it.
  • Version guard. An item whose version jumps more than 100 ahead of a copy from another peer is rejected.
  • Pull only. A peer never writes into this server. The gRPC FederationSync RPC answers Unimplemented.
  • Key rotation. A new peer key is accepted only when it is cross-signed or approved in advance.

The payload

When both sides have keys configured, each item’s payload is sealed with AES-256-GCM under a shared symmetric key and the list is signed with the sender’s Ed25519 key (packages/federation/src/secureEnvelope.ts). The receiver verifies the signature and opens every item; one failure rejects the whole batch.

Without keys, the server serves and accepts the plaintext shape and logs a warning. Configure the keys before syncing anything sensitive.

Syncing

curl -X POST http://localhost:3939/memory/federation/sync \
  -H "Authorization: Bearer mns_live_..." \
  -H "Content-Type: application/json" \
  -d '{"peerId": "peer_1", "conflictResolution": "manual"}'

The call answers 202 with {"jobId": "...", "status": "pending"}. Poll GET /memory/federation/sync/{jobId} until status is done or failed. The server signs the pull with its own identity (MNEMO_FED_PEER_ID and MNEMO_FEDERATION_PRIVATE_KEY), the items land in the caller’s workspace, and a failed pull fails the job. Jobs are kept in Postgres (migration 0063): a restart does not lose one, a job a restart cut short reads as failed, and a workspace only sees its own jobs.

A sync reads the peer in pages, from where the previous sync from that peer ended. An edit arrives as a new version, and a forgotten or deleted fact as a tombstone, sent only to a peer that may hold the fact. One job reads at most 50 pages for at most 5 minutes; the next sync goes on from its cursor.

In recall

POST /recall, and memory_recall through it, returns pulled items after the local hits, each with "federation": { "peer": ..., "trustScore": 20 }. They match by words only, since they carry no embedding, and the caller’s ceiling applies to them as to any hit. Other recall routes do not return them.

Conflicts

When an incoming item collides with a local one, conflictResolution decides:

StrategyEffect
theirs_winsThe incoming version replaces the local one
ours_winsThe local version is kept
manualThe local version is kept and the item is reported as contested
mergeThe incoming version becomes current and the local one is kept as superseded
omittedThe trust-anchor rule decides: trust, then recency, then worth

These apply to a copy from another peer. A copy from the same peer is that peer’s own item: a higher version replaces it, with no conflict to resolve.

Because incoming items always carry the lowest trust, the default rule keeps a local memory with a known attribution over a conflicting incoming one. When no rule decides with confidence above 0.7, the item is contested: the local copy stays, and the server emits a federation.conflict event and webhook. There is no review queue for contested items.

POST /memory/federation/resolve settles a conflict by hand. With {"items": [...]} it runs a weighted supermajority vote over the claims; with {"itemA": ..., "itemB": ...} it applies last-write-wins.

See also