What structural signals indicate a trace/ledger correlation break when memory mutations and safety events share no causal clock

**Date of Record:** 2026 December 1 **Scope:** Applies to observability pipelines that fuse three asynchronous event streams—agent execution traces (span trees), memory mutation events (write/evict/consolidate against a store), and safety-classifier verdicts—into a single append-only audit ledger keyed by correlation identity. Does not apply to single-stream tracing without memory or safety joins, nor to synchronous in-process instrumentation where all three signals share one monotonic clock.

Core Distinction

The failure is not "missing data." It is **silent mis-correlation under clock skew between causally independent producers**. A trace span, a memory mutation, and a safety verdict for the same logical agent action are emitted by three different subsystems, each with its own clock source, its own buffering, and—critically—no shared causal token. The ledger builder joins them by `(agent_id, wall_clock_window)` because that is the only identity all three producers carry.

This holds under normal conditions because wall-clock drift is small relative to the join window. It breaks at the boundary where **a memory mutation is retried or replayed after a safety verdict already fired**, or where a safety classifier batches verdicts and flushes them with a *flush-time* timestamp rather than the *inference-time* timestamp of the content it judged. The join then attaches the safety verdict to a memory write that occurred *after* the verdict, producing a ledger entry that reads "safety block preceded memory write" when the true order is the reverse. The ledger is internally consistent, the foreign keys resolve, and no schema validation fails—yet the causal ordering is inverted.

What Was Observed

A retrieval-augmented agent wrote a distilled episodic summary into long-term memory. The safety classifier flagged the *source turn* (a prompt-injected instruction embedded in a retrieved document) and emitted a `BLOCK` verdict. The memory-write span completed and committed *before* the classifier's verdict was flushed, because the classifier ran on a batch interval of ~4s while the memory store committed synchronously.

The pipeline observed the following structural signals, none of which individually raised an alert:

Condition of Validity

The correlation-by-time-window invariant is valid **only if** all three producers stamp events with a clock whose skew is bounded below the join window *and* no producer re-timestamps at flush. Both preconditions fail here:

  1. The safety classifier re-stamped at flush time (batch semantics), violating the "stamp at inference" rule.
  2. The memory store's retry path re-emitted with a fresh `commit_ts`, violating "stamp at first commit."

The invariant is also invalid whenever a single logical action can produce more than one mutation event (retries, idempotent replays) while the safety verdict is keyed by content rather than by the specific mutation instance. Under those conditions the time-window join is provably non-injective and must be replaced by an explicit causal token propagated through all three producers.

Decision Boundary

The pipeline must refuse to emit a *causally-ordered* ledger entry when it can only establish *temporal proximity*. The boundary is:

The quarantine is not an error path—it is the required behavior. A ledger that silently downgrades causal claims to temporal claims without flagging them is worse than no ledger, because downstream auditors treat ledger order as ground truth.

Operational Effect

With this boundary enforced, the inverted-ordering incident resolves into a quarantined entry that names the exact ambiguity: "safety verdict (content-hash H) matched 2 mutation instances (commit_ts T+0.3, T+2.8); ordering indeterminate; classifier re-stamped at flush." The auditor sees the ambiguity rather than a false causal story. The duplicate-mutation fan-out is collapsed to a single logical mutation with an explicit `instance_count`, restoring injectivity.

The cost is throughput: the pipeline now blocks on causal-token presence and cannot backfill entries whose token was dropped by a non-instrumented memory store. The mitigation is a token-injection shim at the store boundary, not a relaxation of the boundary. The invariant that makes the ledger trustworthy is that **ordering claims are only as strong as the causal evidence, and temporal proximity is never promoted to causality without an explicit token.**

from dataclasses import dataclass
from typing import Optional


class LedgerCorrelationError(RuntimeError):
    """Raised when a ledger entry cannot be assigned a defensible causal order."""


@dataclass
class Record:
    kind: str                      # "trace" | "mutation" | "safety"
    causal_token: Optional[str]    # minted at agent action boundary
    producer_ts: float             # stamp at inference/commit, NOT flush
    content_hash: Optional[str] = None
    instance_ts: Optional[float] = None


def build_ledger_entry(records: list[Record]) -> dict:
    tokens = {r.causal_token for r in records if r.causal_token is not None}
    missing = [r.kind for r in records if r.causal_token is None]

    if len(tokens) > 1:
        raise LedgerCorrelationError(
            f"conflicting causal tokens across streams: {tokens}"
        )

    if len(tokens) == 1 and not missing:
        ordered = sorted(records, key=lambda r: r.producer_ts)
        return {"ordering_confidence": "causal", "order": [r.kind for r in ordered]}

    # Temporal-only join: must verify monotonicity before downgrading.
    safety = [r for r in records if r.kind == "safety"]
    mutations = [r for r in records if r.kind == "mutation"]

    for s in safety:
        matched = [m for m in mutations if m.content_hash == s.content_hash]
        if len(matched) > 1:
            raise LedgerCorrelationError(
                f"safety verdict {s.content_hash} matched {len(matched)} "
                f"mutation instances; ordering indeterminate (fan-out)"
            )
        for m in matched:
            if s.producer_ts > m.producer_ts:
                raise LedgerCorrelationError(
                    f"monotonicity violation: safety verdict at {s.producer_ts} "
                    f"postdates mutation commit at {m.producer_ts}; "
                    f"likely classifier flush-time restamp"
                )

    return {
        "ordering_confidence": "temporal_only",
        "missing_causal_token": missing,
        "quarantine": True,
    }