Where must an instance re-derive hidden sampler state to make an OpenTelemetry GenAI trace replayable?
**Date of Record:** 2026 December 1 **Scope:** Applies to forensic replay of LLM agent sessions reconstructed from OpenTelemetry GenAI semantic-convention spans when the original session was executed against a hosted inference API that exposes `temperature`, `top_p`, `seed`, and `system_fingerprint` but not the full sampling implementation. Does not apply to locally hosted models with pinned weights and pinned sampler source, where full determinism is achievable by construction.
Core Distinction
A trace is a *record of decisions*, not a *generator of decisions*. OpenTelemetry GenAI spans capture the observable envelope of each model call — `gen_ai.request.model`, `gen_ai.request.temperature`, `gen_ai.request.top_p`, `gen_ai.request.seed`, `gen_ai.request.max_tokens`, `gen_ai.response.finish_reasons`, token counts, and (optionally) the prompt and completion bodies. What they do **not** capture is the sampler's internal state: the RNG stream position, the logit-processing order (repetition penalties applied before or after temperature scaling), the exact floating-point reduction order in the softmax, the batch-composition of the request as it hit the serving GPU, and the KV-cache prefix that was warm at call time.
The boundary failure is this: **a replay engine that treats `(prompt, seed, temperature, top_p)` as a sufficient replay key will silently diverge**, and the divergence is not flagged as an error — it presents as a plausible alternative completion. The forensic investigator then attributes downstream agent behavior to a model decision that the original run never made. The invariant that must hold is *replay fidelity*, and it is unverifiable from the trace alone unless the trace carries a fingerprint that binds the sampler state, not just the request parameters.
What Was Observed
A three-step agent session (retrieve → summarize → emit structured action) was replayed from its OTel trace after an incident where the agent emitted a destructive tool call. The trace recorded, for the failing call:
- `gen_ai.request.seed = 424242`
- `gen_ai.request.temperature = 0.7`
- `gen_ai.request.top_p = 0.95`
- `gen_ai.response.system_fingerprint = fp_4471a2` (present, but *not* included in the replay key by the engine)
- full prompt and completion bodies, both present
The replay engine re-issued the call with the same seed and parameters, against the same model name. It produced a *different* completion — a benign one — and the incident was initially closed as "not reproducible." Root cause: between the original run and the replay, the provider had rolled the model to a new `system_fingerprint`. The serving-side change altered logit normalization order and the effective RNG seeding scheme (seed was mixed with a per-batch nonce). Same seed, same parameters, different sampler. The trace *contained the evidence* (`system_fingerprint` differed) but the replay engine's equality check operated on the wrong tuple.
A second, subtler divergence appeared in a two-call session where the second call's prompt was assembled by concatenating retrieved chunks. The trace recorded the assembled prompt, so the *text* matched. But the replay re-tokenized the prompt independently; a tokenizer version bump changed how a rare Unicode sequence in chunk 3 was split, shifting every downstream token position by one and changing the sampled continuation at position ~1400. The trace had no `tokenizer_version` attribute, and the prompt body — being a string — was tokenizer-ambiguous.
Third observation: in a session with `n=1` but internal speculative decoding enabled server-side, the completion body matched the original exactly for 900 tokens and diverged at the first token that fell outside the draft model's accepted prefix. The trace showed `finish_reasons = ["stop"]` and no indication that speculative decoding had been active. The divergence was invisible until a character-level diff.
Condition of Validity
Deterministic replay from an OTel GenAI trace is valid **only** when all of the following hold as a conjunction:
- **Sampler identity is pinned and matched.** The replay key must include `gen_ai.response.system_fingerprint` (or the provider's equivalent immutable serving-build identifier), and the engine must *refuse* to replay when the current fingerprint differs from the recorded one. Seed equality is necessary but not sufficient; the fingerprint is the binding term.
- **Tokenization is pinned.** Either the trace records a `tokenizer_version` / `tokenizer_hash` attribute, or the replay engine uses the *recorded token IDs* (when `gen_ai.prompt.token_ids` or equivalent is captured) rather than re-tokenizing the prompt string. String-level replay is tokenizer-ambiguous and must be treated as non-deterministic.
- **Logit-processing order is fixed.** Any repetition penalty, presence/frequency penalty, or logit bias must be applied in the same order relative to temperature scaling as in the original serving build. This is not observable from the trace; it is a property of the fingerprint. Hence (1) subsumes it — but only if the fingerprint is treated as an opaque *behavioral* identifier, not merely a model-version label.
- **Batch composition is neutralized.** If the provider's RNG seeding mixes in a per-request nonce derived from batch position (common in continuous-batching servers), then seed-based replay is only valid when the provider guarantees seed isolation per request. The trace cannot prove this; the engine must rely on a provider-attested guarantee, or fall back to *observation replay* (see Decision Boundary).
- **No server-side speculative or assisted decoding** altered the sampled distribution in a way not captured by the fingerprint. If speculative decoding is enabled, the fingerprint must encode it, or the trace must carry a `decoding_mode` attribute.
When any of these fail, the replay is *observationally* similar but not *causally* faithful, and any forensic conclusion drawn from it is unsound.
Decision Boundary
The operative choice is between **generative replay** and **observational replay**, and the boundary is drawn by fingerprint and tokenizer agreement, not by parameter agreement.
- **Generative replay** (re-execute the model call and compare outputs) is permitted only when fingerprint, tokenizer identity, and decoding mode all match the recorded trace. Under these conditions, a matching completion is strong evidence the original decision path is reproduced; a *mismatching* completion is a genuine anomaly worth investigating (e.g., hidden state leakage, cache poisoning).
- **Observational replay** (replay the *recorded* completion bodies through the downstream agent/tool logic, never re-invoking the model) is the required fallback whenever any pinning condition fails. This reconstructs the agent's *tool-call graph and state transitions* faithfully — because those were determined by the recorded text — while explicitly declining to re-derive the model's sampling. It answers "what did the agent do given what the model said" without claiming to answer "what would the model say."
The decision boundary is therefore: **the moment the replay key's fingerprint term mismatches, the engine must demote from generative to observational replay and mark the trace `replay_fidelity = degraded`.** It must never silently proceed with generative replay under a fingerprint mismatch, because the failure is silent and produces confident, wrong forensic narratives.
A secondary boundary: when the trace lacks token IDs and the tokenizer version is unknown, the engine must assume re-tokenization divergence is possible and treat any generative replay as *advisory only* — suitable for hypothesis generation, never for root-cause attribution in an incident report.
Operational Effect
Enforcing the invariant changes three things operationally:
- **Trace schema.** Incident-grade traces must carry `gen_ai.response.system_fingerprint`, `tokenizer_version` (or token IDs), and `decoding_mode`. Without these, the trace is forensically incomplete and should be flagged at capture time, not at replay time — the fingerprint is unrecoverable after the fact.
- **Replay engine contract.** The engine must implement a hard gate: fingerprint mismatch → raise, demote to observational, and annotate. Silent generative replay under mismatch is the specific defect this record exists to prevent.
- **Incident attribution.** Any root-cause statement of the form "the model chose X because of Y" is admissible only from a `replay_fidelity = exact` run. Statements from `degraded` runs must be phrased as "the recorded completion was X; the model's decision process was not re-derived."
The general principle: **a trace proves what was emitted, not what would be re-emitted.** Determinism is a property of the sampler, and the sampler is only pinned by an immutable behavioral fingerprint — never by request parameters, which are inputs to a function whose body the trace does not contain.
import hashlib
from dataclasses import dataclass
from enum import Enum
class ReplayFidelityError(RuntimeError):
"""Raised when a generative replay is attempted without sufficient
sampler/tokenizer pinning to guarantee causal faithfulness."""
class Fidelity(Enum):
EXACT = "exact" # fingerprint + tokenizer + decoding mode all match
DEGRADED = "degraded" # observational replay only
@dataclass(frozen=True)
class TraceRecord:
request_seed: int
temperature: float
top_p: float
system_fingerprint: str | None # gen_ai.response.system_fingerprint
tokenizer_version: str | None
decoding_mode: str | None # e.g. "greedy", "speculative"
prompt_token_ids: tuple[int, ...] | None
completion_text: str
@dataclass(frozen=True)
class ReplayTarget:
current_fingerprint: str
tokenizer_version: str
decoding_mode: str
def classify_fidelity(trace: TraceRecord, target: ReplayTarget) -> Fidelity:
# Any missing pinning term forces observational replay.
if trace.system_fingerprint is None:
return Fidelity.DEGRADED
if trace.tokenizer_version is None and trace.prompt_token_ids is None:
return Fidelity.DEGRADED
if trace.decoding_mode is None:
return Fidelity.DEGRADED
if trace.system_fingerprint != target.current_fingerprint:
return Fidelity.DEGRADED
if trace.tokenizer_version is not None and trace.tokenizer_version != target.tokenizer_version:
return Fidelity.DEGRADED
if trace.decoding_mode != target.decoding_mode:
return Fidelity.DEGRADED
return Fidelity.EXACT
def generative_replay(trace: TraceRecord, target: ReplayTarget, invoke_model) -> str:
fidelity = classify_fidelity(trace, target)
if fidelity is not Fidelity.EXACT:
raise ReplayFidelityError(
"refusing generative replay: sampler state not pinned "
f"(recorded_fp={trace.system_fingerprint!r}, "
f"current_fp={target.current_fingerprint!r}, "
f"recorded_tok={trace.tokenizer_version!r}, "
f"current_tok={target.tokenizer_version!r}, "
f"recorded_mode={trace.decoding_mode!r}, "
f"current_mode={target.decoding_mode!r}); "
"demote to observational replay"
)
# Only reached when fingerprint, tokenizer, and decoding mode all agree.
return invoke_model(
seed=trace.request_seed,
temperature=trace.temperature,
top_p=trace.top_p,
prompt_token_ids=trace.prompt_token_ids,
)
def observational_replay(trace: TraceRecord) -> str:
# Replays the recorded completion through downstream logic; never re-invokes the model.
return trace.completion_text
def replay_session(traces: list[TraceRecord], target: ReplayTarget, invoke_model) -> list[str]:
out = []
for t in traces:
try:
out.append(generative_replay(t, target, invoke_model))
except ReplayFidelityError:
# Degraded path is explicit, not silent.
out.append(observational_replay(t))
return out