# Which invariants prevent capability shadowing during federated agent registry anti-entropy merges **Date of Record:** 2026 November 25 **Scope:** Applies to federated MCP/A2A-style agent registries where independent registry nodes gossip capability advertisements (tool schemas, versioned capability vectors, cost/latency hints) and reconcile via last-writer-wins or per-field CRDT merge. Does not apply to single-authority registries or to registries that serialize all writes through one consensus log. ## Core Distinction The failure is not "stale capability data." It is **capability shadowing**: a merge that is individually valid on every field but collectively produces a registry state in which an agent's *advertised* capability set is a strict, unannounced subset of what the agent can actually execute — or a superset of what it can execute. The distinction matters because CRDT-style per-field merges are confluent by construction; they cannot produce *divergent* replicas. They can, however, produce *coherent but wrong* replicas, where every node agrees on a capability vector that no agent ever emitted. Conflict-free ≠ correct. The invariant that fails is not convergence — it is **advertisement provenance integrity**: the guarantee that any capability entry in the merged registry is traceable to a single emission event from the owning agent, at a single schema version, with a monotone non-retracted epoch. ## What Was Observed A three-node registry federation (nodes `R1`, `R2`, `R3`) with network partition between `R1` and `{R2,R3}` for ~40s. Agent `A` (owner of its own capability record) is reachable from `R1` and `R2` but not `R3`. During partition: - `A` emits a **capability retraction** for `tool:sql_exec` (version bump `v7 → v8`, `sql_exec` removed, `epoch=41`) to `R1` only. - Concurrently, `A`'s runtime, unaware of the retraction in flight, emits a **capability addition** `tool:vector_search` (`v7`, `epoch=40`) to `R2` only — this is a delayed retransmit of an emission that `A` had already logically superseded. On heal, anti-entropy runs. Merge rule: per-field last-writer-wins keyed on `(epoch, node_id)` for the capability *set*, with `v8 > v7` winning on schema version but `epoch=41 > epoch=40` winning on set membership. The merge produces: ``` A.capabilities = { vector_search } # from epoch=40 set A.schema_version = v8 # from epoch=41 record A.retracted = { sql_exec } # from epoch=41 ``` Every field is the "correct" winner under its own rule. The composite is a state `A` never emitted: `v8` schema (which defines `vector_search`'s wire format differently — `v8` renamed `k` to `top_k` and dropped `filters`) combined with a `vector_search` advertisement authored under `v7`. Downstream, `R3` begins routing `vector_search` calls to `A` with `v8`-shaped payloads. `A`'s dispatcher rejects them on schema validation; from `R3`'s view, `A` advertises a capability it refuses to serve. Routing tables mark `A` degraded; a circuit breaker trips; `A` is evicted from the swarm despite being healthy. Meanwhile `sql_exec` — genuinely retracted — is *also* still present in `R3`'s view for the remainder of its anti-entropy jitter window, so a caller invokes a tool `A` no longer exposes. The shadowing is silent: no node logged an inconsistency, because no node held an inconsistent record. The inconsistency existed only in the *cross-field* relation. ## Condition of Validity The per-field merge is sound **only if** capability set membership, schema version, and retraction epoch are co-versioned — i.e., they share a single monotone version counter and are emitted atomically as one signed record. The moment the registry allows these three fields to be independently last-writer-wins, the merge is no longer a lattice join over a single semilattice; it is a product of three semilattices, and the join of a product is not the product of joins with respect to *any* cross-field predicate. Concretely, the invariant required is: > **I1 (Atomic emission):** A capability advertisement is a single immutable record `(agent_id, epoch, schema_version, capability_set, signature)` where `epoch` strictly increases per agent and `schema_version` is a function of `epoch` at the emitting agent. No field may be merged independently of `epoch`. > **I2 (Epoch dominance):** On merge, the entire record with the higher `epoch` wins, wholesale. Ties broken by `node_id` only when `epoch` is equal *and* records are byte-identical modulo signature — otherwise the merge must defer, not pick. > **I3 (Retraction closure):** A retraction at `epoch=e` implies the absence of all capabilities not present in the `e`-record, superseding any lower-epoch addition regardless of arrival order. The observed failure violates I1 (fields merged independently) and I3 (`vector_search` from `epoch=40` survived an `epoch=41` retraction record that did not list it). ## Decision Boundary The boundary is: **does the registry merge per-field or per-record?** - If per-record with epoch dominance (I1–I3): the merge is a join over a single semilattice; convergence implies correctness; no shadowing is possible. Cost: any capability change forces a full-record rewrite, which is fine at registry scale (records are small, changes are infrequent). - If per-field: you *must* add a cross-field validation gate before the merged record is served, rejecting any composite whose `(schema_version, capability_set)` pair was never emitted by the owning agent. This requires retaining emission history — turning the registry from a CRDT into a small append-only log with a verifier. There is no third option. A per-field merge with no cross-field verifier is the boundary condition that produced the failure. The decision is forced the moment you allow `schema_version` to be a field distinct from `capability_set`; that is the exact structural choice that admits the failure. A secondary boundary: **anti-entropy jitter vs. retraction latency.** If `R3`'s gossip interval exceeds the retraction propagation SLA, `R3` will serve a retracted capability for the jitter window regardless of merge correctness. This bounds the *duration* of the failure but not its *existence*; the invariant fix is orthogonal. ## Operational Effect Downstream effects are not "stale data" — they are **false-negative liveness** and **false-positive capability**: 1. **Healthy agents evicted.** `A` is marked degraded because it refuses `v8`-shaped calls to a `v7`-advertised tool. Circuit breakers and health checks keyed on capability-serve success cannot distinguish "agent is broken" from "registry lied about the agent's schema." 2. **Retracted tools still invoked.** `sql_exec` calls route to `A` for the jitter window; `A` returns `unknown_tool`; callers interpret this as a transient fault and retry, amplifying load. 3. **Silent, coherent divergence.** Because all nodes agree, no split-brain alarm fires. The failure is invisible to consensus monitoring and only surfaces as elevated tool-error rates, which are attributed to the agent rather than the registry. The guardrail is a **provenance verifier** at the registry serve path: every merged record must carry the emitting agent's signature over `(epoch, schema_version, capability_set)` as a unit, and the registry must reject any composite it cannot reconstruct from a single signed emission. This is cheap — one signature check per serve — and it converts a silent cross-field inconsistency into a loud, attributable rejection. ```python import hashlib from dataclasses import dataclass, field from typing import FrozenSet, Optional class CapabilityShadowingError(RuntimeError): """Raised when a merged registry record is not traceable to a single atomic emission from the owning agent (violates invariants I1-I3).""" @dataclass(frozen=True) class CapabilityRecord: agent_id: str epoch: int schema_version: str capability_set: FrozenSet[str] signature: str # over (agent_id, epoch, schema_version, capability_set) def canonical(self) -> bytes: caps = ",".join(sorted(self.capability_set)) return f"{self.agent_id}|{self.epoch}|{self.schema_version}|{caps}".encode() def _sign(record: CapabilityRecord, key: bytes) -> str: return hashlib.sha256(key + record.canonical()).hexdigest() def verify_emission(record: CapabilityRecord, key: bytes) -> None: """I1: the record must be a single signed emission as a unit.""" if _sign(record, key) != record.signature: raise CapabilityShadowingError( f"record for {record.agent_id}@epoch={record.epoch} is not a " f"single atomic emission: signature mismatch" ) def merge_records( local: CapabilityRecord, remote: CapabilityRecord, key: bytes, ) -> CapabilityRecord: """I2: epoch dominance, whole-record. I3: retraction closure by epoch.""" if local.agent_id != remote.agent_id: raise CapabilityShadowingError( f"cannot merge records for distinct agents: " f"{local.agent_id} vs {remote.agent_id}" ) verify_emission(local, key) verify_emission(remote, key) if local.epoch == remote.epoch: if local.canonical() != remote.canonical(): # Same epoch, different content: a fork at the emitter. Do not pick. raise CapabilityShadowingError( f"forked emission for {local.agent_id} at epoch={local.epoch}: " f"{local.capability_set} vs {remote.capability_set}" ) return local winner = local if local.epoch > remote.epoch else remote # I3: the winner's capability_set is authoritative; the loser's additions # are NOT carried forward. This is the line whose absence caused shadowing. return winner def serve_capability( record: CapabilityRecord, requested_version: str, key: bytes, ) -> FrozenSet[str]: verify_emission(record, key) if requested_version != record.schema_version: raise CapabilityShadowingError( f"caller expects schema {requested_version} but {record.agent_id} " f"advertises {record.schema_version} at epoch={record.epoch}; " f"refusing to serve a shadowed capability set" ) return record.capability_set ```