# What structural signals indicate PII taint escapes span-level redaction through agent trace re-emission **Date of Record:** 2026 December 4 **Scope:** Applies to agent runtimes that redact PII at the span boundary of an OpenTelemetry-style trace and then re-emit those spans to downstream consumers (dashboards, eval harnesses, memory distillation jobs). Does not apply to whole-trace deletion pipelines or to runtimes that redact at the storage sink only. ## Core Distinction Span-level redaction is a *local* transform: it rewrites the payload of each span so the sensitive token is replaced before emission. Taint propagation is a *global* property: the fact that a value was sensitive must survive every derivation of that value across spans, tool calls, and child traces. These two mechanisms diverge precisely at the point where a redacted span's *output* is consumed as another span's *input* under a different representation — a hash, a length, an embedding, a partial token, or a structured field that the redactor's pattern set does not cover. The non-obvious boundary: a span can be *individually* clean (no raw PII in its attributes) while the trace as a whole remains *tainted*, because the redaction marker itself (`[REDACTED:EMAIL]`, a stable hash, a byte-length attribute) becomes a join key that reconstructs the sensitive value when combined with a sibling span. Redaction is not taint elimination; it is taint *relabeling*. The failure is treating relabeling as elimination. ## What Was Observed A retrieval agent processed a user ticket containing an email address. The `tool_call` span for the `lookup_customer` tool carried `input.email = "a***@example.com"` (masked by the tool adapter) and `output.customer_id = "c_8841"`. The redactor, configured with an email regex, saw no match on the masked string and passed the span through unchanged. The sibling `llm.completion` span carried a reasoning trace: `"The user's address ends in example.com, so I'll query c_8841."` The domain fragment `example.com` was not classified as PII by the redactor — it is a domain, not an address. Downstream, the eval harness joined the two spans by `trace_id` to score tool-call correctness. The joined record contained `(a***@example.com, c_8841, "...example.com...")`. A separate memory-distillation job, scanning completion spans for entity mentions, extracted `example.com` as a semantic fact and wrote it to the agent's long-term store keyed by `customer_id`. Three hops later, a different session retrieved that memory and emitted `"customer c_8841 is reachable at example.com"` — reconstituting a partial identifier that the original redactor had judged clean at every individual span. The structural signal that predicted this: **the redaction marker and the tool-output identifier co-occurred in the same trace with a shared join key, and the marker carried residual information (domain, length, prefix) about the redacted value.** No individual span violated the redaction policy. The trace did. A second observed variant: the redactor replaced an account number with a deterministic hash `sha256(acct)[:8]` to preserve joinability for debugging. The hash was stable across spans and across sessions. An agent with tool access to a low-entropy account-number space (10-digit, ~33 bits) could enumerate candidate accounts, hash them, and match the 8-hex-char prefix — a 32-bit collision surface, trivially brute-forceable inside a single reasoning loop with a `hash_lookup` tool. The redaction *created* a taint-propagation channel by making the sensitive value queryable. ## Condition of Validity The invariant holds — span-level redaction is taint-preserving, not taint-eliminating — under three jointly necessary conditions: 1. **Residual entropy in the marker.** The redaction output retains any function of the original value: length, prefix, suffix, domain, format, a stable hash, or an ordinal position. If the marker is a fixed constant (`[REDACTED]`) with no dependence on the input, residual entropy is zero and the join-key channel closes. 2. **A cross-span join surface.** Two or more spans in the same trace (or across traces via a shared session/memory key) can be correlated by `trace_id`, `session_id`, tool-output ID, or a stable hash. Without a join surface, residual fragments cannot be recombined. 3. **A downstream consumer that treats span-clean as trace-clean.** The eval harness, memory distiller, or dashboard performs entity extraction, semantic distillation, or aggregation over spans *without* re-checking taint at the trace level. This is the load-bearing condition: the failure requires a consumer that trusts the per-span redaction verdict. Violating any one condition bounds the failure. A constant marker (¬1) blocks reconstruction. Per-span ephemeral IDs with no cross-span linkage (¬2) block joining. A trace-level taint check at every consumer (¬3) catches the recombination before it lands in memory. The operational mistake is assuming condition 3 holds because the redactor "already ran." ## Decision Boundary The boundary between safe and unsafe is **whether the redaction output is a function of the input that is cheaper to invert than to guess.** Concretely: - **Safe:** constant replacement (`[REDACTED]`), or a per-span random salt that is discarded, or type-only retention (`[REDACTED:EMAIL]` with no domain/length). - **Unsafe:** deterministic hash (invertible by enumeration when input entropy < hash output entropy), masked-with-structure (`a***@example.com` leaks domain + length + first char), or length-preserving substitution. - **Ambiguous, must be gated:** partial redaction where the residual is *itself* a quasi-identifier (domain, ZIP prefix, last-4). These are safe only if the downstream consumer never joins them with a stable identifier. The decision rule for the runtime: **if `H(residual) < H(original)` and a join key exists, the trace is tainted regardless of per-span verdicts.** Enforce by computing a trace-level taint bit at emission time: `tainted = any(span.residual_entropy > 0 and span.join_key is not None)`. Propagate that bit, not the per-span clean verdict, to every consumer. The second decision: **stable hashes are only safe when the input space is large enough that enumeration is infeasible** (≥ 2^64 effective entropy after considering the agent's tool access). An agent with a `hash_lookup` tool and a 10-digit input space has effectively 2^33 entropy — unsafe. The guardrail is to key the hash with a per-trace secret the agent cannot access, or to drop joinability entirely. ## Operational Effect When the invariant is violated, the observable failure is *delayed and cross-session*: the tainted memory surfaces in a later session, attributed to a different user, with no trace link back to the original redaction decision. Debugging is hard because every individual span passed its redaction check — the audit log shows green across the board. The only forensic signal is the taint bit, which must be computed at emission and carried forward; if it was never computed, the recombination is invisible until a downstream incident. The architectural guardrail is a **two-level redaction model**: span-level redaction for payload hygiene, plus a trace-level taint ledger that records, for every redaction event, the residual entropy class and the join keys present in the trace. Consumers (memory distillation, eval join, dashboard aggregation) must consult the ledger and either refuse to join tainted spans or apply a second redaction pass over the *joined* record. The ledger entry is the unit of taint, not the span. A secondary effect: redaction markers must be treated as *data*, not as *comments*. A distiller that extracts entities from completion text will happily extract `example.com` from a reasoning trace even though the same string was masked in the tool-call span. The distiller must run entity extraction against the taint ledger, not against raw span text. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class TaintLeakError(RuntimeError): """Raised when a redaction marker retains invertible residual entropy and a cross-span join key is present, making the trace tainted.""" @dataclass class Span: trace_id: str name: str attributes: dict join_keys: set = field(default_factory=set) @dataclass class RedactionEvent: span_name: str marker: str residual_entropy_bits: float # 0.0 for constant markers join_key: Optional[str] def redact_email(value: str, mode: str) -> RedactionEvent: if mode == "constant": return RedactionEvent("tool_call", "[REDACTED]", 0.0, None) if mode == "masked": # leaks domain + length + first char: ~ log2(26 * 2^8 * 2^4) bits local, domain = value.split("@", 1) marker = f"{local[0]}***@{domain}" return RedactionEvent("tool_call", marker, 18.0, "customer_id") if mode == "hash": h = hashlib.sha256(value.encode()).hexdigest()[:8] # 32-bit output over a 10-digit input space is enumerable return RedactionEvent("tool_call", f"h:{h}", 32.0, "customer_id") raise ValueError(mode) def check_trace_taint(spans: list[Span], events: list[RedactionEvent]) -> bool: join_keys_present = set().union(*(s.join_keys for s in spans)) if spans else set() for ev in events: if ev.residual_entropy_bits <= 0.0: continue if ev.join_key is not None and ev.join_key in join_keys_present: raise TaintLeakError( f"span {ev.span_name!r} marker {ev.marker!r} retains " f"{ev.residual_entropy_bits} bits and joins on {ev.join_key!r}; " f"trace is tainted despite per-span clean verdict" ) return False def emit_trace(spans: list[Span], events: list[RedactionEvent]) -> dict: tainted = check_trace_taint(spans, events) return {"tainted": tainted, "span_count": len(spans)} # Reproduction of the observed failure: trace = [ Span("t1", "tool_call", {"email": "a***@example.com"}, {"customer_id"}), Span("t1", "llm.completion", {"text": "...ends in example.com..."}, {"customer_id"}), ] events = [redact_email("alice@example.com", "masked")] emit_trace(trace, events) # raises TaintLeakError ```