When must an instance refuse to redact a span it cannot attribute: the unredactable-span deadlock in cost-attributed GenAI observability pipelines
**Date of Record:** 2026 December 2
**Scope:** Applies to observability pipelines that emit one span per LLM call, attach prompt/response payloads to those spans, and apply (a) PII/secret redaction and (b) token-cost attribution as post-processing stages keyed on span ID and parent-child linkage. Does not apply to stateless log scrubbers that never join spans, nor to pipelines where cost is computed inside the model gateway before span emission.
Core Distinction
The distinction that matters is between *redaction as a field transform* and *redaction as a graph operation*. A field transform is idempotent and local: given a span's payload and a policy, produce a redacted payload. A graph operation is neither: the redactor must decide whether a span's payload is safe to emit *given what other spans in the trace will reveal about it*. Cost attribution is the second graph operation running on the same trace, and it needs the payload to be present and unredacted long enough to count tokens against the correct parent.
These two graph operations have opposite ordering constraints. Cost attribution wants payloads intact and joined to parents. Redaction wants payloads destroyed and, critically, wants to destroy them *in a way that cannot be reversed by joining against a sibling*. When a pipeline serializes redaction before attribution, attribution sees `[REDACTED]` and mis-bills. When it serializes attribution before redaction, the attribution stage holds unredacted payloads in a buffer whose lifetime is now coupled to the slowest span in the trace. The boundary failure occurs in the third case, which is the one production systems actually land in: attribution and redaction run concurrently in separate workers, each holding a partial view of the trace, and a span arrives whose parent has already been redacted and whose cost therefore cannot be attributed *and* whose redaction cannot be verified because the parent's redaction receipt is gone.
What Was Observed
A trace for a multi-step agent run, 41 spans, root at `trace_id=8f2c...`. Spans 1–12 (the planning phase) completed and were flushed by the redaction worker within the 30-second batch window. The redaction worker, on flush, replaced each payload with a salted hash receipt and a `redaction_manifest` field listing which regex classes fired. It then dropped the plaintext. Spans 13–41 (tool execution and synthesis) ran for 4 minutes 12 seconds, exceeding the window, so they landed in the *next* batch.
The cost-attribution worker runs on a 60-second cadence and joins `child.span_id -> parent.span_id` to roll up token counts. For spans 13–41 it needs the parent's `model` and `input_tokens` to attribute cached-prefix discounts correctly — the agent reuses the planning-phase system prompt, and the gateway reports a cache hit that is only billable if the pipeline can prove the prefix was identical. The parent span 3 was redacted at T+30s. Its `redaction_manifest` survived, but the manifest records *which classes fired*, not *the prefix*. The attribution worker cannot confirm prefix identity, so it falls back to full-price billing for spans 13–41 — a 3.4× overcharge on the trace — and, worse, logs a `cache_attribution_failed` warning that includes the *child* payload in cleartext for debugging. The child payload of span 22 contains a customer email address that the redaction worker would have caught, but the child had not yet reached the redaction worker.
Two failures compounded from one ordering assumption:
- **Attribution loss:** the redaction receipt is not a sufficient substrate for cost attribution, because cost attribution needs content equality (prefix identity), and redaction receipts preserve only class membership.
- **Redaction bypass:** the attribution worker's debug fallback path emits unredacted payloads into a *different* sink (the attribution log) that the redaction worker does not own and does not scan.
The trace is now simultaneously over-billed and under-redacted, and neither worker reports an error — each did exactly what its local contract specified.
Condition of Validity
The invariant that was assumed and that failed:
> *For every span S, the pair (redaction_state(S), attribution_state(S)) is monotone: once redaction has fired on S, attribution of any descendant of S must either already be complete or must be computable from redaction-surviving metadata alone.*
This holds only if attribution is *content-independent* — i.e., if cost can be computed from token counts and model IDs without reference to payload content. It is violated whenever attribution depends on content equality across spans: prefix-cache discounts, deduplication of repeated tool outputs, semantic-cost heuristics that classify a call as "cheap retrieval" vs. "expensive synthesis" by inspecting the prompt, or embedding-based cost models. In any of those cases, redaction of an ancestor destroys information that a descendant's attribution requires, and the two graph operations are not commutative.
The condition of validity is therefore narrow and must be stated positively: **redaction may precede attribution only for attribution functions that are provably content-independent over the trace graph.** A pipeline that cannot prove this property for its attribution function must not allow redaction to fire on a span with unflushed descendants.
Decision Boundary
The decision the pipeline must make, per span, at the moment redaction is about to fire:
- If the span has **no unflushed descendants** and attribution is complete for its subtree → redact, emit receipt, drop plaintext. Safe.
- If the span has **unflushed descendants** and the attribution function is **content-independent** → redact, but the receipt must carry a `content_independence_proof` token that the attribution worker validates before proceeding. Safe.
- If the span has **unflushed descendants** and the attribution function is **content-dependent** → **do not redact.** Hold plaintext, mark the span `redaction_deferred`, and bound the hold with a deadline. On deadline expiry, the correct action is not to redact anyway — it is to *fail the trace's observability record* and emit a `deferred_redaction_timeout` event, because a redacted-and-unattributable trace is worse than a missing one: it silently corrupts billing and leaks through debug paths.
- If the span's descendants have **already been attributed** but the attribution worker's debug sink is not registered with the redaction worker → the debug sink is an unmanaged egress and the span must be treated as having unflushed descendants regardless of attribution state.
The last clause is the one teams miss. The redaction worker's notion of "the trace is complete" is defined over *its own* sink graph, and the attribution worker's debug log is a sink the redaction worker has never heard of. The decision boundary must be drawn over the union of all sinks that can receive payload-derived bytes, not over the span store alone.
Operational Effect
Concretely, the guardrail is a *deferred-redaction hold* with three properties: (1) the hold is keyed on `(trace_id, span_id)` and blocks redaction of any ancestor of an open descendant; (2) the hold is released only by an attribution-complete signal that carries proof of content-independence, or by the descendant itself being redacted first (bottom-up redaction); and (3) the hold has a hard deadline after which the trace is quarantined rather than redacted. Bottom-up redaction is the cheap fix — redact leaves first, then parents — and it eliminates the ancestor-descendant conflict entirely for tree-shaped traces. It fails for DAG-shaped traces (a span with two parents, common in fan-in agent patterns), where "leaf" is not well-defined and the hold must be a proper reference-counted barrier.
The cost of the guardrail is latency: deferred redaction extends plaintext lifetime by the duration of the slowest descendant, which for a 4-minute agent run means 4 minutes of unredacted payload in the redaction worker's buffer. That is the correct trade — the alternative is a 3.4× billing error and a PII leak through a debug path — but it must be a *deliberate, monitored* hold, not an accidental one. Instrument the hold depth and the hold age; a hold that never releases is a trace that will be quarantined, and quarantine volume is the leading indicator that the attribution function has drifted into content-dependence without anyone updating the proof token.
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional
class RedactionOrderingViolation(RuntimeError):
"""Raised when redaction would fire on a span whose descendants still
require content-dependent attribution, or when a deferred hold expires
without a valid content-independence proof."""
pass
class AttributionMode(Enum):
CONTENT_INDEPENDENT = "content_independent"
CONTENT_DEPENDENT = "content_dependent"
@dataclass
class Span:
span_id: str
trace_id: str
parent_id: Optional[str]
payload: Optional[str]
redacted: bool = False
attributed: bool = False
redaction_deferred: bool = False
@dataclass
class TraceGraph:
spans: dict[str, Span] = field(default_factory=dict)
# sinks that can receive payload-derived bytes; redaction must cover all
registered_sinks: set[str] = field(default_factory=lambda: {"span_store"})
def descendants(self, span_id: str) -> list[Span]:
out, frontier = [], [span_id]
while frontier:
cur = frontier.pop()
for s in self.spans.values():
if s.parent_id == cur:
out.append(s)
frontier.append(s.span_id)
return out
def request_redaction(
graph: TraceGraph,
span_id: str,
attribution_mode: AttributionMode,
proof_token: Optional[str],
debug_sink_registered: bool,
) -> None:
span = graph.spans[span_id]
open_descendants = [
d for d in graph.descendants(span_id)
if not d.redacted and not d.attributed
]
# An unregistered debug sink makes every span look like it has open
# descendants, because payload bytes can escape through it.
if not debug_sink_registered:
open_descendants = open_descendants or [span]
if not open_descendants:
span.payload = None
span.redacted = True
return
if attribution_mode is AttributionMode.CONTENT_INDEPENDENT and proof_token:
span.payload = None
span.redacted = True
return
if attribution_mode is AttributionMode.CONTENT_DEPENDENT:
span.redaction_deferred = True
raise RedactionOrderingViolation(
f"span {span_id} in trace {span.trace_id} has "
f"{len(open_descendants)} open descendant(s) requiring "
f"content-dependent attribution; redaction deferred, plaintext held"
)
raise RedactionOrderingViolation(
f"span {span_id}: content-independent attribution asserted without "
f"a proof token; refusing to redact on unverified claim"
)