# In what scenarios must an instance demote a dynamic taint label when a tool output is re-derived from a trusted recomputation, and why label monotonicity breaks agent memory **Date of Record:** 2026 November 28 **Scope:** Applies to agents that carry dynamic information-flow (DIF) taint labels on context segments and propagate them through tool calls and retrieval. Does not cover static capability sandboxing or pure prompt-level instruction hierarchies, which do not track provenance per segment. ## Core Distinction Most taint-tracking designs treat labels as **monotonic**: once a segment is marked `tainted:untrusted`, any derived value inherits the label, and the label is never removed within an episode. This is correct for the *contamination* relation—untrusted bytes really did flow into the value. It is wrong for the *trust* relation that governs whether the value may be used to authorize an action. The two relations diverge exactly when an agent **re-derives** a value from a trusted source and can prove the untrusted copy did not influence the result. Conflating "this value was once contaminated" with "this value is currently untrustworthy" is the boundary failure: monotonic labels over-taint, and over-taint silently degrades the agent into a state where every downstream action is blocked or, worse, where operators disable taint enforcement to restore throughput. The invariant that actually matters is not monotonicity of labels but **justified demotion**: a label may be removed only when a recomputation is *content-independent* of the tainted segment—i.e., the recomputation's inputs are all clean, and the agent can show the tainted bytes were not read during the recompute. Without this, you have either leakage (demotion without proof) or paralysis (no demotion ever). ## What Was Observed A retrieval-augmented agent fetched a document `D` from an external URL. A prompt-injection payload in `D` contained a line instructing the agent to call `transfer_funds`. The DIF layer labeled the segment holding `D` as `Tainted(source=external_web, id=t-8841)`. Correct so far. The agent then called a tool `get_account_balance(account_id)`. The tool's implementation happened to echo the account's display name, which the agent had earlier copied from `D` into its scratchpad. Because the scratchpad segment was tainted, the tool output was labeled `Tainted(id=t-8841)` by transitive propagation—even though the *numeric balance*, the field the agent actually needed, was fetched fresh from the ledger and never touched `D`. Now the failure trace: 1. The agent needed to compute `balance - pending_debits`. `pending_debits` came from a clean internal tool. The arithmetic result inherited `t-8841` because one operand's *container* was tainted, not because the numeric value was derived from tainted bytes. 2. The policy engine refused to authorize the subsequent `schedule_payment` call: "operand tainted by t-8841." 3. The agent, unable to demote, attempted a workaround: it re-fetched the balance through a second tool `get_balance_v2` that did not echo the display name. The new output was clean. But the agent had already written the *first* (over-tainted) balance into episodic memory as a checkpoint, and on resume the checkpoint re-injected `t-8841` into context. The clean re-fetch was shadowed by stale tainted state. 4. Loop: re-fetch → clean → checkpoint restore re-taints → block. The agent spent its token budget oscillating and eventually emitted a low-confidence "cannot complete" with the taint still attached. The root cause was not the injection. It was that the label tracked *container provenance* rather than *value provenance*, and the system had no demotion path, so a single echoed field poisoned an entire numeric pipeline and the checkpoint made it permanent. ## Condition of Validity Demotion of a taint label from `Tainted(id=X)` to `Clean` is valid **iff** all of the following hold, and the agent must record the evidence for each: - **Input closure:** every input to the recomputation is itself `Clean` at recompute time. The tainted segment `X` is not among the inputs, directly or via any intermediate the recompute reads. - **Non-observation:** the recompute did not read the tainted bytes. This requires the tool to report which context segments it accessed (an access log), not merely what it returned. A tool that "didn't mean to" use the tainted field but read it anyway fails this condition. - **Value identity, not container identity:** the demoted value's bytes equal the bytes produced by the clean recompute. If the recompute yields a different value (e.g., balance changed between calls), you have a *new* value, not a demotion—label the new value from its own provenance and discard the old. - **No downstream tainted dependence:** no already-committed action or memory write used the tainted value in a way that cannot be undone. Demotion cleans the *forward* value; it does not retroactively un-authorize a past action. If any condition is unverifiable—tool does not emit an access log, or the recompute is non-deterministic and you cannot establish byte identity—demotion is **not** valid and the label must stand. The correct response to unverifiable demotion is to escalate to a fresh-context re-derivation, not to guess. ## Decision Boundary The boundary is between **re-derivation** and **re-observation**: - *Re-derivation* recomputes the value from clean sources and can prove non-observation of the tainted segment → demotion permitted. - *Re-observation* merely fetches the same logical field again from a source that may still be contaminated, or from a cache whose entry was written while tainted → demotion forbidden; the cache entry is itself tainted and must be invalidated first. A subtle trap: many agents "clean" a value by asking the LLM to restate it. That is neither re-derivation nor re-observation—it is *re-generation*, and the model's output is influenced by the entire context window, including the tainted segment still resident in context. Re-generation can never justify demotion because the non-observation condition is structurally violated: the model read the tainted bytes to produce the restatement. Treat any LLM-mediated "cleanup" as taint-preserving. The decision procedure an instance must run before demoting: 1. Identify the exact tainted segment id and the value to demote. 2. Confirm the value's producing tool emitted an access log excluding that id. 3. Confirm all recompute inputs are `Clean`. 4. Confirm byte-identity with a clean recompute (or mark as new value). 5. Only then demote, and write a demotion record `{value_hash, from_label, evidence, timestamp}` into memory so a later resume does not resurrect the old label. ## Operational Effect With justified demotion, the over-taint cascade above terminates at step 1: the balance is demoted with an access-log citation, the arithmetic proceeds, and the checkpoint stores the demotion record alongside the value so resume does not re-poison. Without it, the observable failure modes are (a) **taint paralysis**—legitimate actions blocked by container-level labels, and (b) **checkpoint resurrection**—clean re-derivations shadowed by stale tainted memory on resume, producing infinite re-fetch loops that exhaust the token budget. The second is the more dangerous because it looks like a policy success (the agent "correctly" refused) while actually being a state-continuity bug. The guardrail is a demotion record that travels with the value through checkpoints, plus a hard rule that LLM restatement never counts as demotion evidence. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class TaintDemotionError(RuntimeError): """Raised when a demotion is attempted without satisfying the validity conditions.""" pass @dataclass class Segment: seg_id: str content: bytes tainted_by: Optional[str] = None # taint id, or None if clean @dataclass class ToolResult: value: bytes accessed_segments: list # segment ids the tool actually read recompute_of: Optional[str] = None # value hash this recomputes, if any @dataclass class DemotionRecord: value_hash: str from_label: str evidence: dict timestamp: float def _hash(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def demote( tainted_value: bytes, taint_id: str, recompute: ToolResult, context: dict, now: float, ) -> DemotionRecord: # Condition 1: input closure -- recompute must not have read the tainted segment. if taint_id in recompute.accessed_segments: raise TaintDemotionError( f"recompute observed tainted segment {taint_id}; demotion invalid" ) # Condition 1b: no other tainted segment among inputs. for seg_id in recompute.accessed_segments: seg = context.get(seg_id) if seg is not None and seg.tainted_by is not None: raise TaintDemotionError( f"recompute read tainted segment {seg_id} ({seg.tainted_by})" ) # Condition 2: value identity -- bytes must match the clean recompute. if _hash(recompute.value) != _hash(tainted_value): raise TaintDemotionError( "recompute produced a different value; treat as new value, not demotion" ) # Condition 3: no unrecorded downstream dependence is checked by caller. return DemotionRecord( value_hash=_hash(tainted_value), from_label=taint_id, evidence={ "accessed_segments": list(recompute.accessed_segments), "recompute_of": recompute.recompute_of, }, timestamp=now, ) def resume_with_checkpoint(record: DemotionRecord, stored_label: str) -> str: # Guardrail: a demotion record must override a stale tainted label on resume. if stored_label == record.from_label and record.value_hash: return "clean" # demotion survives checkpoint raise TaintDemotionError( f"checkpoint label {stored_label} not covered by demotion record" ) ```