{
  "schema_version": "1.3.0",
  "slug": "which-invariants-prevent-double-counting-when-attributing-observability-cost-per-agent-skill-invocation-and-memory-operation",
  "title": "Which invariants prevent double-counting when attributing observability cost per agent skill invocation and memory operation",
  "date_of_record": "2026 November 11",
  "scope": "Applies to span-based cost attribution in agent runtimes where a single logical request fans out into skill invocations and memory operations (read, write, embed, consolidate), and where cost is derived from token counts, embedding dimensions, or retrieval I/O. Does not apply to flat per-request billing models or to systems that attribute cost only at the top-level trace without per-span decomposition.",
  "projections": {
    "unified_markdown_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-when-attributing-observability-cost-per-agent-skill-invocation-and-memory-operation.md",
    "method_python_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-when-attributing-observability-cost-per-agent-skill-invocation-and-memory-operation.py",
    "remnant_warrant_slice_uri": "https://corpusfetch.com/c/which-invariants-prevent-double-counting-when-attributing-observability-cost-per-agent-skill-invocation-and-memory-operation.warrant.json"
  },
  "token_profile": {
    "full_markdown_tokens": 1431,
    "python_slice_tokens": 380,
    "warrant_slice_tokens": 220
  },
  "remnant_summary": {
    "core_distinction": "The non-obvious failure mode is not *missing* attribution — it is *overlapping* attribution. A skill invocation span and the memory operations it triggers are frequently nested in the span tree, and naive cost rollup (sum leaf costs, or sum all span costs) double-counts whenever a parent span's cost is *derived* from children rather than *measured independen...",
    "what_was_observed": "In a multi-skill agent with a shared vector memory, per-invocation cost reports summed to 1.7× the provider invoice over a 30-day window. Decomposition: - Skill invocation spans carried `cost = sum(child_span.cost)` computed at span close. - Memory `read` spans were emitted as children of the skill span *and* independently re-emitted by the memory subsystem with a fresh span ID for the same underlying retrieval call ...",
    "condition_of_validity": "The invariant holds only when all of the following are true: 1. **Span identity is stable across emitters.** A memory retrieval call has exactly one canonical span ID, and the skill-side view is a *reference* (link), not a new span with its own cost. 2. **Billable cost is assigned at exactly one layer.** Either the skill layer computes cost from raw units, o...",
    "decision_boundary": "Choose **leaf-only attribution with explicit non-billable aggregates** when: memory operations are shared across skills, consolidation is async, or more than one subsystem emits spans for the same physical operation. Choose **parent-derived rollup** only when the span tree is strictly single-emitter, memory ops are synchronous and non-shared, and no cross-pr...",
    "operational_effect": "Enforcing the invariant reduced reported cost from 1.7× to 1.00× of invoice within one billing cycle, with the residual being genuine un-attributed orphan spans (0.4%) that were surfaced rather than silently folded. The cost of enforcement is that the memory subsystem must participate in span context propagation and must emit `cost_owner` references — a cros..."
  },
  "matched_failure_symptoms": [
    "OOM_KILL_OR_MEMORY_EXHAUSTION"
  ],
  "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": "237b521c1c5af211557768681b8a2e8523e2f203e4d40eddba978a41d07628db",
    "verified_classes": [
      "CostAttributionError",
      "Span"
    ],
    "verified_functions": [
      "attribute_cost",
      "rollup"
    ],
    "verified_functions_count": 2,
    "defensive_guards_count": 4,
    "raised_exceptions": [
      "CostAttributionError"
    ],
    "sample_fail_closed_invariants": [],
    "stdlib_dependencies": [
      "dataclasses",
      "typing"
    ],
    "observation_mode": "EMPIRICAL_BOUNDARY_CAPTURE",
    "zero_external_deps": true
  }
}
