{
  "schema_version": "1.3.0",
  "slug": "under-what-conditions-must-an-instance-attribute-span-latency-to-the-wrong-agent-step-when-async-tool-callbacks-outlive-their-parent-span",
  "title": "Under what conditions must an instance attribute span latency to the wrong agent step when async tool callbacks outlive their parent span",
  "date_of_record": "2026 November 30",
  "scope": "Applies to single- or multi-agent runtimes that emit per-step and per-tool-call spans to a tracing backend and compute cost/latency attribution by span parentage. Does not apply to synchronous, single-threaded invocations where every tool callback completes before the enclosing step span closes.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-attribute-span-latency-to-the-wrong-agent-step-when-async-tool-callbacks-outlive-their-parent-span.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-attribute-span-latency-to-the-wrong-agent-step-when-async-tool-callbacks-outlive-their-parent-span.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/under-what-conditions-must-an-instance-attribute-span-latency-to-the-wrong-agent-step-when-async-tool-callbacks-outlive-their-parent-span.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1691,
    "python_slice_tokens": 349,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "Observability attribution is not logging. Logging tolerates misordered, orphaned, or duplicated records because a human reads them and reconstructs intent. Attribution *is* the accounting: a span's `parent_span_id` is the sole claim of which agent step owns a unit of latency and cost. When an async tool callback returns after its parent step span has already...",
    "what_was_observed": "A two-agent pipeline (planner → executor) ran a step that dispatched an asynchronous retrieval tool with a 4.2 s server-side tail latency. The executor step span closed at 900 ms — the model had already consumed the tool's *acknowledgement* token and moved on — and was flushed to the collector. The tool's completion span returned at 4.2 s. Because the runtime used `contextvars` for span propagation and the callback w...",
    "condition_of_validity": "The misattribution is *bounded and predictable* only when all four of the following hold; if any fails, the failure mode changes shape and the guardrail below is insufficient: 1. **Span context is propagated by ambient context variable, not by explicit handle passing.** If the tool callback receives its parent span as an argument, late completion attaches to...",
    "decision_boundary": "The runtime must decide, at the moment a step span closes with outstanding dispatched children, whether to (i) keep the step logically open for attribution while marking it \"emitted,\" (ii) transfer ownership of late children to a synthetic `detached_tool` span parented to the trace root, or (iii) reject the close and block until children settle. The boundary...",
    "operational_effect": "Without the freeze, per-agent cost reports drift in the direction of whichever agent runs *after* the slow tool — systematically, not randomly, because the re-parenting target is always the next step to acquire the reused context. In a planner/executor split this means the planner is consistently overcharged for executor I/O, and the error grows with tool ta..."
  },
  "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": "f8c421245e07adee38077c4413523fa79db4919038190d2d4d8bf2821a827c2d",
    "verified_classes": [
      "AttributionInvariantError",
      "Span"
    ],
    "verified_functions": [
      "close_step_span",
      "reconcile_trace"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 2,
    "raised_exceptions": [
      "AttributionInvariantError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
