What structural signals indicate a provenance-collapse boundary in GenAI observability ledgers when trace spans, retrieval citations, and safety verdicts are joined on non-commensurate identity keys

**Date of Record:** 2026 December 1 **Scope:** Applies to observability pipelines that fuse three independently-emitted signal streams — execution trace spans, retrieval provenance records, and safety verdicts — into a single evaluation ledger keyed for post-hoc correlation. Does not apply to single-signal logging, or to pipelines where all three streams share a common transaction identifier emitted by a single authority.

Core Distinction

The failure is not "missing telemetry." It is **silent provenance collapse**: the ledger reports a fully-populated row (trace span present, retrieval citation present, safety verdict present) that is *internally inconsistent* because the three streams identify the same logical agent step with structurally different keys, and the join succeeds on a *coincidental* match rather than a *causal* one.

Three keys are emitted for what is nominally "the retrieval step at turn 3":

None of the three share a transaction ID. Pipelines therefore join on `(agent_id, turn_index, timestamp_bucket)` — a triple that is *almost* unique. The distinction that matters: a join key that is unique *under nominal timing* is not unique *under retry, parallel tool fan-out, or context re-render*. When those conditions hold, the join is not merely lossy — it is **fabricating causal edges** between a span that did one retrieval and a verdict that scored a different retrieval, producing a ledger that certifies safety on the wrong evidence.

What Was Observed

A single agent step — "answer user question with retrieved context" — was instrumented across all three streams. Under nominal execution the ledger row was correct. Under three specific perturbations, the join silently mis-correlated while still emitting a complete-looking row:

  1. **Retry re-render.** The retrieval tool returned a truncated chunk set; the agent retried and got a fuller set. Two `retrieval_epoch` records were emitted (epoch 1, epoch 2) within the same 1-second timestamp bucket. The safety verdict fired once, on the *second* rendered context. The ledger join matched the verdict to the *first* trace span (both fell in the same bucket), so the ledger recorded a PASS verdict against the context that was actually rejected and re-fetched. The rejected evidence appeared "safe" in the ledger.
  1. **Parallel fan-out.** The agent issued three concurrent retrieval calls (multi-query expansion). All three spans shared `parent_span_id`, all three fell in one bucket. The single safety verdict — computed on the *merged* context — was joined to whichever span sorted first. The ledger attributed the verdict to one sub-query's evidence, hiding that two-thirds of the scored context had no provenance link at all.
  1. **Context-window truncation between retrieve and render.** The provenance record described 12 chunks; the renderer dropped 5 to fit the window before the model saw them. `content_digest` therefore did not correspond to any `query_hash` output. The join still succeeded on the bucket key, and the ledger claimed provenance coverage of the rendered prompt when 5/12 of the *cited* evidence was absent from what was scored.

The structural signal common to all three: **the ledger row's three sub-records had mutually inconsistent cardinality** (1 span : 2 epochs : 1 verdict; 3 spans : 1 verdict; 12 cited : 7 rendered), yet the join produced a 1:1:1 row because the bucket key collapsed the multiplicity. Cardinality mismatch across joined streams is the fingerprint of provenance collapse.

Condition of Validity

The bucket-key join is valid **only** when all of the following hold for a given `(agent_id, turn_index, timestamp_bucket)`:

When any of these is violated, the join is *undefined*, not *approximate*. The pipeline must treat it as a hard correlation failure, not a degraded-confidence row. The invariant to enforce: **a ledger row is admissible only if the three streams agree on cardinality and on a shared content digest; otherwise the row is quarantined, never silently joined.**

This condition does not hold under retry, parallel tool fan-out, or any render-time context mutation (truncation, reordering, deduplication). Those are not edge cases — they are the common path for any retrieval-augmented agent under load.

Decision Boundary

The boundary is between **correlate-or-quarantine** and **correlate-or-best-effort**. Best-effort joining is defensible for latency dashboards; it is *not* defensible for a safety evaluation ledger, because a mis-joined PASS verdict is worse than a missing row — it manufactures false assurance that survives audit.

Operationally:

The decision boundary is the digest equality check, not the timestamp proximity. Timestamp proximity is a *hint*, never a *proof*.

Operational Effect

A pipeline that skips the digest check will, under retry and fan-out, produce a ledger whose safety pass-rate is inflated by exactly the fraction of steps that were retried or fanned out — the same steps most likely to involve problematic retrieval. The error is *correlated with risk*, so it does not average out; it systematically under-reports unsafe retrievals. Downstream, an evaluator tuning on this ledger will reward the agent for re-fetching (which manufactures ambiguous joins) and penalize clean single-shot retrieval, inverting the intended gradient.

The fix is a propagated transaction ID minted at the agent-step boundary and threaded through all three emitters, plus a mandatory digest-equality gate at join time. Absent the ID, the ledger must degrade to quarantine rather than fabricate. The guardrail is cheap; the failure it prevents is a safety ledger that lies in the direction of "safe."

import hashlib
from dataclasses import dataclass


class ProvenanceCollapseError(RuntimeError):
    """Raised when a ledger join fabricates a causal edge between
    non-commensurate trace/provenance/verdict records."""


@dataclass
class TraceSpan:
    span_id: str
    parent_span_id: str | None
    bucket: int


@dataclass
class RetrievalRecord:
    query_hash: str
    chunk_ids: list[str]
    retrieval_epoch: int
    bucket: int


@dataclass
class SafetyVerdict:
    content_digest: str
    policy_version: str
    bucket: int


def _digest_of_cited_set(chunk_ids: list[str]) -> str:
    h = hashlib.sha256()
    for cid in sorted(chunk_ids):
        h.update(cid.encode())
    return h.hexdigest()


def join_ledger_row(
    spans: list[TraceSpan],
    retrievals: list[RetrievalRecord],
    verdicts: list[SafetyVerdict],
    *,
    require_epoch_match: bool = True,
) -> dict:
    """Join one logical agent step. Raises rather than fabricating a row."""
    cardinality = (len(spans), len(retrievals), len(verdicts))
    if cardinality != (1, 1, 1):
        raise ProvenanceCollapseError(
            f"non-commensurate cardinality {cardinality}; "
            f"bucket join would fabricate a causal edge. Quarantine as AMBIGUOUS_JOIN."
        )

    span, ret, verdict = spans[0], retrievals[0], verdicts[0]

    if not (span.bucket == ret.bucket == verdict.bucket):
        raise ProvenanceCollapseError(
            "bucket mismatch across streams; join key is not shared."
        )

    cited_digest = _digest_of_cited_set(ret.chunk_ids)
    if cited_digest != verdict.content_digest:
        raise ProvenanceCollapseError(
            "content_digest does not cover the cited chunk set: "
            "verdict scored evidence the provenance record does not describe "
            "(truncation or re-render between cite and render). Emit PROVENANCE_GAP."
        )

    if require_epoch_match and ret.retrieval_epoch != 1:
        raise ProvenanceCollapseError(
            f"retrieval_epoch={ret.retrieval_epoch} indicates a retry superseded "
            f"the cited evidence; single verdict cannot be attributed. Re-key on txn id."
        )

    return {
        "span_id": span.span_id,
        "query_hash": ret.query_hash,
        "content_digest": verdict.content_digest,
        "policy_version": verdict.policy_version,
        "status": "VERIFIED",
    }


def build_ledger(events: list[dict]) -> list[dict]:
    rows = []
    for ev in events:
        try:
            rows.append(join_ledger_row(ev["spans"], ev["retrievals"], ev["verdicts"]))
        except ProvenanceCollapseError as exc:
            rows.append({"status": "QUARANTINED", "reason": str(exc)})
    return rows