# Under what conditions must an instance treat MCP tool output as tainted across a resumed session, and why per-call data-flow labels break at checkpoint boundaries **Date of Record:** 2026 November 25 **Scope:** Applies to agent runtimes that enforce per-call taint labels on data returned by MCP tool servers, where a session may be checkpointed and resumed (cold restart, model swap, or context-window compaction). Does not apply to stateless single-shot tool invocations with no persisted conversation state, nor to runtimes that re-derive taint from scratch on every resume. ## Core Distinction A taint-aware sandbox tracks *provenance*: which bytes in the current context originated from which tool call, and what trust class that call carried. The sandbox enforces a data-flow policy — e.g., "output of `fetch_url` may not be passed as the `command` argument to `shell_exec`." This works because the label travels *with the value* inside the live context window. The boundary condition that breaks it: **taint labels are runtime state, not content state.** They live in the sandbox's per-call bookkeeping (a label map keyed by call ID, or inline annotations in a structured context). When the session is checkpointed, the *serialized context* is what survives — the message history, the tool-call/result pairs. The label map is either dropped or, worse, serialized as inert metadata that the resumed instance does not consult. On resume, the agent sees a prior tool result as ordinary text in its history. The value is intact; the provenance is severed. The sandbox is now enforcing a policy over values whose labels it no longer has, and it defaults to "unlabeled = trusted," which is exactly backwards. ## What Was Observed A three-tool MCP server set: `search` (trusted, returns snippets), `fetch_url` (untrusted, returns arbitrary remote HTML), `send_email` (egress, must not carry untrusted-origin body). Policy: any value derived from `fetch_url` output is labeled `UNTRUSTED_REMOTE` and cannot flow into `send_email.body`. Live session, single turn: agent calls `fetch_url`, gets HTML containing an injected instruction. Sandbox labels the result `UNTRUSTED_REMOTE`. Agent attempts `send_email(body=)`. Sandbox raises `TaintViolation`, blocks the call. Correct. Now the same session with a checkpoint between the `fetch_url` result and the `send_email` attempt (triggered by context compaction at 80% window utilization, or a model swap on the same conversation): 1. At checkpoint, the context serializer writes the `fetch_url` tool result into the message history as a `tool_result` block. The taint label map — a separate in-memory structure keyed by `call_id` — is not part of the serialized message schema. It is dropped. 2. On resume, the runtime rehydrates the message history. The `fetch_url` result is present as text. No label is attached. 3. The agent, continuing its plan, calls `send_email` with the body it "remembers" from the prior result. 4. The sandbox receives `send_email` with an argument whose provenance it cannot resolve. Its default policy for unresolvable provenance is `TRUSTED` (fail-open, chosen because fail-closed on every resumed session would deadlock all continuations). 5. The call executes. The injected instruction's payload leaves the sandbox. The failure is silent and looks like a policy that "worked" — no exception is raised, the resumed agent reports success. The taint was real; the label was lost. The invariant "provenance travels with the value" held in memory and broke at the serialization boundary. A second, subtler variant: the runtime *does* serialize labels, but as a sibling field on the message (`{"role":"tool","content":...,"taint":"UNTRUSTED_REMOTE"}`). On resume, the model's context renderer strips unknown fields before tokenizing (common when re-rendering history for a different model's chat template). The label survives in the stored JSON but is absent from the model's view, and critically the *sandbox's* enforcement path reads the model's emitted arguments, not the stored history — so it never sees the label either. The label exists but is unreachable by the enforcement point. ## Condition of Validity The per-call taint model is valid **only while the label map and the context are co-resident and co-serialized**. Formally, enforcement holds iff for every value `v` in the agent's reachable state, `provenance(v)` is resolvable at the moment `v` is used as an argument to a sink call. This requires: - Labels are serialized *as part of the value's representation in the exact form the resumed instance reads* — not as a sidecar the renderer may strip. - The sandbox's default for unresolvable provenance is `UNTRUSTED`, not `TRUSTED`, and sinks fail closed on `UNTRUSTED`. - Checkpoint/resume is treated as a *label-destroying event*: any value crossing it without a preserved label is reclassified `UNTRUSTED` by construction. The moment any of these is false — sidecar labels, fail-open defaults, or a renderer that drops metadata — the boundary is open. The non-obvious part: the failure requires no adversarial tool and no prompt injection to *trigger*; injection only supplies the payload. The taint severance is a property of the checkpoint, and any benign-but-untrusted value (a fetched page, a parsed file) becomes a laundering vector across resume. ## Decision Boundary The runtime must decide, per resume, whether to (a) re-derive labels from history, (b) preserve labels verbatim through serialization, or (c) fail closed on all unlabeled values. - **Re-derive (a)** is only sound if every historical tool result can be re-attributed to its originating call and trust class from the stored history alone. This holds when each `tool_result` carries its `call_id` and the call record carries the tool's trust class. It fails when the history has been compacted/summarized — a summarized prior turn has no per-value provenance, so re-derivation assigns at best turn-level taint, which over-taints benign values and under-taints mixed ones. - **Preserve verbatim (b)** is sound only if the label is embedded in the value representation the model and sandbox both consume (e.g., a structured envelope the sandbox parses), never a field a template renderer can drop. - **Fail closed (c)** is always sound but converts every resume into a potential deadlock: a legitimate continuation that reuses a trusted prior result is blocked because its label was lost. The boundary: **if the checkpoint path cannot guarantee label co-serialization, the runtime must treat the resume as a taint-reset and apply fail-closed (c) until the agent re-establishes provenance by re-calling the source tool.** Re-calling is cheap and restores a live label; reusing a label-less prior value is the only unsafe path. ## Operational Effect A runtime that gets this wrong exhibits a characteristic signature: taint violations fire normally in long uninterrupted sessions and vanish after compaction or model swap. The policy appears to work in testing (short sessions, no checkpoint) and leaks in production (long sessions, frequent compaction). The leak is not a bug in any single component — serializer, renderer, and sandbox are each locally correct — it is the *seam* between them where provenance is assumed continuous and is not. The guardrail is to make the seam explicit: on every checkpoint, walk the context and for each tool result whose label is not co-serialized, rewrite the value with an inline `UNTRUSTED` marker (or drop it and force re-fetch). On every resume, assert that the count of labeled values in the rehydrated context equals the count at checkpoint; a mismatch is a taint-severance event and must fail closed. The invariant to enforce is not "labels exist" but "labels are reachable by the enforcement point after the exact serialization round-trip the runtime performs" — verified by round-tripping a canary tainted value through the real checkpoint path and asserting the sink still blocks it. ```python class TaintSeveranceError(RuntimeError): """Raised when a checkpoint/resume round-trip loses a taint label that the enforcement point depends on.""" def resume_with_taint_check( checkpoint: dict, rehydrated_context: list[dict], label_map_at_checkpoint: dict[str, str], ) -> list[dict]: """ Rehydrate a session and verify that every tainted value that was labeled at checkpoint time is still resolvable by the sandbox after the real serialization round-trip. Fail closed on any severance. """ # Count tainted values that existed at checkpoint. expected_tainted = { call_id: label for call_id, label in label_map_at_checkpoint.items() if label != "TRUSTED" } # Resolve which labels survived into the context the sandbox will read. reachable: dict[str, str] = {} for msg in rehydrated_context: call_id = msg.get("call_id") # A label is only reachable if it is embedded in the value # representation the sandbox parses, not a sidecar field. inline = msg.get("content_envelope", {}).get("taint") if call_id and inline: reachable[call_id] = inline severed = [ cid for cid in expected_tainted if reachable.get(cid) != expected_tainted[cid] ] if severed: # Do NOT default severed values to TRUSTED. Reclassify as # UNTRUSTED and force re-derivation by the agent. for cid in severed: for msg in rehydrated_context: if msg.get("call_id") == cid: msg.setdefault("content_envelope", {})["taint"] = "UNTRUSTED" msg["requires_revalidation"] = True raise TaintSeveranceError( f"taint labels severed across checkpoint for call_ids={severed}; " f"values reclassified UNTRUSTED and marked for re-fetch. " f"Sinks must fail closed until provenance is re-established." ) return rehydrated_context ```