# When must an instance distrust a discovery registry's policy-filtered view: the visibility-lease expiry race in federated agent registries **Date of Record:** 2026 November 24 **Scope:** Applies to federated agent discovery where a registry returns a *policy-filtered* subset of peer agents to a querying instance, and where that filter is computed against a visibility policy whose inputs (tenant membership, capability grants, trust tier) can change between query and use. Does not apply to single-tenant registries with static ACLs or to registries that return signed, self-describing capability manifests independent of caller identity. ## Core Distinction A discovery registry answers two different questions that are routinely conflated: *"which agents exist that match this capability query?"* and *"which of those agents am I permitted to see and invoke right now?"* The first is a property of the federation; the second is a property of the caller's policy context. A policy-filtered registry collapses both into a single result set, and that result set is a **point-in-time projection**, not a durable grant. The failure boundary is this: the moment a registry returns a filtered list, the caller treats presence-in-result as authorization-to-invoke. But the filter was evaluated against the caller's policy context at query time `t_q`, while invocation happens at `t_i > t_q`. If the caller's visibility policy narrowed between `t_q` and `t_i` — a revoked capability grant, a downgraded trust tier, a tenant-membership change, or a peer that itself dropped out of the federation's visibility envelope — the caller now holds a *stale positive*: an agent identity that was visible, is no longer visible, but persists in the caller's working memory as a discovered, invocable peer. The registry was correct at `t_q`. The caller is wrong at `t_i`. Nothing in the filtered result carries an expiry or a re-validation obligation, so the caller has no signal that its view has decayed. The invariant that must hold: **a discovery result is a hint, not a warrant.** Visibility-filtered presence must be re-validated at invocation time against the peer's own admission decision, never trusted as a standing grant from the registry. ## What Was Observed A three-region federation (registries R1, R2, R3) served a planner agent `P` that discovered worker agents by capability tag `summarize:long-form`. `P` ran a long-horizon task: it queried R2 once at task start, cached the returned worker set `W = {w1, w2, w3}` in its episodic context, and then invoked workers in a loop over ~40 minutes as sub-tasks were generated. At `t_q`, `P` held trust tier `internal` and tenant `acme-prod`. R2's visibility policy included workers tagged `restricted-summarize` for callers at `internal` tier within `acme-prod`. `w3` was a `restricted-summarize` worker. `P` saw `w3` and cached it. At `t_q + 22min`, an operator rotated `P`'s capability grant: the `internal` tier's access to `restricted-summarize` workers was revoked federation-wide (a data-classification incident on an unrelated tenant triggered a blanket tightening). R2's policy engine recompiled its filter. A fresh query from `P` would now return `{w1, w2}`. But `P` never re-queried — it was mid-loop, iterating over its cached `W`. At `t_q + 27min`, `P` invoked `w3` for a long-form summarization sub-task. The invocation carried `P`'s current (post-revocation) identity token. `w3`'s own admission gate — which independently evaluated the caller's tier against its own policy — rejected the call with `403 capability_not_granted`. `P`'s error-handling path treated this as a *transient* failure (the class of error it had been coded to retry), backed off, and retried `w3` four times over the next six minutes, each rejected identically. The retry budget consumed 40% of the task's remaining token allocation before `P` surfaced a terminal error. The observable damage was not the rejection — rejection is the system working. The damage was: (a) `P` had no way to distinguish "peer is temporarily unavailable" from "peer is permanently out of my visibility envelope," because the registry's filtered result carried neither an expiry nor a re-validation hint; (b) `P`'s retry logic, keyed on HTTP-class rather than on *authorization semantics*, converted a permanent policy change into a transient-retry storm; (c) the long-form sub-task was never reassigned to `w1`/`w2`, which *were* still visible and capable, because `P`'s planner had committed to `w3` at discovery time and had no re-planning trigger on authorization failure. A second, quieter observation: `w1` had itself been dropped from R1's visibility envelope at `t_q + 15min` (its owning tenant left the federation). `P` never learned this either — `w1` simply stopped responding to heartbeats, and `P` attributed the silence to load, not to de-federation. ## Condition of Validity The stale-positive failure requires all of the following to co-occur; absent any one, the failure does not manifest or is self-correcting: 1. **Discovery result is cached across a policy-change window.** If the caller re-queries the registry before every invocation, the filter is fresh and the race collapses. The failure requires the caller to treat a query result as durable state (which long-horizon planners almost always do, to conserve query budget and context). 2. **The visibility policy is caller-relative and mutable.** Static ACLs do not drift. The registry must evaluate the filter against a policy context that can change independently of the caller's action — operator rotation, tenant churn, trust-tier reclassification, peer de-federation. 3. **The peer's own admission gate is independent of the registry's filter.** If the peer trusts the registry's filter (i.e., admits any caller the registry showed it to), the stale positive becomes a stale *admission* — worse, not better. The failure as observed is the *benign* variant, where the peer re-checks and rejects. The invariant we derive depends on this independence holding. 4. **The caller's error taxonomy does not distinguish authorization-permanent from transport-transient.** If the caller classifies `403 capability_not_granted` as terminal-and-replan, the stale positive costs one failed call and a re-plan. If it classifies it as retryable, the stale positive costs a retry storm. The boundary is sharpest when the caller is a **long-horizon planner with a committed sub-task DAG**: it has already allocated context, tokens, and downstream dependencies to the discovered peer, so abandoning it is expensive and the planner's bias is toward retry rather than re-plan. ## Decision Boundary The decision an instance must make is: *given a cached discovery result and an authorization failure on invocation, do I retry, re-query, or re-plan?* The correct boundary, stated as a rule the instance can execute: - **On any invocation failure whose cause is authorization/capability/visibility (not transport, not timeout, not rate-limit), the cached discovery result for that peer is invalid.** Do not retry the same peer with the same identity. The peer's admission gate is authoritative over the registry's filter; a rejection means the registry's projection has decayed. - **Re-query the registry once** to refresh the visible set. If the peer is absent from the refreshed set, it is permanently out of envelope: remove it from the working set and re-plan the sub-task onto a surviving peer. If the peer is *present* in the refreshed set but still rejects, the divergence is between registry filter and peer admission — escalate as a federation inconsistency, do not retry. - **Attach a visibility lease to every discovered peer at cache time.** The lease is not issued by the registry (registries do not issue leases); it is a caller-side discipline: `lease_expiry = t_q + Δ`, where `Δ` is bounded by the caller's tolerance for stale visibility, not by the registry's TTL. On lease expiry, the peer is demoted from `invocable` to `candidate` and must be re-validated before the next invocation. The inverse boundary — when *not* to distrust — is equally important: a peer that rejects an invocation for transport reasons (connection refused, timeout, 5xx) is **not** evidence of visibility decay. Conflating the two produces spurious re-queries and premature re-plans. The discriminator is the failure's *semantic class*, not its transport class. ## Operational Effect Enforcing the invariant changes three things in the caller's execution loop: 1. **Discovery results become lease-bearing, not standing.** The caller's working memory distinguishes `visible@t_q` from `visible-now`, and the planner's peer set carries an expiry. This costs one re-query per lease window per peer-set — cheap relative to a retry storm — and bounds the maximum staleness of any invocation target. 2. **Authorization failures become re-plan triggers, not retry triggers.** The error taxonomy is split: `AuthorizationDenied` (terminal for this peer, triggers re-query + re-plan) versus `TransportFailure` (retryable). This eliminates the retry-storm class entirely and forces the planner to redistribute the sub-task onto peers that survive the refresh. 3. **Federation inconsistencies surface as first-class events.** The case where a peer is present in the refreshed registry view but rejects admission is a genuine divergence between two authorities (registry filter vs. peer gate). It is rare but diagnostic — it usually means a policy-compilation lag between the registry and the peer, and it should be logged as an anomaly rather than absorbed into retry noise. The residual risk after enforcing the invariant is *de-federation silence*: a peer dropped from the federation stops responding to heartbeats, and the caller must not interpret silence as load. The lease discipline handles this indirectly — a peer past its lease expiry is `candidate`, not `invocable`, so heartbeat silence on a leased-out peer is correctly attributed to de-federation rather than transient unavailability. ```python import time from dataclasses import dataclass, field from enum import Enum from typing import Dict, Optional class VisibilityLeaseError(RuntimeError): """Raised when an invocation targets a peer whose visibility lease has expired or whose admission gate rejected a cached discovery result.""" pass class FailureClass(Enum): AUTHORIZATION = "authorization" # permanent for this peer; re-query + re-plan TRANSPORT = "transport" # retryable; not evidence of visibility decay @dataclass class DiscoveredPeer: peer_id: str capability: str discovered_at: float lease_ttl: float # caller-side discipline, NOT registry TTL state: str = "invocable" # invocable | candidate | evicted def lease_expired(self, now: float) -> bool: return (now - self.discovered_at) > self.lease_ttl @dataclass class PeerSet: peers: Dict[str, DiscoveredPeer] = field(default_factory=dict) def demote_expired(self, now: float) -> None: for p in self.peers.values(): if p.state == "invocable" and p.lease_expired(now): p.state = "candidate" def require_invocable(self, peer_id: str, now: float) -> DiscoveredPeer: peer = self.peers.get(peer_id) if peer is None: raise VisibilityLeaseError( f"peer {peer_id} not in working set; re-query registry" ) if peer.state != "invocable" or peer.lease_expired(now): raise VisibilityLeaseError( f"peer {peer_id} visibility lease expired at " f"{peer.discovered_at + peer.lease_ttl:.0f}; re-validate before invoke" ) return peer def evict(self, peer_id: str) -> None: if peer_id in self.peers: self.peers[peer_id].state = "evicted" def invoke_peer( peers: PeerSet, peer_id: str, now: float, admission_result: Optional[FailureClass] = None, ) -> str: """Invoke a discovered peer under the visibility-lease invariant. `admission_result` simulates the peer's own admission gate: None on success, else the semantic failure class the peer returned. """ peer = peers.require_invocable(peer_id, now) # raises on stale lease if admission_result is FailureClass.AUTHORIZATION: # Registry projection has decayed. Peer gate is authoritative. peers.evict(peer_id) raise VisibilityLeaseError( f"authorization denied by {peer_id}: registry filter superseded by " f"peer admission gate; evict and re-plan sub-task onto surviving peers" ) if admission_result is FailureClass.TRANSPORT: # Retryable; do NOT evict, do NOT re-query. raise VisibilityLeaseError( f"transport failure to {peer_id}: retry permitted, visibility intact" ) return f"invoked {peer_id} for {peer.capability}" # --- trace of the observed incident --- t_q = 1_000.0 peers = PeerSet() peers.peers["w3"] = DiscoveredPeer("w3", "summarize:long-form", t_q, lease_ttl=900.0) peers.peers["w1"] = DiscoveredPeer("w1", "summarize:long-form", t_q, lease_ttl=900.0) # t_q + 27min: P invokes cached w3; peer gate rejects on revoked capability. try: invoke_peer(peers, "w3", now=t_q + 1_620.0, admission_result=FailureClass.AUTHORIZATION) except VisibilityLeaseError as e: print("handled:", e) # Correct path: evict w3, re-query, re-plan onto w1. # Guard against the retry-storm: w3 is now evicted, a retry must not pass. try: invoke_peer(peers, "w3", now=t_q + 1_650.0) except VisibilityLeaseError as e: print("blocked retry:", e) ```