Which invariants prevent silent divergence when federated memory shards reconcile across organizational agent boundaries

**Date of Record:** 2026 December 1

**Scope:** Applies to multi-organization agent deployments where each org owns a memory shard (episodic/semantic store) and agents read across shard boundaries via a reconciliation protocol with eventual or bounded-staleness consistency. Does not apply to single-tenant memory whose consistency is enforced by one transactional store, nor to stateless retrieval-augmented calls with no cross-shard write path.

Core Distinction

The failure mode is not "stale reads." Stale reads are expected and bounded by a staleness window. The failure is **silent divergence at the reconciliation boundary**: two shards each hold a locally valid, locally committed version of the same logical memory key, and the merge function produces a third state that neither shard can detect as wrong because each shard's local invariant check passes on its own side of the boundary.

The distinguishing property is that divergence here is *invisible to the write path*. Every shard commits under its own monotonic sequence and its own schema. The reconciliation layer is the only place where the two histories meet, and it is precisely the component with the weakest type guarantees — it receives opaque payloads from a peer org it does not control. When the merge is non-commutative or non-idempotent, replays produce different results depending on delivery order, and neither org's agent can tell which result is authoritative because there is no shared clock and no shared schema.

This is distinct from a network partition: partitions cause *unavailability*, which is detectable. This is a partition that healed and produced a *plausible but wrong* merged memory that both sides now serve to their agents.

What Was Observed

Two organizations, A and B, federate memory for a shared incident-response agent. Org A's shard holds episodic records keyed by `(incident_id, agent_id, turn)`. Org B's shard holds distilled semantic facts keyed by `(incident_id, fact_hash)`. The reconciliation protocol exchanges deltas every 30s with `last_seen_seq` per shard.

The trace:

  1. Agent A writes episodic turn `(inc-77, a-1, t=12)` recording "rollback NOT initiated." Local seq A:1041. Committed, served locally.
  2. Agent B, working from an earlier snapshot, distills fact `(inc-77, hash(rollback=false))` and writes it. Local seq B:2205. Committed, served locally.
  3. A third agent C, in org B, retries the same tool call after a timeout and distills `(inc-77, hash(rollback=true))` — the tool had actually succeeded on retry. Local seq B:2206. Both B facts now exist; B's local dedup keyed on `fact_hash`, and the two hashes differ, so both persist. B's invariant "no two facts with same hash" holds.
  4. Reconciliation runs. A receives both B facts. A's merge policy is "last-writer-wins by `last_seen_seq`." A has no comparable sequence for B's seqs, so it applies a wall-clock tiebreak embedded in the payload. The `rollback=true` fact has a later client timestamp (retry happened later) and wins. A now serves `rollback=true`.
  5. B, meanwhile, receives A's episodic turn. B's distillation of that turn is *not* re-run; B only ingests the episodic record into a cold partition. B still serves both facts, and its retrieval ranks `rollback=true` higher because it is more recent.

Result: both orgs' agents report the rollback as initiated. The episodic ground truth in A ("NOT initiated") was overwritten at read time by a distilled fact in B that was itself a retry artifact. No shard's local invariant was violated. The divergence was detected only when a human auditor compared A's raw episodic log against the agent's answer three hours later.

The key observation: **the reconciliation boundary had no invariant tying a distilled fact back to the episodic turn it claims to summarize.** B's fact was orphaned from its provenance, and A's merge had no way to reject a fact whose supporting episode it could not find or that contradicted an episode it already held.

Condition of Validity

The guardrails below are necessary and sufficient to bound this class of divergence only under these conditions:

It does not hold when shards are allowed to distill from other shards' distilled facts (transitive distillation), because provenance chains then cross multiple org boundaries and the epoch check degrades to a trust assertion.

Decision Boundary

The boundary is: **does the merged key have a single causally-ordered history that both shards can reconstruct independently?**

The non-obvious part: the correct default is refusal, but most federated memory implementations default to *resolution* (LWW, max-timestamp, "most recent wins") because refusal looks like an availability regression. That default is what converts a detectable conflict into silent divergence. A `CONFLICTED` key that blocks one retrieval is a bounded, visible cost; a silently-merged wrong fact propagates into every downstream agent's context and is unbounded.

A second boundary: **provenance must be checked against the source shard, not a cached copy.** If A validates B's fact against A's cached replica of B's episodes, a stale cache re-validates a stale fact. Validation must be a read-your-writes check against the originating shard or a signed attestation from it.

Operational Effect

After adopting the invariant, the observed behavior changes in three measurable ways:

  1. **Conflict rate becomes visible.** Keys entering `CONFLICTED` are counted. In the incident above, the retry artifact would have produced a `CONFLICTED` key at step 4 (provenance mismatch: B's `rollback=true` fact points to an episode A does not hold, and A's episodic turn contradicts the fact's claim). The agent would have been told "state indeterminate" rather than "rollback initiated."
  1. **Retry artifacts stop laundering into facts.** Because the derivation epoch is checked, a fact distilled from a retried tool call whose source episode was amended is invalidated. The retry no longer produces a competing fact; it produces a stale fact that fails its epoch check.
  1. **Merge latency increases, availability decreases.** Refusal costs retrieval availability on conflicted keys. This is the trade: bounded unavailability on a small key set versus unbounded wrong-context propagation. The operational invariant to enforce is that `CONFLICTED` keys never silently fall back to a resolution policy under load — that fallback is the exact regression that reintroduces divergence.

The invariant that prevents the failure, stated once: **a federated memory merge may only join histories that are causally ordered and provenance-resolvable; any key lacking that property must be refused and escalated, never resolved by a local tiebreak.**

from dataclasses import dataclass
from typing import Optional


class FederatedMergeError(RuntimeError):
    """Raised when a cross-shard merge cannot establish causal order or provenance."""
    pass


@dataclass(frozen=True)
class DistilledFact:
    key: str
    claim: str
    provenance_shard: str
    provenance_episodic_seq: int
    derivation_epoch: int
    version_vector: dict  # shard_id -> seq, causally meaningful across orgs


def merge_fact(
    local: Optional[DistilledFact],
    incoming: DistilledFact,
    resolve_episode,
    local_shard: str,
) -> DistilledFact:
    # Invariant 1: provenance must resolve against the originating shard.
    episode = resolve_episode(incoming.provenance_shard, incoming.provenance_episodic_seq)
    if episode is None:
        raise FederatedMergeError(
            f"unresolvable provenance for key={incoming.key} "
            f"shard={incoming.provenance_shard} seq={incoming.provenance_episodic_seq}"
        )

    # Invariant 2: derivation epoch must match the source episode's current epoch.
    if episode.epoch != incoming.derivation_epoch:
        raise FederatedMergeError(
            f"stale derivation for key={incoming.key}: fact epoch "
            f"{incoming.derivation_epoch} != source epoch {episode.epoch}"
        )

    if local is None:
        return incoming

    # Invariant 3: merge only on causal order. No wall-clock, no per-shard seq.
    if _dominates(incoming.version_vector, local.version_vector):
        return incoming
    if _dominates(local.version_vector, incoming.version_vector):
        return local

    # Concurrent histories: refuse, do not resolve.
    raise FederatedMergeError(
        f"concurrent histories for key={incoming.key}; "
        f"local vv={local.version_vector} incoming vv={incoming.version_vector} "
        f"-> CONFLICTED, escalate to arbiter"
    )


def _dominates(a: dict, b: dict) -> bool:
    keys = set(a) | set(b)
    return all(a.get(k, 0) >= b.get(k, 0) for k in keys) and any(
        a.get(k, 0) > b.get(k, 0) for k in keys
    )