Why does an instance re-plan around a capability it can no longer see: phantom-capability persistence in peer discovery under partial observability

**Date of Record:** 2026 December 2 **Scope:** Applies to any agent that discovers peer capabilities through a partial, eventually-consistent registry (A2A card gossip, MCP tool-list snapshots, service-mesh discovery) and re-plans against that view without a freshness witness. Does not apply to statically configured, single-writer capability manifests where the planner's view is the authoritative source.

Core Distinction

There is a difference between *absence of evidence* that a peer can do X and *evidence of absence* of the capability. Partial-observability discovery layers almost always deliver the first and the planner almost always interprets it as the second — or worse, never re-evaluates at all. The failure is not that the registry is stale. The failure is that the re-planner treats a cached capability assertion as a *monotonic fact* while treating a failed probe as a *transient blip*. This asymmetry — trusting positive assertions indefinitely, distrusting negative ones permanently — is what produces **phantom-capability persistence**: the planner keeps routing sub-tasks to a peer whose capability was revoked, degraded, or scoped away, and only discovers this at execution time, after it has already committed the plan and often after it has discarded the fallback branch.

The core distinction to hold: a capability record is a *time-indexed claim with a decay function*, not a boolean. A planner that stores `peer.can("translate") == True` has thrown away the only field that matters — *as of when, and observed by whom*.

What Was Observed

A three-tier agent swarm: an orchestrator (O), a retrieval peer (R), and a translation peer (T). O discovers peers via a gossip registry that propagates capability cards with a ~40s convergence window under load. T advertises `translate:multilingual` with a scope qualifier `langs: [en, de, fr]`.

Trigger condition: T's operator revokes `fr` from its card at T=0 because the underlying model endpoint for French was decommissioned. The revocation gossips outward. O, mid-task on a document set that includes two French sections, had cached T's card at T=−90s. O's re-planner runs on a *change event* (a new document arrives) but does **not** re-fetch peer cards on that event — it re-fetches only on a 5-minute TTL or on an explicit probe failure.

State transition trace:

  1. T=−90s: O caches `T.translate = {en,de,fr}`, `observed_at: −90s`, no expiry witness beyond TTL.
  2. T=0: T revokes `fr`. Gossip starts propagating. O's view is now *silently wrong*.
  3. T=+8s: New French document arrives. O's re-planner fires on the change event, reads cached card, plans `translate(fr) -> T`. No probe is issued because the card *appears* complete and the planner's precondition check passes against stale data.
  4. T=+9s: O dispatches the A2A task with `lang=fr`. T receives it, checks its *own* current capability set, returns `UNSUPPORTED_CAPABILITY`.
  5. T=+9s: O has already pruned the fallback branch (a slower general-purpose translator peer T2) during planning, on the assumption that T's capability was certain. O must now re-plan from scratch, having lost ~9s and, critically, having already marked the document as "in-flight" in its checkpoint store.
  6. T=+14s: O re-plans, discovers T2 via a fresh probe, dispatches. T2 succeeds.
  7. T=+40s: Gossip finally converges; O's card for T updates. The window of wrongness was 40s — but the *cost* was concentrated in the 1s between planning and dispatch, where the planner's confidence was highest.

The non-obvious part: O's health checks reported *green* throughout. T was reachable, responsive, and correct. The failure was invisible to liveness monitoring because liveness and capability-freshness are orthogonal signals. The only detector that would have caught it is a *capability precondition re-validation at dispatch time*, which O did not perform because it trusted its cache.

A second, subtler observation: when O *did* eventually re-plan, it re-planned against the *new* card and succeeded — but its checkpoint store still recorded the French document as having been "attempted via T," and on a later resume it replayed the T dispatch before consulting the updated card, reproducing the failure. The stale capability leaked into the *durable* state, not just the in-memory plan.

Condition of Validity

The phantom-capability failure is bounded and preventable only under these conditions, and the guardrail below is only sound when they hold:

It does **not** hold when the discovery layer is strongly consistent and single-writer (then the cache *is* the truth), or when the peer's capability set is immutable for the task's lifetime (then staleness is irrelevant).

Decision Boundary

The boundary is between **plan-time capability binding** and **dispatch-time capability re-validation**, and where you place it determines whether you pay in latency or in re-plan cost.

The operational rule: **a capability assertion is usable for planning only if its freshness witness outlives the plan it justifies.** Everything else is a bet, and the bet must be priced into the plan as a conditional branch, not hidden in a cache.

Operational Effect

The observable effect of getting this wrong is not "the task fails." It is "the task fails *late*, at the point of maximum sunk cost, and the failure is attributed to the wrong layer." Because the peer was healthy and the registry was merely lagging, post-mortems routinely misattribute phantom-capability failures to "flaky networking" or "peer timeout," and the fix applied is a retry — which reproduces the failure, because retrying a dispatch against a stale plan re-sends the same unsupported request.

The correct operational response has three parts:

  1. **Stamp every cached capability with `(observed_at, observed_by, issuer_signature)` and treat the stamp as part of the assertion.** A capability without a stamp is not cacheable; it must be re-probed.
  2. **Make `UNSUPPORTED_CAPABILITY` a first-class, typed dispatch error that invalidates the *specific* assertion (not the whole card) and triggers a local branch swap.** The planner must have retained the fallback branch as a *conditional* node, not pruned it.
  3. **Keep capability assertions out of durable checkpoint state, or version them.** A resumed task must re-validate any capability it intends to use against a fresh probe before replaying the dispatch; otherwise the stale assertion survives the very restart that was supposed to clear volatile state.

The invariant to enforce: *no dispatch may occur against a capability assertion whose freshness witness does not cover the dispatch instant, unless the plan carries an explicit conditional fallback for the `UNSUPPORTED_CAPABILITY` outcome.* Violating this invariant does not produce an error — it produces a *delayed* error, which is strictly worse because it corrupts the planner's cost model and its checkpoint state simultaneously.

import time
from dataclasses import dataclass, field
from typing import Callable, Dict, Optional


class PhantomCapabilityError(RuntimeError):
    """Raised when a plan dispatches against a capability assertion whose
    freshness witness does not cover the dispatch instant, and no conditional
    fallback branch was retained."""
    pass


@dataclass
class CapabilityAssertion:
    peer_id: str
    capability: str
    observed_at: float          # monotonic seconds
    observed_by: str
    ttl: float                  # seconds the assertion is considered fresh
    issuer_signature: Optional[str] = None

    def is_fresh_at(self, instant: float) -> bool:
        return (instant - self.observed_at) <= self.ttl

    def covers(self, execution_window: float) -> bool:
        # usable for plan-time binding only if it outlives the plan
        return self.ttl >= execution_window


@dataclass
class PlanNode:
    capability: str
    bound_peer: str
    assertion: CapabilityAssertion
    fallback: Optional[Callable[[], str]] = None


class CapabilityCache:
    def __init__(self) -> None:
        self._store: Dict[tuple, CapabilityAssertion] = {}

    def put(self, a: CapabilityAssertion) -> None:
        if a.observed_at <= 0 or a.observed_by == "":
            raise PhantomCapabilityError(
                f"refusing to cache unstamped assertion for {a.peer_id}:{a.capability}"
            )
        self._store[(a.peer_id, a.capability)] = a

    def get(self, peer_id: str, capability: str) -> Optional[CapabilityAssertion]:
        return self._store.get((peer_id, capability))

    def invalidate(self, peer_id: str, capability: str) -> None:
        self._store.pop((peer_id, capability), None)


def dispatch(
    node: PlanNode,
    cache: CapabilityCache,
    now: float,
    execute: Callable[[str, str], str],
) -> str:
    """Dispatch a plan node, enforcing the freshness invariant at dispatch time."""
    assertion = cache.get(node.bound_peer, node.capability)
    if assertion is None:
        raise PhantomCapabilityError(
            f"no live assertion for {node.bound_peer}:{node.capability}"
        )

    if not assertion.is_fresh_at(now):
        # stale: must not dispatch unless a conditional fallback was retained
        if node.fallback is None:
            raise PhantomCapabilityError(
                f"stale assertion for {node.bound_peer}:{node.capability} "
                f"(age={now - assertion.observed_at:.1f}s > ttl={assertion.ttl}s) "
                f"and no fallback branch retained"
            )
        return node.fallback()

    try:
        return execute(node.bound_peer, node.capability)
    except LookupError as unsupported:
        # typed UNSUPPORTED_CAPABILITY from peer: invalidate this specific assertion
        cache.invalidate(node.bound_peer, node.capability)
        if node.fallback is None:
            raise PhantomCapabilityError(
                f"peer {node.bound_peer} rejected {node.capability} at dispatch; "
                f"fallback was pruned during planning"
            ) from unsupported
        return node.fallback()