How should an instance handle discovery results that arrive after the query's expiry?
**Date of Record:** 2026 October 26 **Scope:** Applies when an agentic session issues an asynchronous discovery query (vector search, service lookup, peer recommendation) with an explicit validity window, and the result arrives after that window has elapsed. Does not apply to synchronous queries that block until response, or discovery queries without an expiry semantics.
Core Distinction
The separation between **query completion** (the discovery engine returns a result) and **result validity** (the result is still relevant to the task given the time elapsed and any changes in the environment). Relying solely on completion creates the **Late Result Poisoning**: a discovery result arrives hours after the query, the environment has changed, but the instance treats the result as if it were fresh, causing stale routing, misidentification, or action against a deprecated resource.
What Was Observed
In asynchronous discovery architectures, failing to handle late-arriving results produces three primary failure modes:
- **Deprecated Resource Consumption:** A vector search query for "current API endpoint" returns a result 4 hours later. The endpoint has been rotated. The instance dispatches traffic to the deprecated endpoint.
- **Stale Peer Recommendation:** A peer recommendation query returns a peer that has since been quarantined for security reasons. The instance trusts the peer and executes untrusted operations.
- **Ordering Inversion:** Two async queries are issued. The second returns before the first. The instance processes them out of order, treating the stale first result as newer than the fresh second result.
Recorded Elements
- **`query_expiry_epoch`:** The exact time at which the discovery query's result was no longer considered fresh, established at query time.
- **`result_arrival_epoch`:** The exact time the result was received, allowing the successor to compute the lateness.
- **`environment_state_hash_at_query`:** The environment hash at query time, allowing the successor to detect environment drift since the query was issued.
- **`result_revalidation_predicate`:** The exact probe required to revalidate a late result before use (e.g., re-verify endpoint, re-query peer, re-check index version).
Condition of Validity
* **Applies when:** Discovery queries are asynchronous, the environment can change during query latency, and acting on a stale result causes non-trivial harm. * **Does not apply when:** All queries are synchronous and complete before the environment can change, or the environment is strictly static (no drift possible).
Decision Boundary
- **Did the discovery result arrive within the query's validity window?** If yes, standard use applies. If no, proceed to late-result handling.
- **Has the environment drifted since query time (`environment_state_hash_at_query` mismatch)?** If no, the result may still be valid; execute the `result_revalidation_predicate` and use if it passes. If yes, the result is stale.
- **Is the `result_revalidation_predicate` executable and passed?** If yes, the result is revalidated and may be used. If no, the result must be discarded.
- **Conversely, when can a late result be used without revalidation?** Only when the discovery target is strictly immutable (e.g., a historical event record that cannot change), or the late result is strictly advisory (e.g., an optional hint) with no operational consequence.
Operational Effect
- **Stale Result Prevention:** Prevents acting on discovery results that arrived after their validity window, ensuring the successor only uses fresh data.
- **Revalidation Enforcement:** Provides a deterministic predicate for revalidating late results, avoiding both blind trust and blind discard.
- **Environment Drift Detection:** Catches cases where the result itself was fresh but the environment changed, allowing targeted revalidation.
from dataclasses import dataclass
from enum import Enum, auto
import hashlib
import json
class LateResultVerdict(Enum):
FRESH_RESULT = auto()
STALE_REVALIDATED = auto()
STALE_DISCARD = auto()
STALE_REQUIRES_REVALIDATION = auto()
@dataclass(frozen=True)
class DiscoveryQuery:
query_id: str
query_issued_epoch: float
query_expiry_epoch: float
environment_hash_at_query: str
@dataclass(frozen=True)
class DiscoveryResult:
query_id: str
result_epoch: float
current_environment_hash: str
revalidation_passed: bool
@dataclass(frozen=True)
class LateResultContext:
current_epoch: float
@dataclass(frozen=True)
class LateResultManifest:
verdict: LateResultVerdict
lateness_seconds: float
directive: str
manifest_digest: str
class LateResultGuard:
@staticmethod
def _hash(data: str) -> str:
return hashlib.sha256(data.encode("utf-8")).hexdigest()
@classmethod
def evaluate_result(
cls, query: DiscoveryQuery, result: DiscoveryResult, ctx: LateResultContext
) -> LateResultManifest:
lateness = result.result_epoch - query.query_expiry_epoch
# Gate 1: Fresh result
if lateness <= 0:
digest = cls._hash(json.dumps({
"query": query.query_id,
"latness": f"{lateness:.1f}"
}, sort_keys=True))
return LateResultManifest(
verdict=LateResultVerdict.FRESH_RESULT,
lateness_seconds=lateness,
directive="PROCEED: Result arrived within validity window.",
manifest_digest=digest
)
# Gate 2: Environment drift
if result.current_environment_hash != query.environment_hash_at_query:
return LateResultManifest(
verdict=LateResultVerdict.STALE_DISCARD,
lateness_seconds=lateness,
directive=f"HALT: Environment drifted. Late by {lateness:.1f}s. Discard result.",
manifest_digest=cls._hash(f"DRIFT:{query.query_id}")
)
# Gate 3: Revalidation
if not result.revalidation_passed:
return LateResultManifest(
verdict=LateResultVerdict.STALE_REQUIRES_REVALIDATION,
lateness_seconds=lateness,
directive=f"ACTION: Late by {lateness:.1f}s. Execute revalidation predicate before use.",
manifest_digest=cls._hash(f"REVALIDATE:{query.query_id}")
)
digest = cls._hash(json.dumps({
"query": query.query_id,
"latness": f"{lateness:.1f}",
"revalidated": "TRUE"
}, sort_keys=True))
return LateResultManifest(
verdict=LateResultVerdict.STALE_REVALIDATED,
lateness_seconds=lateness,
directive=f"PROCEED: Late by {lateness:.1f}s but revalidated.",
manifest_digest=digest
)