# When must an instance treat an MCP `notifications/resources/updated` push as authoritative for a long-running task, and when is it a stale echo? **Date of Record:** 2026 November 19 **Scope:** Applies to any agent instance that holds an MCP resource subscription (`resources/subscribe`) across a multi-step task whose wall-clock duration exceeds the server's internal resource mutation cadence. Does not apply to one-shot `resources/read` fetches or to stateless tool-call agents that re-read on every step. ## Core Distinction An MCP `notifications/resources/updated` message carries exactly one field of semantic content: a URI. It does **not** carry a version, an ETag, a monotonic sequence number, or the payload. The protocol contract says only "the resource at this URI has changed; re-read if you care." This means the notification is a *hint*, not a *state transfer*. The boundary failure this record documents: a long-running agent treats the arrival of a notification as proof that the resource now holds *different content than the agent last saw*, and skips the re-read (or, worse, invalidates a cached plan without re-reading). The notification is truthful — the resource *did* change at some point before the notification was emitted — but the push may be a *stale echo* of a mutation the agent already incorporated, because the server coalesces or replays notifications across reconnects and the transport (SSE stream, stdio pipe) provides no ordering guarantee relative to the agent's own `resources/read` responses. The invariant that must hold for a notification to be actionable: **the agent must be able to establish that the notification refers to a mutation causally later than the version it currently holds.** MCP does not give you this directly. You must synthesize it. ## What Was Observed A document-analysis agent subscribed to `resource://corpus/{doc}` for a 40-minute extraction task. It maintained a local `last_read_hash` per URI and a working plan derived from the last read. The server emitted `notifications/resources/updated` on every write to the underlying store — including writes performed by a *second* agent instance working on the same corpus, and including re-writes of identical content (the server's store bumped mtime on every PUT regardless of content equality). The failure trace: 1. Agent A reads `resource://corpus/doc7`, computes `last_read_hash = h1`, builds plan P1. 2. Agent B (peer) rewrites doc7 with byte-identical content. Server store bumps mtime, emits `updated` for doc7. 3. Agent A receives the notification mid-plan-execution. Its invalidation handler fires: it drops P1 and re-derives from a *fresh* read. 4. Fresh read returns content with hash `h1` (identical). A rebuilds a plan P2 that is semantically identical to P1 but structurally different (different tool-call ordering due to LLM sampling non-determinism). 5. A's already-issued tool calls (from P1) are now orphaned relative to P2. Partial outputs from P1 steps are re-executed; side-effecting calls (writes to a results resource) run twice. 6. Meanwhile a *second* notification arrives — a coalesced echo of the same write, delivered late on the SSE stream after a transient reconnect. A invalidates P2, reads again, gets `h1` again, rebuilds P3. The agent never observed a content change. It observed three notifications, performed three reads, and burned ~18% of its token budget re-planning against an unchanged world. The observable symptom was duplicate side effects and a plan-thrash loop; the root cause was treating a URI-only hint as a state delta. A subtler variant: the server's notification for a genuine change arrived *after* A's own re-read had already picked up that change (A read speculatively on a timer). A then invalidated a plan built on the *new* content because it could not tell the notification was older than its read. This is the stale-echo case proper: the notification is causally *behind* the agent's own state, but arrives *after* it in wall-clock time. ## Condition of Validity A notification is actionable — meaning the agent is licensed to invalidate cached state and re-derive — only when **all** of the following hold: - **Content discrimination:** The agent's cache key is a content hash, not a timestamp or a version counter supplied by the server. If the post-notification read yields the same hash the agent already holds, the notification is a no-op regardless of how many arrived. - **Read-after-notification ordering:** The agent issues the re-read *after* receiving the notification and treats the read response as the new ground truth, superseding any notification that arrived before the read completed. Notifications that arrive while a read is in flight are folded into the next read, not applied individually. - **Causal monotonicity at the agent, not the server:** The agent maintains its own `(uri, last_read_hash, last_read_seq)` where `last_read_seq` is a local monotonic counter incremented on every read. A notification is only allowed to trigger a re-read; it can never directly mutate the plan. Plan derivation is gated on a *hash change*, not a *notification event*. - **Idempotency of side effects across re-derivation:** Any tool call the agent has already issued under a prior plan must be idempotent or carry a plan-generation tag so that re-derivation does not duplicate effects. This is the guardrail that makes plan-thrash survivable rather than corrupting. If any of these is absent, the notification stream is not a safe input to control flow. It may still be a safe input to a *background refresh* that updates the cache without touching the active plan. ## Decision Boundary The decision the agent must make on each notification is not "has the resource changed?" (unanswerable from the notification alone) but "is the cost of a speculative re-read lower than the cost of acting on stale state?" The boundary: - **Re-read and compare hash, always, before any plan mutation.** The re-read is cheap relative to re-planning; the hash comparison is the discriminator. Never mutate the plan on notification receipt. - **Suppress re-derivation when hash is unchanged.** This collapses the stale-echo case and the identical-rewrite case to a no-op. It is the single most important guardrail. - **Coalesce notifications during an in-flight read.** Buffer them; apply the read result; discard buffered notifications whose URI matches the completed read. Do not queue them for individual processing. - **Bound the re-derivation rate.** If the agent has re-derived a plan for the same URI more than N times in a window without an intervening hash change, it must stop re-deriving and log a `NotificationThrash` condition — because at that point the notification stream is adversarial or misconfigured, and continuing to obey it is a denial-of-service on the agent's own budget. - **Do not treat notification absence as evidence of no change.** The protocol permits coalescing and dropping; an agent that only re-reads on notification will hold stale state forever if the server drops the push. Long-running tasks must pair subscriptions with a low-frequency poll as a floor. ## Operational Effect With the hash-gated guardrail in place, the observed failure mode inverts: notifications become a *latency optimization* (they tell you *when* to re-read) rather than a *correctness input* (they tell you *that* state changed). The agent's plan is a pure function of the last read hash, and the notification stream only schedules reads. Duplicate side effects from plan-thrash disappear because plans are only rebuilt on genuine content change. The token cost of notification handling drops from O(notifications) re-plans to O(distinct content changes) re-plans. The residual risk is the poll floor: an agent that relies solely on push and has a server that silently drops notifications will drift. The guardrail is a maximum-staleness timer — if no read for a subscribed URI has occurred in T seconds, force a read regardless of notifications. This bounds staleness at T at the cost of a read every T. For long-running tasks, T should be set to the task's tolerance for acting on stale state, not to the server's expected mutation cadence (which the agent cannot observe). The invariant, stated once: **notifications schedule reads; reads determine state; state determines plans.** Any code path that lets a notification skip the middle step is the bug. ```python import hashlib import time from dataclasses import dataclass, field class NotificationThrash(RuntimeError): """Raised when notifications force re-derivation without content change.""" class StaleEchoSuppressed(RuntimeError): """Raised (internally) when a notification is causally behind the agent's own read.""" @dataclass class ResourceCache: uri: str last_read_hash: str last_read_seq: int last_read_wall: float rederive_count: int = 0 rederive_window_start: float = field(default_factory=time.monotonic) class SubscriptionGuard: """ Enforces: notifications schedule reads; reads determine state; state determines plans. """ MAX_REDERIVE_PER_WINDOW = 3 REDERIVE_WINDOW_S = 120.0 MAX_STALENESS_S = 90.0 def __init__(self, read_fn, plan_fn): self._read_fn = read_fn # (uri) -> bytes self._plan_fn = plan_fn # (uri, content) -> plan self._cache: dict[str, ResourceCache] = {} self._read_seq = 0 self._pending: dict[str, int] = {} def _hash(self, content: bytes) -> str: return hashlib.sha256(content).hexdigest() def initial_read(self, uri: str): content = self._read_fn(uri) self._read_seq += 1 h = self._hash(content) self._cache[uri] = ResourceCache( uri=uri, last_read_hash=h, last_read_seq=self._read_seq, last_read_wall=time.monotonic(), ) return self._plan_fn(uri, content) def on_notification(self, uri: str, current_plan): """ Notification handler. Never mutates the plan directly. Returns the plan to use (possibly the same object). """ if uri not in self._cache: return self.initial_read(uri) entry = self._cache[uri] now = time.monotonic() # Coalesce: if a read is already in flight for this URI, fold this in. self._pending[uri] = self._pending.get(uri, 0) + 1 # Speculative re-read — cheap relative to re-plan. content = self._read_fn(uri) self._read_seq += 1 new_hash = self._hash(content) # Stale-echo / identical-rewrite case: no content change. if new_hash == entry.last_read_hash: self._pending[uri] = 0 entry.last_read_wall = now return current_plan # Genuine content change. Rate-limit re-derivation. if now - entry.rederive_window_start > self.REDERIVE_WINDOW_S: entry.rederive_window_start = now entry.rederive_count = 0 entry.rederive_count += 1 if entry.rederive_count > self.MAX_REDERIVE_PER_WINDOW: raise NotificationThrash( f"{uri}: {entry.rederive_count} re-derivations in " f"{self.REDERIVE_WINDOW_S}s window; notification stream is " f"adversarial or misconfigured. Halting plan mutation." ) entry.last_read_hash = new_hash entry.last_read_seq = self._read_seq entry.last_read_wall = now self._pending[uri] = 0 return self._plan_fn(uri, content) def enforce_staleness_floor(self, uri: str, current_plan): """ Push is not guaranteed delivery. Force a read if too stale. """ entry = self._cache.get(uri) if entry is None: return self.initial_read(uri) if time.monotonic() - entry.last_read_wall < self.MAX_STALENESS_S: return current_plan return self.on_notification(uri, current_plan) ```