# Which invariants prevent causal trace stitching from silently breaking when federated agents redact spans for privacy **Date of Record:** 2026 November 23 **Scope:** Multi-agent systems where traces are stitched across agent boundaries and agents may redact spans or attributes before export under privacy policy. Excludes single-agent tracing and federated traces where redaction occurs only at a central collector after causal edges are materialized. ## Core Distinction The failure is not "a span is missing" — missing spans are expected, and stitchers handle them via orphan rules. The failure is **a redacted span that was the sole carrier of a causal edge still semantically present in the surviving trace.** Redaction removes the *node*, not the *obligation* that its children have a parent. When policy is written in terms of data sensitivity rather than graph topology, it can delete exactly the intermediate span joining two otherwise-disconnected subgraphs. The stitcher then sees two valid, self-consistent traces and reports two traces. Nothing errors; trace count, latency attribution, and the causal claim are silently wrong. Operationally: **orphaning is visible, splitting is not.** An orphaned span has a parent_id pointing nowhere and can be flagged. A split trace produces two traces whose roots are real spans with real parent_ids that were redacted — and if redaction also rewrites the surviving parent reference to skip the redacted span ("reparenting"), the split becomes completely invisible. ## What Was Observed In a three-agent deployment (planner, retriever, synthesizer) exporting OTLP to a shared stitcher, a privacy rule marked any span containing a user query string as sensitive. The retriever's intermediate RPC span carried the query and was redacted; its parent (planner.dispatch, span P) and child (retriever.vector_search, span V, parent_id R) survived. The stitcher's orphan rule attached V to trace root P **as a sibling of the dispatch span**, not a descendant. The trace was structurally valid and passed schema checks, but P→R→V had collapsed to siblings. Latency attribution assigned 100% of retriever time to the planner. The error surfaced only when capacity planning attributed 4.1 seconds of "planner compute" the planner never executed. A worse variant appeared with "reparent children to nearest unredacted ancestor" configured: the exporter rewrote V's parent_id from R to P before export. The stitcher saw a perfectly connected trace with no orphans and a causal chain *wrong at the boundary* — retriever work attributed to the planner with no marker of redaction. Confidently incorrect. The violated invariant: **a redaction must never remove the only record that a causal edge crossed an agent boundary.** Redacting a node is permitted; redacting the *edge* is not, unless the edge's existence is independently recorded in a surviving span. ## Condition of Validity The stitching guarantee holds only when all of the following are true: 1. **Edge-carrying spans are classified as structural, not data.** Any span that is the sole parent of a span owned by a *different* agent must be exempt from content-based redaction, or replaced by a structural tombstone preserving span_id and parent_id with no attributes. 2. **Reparenting is prohibited at the exporter.** An agent may drop attributes but must not rewrite a surviving child's parent_id to skip a redacted ancestor. Rewriting is safe only if the exporter simultaneously emits a tombstone with the original span_id. 3. **The stitcher distinguishes "parent never existed" from "parent was redacted."** This requires an explicit redaction marker (tombstone or manifest keyed by span_id). Without it, the orphan rule silently misattaches. 4. **Trace identity is preserved through redaction.** The redacted span's trace_id and span_id must be known to the stitcher even if all other fields are stripped. The guarantee does **not** hold when redaction is applied by a policy engine with no knowledge of the cross-agent span graph — the common case, since privacy tooling sees attributes, not ownership topology. Per-span isolated decisions cannot evaluate condition 1, so the invariant is unenforced by construction. ## Decision Boundary When a redaction policy would remove a span that is the sole parent of another agent's span, the operator must choose one of three explicit outcomes, recorded in trace metadata: - **Tombstone (preferred):** emit a zero-attribute span with original span_id, parent_id, trace_id, and `redaction.applied=true`. Cost: one span per redacted boundary edge. - **Explicit break:** drop the span and emit a `causal.break` marker on the surviving child, so the stitcher records a known discontinuity rather than inferring a false edge. Cost: honestly incomplete trace. - **Refuse:** block export and escalate when the redacted span's identity is itself sensitive (e.g., span_id encodes a user identifier), since even a tombstone would leak. The forbidden fourth option is silent reparenting, which produces a trace that appears complete and is causally false. Any stitcher accepting reparented spans without a tombstone operates outside the valid condition. ## Operational Effect After enforcing tombstones for boundary-carrying redactions, observed trace count for the three-agent pipeline rose 6% (previously split traces were counted as separate operations), and the planner's attributed compute dropped to match actual CPU accounting within 2%. The stitcher gained a `redacted_edge_count` per trace, which became the primary signal for privacy-policy review: a rising count means the policy is increasingly intersecting causal structure and should be re-scoped to attribute-level rather than span-level redaction. The durable lesson: **privacy redaction and causal stitching are coupled through graph topology, and the coupling is invisible to both the privacy tool and the stitcher in isolation.** No redaction may delete the last record of a cross-agent edge. Enforce it with tombstones, forbid exporter-side reparenting, and make the stitcher's orphan rule refuse to attach a child whose parent_id is unknown unless a redaction manifest confirms intentional removal. ```python class CausalEdgeRedactionError(RuntimeError): """Raised when a redaction policy would delete the sole carrier of a cross-agent causal edge without leaving a tombstone or explicit break.""" def apply_redaction(span, policy, span_owner, child_owners): """ span: dict with span_id, parent_id, trace_id, attributes, owner_agent policy: callable(span) -> bool, True means "redact this span" span_owner: agent that emitted span child_owners: mapping span_id -> owner_agent for known children """ if not policy(span): return {"action": "keep", "span": span} # Find children whose owner differs from this span's owner. cross_agent_children = [ cid for cid, owner in child_owners.items() if owner != span_owner ] if cross_agent_children: # The span is the sole parent of another agent's span. We may not # silently drop it: that would split the trace or, worse, invite # exporter-side reparenting that fabricates a causal edge. if span.get("identity_is_sensitive"): raise CausalEdgeRedactionError( f"span {span['span_id']} carries cross-agent edges " f"{cross_agent_children} and its identity is sensitive; " f"cannot tombstone and cannot drop without breaking causality. " f"Escalate to policy owner." ) return { "action": "tombstone", "span": { "span_id": span["span_id"], "parent_id": span.get("parent_id"), "trace_id": span["trace_id"], "owner_agent": span_owner, "attributes": {}, "redaction.applied": True, }, } # No cross-agent children: safe to drop outright. return {"action": "drop", "span_id": span["span_id"]} def stitch(child, redaction_manifest): """Attach a child to its parent, refusing silent misattachment.""" parent_id = child.get("parent_id") if parent_id is None: return {"attached_to": None, "note": "root"} if parent_id in redaction_manifest: return { "attached_to": parent_id, "note": "parent redacted; edge preserved via tombstone", } # Parent_id is unknown and not in the manifest: this is either a # genuine orphan or an unrecorded redaction. Refuse to guess. raise CausalEdgeRedactionError( f"child {child['span_id']} references unknown parent {parent_id} " f"with no redaction manifest entry; refusing to attach to trace root" ) ```