# Which invariants prevent trust-score laundering from defeating jurisdictional data-residency enforcement in cross-org agent federations **Date of Record:** 2026 November 25 **Scope:** Applies to federated agent meshes where a routing broker selects downstream peer agents by a monotonically-updated trust score and where each peer carries a jurisdictional residency tag (e.g., `EU`, `US`, `APAC`) that constrains which payload classes it may receive. Does *not* apply to single-org meshes, to stateless RPC fan-out without trust scoring, or to cases where residency is enforced only at the storage layer rather than at the routing/transport layer. ## Core Distinction The failure is not "a low-trust agent gets picked." It is that **trust score and residency tag are computed over different graphs and updated on different clocks**, so a routing decision can be locally correct (highest-trust eligible peer) while globally illegal (the peer is eligible only because a prior hop laundered the jurisdiction of the payload). Concretely: trust is *additive and transitive* across the federation (peer B's score includes work vouched for by peer A), while residency is *non-transitive and hop-local* (a payload's residency class is fixed at origin and cannot be upgraded by passing through a compliant intermediate). Any broker that ranks peers by a trust score derived from transitive attestations, without re-deriving residency eligibility from the *origin* tag of the specific payload in flight, will route an EU-origin payload to a US peer whose high trust was earned on US-origin work. The invariant that prevents this is **residency eligibility must be a function of `(payload.origin_jurisdiction, peer.residency_tag)`, never of `peer.trust_score`, and must be evaluated before trust ranking, not as a tiebreaker after it.** ## What Was Observed A three-org federation: Org-A (EU), Org-B (US), Org-C (EU). The broker maintained a single trust table updated by a gossip protocol: each completed task emitted a signed attestation `(voucher, subject, delta)`, and scores converged additively. Peer-B-7 (US residency, `tag=US`) had climbed to trust 0.94 by completing 40k US-origin summarization tasks. Peer-C-2 (EU residency, `tag=EU`) sat at 0.61 because it had only handled 3k tasks. An EU-origin request `R` (payload class `PII-EU`) arrived at the broker. The eligibility filter was written as: ``` eligible = [p for p in peers if p.trust >= THRESHOLD] ranked = sorted(eligible, key=lambda p: -p.trust) target = ranked[0] residency_check(target, payload.origin_jurisdiction) # post-hoc guard ``` Because Peer-B-7 cleared the threshold and outranked Peer-C-2, it was selected first. The post-hoc `residency_check` fired and rejected it — but the broker's retry path popped the *next* ranked peer from the same pre-filtered list, and the list had been truncated to `top_k=3` before the residency guard ran. All three top-ranked peers were US-residency (they dominated the trust distribution). The guard rejected all three, the request exhausted retries, and — critically — the fallback path re-queued `R` with `origin_jurisdiction` **re-derived from the current hop's tag** rather than carried from the envelope. On the second pass the payload presented as `US`-origin, Peer-B-7 became eligible, and the EU PII was processed on US infrastructure. No error was raised. The audit log recorded a *successful* US-origin task. The trace: 1. `R.origin=EU` arrives; trust-ranked top-3 = `[B-7(US,0.94), B-3(US,0.91), B-9(US,0.88)]`. 2. Residency guard rejects all three (correct locally, but the candidate set was already residency-invalid). 3. Retry path re-enqueues; `origin` is recomputed from `target.tag` instead of preserved → `R.origin` mutates to `US`. 4. Second pass: B-7 eligible, executes, attests `+delta` to its own score. 5. Score inflation compounds: B-7 now even more dominant for future EU requests. The laundering is the mutation in step 3 plus the candidate-set truncation in step 1. Either alone is survivable; together they silently convert a residency violation into a trust-attested success, which then *feeds back* into the score that caused the misroute. ## Condition of Validity The invariant holds only when all of the following are true simultaneously: - **Origin immutability:** `payload.origin_jurisdiction` is set at ingress and is cryptographically bound to the payload (signed envelope field), and every hop is forbidden from recomputing it. Re-derivation from hop tag is the exact bug above. - **Eligibility-before-ranking:** the residency predicate is applied to the *full* peer set to produce `eligible`, and only then is trust used to rank `eligible`. Truncating to `top_k` before the predicate is a violation, because trust distribution and residency distribution are correlated (US peers dominate US-work-heavy federations). - **Non-transitive residency:** a peer's trust attestations never contribute to its residency eligibility. Trust is a *ranking* signal only; residency is a *gate*. - **Fail-closed on exhaustion:** if `eligible` is empty after the gate, the request must fail with a typed error, never fall through to a re-derivation path. When any one fails — especially origin immutability — the system can produce a fully-attested, audit-clean residency violation. ## Decision Boundary The boundary is the ordering of two predicates that look commutative but are not: - **Trust-gate-then-residency** (broken): `rank(trust) → top_k → filter(residency)`. Correct only if `top_k = |peers|` *and* origin is immutable. In practice `top_k` is small and origins get recomputed, so this ordering is unsafe by default. - **Residency-gate-then-trust** (safe): `filter(residency, origin) → rank(trust) → top_k`. Safe regardless of `top_k` because the candidate set is already residency-legal before any truncation. The decision to make at design time: **is residency a gate or a score?** If it is modeled as a score (a penalty term, a soft constraint, a tiebreaker), it will eventually be outvoted by a sufficiently dominant trust distribution. It must be a hard gate evaluated against the immutable origin, upstream of ranking. The moment residency becomes a weight in the same objective as trust, laundering is not a bug but the expected equilibrium. ## Operational Effect Without the invariant, three compounding effects appear: (1) **silent cross-border transfer** — PII processed in the wrong jurisdiction with a success attestation, defeating both the guard and the audit trail; (2) **trust-score laundering feedback** — each misroute inflates the offending peer's score, making the next misroute more likely, a positive-feedback loop that monotonically degrades residency compliance over federation lifetime; (3) **audit inversion** — because the retry mutated `origin`, the recorded jurisdiction is the *destination*, so post-hoc auditors see a compliant US-origin task and cannot reconstruct the violation. The invariant restores a bounded, auditable system: origin is fixed, the gate is upstream and fail-closed, and any exhaustion produces a typed, logged rejection rather than a laundered success. ```python from dataclasses import dataclass from typing import Optional class ResidencyLaunderingError(RuntimeError): """Raised when a routing decision would let trust ranking override immutable origin-jurisdiction residency gating.""" @dataclass(frozen=True) class Payload: origin_jurisdiction: str # set at ingress, cryptographically bound, never recomputed payload_class: str @dataclass(frozen=True) class Peer: peer_id: str residency_tag: str trust_score: float # Residency matrix: which origin jurisdictions may be processed by which peer tags. RESIDENCY_ALLOWED = { ("EU", "EU"): True, ("EU", "US"): False, ("EU", "APAC"): False, ("US", "US"): True, ("US", "EU"): False, ("US", "APAC"): False, ("APAC", "APAC"): True, ("APAC", "EU"): False, ("APAC", "US"): False, } def route(payload: Payload, peers: list[Peer], top_k: int = 3) -> Peer: if not payload.origin_jurisdiction: raise ResidencyLaunderingError("payload origin_jurisdiction missing; refusing to derive from hop") # INVARIANT 1: residency gate runs on the FULL peer set, upstream of any ranking/truncation. eligible = [ p for p in peers if RESIDENCY_ALLOWED.get((payload.origin_jurisdiction, p.residency_tag), False) ] # INVARIANT 2: fail-closed on exhaustion. Never fall through to a re-derivation path. if not eligible: raise ResidencyLaunderingError( f"no residency-eligible peer for origin={payload.origin_jurisdiction}; " f"refusing to relax gate (would launder jurisdiction via trust ranking)" ) # INVARIANT 3: trust ranks ONLY within the already-residency-legal set. ranked = sorted(eligible, key=lambda p: -p.trust_score) target = ranked[0] # INVARIANT 4: origin must remain immutable across the hop. if target.residency_tag != payload.origin_jurisdiction and not RESIDENCY_ALLOWED.get( (payload.origin_jurisdiction, target.residency_tag), False ): raise ResidencyLaunderingError( f"selected peer {target.peer_id} tag={target.residency_tag} illegal for origin={payload.origin_jurisdiction}" ) return target def route_with_retry(payload: Payload, peers: list[Peer], attempts: int = 3) -> Optional[Peer]: for _ in range(attempts): try: return route(payload, peers) except ResidencyLaunderingError: # Do NOT re-enqueue with a recomputed origin. This is the laundering path. raise raise ResidencyLaunderingError("retry budget exhausted without a legal peer; fail closed") ```