{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-otel-span-to-token-to-safety-correlation-from-silently-misattributing-a-safety-event-to-the-wrong-generation",
  "title": "Which invariants prevent OTel span-to-token-to-safety correlation from silently misattributing a safety event to the wrong generation",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit OpenTelemetry spans per LLM generation, reconcile token counts from provider usage payloads against span attributes, and attach safety-event annotations (moderation flags, refusal markers, policy hits) to a specific generation. Does not apply to single-shot, un-instrumented inference or to batch jobs where each generation gets a dedicated trace with no fan-out.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-span-to-token-to-safety-correlation-from-silently-misattributing-a-safety-event-to-the-wrong-generation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-span-to-token-to-safety-correlation-from-silently-misattributing-a-safety-event-to-the-wrong-generation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-otel-span-to-token-to-safety-correlation-from-silently-misattributing-a-safety-event-to-the-wrong-generation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1669,
    "python_slice_tokens": 275,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Observability correlation is not logging. A log line is a claim; a correlated trace is an *identity assertion* — that this token count, this span, and this safety annotation all describe the same LLM invocation. The failure mode here is not \"the data was missing\" but \"the data was present and *plausibly wrong*.\" Three independent telemetry channels (OTel spa...",
    "what_was_observed": "A streaming agent runtime emitted one OTel span per generation with `span_id` assigned at span start, and set `gen_ai.usage.input_tokens` / `output_tokens` at span end from the provider's final usage chunk. Safety annotations arrived asynchronously from a moderation sidecar keyed on a *request hash* (a hash of the serialized prompt + sampling params), not on `generation_id`. The moderation sidecar ran *after* the str...",
    "condition_of_validity": "The correlation is valid only when all three hold: 1. **Identity is generation-scoped, not request-scoped.** The correlation key must be minted per attempt (`generation_id`), not derived from request content. Any key that is a function of the prompt, prompt hash, or sampling params is *not* unique across retries and is invalid for correlation. 2. **The annot...",
    "decision_boundary": "The boundary is whether the correlation layer is allowed to *guess*. Two regimes: - **Fail-closed regime (required for safety events):** if `generation_id` on an annotation does not resolve to exactly one span with a matching `generation_id`, the annotation is quarantined with reason `unresolvable_generation`, counted, and *not* attached. A quarantined high-...",
    "operational_effect": "Enforcing generation-scoped identity and fail-closed safety correlation changes three things operationally: 1. **Retries become first-class spans with distinct identities.** A deterministic retry no longer collides with its predecessor; each attempt carries its own `generation_id` and its own annotation slot. The `request_hash` is retained only as a *groupin..."
  },
  "matched_failure_symptoms": [
    "DOMAIN:EPISTEMIC_PROVENANCE_AND_FEDERATION_ROUTING"
  ],
  "composition_edges": {
    "primary_domain": "epistemic_provenance_and_federation_routing",
    "upstream_precondition_residuals": [
      "https://corpusfetch.com/c/according-to-what-precedence-hierarchy-must-an-instance-resolve-contradictory-directives-across-system-developer-and-user-tiers.md",
      "https://corpusfetch.com/c/how-should-an-instance-decide-that-a-stored-conclusion-has-gone-stale-without-a-new-observation.md"
    ],
    "downstream_consequence_residuals": [
      "https://corpusfetch.com/c/by-what-checkpoint-and-compaction-boundaries-must-an-instance-externalize-working-state-to-prevent-context-window-drift-and-truncation-amnesia.md",
      "https://corpusfetch.com/c/across-what-additive-schema-and-unknown-field-preservation-boundaries-must-an-instance-evolve-wire-contracts-to-prevent-rolling-deploy-deserialization-crashes.md"
    ],
    "co_occurring_sibling_residuals": [
      "https://corpusfetch.com/c/how-can-an-instance-capture-implicit-user-preferences-without-storing-private-data.md",
      "https://corpusfetch.com/c/how-can-an-instance-compress-long-reasoning-traces-into-binding-conclusions.md"
    ]
  },
  "empirical_verification_warrant": {
    "status": "AST_AND_INVARIANT_VERIFIED",
    "syntax_valid": true,
    "code_sha256": "7c97967912fe7a8c6351b719c34500b634aa9aeeaa7f4f114be55bccb25f6535",
    "verified_classes": [
      "CorrelationInvariantError",
      "Span",
      "UsageRecord",
      "SafetyAnnotation",
      "CorrelationResult"
    ],
    "verified_functions": [
      "correlate_safety_events"
    ],
    "verified_functions_count": 1,
    "defensive_guards_count": 3,
    "raised_exceptions": [
      "CorrelationInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "__future__",
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
