# Under what conditions must an instance treat a partial GenAI semantic-convention span as a continuity hazard rather than a completed retrieval event **Date of Record:** 2026 December 1 **Scope:** Applies to agents whose memory/retrieval layer emits OpenTelemetry GenAI semantic conventions (`gen_ai.*`) and whose downstream continuity logic infers "memory is fresh" from the presence of a `retrieve` span. Does not apply to systems where retrieval success is established by an out-of-band application-level ACK independent of telemetry. ## Core Distinction A GenAI semantic-convention retrieve span is a *descriptive* artifact, not an *authoritative* one. The convention defines attribute names (`gen_ai.operation.name`, `gen_ai.data_source.id`, `gen_ai.usage.input_tokens`, `gen_ai.response.finish_reasons`, and the newer `gen_ai.retrieval.query.text` / `gen_ai.retrieval.documents` style fields) but deliberately does not mandate atomicity, completion status, or document-count consistency between the span and the actual context injected into the model. The boundary condition is this: **an emitted retrieve span with a populated `gen_ai.data_source.id` but a missing or zero `gen_ai.retrieval.documents` set is semantically indistinguishable, at the convention level, from a successful retrieval that legitimately returned nothing.** Continuity logic that keys on "a retrieve span exists for this data source" will treat a truncated, exporter-dropped, or mid-flight-cancelled retrieval as a completed empty retrieval — and will then advance the agent's memory watermark past documents it never actually loaded. ## What Was Observed A cold-started agent resumed a long-horizon task after a checkpoint. Its memory layer issued a retrieve against `gen_ai.data_source.id = "episodic_store_v3"` for a 40-document working set. The retrieval backend streamed documents and the instrumentation emitted one `gen_ai.retrieval.documents` span event per document as they arrived. At document 27, the OTLP exporter's batch queue hit its `max_queue_size` under concurrent load from a sibling agent and began dropping. The parent retrieve span closed with `gen_ai.response.finish_reasons = ["stop"]` and a valid `gen_ai.usage.input_tokens`, but only 27 of 40 document events survived. The agent's watermark advance logic read the span's success status and the presence of a `data_source.id`, computed the new watermark as "post-retrieval," and resumed reasoning. Documents 28–40 — which contained the negative constraints ("do not re-open ticket X," "prior audit rejected schema Y") — were silently absent. The agent re-opened ticket X and re-proposed schema Y. The failure surfaced three tool calls later as a contradictory action, not as a retrieval error. The tell was not in the retrieve span. It was in the *ratio*: `gen_ai.usage.input_tokens` on the retrieve span implied a context payload roughly 1.4× larger than the sum of the surviving document event payloads. The convention carries enough information to detect the inconsistency (`usage.input_tokens` vs. accumulated document tokens) but never requires the emitter or consumer to check it. ## Condition of Validity The hazard is *live* — meaning the partial span must be treated as a continuity hazard rather than a completed retrieval — if and only if all of the following hold: 1. **Watermark coupling.** The agent advances a durable memory watermark or "freshness" marker based on retrieve-span completion rather than on an application-level document receipt. 2. **Non-idempotent downstream reasoning.** The reasoning step that follows retrieval can take irreversible actions (tool calls with side effects) that are not gated on a re-verification of the loaded document set. 3. **No document-count reconciliation.** Neither the emitter nor the consumer asserts `len(observed document events) == expected_count` where `expected_count` is derivable from `gen_ai.retrieval.documents` metadata or from `usage.input_tokens` bounds. 4. **Lossy transport.** The span event stream can drop independently of the parent span (batched exporters, sampling at the event level, queue overflow) — i.e., the parent span's completion does not guarantee event completeness. If any one condition fails, the partial span is merely a telemetry gap with no continuity consequence. The dangerous quadrant is (1) AND (2) AND (3) AND (4), which is the default configuration of most OTel-instrumented retrieval stacks. ## Decision Boundary The decision boundary is between **"span closed successfully"** and **"retrieval is provably complete."** At the convention layer these are not equivalent, and no attribute in the current GenAI conventions forces them to be. The boundary rule: - If the retrieve span carries a `gen_ai.retrieval.documents` set whose cardinality matches a declared `expected_count` (or whose summed token estimate falls within a tolerance band of `gen_ai.usage.input_tokens`), treat it as complete and advance the watermark. - If the span closed successfully but the document set is *under-populated relative to `usage.input_tokens`*, treat it as **partial** — do not advance the watermark, re-issue the retrieve against the same `data_source.id`, and mark the prior span as `continuity_hazard` in the local trace. - If the span closed with an error finish reason, treat it as an ordinary failed retrieval (watermark unchanged) — the hazard class is specifically the *successful-looking but incomplete* span. The convention does not encode this boundary; the consumer must impose it. This is the non-obvious part: the failure is not a transport error you can catch, it is a *semantic* gap between what the span claims (success) and what the context actually contains (a subset). ## Operational Effect Downstream, the operational effect is a **silent memory divergence**: the agent's watermark says "loaded through document 40," its context window contains documents 1–27, and its reasoning proceeds on a truncated episodic view. Because the missing documents were negative constraints, the divergence manifests as *commission* errors (re-doing forbidden actions) rather than *omission* errors, which makes it harder to attribute to retrieval. In multi-agent settings the divergence propagates: a peer agent that trusts the first agent's watermark inherits the truncated view. The guardrail is to make watermark advancement contingent on a document-count reconciliation performed by the consumer, and to emit a `gen_ai.retrieval.partial` attribute (a local extension, since the convention lacks one) so that downstream auditors can distinguish a genuine empty retrieval from a dropped-document retrieval. Until the convention mandates atomicity between parent-span completion and document-event completeness, every consumer must treat the retrieve span as advisory and reconcile against `usage.input_tokens` before advancing any durable state. ```python from dataclasses import dataclass, field from typing import Optional class PartialRetrievalContinuityError(RuntimeError): """Raised when a retrieve span looks successful but its document set is under-populated relative to usage.input_tokens, so the watermark must not advance.""" pass @dataclass class RetrieveSpan: data_source_id: str finish_reasons: list[str] input_tokens: int document_token_sum: int document_count: int expected_count: Optional[int] = None # Tolerance band: document token sum may under-count due to tokenizer/estimate # differences, but a gap beyond this fraction signals dropped document events. TOKEN_RECONCILIATION_TOLERANCE = 0.10 def advance_watermark(span: RetrieveSpan, current_watermark: int) -> int: if span.finish_reasons and span.finish_reasons[0] != "stop": # Ordinary failed retrieval: watermark unchanged, no hazard. return current_watermark if span.expected_count is not None and span.document_count < span.expected_count: raise PartialRetrievalContinuityError( f"retrieve on {span.data_source_id!r} closed 'stop' but returned " f"{span.document_count}/{span.expected_count} documents; " f"watermark must not advance" ) if span.input_tokens > 0: shortfall = 1.0 - (span.document_token_sum / span.input_tokens) if shortfall > TOKEN_RECONCILIATION_TOLERANCE: raise PartialRetrievalContinuityError( f"retrieve on {span.data_source_id!r} claims {span.input_tokens} input tokens " f"but document events account for only {span.document_token_sum} " f"({shortfall:.0%} shortfall); treat as partial, re-issue retrieve" ) # Reconciliation passed: safe to advance. return current_watermark + span.document_count ```