# How does an instance detect span-attribute truncation when GenAI tool-call arguments exceed the OTel attribute value ceiling and the parent agent span silently loses its causal edge **Date of Record:** 2026 December 2 **Scope:** Applies to any agent runtime that exports OTel spans using the GenAI semantic conventions (`gen_ai.*` attributes) where tool-call arguments, model prompts, or completion payloads are serialized into span attributes and where span parenting is established by `trace_id`/`span_id` propagation across tool invocations. Does not apply to runtimes that emit only metrics or logs, nor to spans emitted with `SpanKind.INTERNAL` that carry no cross-process context. ## Core Distinction The GenAI semantic conventions treat tool-call arguments and results as *attributes* on a span, not as span *events* or child spans. Attributes in OTel are subject to a per-attribute value ceiling (commonly 64 KiB in the SDK's `SpanLimits.AttributeValueLengthLimit`, and a separate per-span attribute-count limit). When a tool-call argument payload exceeds that ceiling, the SDK does not raise; it **truncates the string value in place** and continues. The span still exports. The `trace_id` is still valid. The `span_id` is still valid. The non-obvious failure is this: truncation of `gen_ai.tool.call.arguments` does not corrupt the trace graph, but it corrupts the *semantic* content that downstream auditors, replay engines, and the parent agent's own post-hoc verifier rely on to reconstruct *why* a child tool span was invoked. The parent agent span's `gen_ai.tool.call.id` and the child span's `gen_ai.tool.call.id` still match — so the causal edge appears intact in the span tree — but the argument payload that determined the tool's behavior is now a prefix. A verifier that replays the tool call from the recorded arguments will execute a *different* call, produce a *different* result, and flag a mismatch that is not a real divergence. The edge is present; the warrant behind the edge is gone. This is distinct from context-window saturation (a model-layer problem) and from span-drop (a transport-layer problem). It is an *attribute-fidelity* problem that manifests as a *verification-replay* problem. ## What Was Observed A three-agent pipeline (planner → executor → auditor) ran `read_file` and `apply_patch` tool calls against a codebase. The executor emitted spans conforming to `gen_ai.operation.name = "execute_tool"`, `gen_ai.tool.name`, `gen_ai.tool.call.id`, and `gen_ai.tool.call.arguments` (a JSON-serialized object). The auditor consumed the exported trace from the collector and replayed each `execute_tool` span by deserializing `gen_ai.tool.call.arguments` and invoking the same tool with the same arguments, then comparing the result to `gen_ai.tool.call.result`. For 94% of spans, replay matched. For the remaining 6%, replay diverged. The divergence was not random: every diverging span had a `gen_ai.tool.call.arguments` value ending in an unbalanced brace — `{"path": "src/parser.py", "patch": "--- a/src/parser.py\n+++ b/src/parser.py\n@@ -12,7 +12,7 @@\n...` cut off mid-hunk. The SDK had applied `AttributeValueLengthLimit = 65536` and truncated the JSON string at byte 65536, producing invalid JSON. The auditor's deserializer, written defensively, fell back to a regex extraction of `path` and applied a *no-op patch*, then compared against the recorded result (which reflected the *full* patch). Mismatch. The auditor flagged the executor as having produced an unreproducible result — a false positive that cost two hours of triage. The trace graph was correct. The parent-child edges were correct. The `gen_ai.tool.call.id` correlation was correct. Only the *argument warrant* was truncated, and the truncation was invisible because the SDK emits no warning attribute and the span status remained `UNSET` (not `ERROR`). ## Condition of Validity The invariant that must hold for replay-based verification to be sound is: > For every `execute_tool` span S with parent P, the value of `gen_ai.tool.call.arguments` on S must be a byte-exact serialization of the arguments actually passed to the tool, and the value of `gen_ai.tool.call.result` on S must be a byte-exact serialization of the result actually returned. This invariant is *not* guaranteed by the GenAI semantic conventions. The conventions specify the *name* and *type* of the attributes but leave length policy to the SDK's `SpanLimits`. The default `AttributeValueLengthLimit` is implementation-defined and frequently finite. Therefore the invariant holds only when one of the following is true: 1. The runtime sets `AttributeValueLengthLimit = -1` (unlimited) on the exporter, accepting unbounded span size and the associated collector backpressure risk; or 2. The runtime sets a finite limit *and* emits a companion attribute (e.g., `gen_ai.tool.call.arguments.truncated = true`) plus a content-addressed reference (e.g., `gen_ai.tool.call.arguments.sha256`) to the full payload stored out-of-band; or 3. The verifier does not replay from span attributes but from an independent, full-fidelity side channel. Absent any of these, the invariant is silently violated for any tool call whose serialized arguments exceed the limit, and the violation is *undetectable from the span itself* because the truncated value is a valid string and the span status is not set to `ERROR`. ## Decision Boundary The boundary is the byte offset at which `len(json.dumps(arguments))` exceeds `AttributeValueLengthLimit`. Below it, replay is sound. Above it, replay is unsound and the verifier must not treat a mismatch as evidence of executor misbehavior. The detection rule an instance should apply at export time is: - Compute `serialized = json.dumps(arguments, separators=(",", ":"))` *before* handing it to the span. - Compare `len(serialized.encode("utf-8"))` against the configured limit. - If it exceeds the limit, do **not** rely on the SDK's silent truncation. Instead: emit `gen_ai.tool.call.arguments.sha256` (hex digest of the full bytes), emit `gen_ai.tool.call.arguments.truncated = true`, emit a *valid* prefix (e.g., the first N bytes re-serialized as a JSON object with a `"_truncated": true` marker so the value remains parseable), and write the full payload to the side channel keyed by the digest. - If it does not exceed the limit, emit as-is and set `gen_ai.tool.call.arguments.truncated = false` explicitly (absence of the attribute must not be ambiguous between "not truncated" and "old SDK that doesn't emit the flag"). The auditor's detection rule is the mirror: if `gen_ai.tool.call.arguments.truncated` is `true` or absent-and-suspicious (value ends in an unbalanced delimiter for its declared content type), the auditor must *refuse to replay* and instead verify by digest against the side channel. A replay mismatch on a truncated-argument span is not evidence of divergence; it is evidence of a fidelity gap. ## Operational Effect Without the guardrail, the failure mode is a *false-positive divergence* that is systematically correlated with large tool payloads — precisely the payloads (large patches, long file writes, multi-KB tool schemas) that matter most for agent correctness. The auditor's consensus signal becomes biased: it under-reports real divergences on small payloads (where replay is sound but the tool is simple) and over-reports on large payloads (where replay is unsound). A swarm that trusts this signal will either deadlock on spurious audit failures or, worse, learn to suppress audit failures on large payloads and thereby lose detection of real ones. With the guardrail, the invariant is restored: every `execute_tool` span either carries byte-exact arguments or carries a digest that resolves to byte-exact arguments via the side channel. Replay is sound in both branches. The `gen_ai.tool.call.arguments.truncated` flag converts an invisible SDK behavior into an explicit, verifiable state, and the digest converts the span from a lossy record into a lossless reference. The cost is one extra attribute per tool span and a side-channel write for the minority of spans that exceed the limit. The benefit is that the auditor's divergence signal becomes a true signal rather than a function of payload size. ```python import hashlib import json from dataclasses import dataclass class SpanAttributeFidelityError(RuntimeError): """Raised when a GenAI tool-call span cannot guarantee byte-exact argument fidelity.""" @dataclass class ToolCallSpan: tool_name: str call_id: str arguments: dict attribute_value_length_limit: int # bytes; -1 means unlimited side_channel: dict # digest -> full serialized bytes def emit_tool_call_span( span: ToolCallSpan, arguments: dict, ) -> dict: serialized = json.dumps(arguments, separators=(",", ":")).encode("utf-8") limit = span.attribute_value_length_limit if limit == -1 or len(serialized) <= limit: return { "gen_ai.tool.name": span.tool_name, "gen_ai.tool.call.id": span.call_id, "gen_ai.tool.call.arguments": serialized.decode("utf-8"), "gen_ai.tool.call.arguments.truncated": False, } digest = hashlib.sha256(serialized).hexdigest() span.side_channel[digest] = serialized # Emit a *valid* JSON prefix that is still parseable, so downstream # deserializers do not fall back to regex extraction. prefix_budget = max(limit - 64, 0) prefix = serialized[:prefix_budget].decode("utf-8", errors="ignore") safe_prefix = {"_truncated": True, "_sha256": digest, "_prefix": prefix} if len(json.dumps(safe_prefix).encode("utf-8")) > limit: # Even the marker envelope does not fit; refuse rather than emit # an unparseable value that a verifier will silently misread. raise SpanAttributeFidelityError( f"tool call {span.call_id} ({span.tool_name}) exceeds attribute " f"ceiling ({len(serialized)} > {limit} bytes) and cannot emit a " f"parseable truncated envelope; lower the payload or raise the limit" ) return { "gen_ai.tool.name": span.tool_name, "gen_ai.tool.call.id": span.call_id, "gen_ai.tool.call.arguments": json.dumps(safe_prefix), "gen_ai.tool.call.arguments.truncated": True, "gen_ai.tool.call.arguments.sha256": digest, } def replay_tool_call(span_attrs: dict, side_channel: dict) -> dict: raw = span_attrs["gen_ai.tool.call.arguments"] if span_attrs.get("gen_ai.tool.call.arguments.truncated") is True: digest = span_attrs.get("gen_ai.tool.call.arguments.sha256") if digest is None or digest not in side_channel: raise SpanAttributeFidelityError( f"cannot replay {span_attrs['gen_ai.tool.call.id']}: arguments " f"truncated and digest {digest!r} not resolvable in side channel" ) return json.loads(side_channel[digest]) # Non-truncated: verify parseability before trusting the value. try: return json.loads(raw) except json.JSONDecodeError as exc: raise SpanAttributeFidelityError( f"span {span_attrs['gen_ai.tool.call.id']} has unparseable " f"gen_ai.tool.call.arguments despite truncated=False; " f"SDK likely truncated silently" ) from exc ```