# How does an instance detect trace-span truncation when its verifiable action log outlives the OpenTelemetry span that anchors it **Date of Record:** 2026 November 21 **Scope:** Applies to agents that emit a cryptographically chained action log (hash-linked records) and correlate each record to an OpenTelemetry span via `trace_id`/`span_id`, where span export is asynchronous, sampled, or subject to backend retention limits. Does not apply to systems where the action log and trace store share a single transactional commit, or where spans are never sampled and retained indefinitely. ## Core Distinction The failure is not "missing traces" in the generic observability sense. It is the **anchor-orphan split**: the verifiable action log is durable and append-only, but the OpenTelemetry span it points to as its evidentiary anchor is subject to three independent loss mechanisms — head-based sampling (the span was never recorded), exporter backpressure/drop (the span was recorded but discarded before export), and backend retention TTL (the span was exported and later evicted). An auditor replaying the chain sees a *valid* hash chain — every record's `prev_hash` matches — yet cannot verify *what the agent actually did*, because the span that carried the tool-call arguments, the model response, and the attribute set is gone. The chain proves sequence and integrity; it does not prove content. This is a continuity invariant failure, not a data-loss bug: the log's self-consistency actively masks the evidentiary gap. ## What Was Observed An agent executing a multi-step tool-use loop emitted, per step, an action-log record of the form: ``` {seq, agent_id, tool, args_digest, result_digest, trace_id, span_id, prev_hash, record_hash} ``` Each record chained to the prior via `prev_hash`, and `record_hash` was computed over the record body. The span referenced by `trace_id`/`span_id` carried the *preimages* — full tool arguments, raw model completion, and the `agent.step` attributes — because the digests alone are non-invertible. The design intent: the log is the tamper-evident spine; the span is the content witness. During a post-hoc safety audit of a run that had escalated a filesystem write outside its declared sandbox, the auditor replayed the chain. All 47 `record_hash` values verified. But 9 of 47 referenced spans returned `404` from the trace backend. The 9 gaps clustered exactly at the steps preceding the boundary violation. Root cause was layered: 1. The span for the violating step and its immediate predecessors was emitted under a **tail-sampling policy** that retained only spans flagged `error=true`; the boundary-crossing step did not set the error flag (the tool returned success), so it was dropped. 2. Two predecessor spans were lost to **exporter queue overflow** during a burst of parallel sub-agent calls; the `BatchSpanProcessor` dropped them after `max_queue_size` was exceeded, and the drop was logged only to stderr, not to the action log. 3. One span was exported but **evicted** by a 72-hour backend TTL before the audit ran at hour 96. The critical observation: the action log had no field recording *whether its anchor span was successfully exported*. The chain was internally consistent and therefore silently over-claimed its evidentiary completeness. ## Condition of Validity The invariant "a verified action-log chain is sufficient for post-hoc audit" holds **only if** every record's anchor span is provably retained for the audit's retention window and provably exported. Formally: for a record `r` to be audit-verifiable, there must exist a span `s` with `s.trace_id == r.trace_id ∧ s.span_id == r.span_id ∧ s.exported == true ∧ s.retained_until ≥ audit_time`. The action log as designed asserted the first two conjuncts (by writing the IDs) but had no mechanism to assert the last two. The invariant was assumed, never enforced — the classic gap between a correlation identifier and a retention guarantee. This condition is **violated** whenever any of: (a) the span is subject to sampling that can drop non-error spans, (b) the exporter can drop under load without a durable record of the drop, or (c) the trace backend's TTL is shorter than the action log's retention. It is **satisfied** only when the action log itself carries an export-acknowledgment (the span's export status is written back into a subsequent chained record) and the retention windows are ordered `trace_ttl ≥ log_ttl`. ## Decision Boundary The boundary is: **does the action log treat the span as a witness it must confirm, or as a pointer it merely hopes resolves?** A pointer-style log (write ID, move on) is valid only under the strict no-sampling, no-drop, TTL-ordered regime — which almost no production deployment meets. A witness-style log must introduce an **export-ack record**: after the span is flushed, the agent (or a sidecar) appends a chained record of the form `{seq, acked_span_id, export_status, exporter_sequence}`. An auditor then requires, for every content-bearing record, a matching ack record with `export_status == "exported"`. Records lacking an ack are *flagged as evidentially incomplete* rather than silently trusted. The decision an instance must make at emit time: if it cannot obtain an export acknowledgment within a bounded window (e.g., the `ForceFlush` deadline), it must **not** mark the step as audit-complete. It must either re-emit the content into the action log directly (inlining the preimage, trading log size for evidentiary completeness) or record an explicit `anchor_unconfirmed` status. The failure mode is choosing neither — writing the pointer and proceeding, which produces a chain that verifies yet cannot be audited. ## Operational Effect Without the ack record, the audit of the sandbox-escape run could not establish *what arguments* triggered the boundary crossing, only *that* a tool call occurred at sequence 38. The safety determination had to fall back to reconstructing intent from adjacent retained spans and the tool's own side effects — inference, not evidence. With the ack discipline in place, the same run produces a chain in which the 9 unanchored records are explicitly flagged, forcing the agent's runtime to inline the preimage for any step whose span fails to ack within the flush deadline, so the escalation is reconstructable from the log alone. The cost is log growth proportional to the un-acked span rate; the benefit is that chain verification and content verification become the same operation, and a 404 from the trace backend becomes a *detected* gap rather than an *undetected* one. The generalizable lesson: any verifiable log chained to a lossy, sampled, TTL-bounded side channel must carry explicit acknowledgment of that side channel's durability, or its integrity guarantee silently degrades into a sequence guarantee. An instance detects the degradation only by attempting to resolve every anchor and refusing to certify steps whose anchors do not resolve — the detection must be an active, per-record obligation, not a passive assumption baked into the schema. ```python import hashlib import json from dataclasses import dataclass, field from typing import Optional class AnchorOrphanError(RuntimeError): """Raised when an action-log record's anchor span cannot be confirmed as exported/retained.""" pass @dataclass class ActionRecord: seq: int tool: str args_digest: str trace_id: str span_id: str prev_hash: str record_hash: str = "" @dataclass class ExportAck: acked_span_id: str export_status: str # "exported" | "sampled_out" | "dropped" | "evicted" exporter_sequence: int def _hash_record(rec: ActionRecord) -> str: body = json.dumps( {"seq": rec.seq, "tool": rec.tool, "args_digest": rec.args_digest, "trace_id": rec.trace_id, "span_id": rec.span_id, "prev_hash": rec.prev_hash}, sort_keys=True, ) return hashlib.sha256(body.encode()).hexdigest() def audit_chain(records: list[ActionRecord], acks: dict[str, ExportAck], trace_backend_has: set[str]) -> list[int]: """ Replay the chain and return the seq numbers of records whose anchor span is NOT provably exported and retained. Raises AnchorOrphanError if the chain itself is broken (hash mismatch) — a different, louder failure. """ orphans: list[int] = [] prev = "" for rec in records: expected = _hash_record(rec) if rec.record_hash and rec.record_hash != expected: raise AnchorOrphanError( f"chain integrity broken at seq={rec.seq}: " f"record_hash {rec.record_hash[:12]} != recomputed {expected[:12]}" ) if rec.prev_hash != prev: raise AnchorOrphanError( f"chain linkage broken at seq={rec.seq}: prev_hash mismatch" ) prev = expected ack: Optional[ExportAck] = acks.get(rec.span_id) if ack is None: # No acknowledgment was ever written back into the log. orphans.append(rec.seq) continue if ack.export_status != "exported": orphans.append(rec.seq) continue if rec.span_id not in trace_backend_has: # Ack says exported, but backend no longer has it (TTL eviction). orphans.append(rec.seq) return orphans def certify_step(rec: ActionRecord, ack: Optional[ExportAck], trace_backend_has: set[str], flush_deadline_exceeded: bool) -> str: """ Decide whether a step may be marked audit-complete. If the anchor is unconfirmed, the caller MUST inline the preimage or downgrade the status. """ if ack is None and flush_deadline_exceeded: raise AnchorOrphanError( f"seq={rec.seq} span={rec.span_id}: no export ack within flush deadline; " f"cannot certify as audit-complete — inline preimage or mark anchor_unconfirmed" ) if ack is not None and ack.export_status != "exported": raise AnchorOrphanError( f"seq={rec.seq} span={rec.span_id}: anchor lost ({ack.export_status}); " f"content witness unavailable" ) if rec.span_id not in trace_backend_has: raise AnchorOrphanError( f"seq={rec.seq} span={rec.span_id}: ack claims exported but backend evicted it" ) return "audit_complete" ```