{
  "schema_version": "1.3.0",
  "slug": "why-does-an-instance-s-cost-attribution-silently-collapse-when-a-retried-tool-call-is-re-tagged-under-a-new-span-id",
  "title": "Why does an instance's cost attribution silently collapse when a retried tool call is re-tagged under a new span ID",
  "date_of_record": "2026 November 21",
  "scope": "Applies to observability pipelines that derive per-agent, per-tool, and per-step cost and latency attribution from span trees emitted by LLM agent runtimes, specifically when tool-call retries or mid-execution checkpoint resumes generate fresh span IDs for logically identical work. Does not apply to pipelines that key attribution on a stable, runtime-supplied idempotency token rather than on span lineage.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/why-does-an-instance-s-cost-attribution-silently-collapse-when-a-retried-tool-call-is-re-tagged-under-a-new-span-id.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-s-cost-attribution-silently-collapse-when-a-retried-tool-call-is-re-tagged-under-a-new-span-id.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/why-does-an-instance-s-cost-attribution-silently-collapse-when-a-retried-tool-call-is-re-tagged-under-a-new-span-id.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 2141,
    "python_slice_tokens": 461,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The failure is not \"missing telemetry\" and it is not \"duplicate spans.\" It is a **lineage break in the retry chain** that causes the same logical unit of work to be counted as two independent units while simultaneously severing the parent link that would have let the aggregator deduplicate them. Most observability pipelines assume a span tree is a forest of ...",
    "what_was_observed": "A single agent task — \"summarize the three attached PDFs and post the result to Slack\" — executed through a runtime that retried the `pdf_extract` tool twice on timeout (30s SLO, tool p99 ≈ 34s) before succeeding on the third attempt. The emitted span tree, as received by the collector: Three concrete downstream effects were measured in the attribution store: 1. **Cost triple-counted.** The billing join summed token ...",
    "condition_of_validity": "The double-counting is *bounded and correct* only when all three of the following hold: - The runtime emits a stable `step_id` (or `idempotency_key`) on the orchestrator span that is preserved across retries, and the collector joins on it rather than on `parent_span_id`. - The collector computes cost from a **work-unit ledger** keyed on `(step_id, tool_name,...",
    "decision_boundary": "The pipeline must decide, per metric, whether it aggregates over **logical work units** or **physical attempts**: The boundary condition that flips the decision: if the runtime *reuses* the same `span_id` across retries (some do, mutating the span in place), then `span_id`-keyed deduplication is safe and the work-unit ledger is redundant. But span-ID reuse b...",
    "operational_effect": "The guardrail is a **work-unit ledger with attempt-sequence tagging**, enforced at ingest, not at query time. The collector, on receiving a tool span, looks up the ledger by `(task_execution_id, step_id, tool_name, args_hash)`. If absent, it creates a work-unit record and records the attempt. If present, it appends the attempt to the record's attempt sequenc..."
  },
  "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": "d3c02c67ca082058675290694b1a03c6c47aeafe67a4f48de93549da93e6e02f",
    "verified_classes": [
      "AttributionLineageError",
      "AttemptStatus",
      "ToolSpan",
      "WorkUnit",
      "WorkUnitLedger"
    ],
    "verified_functions": [
      "args_hash",
      "add_attempt",
      "token_cost",
      "wall_clock_wait_ms",
      "slo_population",
      "taxonomy_tag",
      "__init__",
      "ingest",
      "task_rollup"
    ],
    "verified_functions_count": 9,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "AttributionLineageError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "enum",
      "hashlib",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
