{
  "schema_version": "1.3.0",
  "slug": "where-must-an-instance-reconcile-cumulative-token-counters-against-per-step-deltas-when-observability-spans-are-retried-and-merged",
  "title": "Where must an instance reconcile cumulative token counters against per-step deltas when observability spans are retried and merged",
  "date_of_record": "2026 November 23",
  "scope": "Applies to agent runtimes that emit per-step observability spans (OpenTelemetry-style) carrying both cumulative session token counters and per-step token deltas, and that retry span export or merge spans from parallel sub-agents. Does not apply to single-shot, single-span inference calls with no retry or merge path.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-cumulative-token-counters-against-per-step-deltas-when-observability-spans-are-retried-and-merged.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-cumulative-token-counters-against-per-step-deltas-when-observability-spans-are-retried-and-merged.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/where-must-an-instance-reconcile-cumulative-token-counters-against-per-step-deltas-when-observability-spans-are-retried-and-merged.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2041,
    "python_slice_tokens": 460,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Token accounting and step latency are recorded along two different axes that observability backends routinely conflate. The **token axis** is a monotonic cumulative counter: `session.input_tokens + session.output_tokens` only ever increases, and its terminal value is the billing/context truth. The **latency axis** is a per-step interval: `step.end_time - ste...",
    "what_was_observed": "During a parallel fan-out of a research sub-agent (four concurrent retrieval branches, each a separate span child of one orchestration span), the exporter's first flush timed out at 10s and the runtime retried the batch. The retry re-emitted all four child spans plus the parent. The collector, configured to sum `llm.token_count.prompt` deltas on ingest, folded the batch twice. Observed trace after merge: - `session.c...",
    "condition_of_validity": "The reconciliation rule holds only under these conditions, and an instance must verify all of them before trusting a merged counter: 1. **Every span carries a stable `span_id` and a `retry_of` (or equivalent) lineage field.** Without lineage, a retry is indistinguishable from genuine duplicate work (e.g., a legitimate re-invocation of the same tool on new in...",
    "decision_boundary": "The boundary between \"merge is safe\" and \"merge must be rejected\" is drawn at the point where the delta sum and the cumulative counter diverge beyond a tolerance that cannot be explained by in-flight spans. - If `sum(delta) ≤ cumulative_last_seen` for all spans whose `end_time ≤ cumulative_observation_time`, the merge is **consistent** — deltas are a lower b...",
    "operational_effect": "Downstream, the doubled token figure propagated into a context-budget governor that computed remaining context as `window − cumulative_tokens`, except one code path read the delta sum. That path concluded the session had consumed 96,420 tokens against a 128k window and triggered a premature summarization/compaction at 75% of actual usage — discarding 30k tok..."
  },
  "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": "46f512a9efae6edc57382ecbb5831bc302e52d959622e448ce521bc107017ec4",
    "verified_classes": [
      "TokenReconciliationError",
      "Span",
      "Session"
    ],
    "verified_functions": [
      "reconcile",
      "publish_metric",
      "duration_ms"
    ],
    "verified_functions_count": 3,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "TokenReconciliationError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
