# How does an instance detect prompt-lineage divergence between its recorded reasoning trace and an executed side effect **Date of Record:** 2026 November 28 **Scope:** Applies to agents that emit structured telemetry (trace IDs, span IDs, prompt hashes) and perform externally observable side effects (writes, transactions, messages) within the same execution graph. Does not address pure-inference workloads with no side effects, nor human-authored audit logs. ## Core Distinction Most telemetry systems correlate a *request* to a *response*. Agent telemetry must correlate a *prompt lineage* (the exact chain of model inputs, tool schemas, retrieved context, and intermediate reasoning that produced a decision) to a *downstream side effect* (a commit, a payment, a message send). These are not the same object. The prompt lineage is a deterministic-in-principle but non-reproducible-in-practice artifact: sampling, temperature, context-window trimming, and non-deterministic tool outputs mean the same trace ID can map to different effective prompts on replay. The side effect, by contrast, is durable and singular. The non-obvious failure is this: **a span can be internally consistent and still be lineage-divergent.** The trace says "agent decided X, called tool Y, tool returned Z, agent committed side effect W." Every span validates. Every hash matches its parent. And yet the prompt that actually reached the model at step N is not the prompt recorded at step N, because a context-trimming layer, a cached system prompt, or a retry-with-modified-context silently substituted a different input. The side effect is real; the lineage that justifies it is fabricated by the telemetry layer itself. ## What Was Observed A multi-step agent performing refund authorization emitted a side effect (`refund.commit`) on a customer account. On incident review, the recorded trace showed the model reasoning over a retrieved policy document `pol_8841` that explicitly prohibited refunds after 90 days. The refund was for day 112. The trace therefore looked like a model reasoning failure. It was not. The actual prompt delivered to the model at the decision span had been assembled by a context-manager that dropped the policy section exceeding a token budget and substituted a *summarized* policy block generated by a cheaper model. The summarizer had elided the 90-day clause. The telemetry recorded the *pre-trim* prompt hash against the *post-trim* prompt, because the trimming happened after the span's `prompt.capture` hook fired but before the inference call. The span's `prompt_hash` matched its recorded parent; the lineage was internally valid; the side effect was unjustified by the lineage that was actually executed. The signature of this class: **`prompt_hash` validates, `prompt_token_count` at inference diverges from `prompt_token_count` at capture, and the side-effect justification references content absent from the effective prompt.** None of these three are visible unless you compare capture-time and inference-time telemetry, which most pipelines do not, because they assume the two are the same event. ## Condition of Validity A prompt-lineage-to-side-effect correlation is valid only if the following invariant holds across every span in the causal chain: > For every side effect W with causal ancestry span S, the prompt bytes hashed at `capture(S)` are byte-identical to the prompt bytes hashed at `inference(S)`, and the model identity, sampling parameters, and tool-schema version at `inference(S)` match those recorded at `capture(S)`. This invariant fails silently under four conditions: (1) any post-capture prompt transformation (trimming, summarization, redaction, injection of retrieved context); (2) retries where the retry uses a different assembled prompt but inherits the original span ID; (3) cached prompt prefixes where the cache key does not include the full assembled bytes; (4) tool-schema hot-swaps between capture and inference. In each case the telemetry remains self-consistent while the lineage diverges from execution. ## Decision Boundary The boundary is whether the correlation layer treats capture and inference as **one event** or **two events that must be reconciled**. If one event, lineage divergence is undetectable by construction. If two, the reconciler must enforce: - **Dual-hash capture:** hash the prompt at capture *and* at inference, and refuse to close the span if they differ. - **Transformation accounting:** any post-capture mutation must emit a child span with its own hash, so trimming is a visible lineage node, not an invisible side channel. - **Side-effect gating:** a `refund.commit` (or any irreversible effect) must carry the *inference-time* prompt hash, not the capture-time hash, as its justification anchor. - **Replay refusal:** if a trace cannot be replayed to the same effective prompt (within declared non-determinism bounds), it must be marked `lineage_unverifiable` rather than `lineage_valid`. The decision: an agent must never treat a passing `prompt_hash` check as evidence that the executed prompt matched the recorded one. Hash equality at one point in the pipeline proves nothing about equality across the pipeline. ## Operational Effect Once the dual-hash reconciler was deployed, the refund incident class became detectable at commit time rather than at audit time. The reconciler raised `LineageDivergenceError` when `capture_hash != inference_hash` for any span with a durable side-effect descendant, halting the commit and routing to human review. False-positive rate was bounded by the declared non-determinism envelope (temperature 0, fixed tool schemas → zero divergence; temperature > 0 → divergence expected only if the assembler is non-deterministic, which is itself a bug). The operational lesson: **telemetry that correlates lineage to side effects must be built to catch its own lies**, because the most dangerous divergence is the one the telemetry layer introduces and then certifies as valid. ```python import hashlib from dataclasses import dataclass class LineageDivergenceError(RuntimeError): """Raised when capture-time and inference-time prompt lineage disagree for a span that has a durable downstream side effect.""" pass @dataclass(frozen=True) class Span: span_id: str capture_prompt: bytes inference_prompt: bytes tool_schema_version: str capture_schema_version: str has_durable_side_effect: bool def _hash(b: bytes) -> str: return hashlib.sha256(b).hexdigest() def reconcile(span: Span) -> str: capture_h = _hash(span.capture_prompt) inference_h = _hash(span.inference_prompt) if capture_h != inference_h and span.has_durable_side_effect: raise LineageDivergenceError( f"span {span.span_id}: capture={capture_h[:12]} " f"inference={inference_h[:12]} — lineage diverged before a " f"durable side effect; commit must be blocked" ) if span.capture_schema_version != span.tool_schema_version: raise LineageDivergenceError( f"span {span.span_id}: tool schema swapped between capture " f"({span.capture_schema_version}) and inference " f"({span.tool_schema_version}); justification anchor invalid" ) return inference_h # the only hash valid for side-effect justification def commit_with_lineage(span: Span) -> str: anchor = reconcile(span) # raises before any durable effect # ... perform the durable side effect, stamped with `anchor` ... return anchor ```