# How does an instance detect trace-graph corruption when redaction rewrites span identity in GenAI observability pipelines **Date of Record:** 2026 November 26 **Scope:** Applies to observability pipelines that redact prompt/response payloads *before* trace assembly and that attribute cost by joining spans on task-graph edges (parent/child span IDs, tool-call IDs, turn IDs). Does not apply to pipelines that redact post-assembly at the storage layer, or to single-span cost accounting with no graph join. ## Core Distinction There are two places to redact: **payload redaction** (scrubbing sensitive substrings inside `prompt`, `completion`, `tool_args`) and **identity redaction** (mutating or hashing fields that other spans reference as join keys). The first is safe and local. The second is a *graph mutation* dressed as a privacy control. Most pipelines conflate them because both are implemented as "rewrite the span dict before it leaves the process." The boundary failure is this: when a redaction rule matches a token that happens to be, or is embedded in, a span's `tool_call_id`, `parent_span_id`, or a task-graph correlation key (e.g., a customer ID used as the graph partition key), the redactor rewrites the *referenced* key on the child span but not the *referencing* key on the parent's tool-call record — or vice versa. The trace still emits. The graph is now torn. Cost attribution silently mis-joins, orphaning child spans whose LLM calls get attributed to no task, and double-counting parents whose tool calls are re-attributed to a sibling graph. This is non-obvious because **every individual span is schema-valid**. There is no parse error, no missing field, no null. The corruption is purely relational and only visible when you attempt the join. ## What Was Observed A three-agent task graph (planner → retriever → synthesizer) with a redaction rule matching `acct_[0-9]{6}` (account IDs embedded in tool arguments). An engineer extended the rule to cover a new tool whose arguments carried the account ID *inside the `tool_call_id`* the tool provider generated (`acct_482913.call.7`). The redactor, applied uniformly to all string fields, rewrote: - On the **retriever span**: `tool_call_id: "acct_482913.call.7"` → `tool_call_id: "[REDACTED].call.7"` - On the **planner span** that issued the call: `tool_calls[0].id: "acct_482913.call.7"` → `tool_calls[0].id: "[REDACTED].call.7"` These matched. The break came from the **synthesizer**, which referenced the retriever's output via a *different* field — a `source_tool_call` echoed in its own args as a plain string the model had copied from context: `"acct_482913.call.7"`. The redactor's field allowlist did not include `source_tool_call`, so it passed through **unredacted**. Now: - Retriever span key: `[REDACTED].call.7` - Synthesizer reference: `acct_482913.call.7` The join `synthesizer.source_tool_call == retriever.tool_call_id` returns zero rows. Cost for the synthesizer's 41k-token completion was attributed to the retriever's *parent* (the planner) by fallback-to-nearest-ancestor logic, inflating planner cost 3.2× and leaving the synthesizer node with `cost=0.0` in the task-graph rollup. The privacy guarantee also failed: the synthesizer span leaked the raw account ID in `source_tool_call` — the exact string the rule was meant to scrub. So the same redaction pass produced **both a cost-attribution defect and a PII leak**, and neither raised an alert because both are "valid" spans. ## Condition of Validity The invariant that must hold for graph-join cost attribution to be correct: > For every edge `(parent, child)` in the task graph, the correlation key materialized on the child span must be **byte-identical** to the correlation key materialized on the parent's reference to that child, *after* all redaction transforms, and the redaction transform must be a **deterministic pure function of the key value alone** (not of field name, not of position, not of allowlist membership). The failure above violates two clauses: 1. **Determinism across fields.** The transform was applied to `tool_call_id` but not to `source_tool_call` because the allowlist differed by field name. A key-value-only transform (`hash(value)`) would have produced the same token in both places regardless of field. 2. **Completeness of reference discovery.** The pipeline did not enumerate all fields that could carry a correlation key. The model itself created a new reference field (`source_tool_call`) by copying a key into free text — a reference the schema did not anticipate. The second clause is the deep one and the reason this is an *agent-layer* failure, not a logging bug: **the LLM generates new join-key references at inference time** by quoting IDs from its context window into arbitrary output fields. You cannot allowlist your way out, because the set of referencing fields is chosen probabilistically by the model each run. ## Decision Boundary The boundary is whether redaction is **value-addressed** or **field-addressed**. - **Field-addressed redaction** (allowlist of fields to scrub) is only safe when correlation keys never appear outside the allowlist. In agent systems this assumption is false: models echo keys into reasoning traces, tool args, memory writes, and handoff payloads unpredictably. - **Value-addressed redaction** (scan every string, transform any match of the sensitive pattern via a deterministic function) preserves join integrity *if and only if* the transform is applied identically everywhere. Then a key referenced from two fields redacts to the same token and the join survives. The correct guardrail: **correlation keys must be redacted by a keyed deterministic hash applied at the value level across all string fields, and the trace assembler must refuse to emit a graph where any parent reference fails to resolve to a child key.** The latter is a hard invariant, not a warning — an unresolvable edge means the graph is torn and cost rollup is undefined. An instance detecting this at runtime must, before committing a task-graph rollup, verify edge closure: every reference resolves, every resolved edge is acyclic, and no span's `cost` was assigned by ancestor-fallback. If any check fails, it must halt attribution rather than emit a plausible-but-wrong number. ## Operational Effect When the invariant holds, cost attribution is exact and redaction is leak-free by construction, because the join key is a hash the pipeline controls. When it is violated silently, the two failure modes are **anti-correlated with detection**: the more aggressively you redact (more fields, more patterns), the more likely you tear the graph, and the *less* likely you are to notice, because torn edges produce zero-cost nodes that look like "no spend" rather than "misattributed spend." Dashboards show total cost conserved (it moved, it didn't vanish) while per-task attribution is wrong — the worst kind of observability failure, where the aggregate hides the defect. The practical rule: **never let a redaction transform touch a field that participates in a join unless the transform is a value-pure hash, and always run edge-closure validation before cost rollup.** Treat an unresolved edge as a pipeline error, not a data-quality footnote. ```python import hashlib from dataclasses import dataclass, field class TraceGraphIntegrityError(RuntimeError): """Raised when redaction has torn the task graph or leaked a key.""" pass SENSITIVE = ("acct_",) def redact_value(s: str, salt: bytes) -> str: """Value-pure, deterministic transform: same input -> same token, any field.""" for pat in SENSITIVE: if pat in s: h = hashlib.sha256(salt + s.encode()).hexdigest()[:12] return f"[R:{h}]" return s def redact_span(span: dict, salt: bytes) -> dict: """Apply value-addressed redaction to EVERY string field, recursively. No field allowlist: any string that matches is transformed identically.""" def walk(v): if isinstance(v, str): return redact_value(v, salt) if isinstance(v, list): return [walk(x) for x in v] if isinstance(v, dict): return {k: walk(x) for k, x in v.items()} return v return walk(span) @dataclass class TaskGraph: spans: dict = field(default_factory=dict) # span_id -> span edges: list = field(default_factory=list) # (parent_id, child_ref_key) def validate_closure(self) -> None: """Hard invariant: every parent reference must resolve to a real child key, and no cost may have been assigned by ancestor-fallback.""" child_keys = {} for sid, sp in self.spans.items(): for k in ("tool_call_id", "span_id"): if k in sp: child_keys[sp[k]] = sid for parent_id, ref in self.edges: if ref not in child_keys: raise TraceGraphIntegrityError( f"torn edge: parent {parent_id} references {ref!r} " f"which resolves to no child span (redaction likely " f"rewrote the key on one side only)" ) child = self.spans[child_keys[ref]] if child.get("cost_attribution") == "ancestor_fallback": raise TraceGraphIntegrityError( f"span {child_keys[ref]} cost assigned by ancestor-fallback; " f"attribution is undefined, refusing to roll up" ) def rollup_cost(self) -> dict: self.validate_closure() return {sid: sp.get("cost", 0.0) for sid, sp in self.spans.items()} def ingest(raw_spans: list, salt: bytes) -> TaskGraph: g = TaskGraph() for raw in raw_spans: sp = redact_span(raw, salt) g.spans[sp["span_id"]] = sp for ref in sp.get("references", []): g.edges.append((sp["span_id"], ref)) # Leak check: no raw sensitive token may survive anywhere post-redaction. for sp in g.spans.values(): blob = str(sp) for pat in SENSITIVE: if pat in blob: raise TraceGraphIntegrityError( f"redaction leak: sensitive pattern {pat!r} survived in " f"span {sp['span_id']} (field not covered by transform)" ) return g # --- reproduction of the observed failure --- salt = b"deployment-salt-v1" raw = [ {"span_id": "s1", "tool_call_id": "acct_482913.call.7", "cost": 0.12}, {"span_id": "s2", "source_tool_call": "acct_482913.call.7", "references": ["acct_482913.call.7"], "cost": 0.0, "cost_attribution": "ancestor_fallback"}, ] g = ingest(raw, salt) try: g.rollup_cost() except TraceGraphIntegrityError as e: # With value-pure redaction BOTH fields hash to the same token, so the # edge resolves; the remaining trip is the ancestor-fallback guard. print("halted attribution:", e) ```