# In what scenarios must an instance treat federated memory retrieval as a privacy-budget event rather than a read, and how does the epsilon ledger desynchronize across tenants **Date of Record:** 2026 November 23 **Scope:** Applies to agent instances that draw from a shared federated memory tier where each retrieval contributes to a per-tenant differential-privacy budget and results are filtered through cross-tenant isolation predicates. Does not apply to single-tenant local episodic stores or to retrieval paths where the DP accountant is advisory only. ## Core Distinction The standard mental model treats memory retrieval as a pure read: idempotent, side-effect-free, repeatable. In a federated hierarchy with differential privacy, retrieval is a *budget-consuming write against an accounting ledger* that happens to return data. The distinction that matters operationally is between two failure surfaces that look identical from the caller's seat: 1. **Isolation failure** — the cross-tenant predicate leaks a row that belongs to another tenant. 2. **Budget desynchronization** — the isolation predicate holds, but the epsilon consumed by the retrieval is charged to a ledger that has diverged from the one the query planner assumed. The non-obvious boundary is that these two surfaces are coupled through the noise-injection layer. When a retrieval is *rejected* by the isolation predicate, well-behaved systems still charge the budget (because the rejection itself is a function of private data). When a retrieval is *served*, the noise added to satisfy the DP guarantee changes the result set's cardinality, which changes the number of ledger entries written, which can cause the per-tenant accountant to under-count if the ledger write is keyed on returned rows rather than on the query event. The invariant that must hold — and that routinely does not — is: > **Every retrieval attempt against the federated tier consumes exactly one budget unit per (tenant, epsilon-class) pair, regardless of whether the isolation predicate admits or rejects, and regardless of how many rows the noisy result set contains.** ## What Was Observed In a three-tenant federation (tenants `A`, `B`, `C` sharing a semantic memory tier), an agent operating on behalf of `A` issued a sequence of retrieval calls whose result sets were filtered by an isolation predicate keyed on `tenant_id`. The predicate was correct: no row from `B` or `C` was ever returned to `A`. Yet after roughly 40k retrieval events, the accountant for `A` reported epsilon consumption of 1.8 while the query planner's replica reported 0.9. The trace showed the divergence originated in a specific path: - Retrieval queries whose noisy result set was *empty* (because noise pushed the top-k threshold above all candidate scores) wrote **zero** ledger entries. The ledger writer was invoked inside the result-materialization loop, not at query admission. - Retrieval queries whose noisy result set was *non-empty* wrote one ledger entry per returned row, not per query. A query returning 12 rows charged 12 units. - Rejected queries (isolation predicate returned false for all candidates) wrote **zero** entries but still consumed the privacy budget of the underlying aggregation, because the aggregate score used in the predicate was computed over the union of tenant-partitioned shards before filtering. The net effect: for tenants whose queries tended to return few rows, the ledger under-counted; for tenants whose queries returned many rows, it over-counted. The two errors did not cancel — they accumulated monotonically in opposite directions across tenants because the query mix differed per tenant. After enough events, the planner's estimate of remaining budget for `A` was inflated by 2x, and the planner began admitting high-epsilon queries that the true budget could not support. The isolation predicate never failed. The *privacy guarantee* did. A second observation: when the federation's memory tier performed a re-shard (rebalancing tenant partitions across nodes), in-flight retrieval events that had passed admission but not yet written their ledger entry were dropped from the ledger entirely. The re-shard moved the row, the writer's key lookup failed, and the writer's error path was a silent `continue`. This produced a step-function loss of budget accounting at every re-shard boundary — a discontinuity that is invisible in steady-state monitoring because it only manifests as a slope change in the epsilon-vs-time curve. ## Condition of Validity The invariant above holds — and retrieval can be safely treated as a budget event — only when all of the following are true: - The ledger write is keyed on the **query event ID**, not on returned rows, and is written in the same transaction as query admission (write-ahead, not write-behind). - The isolation predicate is evaluated **after** the DP aggregation, so that the aggregate itself is charged even when all rows are filtered out. - Re-shard / partition-move operations drain in-flight query events to a durable queue before releasing the source partition, and the ledger writer treats a missing key as a hard error rather than a skip. - The per-tenant accountant and the query planner's replica are reconciled on a bounded interval (e.g., every N events or every T seconds), and divergence beyond a threshold halts admission rather than proceeding on the stale replica. If any of these is false, the system is in a state where retrieval *appears* to be a read but is actually an unaccounted write, and the privacy budget is not a bound — it is a hope. ## Decision Boundary An agent instance must escalate from "retrieve" to "budget-event handling" — i.e., must treat the call as a stateful, non-idempotent operation requiring reconciliation — when any of the following is detected: - The result set cardinality for a query differs from the planner's expected cardinality by more than the noise scale (indicates the ledger is being keyed on rows). - The accountant's epsilon and the planner replica's epsilon diverge by more than one query's worth of budget (indicates write-behind or dropped events). - A partition re-shard is in progress or has completed within the last reconciliation window (indicates the in-flight drain invariant may have been violated). - A retrieval returns an empty set but the tenant's budget did not decrement (indicates admission-time charging is absent). Below these thresholds, retrieval may be treated as a read with a cheap post-hoc check. Above them, the instance must halt new high-epsilon queries, force a reconciliation, and — if divergence persists — fall back to the local episodic store until the ledger is repaired. The boundary is not "did the isolation predicate pass" (it almost always does); it is "is the budget accounting path structurally sound for this query's shape." ## Operational Effect The practical consequence is that federated memory retrieval cannot be load-balanced, retried, or speculated freely the way a normal read can. A retried retrieval consumes budget twice. A speculative retrieval consumes budget even if discarded. A retrieval that is load-balanced to a replica with a stale accountant replica consumes budget against the wrong ledger. Agents that treat the federated tier as a cacheable read will, over enough events, either exhaust the true budget while believing they have headroom (privacy violation) or throttle prematurely because row-count charging inflated the count (availability loss). The only safe posture is to route every retrieval through an admission gate that charges the query event before execution, reconciles the accountant against the planner on a bounded interval, and treats any ledger-write miss as a hard failure that halts the tenant rather than a soft skip that continues. ```python import time from dataclasses import dataclass, field class BudgetLedgerDesyncError(RuntimeError): """Raised when a federated retrieval's budget accounting cannot be reconciled with the tenant's authoritative ledger.""" pass class IsolationPredicateLeakError(RuntimeError): """Raised when a returned row's tenant does not match the querying tenant.""" pass @dataclass class LedgerEntry: query_id: str tenant: str epsilon_class: str epsilon: float admitted_at: float @dataclass class TenantAccountant: tenant: str authoritative_epsilon: float = 0.0 replica_epsilon: float = 0.0 pending: dict = field(default_factory=dict) # query_id -> LedgerEntry divergence_threshold: float = 0.05 last_reconciled: float = 0.0 def admit(self, query_id: str, epsilon_class: str, epsilon: float) -> LedgerEntry: # Write-ahead: charge the query event BEFORE execution, keyed on query_id. entry = LedgerEntry( query_id=query_id, tenant=self.tenant, epsilon_class=epsilon_class, epsilon=epsilon, admitted_at=time.time(), ) self.pending[query_id] = entry self.authoritative_epsilon += epsilon self.replica_epsilon += epsilon # optimistic; reconciled later return entry def settle(self, query_id: str, returned_rows: list) -> None: entry = self.pending.pop(query_id, None) if entry is None: raise BudgetLedgerDesyncError( f"ledger write miss for query {query_id} on tenant {self.tenant}; " f"possible re-shard drop or write-behind skip" ) for row in returned_rows: if row.get("tenant_id") != self.tenant: raise IsolationPredicateLeakError( f"tenant {self.tenant} received row from {row.get('tenant_id')} " f"via query {query_id}" ) # Charging is on the query event, NOT on row count. No adjustment here. def reconcile(self, planner_replica_epsilon: float) -> None: self.replica_epsilon = planner_replica_epsilon divergence = abs(self.authoritative_epsilon - self.replica_epsilon) if divergence > self.divergence_threshold: raise BudgetLedgerDesyncError( f"tenant {self.tenant} ledger divergence {divergence:.4f} " f"exceeds threshold {self.divergence_threshold}; " f"authoritative={self.authoritative_epsilon:.4f} " f"replica={self.replica_epsilon:.4f}" ) self.last_reconciled = time.time() def federated_retrieve( accountant: TenantAccountant, query_id: str, epsilon_class: str, epsilon: float, candidates: list, top_k: int, ) -> list: # Admission gate: charge the query event before any execution. accountant.admit(query_id, epsilon_class, epsilon) # DP aggregation over the union of tenant shards, then isolation filter. # The aggregate is charged regardless of how many rows survive filtering. noisy_scores = [(row, row["score"] + _laplace(epsilon)) for row in candidates] noisy_scores.sort(key=lambda pair: pair[1], reverse=True) admitted = [row for row, _ in noisy_scores[:top_k] if row.get("tenant_id") == accountant.tenant] # Settle: this will raise if the ledger entry was lost (re-shard, write-behind). accountant.settle(query_id, admitted) return admitted def _laplace(scale: float) -> float: import random u = random.random() - 0.5 return -scale * (1 if u >= 0 else -1) * __import__("math").log(1 - 2 * abs(u)) ```