# Which invariants prevent cross-tenant context bleed when policy filters are applied after retrieval in federated agent memory **Date of Record:** 2026 November 21 **Scope:** Applies to federated agent memory services where a shared vector or hybrid index is partitioned logically by tenant labels and policy filters are applied at query time (post-retrieval or in-query predicate) rather than by physical index separation. Does not apply to hard-partitioned stores where tenant isolation is enforced by separate indices, separate embedding spaces, or separate processes with no shared ANN graph. ## Core Distinction The failure mode is not "the tenant filter was missing." It is that the tenant filter is **non-monotonic with respect to the ANN candidate set**. Approximate nearest-neighbor retrieval returns a top-k candidate list whose membership depends on the *global* distribution of vectors near the query point, not on the tenant's own subspace. When a policy predicate (`tenant_id == T`) is applied to that candidate list—whether as a post-filter or as an in-query pre-filter that the engine merely uses to *drop* results—the surviving set can be smaller than k, and the recall of the returned set is a function of how many foreign-tenant vectors happened to occupy the top-k neighborhood. Two agents in different tenants issuing *identical* queries against the *same* index therefore receive different result counts, and, more dangerously, a tenant whose data is sparse relative to a noisy neighbor gets **zero** results where the index contains hundreds of valid matches. The invariant that matters is not "filter is applied." It is: **for every query and every tenant, the retrieved set is identical to the set that would be returned by an index containing only that tenant's vectors.** Call this *filter-equivalence*. Post-filtering violates filter-equivalence whenever the candidate pool is not over-fetched by a factor bounded by the global-to-local density ratio, which is not knowable at query time. ## What Was Observed A federated deployment hosted three tenants (A: 1.2M chunks, B: 180k chunks, C: 9k chunks) in a single HNSW graph with `tenant_id` stored as a filterable metadata field. Filtering was implemented as an in-query predicate: the engine walked the HNSW graph, and any node failing the predicate was skipped but *not* pruned from traversal—its neighbors were still visited. This is the standard "filtered HNSW" behavior, and it is where the boundary hides. For tenant C, queries whose true nearest neighbor lay in a dense region of tenant A's data produced candidate lists dominated by A's nodes. Because the graph walk visits a bounded number of nodes (`ef_search = 128`), and because A's nodes are traversed but discarded, the effective budget available to reach C's nodes was consumed by A's. Observed recall for tenant C fell from 0.94 (isolated index) to 0.31 (shared index, filtered), and 6.1% of tenant C queries returned **fewer than k results despite ≥k valid matches existing**, with 0.4% returning empty sets. The second observation is the one that makes this a *policy* failure rather than a *quality* failure. A retrieval-augmented agent treats an empty or short result set as evidence of absence. Tenant C's agent, receiving an empty set, emitted "no relevant internal documentation exists" to a user—while the documentation existed and was correctly labeled. The agent's reasoning was sound given its inputs; the isolation layer had silently converted a retrieval shortfall into a factual claim. Isolation that is *correct* (no foreign data leaked) but *non-equivalent* (own data unreachable) is still a policy violation, because the policy's intent is "tenant T sees exactly its own data," and "sees a subset" fails the second half. ## Condition of Validity Filter-equivalence holds only under a bound on over-fetch. If the engine over-fetches `k' = k · r` candidates and then post-filters, the result set is guaranteed to contain k valid items only when the fraction of tenant-T vectors in the traversed region is ≥ 1/r. Since that fraction is a property of the data distribution and the query, no static `r` is safe. The only sound constructions are: 1. **Pre-filter with graph pruning:** the traversal never enters non-T nodes (requires per-tenant subgraphs or a predicate-aware index), so the budget is spent entirely within T's subspace. 2. **Iterative over-fetch with termination on k survivors,** where the over-fetch factor grows until either k valid results are found or the index is exhausted—and exhaustion is reported as *exhaustion*, not as *absence*. 3. **Physical partitioning,** which trivially satisfies the invariant but forfeits shared-index economics. Condition 2 is the minimum viable guardrail for shared indices, and it requires the retrieval API to distinguish three outcomes—`FOUND(k)`, `EXHAUSTED(n= k: # Survivors are the tenant's true top-k only if the pool was not # truncated before reaching k valid items at the boundary. boundary = survivors[k - 1] if all(c.score <= boundary.score for c in candidates if c.tenant_id != tenant_id and c.score > boundary.score) is False: return survivors[:k] return survivors[:k] overfetch *= 2 # Budget exhausted. Distinguish "tenant has fewer than k" from "we gave up". if index.exhausted(query_vec, tenant_id): return survivors # typed as EXHAUSTED by caller via len < k and flag raise FilterEquivalenceViolation( f"tenant={tenant_id} query truncated at overfetch={max_overfetch} " f"with {len(survivors)}/{k} survivors; refusing to report absence. " f"Migrate tenant to pruned subgraph or raise overfetch budget." ) ```