Skip to content

[Bug]: Model cost reports $0 since 2026.6.10 — model_capability_cache never populates (persists on 2026.6.11) #106080

Closed

Description

@dltlaos11

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Built-in model cost/usage statistics stopped working after updating 2026.3.13 → 2026.6.10. Token counts are still tracked, but all dollar cost reports as $0 across /usage, sessions.usage, and usage.cost. model_capability_cache never populates. Updating to 2026.6.11 did not fix it.

Steps to reproduce

  1. Run a gateway on 2026.6.10/2026.6.11 with an Anthropic model (anthropic/claude-sonnet-4-6, api-key auth).
  2. Generate normal traffic so session logs accrue tokens.
  3. Query cost: openclaw gateway call sessions.usage --json --params '{"startDate":"","endDate":"","agentScope":"all"}'
  4. Observe totals.totalTokens is correct but totals.totalCost is 0 and missingCostEntries > 0.
  5. Check pricing cache: sqlite3 state/openclaw.sqlite "SELECT count(*) FROM model_capability_cache;" → 0.

Expected behavior

totalCost reflects real cost, computed from the external pricing catalog (as it did on 2026.3.13). model_capability_cache is populated for the active model.

Actual behavior

totalCost = 0 for all date ranges after the update; model_capability_cache has 0 rows. Persists across multiple gateway restarts and after updating to 2026.6.11.

OpenClaw version

2026.6.11 (also reproduced on 2026.6.10)

Operating system

macOS (Darwin 25.x)

Install method

npm (global)

Model

anthropic/claude-sonnet-4-6

Provider / routing chain

anthropic provider, api-key auth, default routing

Additional provider/model setup details

Model catalog is a custom/aggregated catalog that includes non-Anthropic providers alongside Anthropic. The bundled anthropic plugin's modelPricing policy points to OpenRouter with modelIdTransforms: ["version-dots"].

Logs

config-health / gateway warnings (repeat on every restart):
- plugins.entries.openrouter: plugin openrouter: plugin id mismatch (manifest uses "openrouter", entry hints "openrouter-provider")
- plugins.entries.litellm:   plugin litellm: plugin id mismatch (manifest uses "litellm", entry hints "litellm-provider")

Screenshots, recordings, and evidence

Verified the pricing source is healthy and reachable, so the failure is on the gateway-population side:

  • OpenRouter catalog reachable; contains anthropic/claude-sonnet-4.6 (version-dots transform of the model id) with correct pricing (prompt 3e-6, completion 15e-6, input_cache_read 3e-7, input_cache_write 3.75e-6).
  • LiteLLM catalog likewise reachable with matching pricing.
  • anthropic, openrouter, litellm plugins all show enabled.
  • Despite this, model_capability_cache = 0 rows and sessions.usage.totals.totalCost = 0.

Impact and severity

All cost analytics/reporting built on usage.cost / sessions.usage report $0 (token counts unaffected). Any automated cost report silently shows $0 for periods after the update.

Additional information

Suspected cause: the persistent id mismatch for the two external-pricing-source plugins (openrouter, litellm) may prevent their pricing catalog fetchers/policies from registering, so getCachedGatewayModelPricing returns nothing and cost computes as 0. Also unclear whether cost is recomputed retroactively once pricing is available or only baked at write time — clarification appreciated.

Activity

  1. clawsweeper commented on Jul 13, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 13, 2026, 2:31 AM ET / 06:31 UTC.

    Summary
    Keep this issue open: the latest shipped release has a concrete regression report, current main still depends on a background external-pricing bootstrap, and no merged fix or canonical replacement was found. The empty SQLite table is not by itself proof of the cause because current gateway cost lookup uses an in-memory pricing map, but the reported zero-cost behavior remains actionable.

    Reproducibility: no. current-main live reproduction was established, but the reporter supplies a concrete released-version path with token totals, missingCostEntries, and repeated restarts. The source confirms the downstream zero/missing-cost behavior when no pricing reaches the runtime cache.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Include the exact command, prompt, or workflow that triggered it.
    • Add expected vs actual behavior.

    Next step
    A maintainer should first reproduce the exact custom-catalog and plugin-entry state on current main and identify which bootstrap stage stays empty before assigning a repair boundary.

    Review details

    Best possible solution:

    Make external pricing bootstrap reliably resolve the active model through canonical manifest metadata, expose a clear degraded-health reason when no price is loaded, and add regression coverage showing existing session usage gains correct costs after pricing becomes available.

    Do we have a high-confidence way to reproduce the issue?

    No current-main live reproduction was established, but the reporter supplies a concrete released-version path with token totals, missingCostEntries, and repeated restarts. The source confirms the downstream zero/missing-cost behavior when no pricing reaches the runtime cache.

    Is this the best way to solve the issue?

    Unclear. The suggested plugin-ID mismatch is plausible but not yet proven; the best investigation must distinguish persistent capability rows from the in-memory pricing map and trace bootstrap health, active manifests, selected refs, transforms, and fetch results.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The reporter's custom aggregated model catalog and stale plugin-entry hints may be necessary to trigger the failure, so a generic clean-install reproduction could miss the actual activation path.
    • The empty model_capability_cache table may be a misleading diagnostic because current cost estimation reads an in-memory pricing cache; fixing only SQLite population may leave cost reports broken.
    • It remains unproven whether the regression is bootstrap scheduling, active-manifest filtering, model-reference selection, ID transformation, or a fetch failure that lacks sufficiently visible health diagnostics.

    Codex review notes: model internal, reasoning high; reviewed against ab8cbfd73c42.

    Label changes

    Label changes:

    • add P2: Cost analytics are silently incorrect for a reported released configuration, but token accounting and core model execution continue to work.
    • add impact:other: The issue affects maintainer-visible usage and cost analytics without matching the data-loss, session, delivery, auth, availability, or UX-blocker categories.
    • add issue-rating: 🦪 silver shellfish: Current issue advisory state selects this label.
    • add clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.
    • add clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.

    Label justifications:

    • P2: Cost analytics are silently incorrect for a reported released configuration, but token accounting and core model execution continue to work.
    • impact:other: The issue affects maintainer-visible usage and cost analytics without matching the data-loss, session, delivery, auth, availability, or UX-blocker categories.
    Evidence reviewed

    What I checked:

    • Current pricing lifecycle: Current documentation says external OpenRouter and LiteLLM pricing is loaded by a background bootstrap after the Gateway ready path, with pricing enabled by default. Public docs: docs/gateway/configuration-reference.md. (docs/gateway/configuration-reference.md, ab8cbfd73c42)
    • Active plugin metadata boundary: The current pricing refresh resolves manifest metadata and filters policies through enabled installed plugins, making plugin identity and activation relevant surfaces to inspect with the reporter's configuration warnings. (src/gateway/model-pricing-cache.ts, ab8cbfd73c42)
    • Runtime cache behavior: Current main stores gateway pricing in an in-memory Map through replaceGatewayModelPricingCache; model_capability_cache row count therefore does not directly prove whether the runtime pricing map was populated. (src/gateway/model-pricing-cache-state.ts, ab8cbfd73c42)
    • Cost lookup path: Usage formatting checks models.json and configured provider costs before falling back to getCachedGatewayModelPricing, so absent external pricing can produce missing cost entries while token totals remain intact. (src/utils/usage-format.ts, ab8cbfd73c42)
    • Existing regression coverage: Current pricing tests cover Anthropic dotted-ID transformation and successful mapping from OpenRouter pricing, but the available evidence does not establish coverage for the reporter's custom aggregated catalog plus plugin-entry mismatch state. (src/gateway/model-pricing-cache.test.ts, ab8cbfd73c42)
    • Shipped reproduction: The reporter provides repeatable CLI and SQLite observations on both v2026.6.10 and the latest release v2026.6.11; no later shipped release is identified in the supplied repository state. (e085fa1a3ffd)

    Likely related people:

    • RomneyDa: Merged work in perf(plugins,gateway): thread metadata snapshot + discovery through hot paths + plugin owner fixes #84649 threaded plugin metadata snapshots and discovery through Gateway hot paths, which is directly adjacent to pricing-policy manifest resolution. (role: recent plugin metadata contributor; confidence: medium; files: src/gateway/model-pricing-cache.ts, src/plugins/plugin-metadata-snapshot.ts, src/plugins/plugin-metadata-snapshot.types.ts)
    • MichaelZelbel: Authored the merged missing-cost reporting change in fix(usage-cost): surface unpriced-model spend as missingCostEntries instead of a confident $0 #85882 and is connected to the downstream usage-cost behavior when pricing is unavailable. (role: recent usage-cost contributor; confidence: medium; files: src/utils/usage-format.ts, src/gateway/server-methods/usage.ts)
    • steipete: Recent merged Gateway/plugin metadata performance work, including perf: cache plugin package realpaths #86517, makes this a useful routing candidate for bootstrap lifecycle and metadata-snapshot interactions. (role: recent adjacent Gateway and plugin contributor; confidence: low; files: src/gateway/model-pricing-cache.ts, src/plugins/installed-plugin-index-record-builder.ts, src/plugins/manifest-registry-installed.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. dltlaos11 commented on Jul 15, 2026

    @dltlaos11
    Author

    Thanks for the triage. Good catch on the in-memory pricing map — you're right that
    the empty model_capability_cache SQLite table isn't proof by itself. I re-checked
    against the runtime path (the CLI gateway call RPC, not the web UI), and it also
    returns totalCost: 0 — so the runtime pricing resolution itself is yielding nothing
    for this model, not just the SQLite table or the dashboard. Answering the repro asks
    and adding evidence that should narrow which bootstrap stage stays empty.

    Reproduction (released version)

    Env: OpenClaw 2026.6.11 (also 2026.6.10), npm install, macOS, local gateway.
    Model: anthropic/claude-sonnet-4-6, api-key auth.

    Command (same RPC the dashboard reads, so it isolates the dashboard out):

    openclaw gateway call sessions.usage --json --params '{"startDate":"2026-07-09","endDate":"2026-07-15","agentScope":"all","limit":1000}'
    
    • Expected: totals.totalCost reflects tokens × model pricing (as it did before ~2026-06-29).
    • Actual: totals.totalTokens = 18,763,485 (correct, matches the dashboard), but
      totals.totalCost = 0, and every byAgent[].totals.totalCost / byModel[].totals.totalCost is 0.
      The attached dashboard screenshot shows the same window: 18.8M tokens · $0.00 · 39 sessions.
    • Since this is the CLI RPC (not the web UI), the zero comes from the runtime cost lookup
      itself — this is not a dashboard/WebSocket/field-mapping issue.

    Narrowing: the external source is healthy — the break is local to the pricing pipeline

    The bundled anthropic plugin's modelPricing policy points to OpenRouter with
    modelIdTransforms: ["version-dots"], i.e. claude-sonnet-4-6 → claude-sonnet-4.6.

    I fetched both catalogs directly from the same host:

    • OpenRouter (/api/v1/models): reachable (200), contains anthropic/claude-sonnet-4.6
      with pricing prompt 0.000003, completion 0.000015, input_cache_read 0.0000003,
      input_cache_write 0.00000375.
    • LiteLLM catalog: reachable (200), has the same model with matching pricing.

    So the source data is present, reachable, correctly keyed, and the id transform matches.
    The break is therefore local to the gateway's pricing pipeline — and the health probe below pins the stage further.

    For the catalog state mentioned in the next step: the agent model catalog on this host is
    a custom/aggregated one that includes non-Anthropic providers alongside Anthropic (as noted
    in the issue body).

    Update — health probe + code path narrow the empty stage: openclaw gateway call health
    reports "modelPricing": {"state": "ok", "sources": []} (stable across restarts). Per
    src/gateway/model-pricing-cache.ts, sources lists recorded fetch failures, and every
    failure path (openrouter, litellm, bootstrap, refresh) both records a failure
    (→ state "degraded") and log.warns — yet health is "ok", no pricing warnings appear
    in logs, and cost is 0 for all configured models (both the Anthropic and OpenAI refs).
    So no fetch error ever occurred; the bootstrap exits through a silent-empty path.
    The most direct candidate is the early-return:

    if (refs.length === 0) {
      replaceGatewayModelPricingCache(seededPricing);
      clearGatewayModelPricingFailures();
      clearRefreshTimer();
      return;
    }
    

    (the other silent possibility — a successful fetch that matches zero refs — lands in the
    same policy/transform wiring). Either way, the empty stage is the ref/policy collection
    (plugin modelPricing policies → refs → id transforms), not the fetch itself — consistent
    with the persistent openrouter/litellm plugin id-mismatch warnings noted under
    Additional signals below.

    Additional signals

    • Persistent plugin id-mismatch warnings on every restart, specifically for the two
      external-pricing-source plugins:
      • plugins.entries.openrouter: plugin openrouter: plugin id mismatch (manifest uses "openrouter", entry hints "openrouter-provider")
      • same for litellm (litellm vs litellm-provider).
        Might be worth checking as a reason the bootstrap doesn't wire up the pricing fetchers.
    • Sharp regression boundary. Windows entirely before ~2026-06-29 return correct,
      non-zero totalCost (matches tokens × published rates to the cent). From ~2026-06-29
      onward, totalCost = 0. The transition coincides with the 2026.3.13 → 2026.6.x update
      on this host. Some post-boundary windows also show missingCostEntries > 0.
    • Cost appears baked per-message, not recomputed. Any window spanning the 2026-06-29
      boundary shows native totalCost lower than tokens × rate would give (e.g. $17.46 vs
      $19.07 for one week) — i.e. the aggregate sums baked per-message cost, and post-update
      messages were baked at 0.
    • Config workaround does not restore it. Adding models.providers.anthropic.models[].cost
      (a valid {id, name, cost} entry that passes config validate) and restarting did not
      repopulate cost for existing data — consistent with the baked-per-message behavior above.
      Multiple restarts (including a fresh process after the 6.11 update) also had no effect.

    Happy to run any additional gateway call probes if that helps identify the empty stage.

    Image
  3. dltlaos11 commented on Jul 23, 2026

    @dltlaos11
    Author

    Root cause found — instrumented the gateway and traced it end-to-end. This supersedes
    parts of my previous comment (corrections noted below).

    TL;DR: The pricing fetch/bootstrap pipeline is actually fine. The defect is that
    per-message cost baking never reads any pricing source that exists on a default install —
    so every built-in-model message is written with cost: 0 at generation time, and all
    aggregates (/usage, sessions.usage, usage.cost) just sum those baked zeros. On a
    default 2026.6.x install, no built-in Anthropic model can ever produce a nonzero cost.

    1. The bootstrap works — my earlier "empty ref/policy stage" hypothesis was wrong

    I added temporary debug logging to refreshGatewayModelPricingCache and
    startGatewayModelPricingRefreshOnDemand (installed dist, reverted afterwards) and
    restarted. In the gateway process, at startup:

    [pricing-debug] onDemand called, gate=true
    [pricing-debug] import ok, stopped=false
    [pricing-debug] refresh invoked
    [pricing-debug] allRefs=... refs=1 policies=8
    [pricing-debug] COMMIT nextPricing=1 orCatalog=342 llCatalog=2487 orFailed=false llFailed=false
    

    So: refs are collected, plugin modelPricing policies load (8), OpenRouter/LiteLLM fetch
    succeeds, and the in-memory map is committed with the correct sonnet-4.6 pricing.
    The plugin id-mismatch warnings I flagged earlier appear unrelated to this issue.

    2. The break: cost baking can't reach that map

    With the map confirmed populated, subsequent agent turns (scheduled heartbeats over
    the following hours) still baked usage.cost.total = 0 in their session transcripts —
    9/9 samples. So the write-time path (buildUsage → resolveModelCostConfig({provider, model, config})) never benefits from the gateway's fetched pricing.

    3. Even bundled catalog cost doesn't reach the bake path

    Two independent data points:

    • In the bundled anthropic plugin manifest (extensions/anthropic/openclaw.plugin.json),
      only claude-fable-5 still has a cost block — claude-sonnet-4-6,
      claude-opus-4-6/4-7/4-8, claude-haiku-4-5 have none.
    • Even where the cost exists, it doesn't flow: in a fresh process,
      resolveModelCostConfig({provider:'anthropic', model:'claude-fable-5', config:{}})
      returns undefined. So restoring catalog costs alone would not fix baking either.

    With models.json and config.models.providers empty by default, the bake-time lookup
    chain has no reachable source at all for built-in models → bakes 0 → zeros are
    permanent (aggregation sums baked values; windows spanning the regression boundary
    confirm no recompute).

    4. Correction: the config workaround DOES fix new messages

    My earlier "config workaround does not restore it" only tested retroactive data.
    Re-tested properly: seeding

    models: { providers: { anthropic: { models: [{
      id: "claude-sonnet-4-6", name: "Claude Sonnet 4.6",
      cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 }
    }]}}}

    passes config validate, and after a restart new messages bake correct costs
    (verified: a test turn baked $0.0774 = exactly tokens × seeded rates, and it appears in
    sessions.usage). Existing data stays $0, as expected from baked-per-message semantics.
    (Seeding the agent-dir models.json instead is not viable: the model registry loader
    rejects cost-only providers — "baseUrl" is required when defining custom models.)

    Suggested fix directions (maintainers' call)

    1. Make the bake-time resolveModelCostConfig able to reach the bundled plugin catalog
      cost and/or the gateway pricing cache (or bake tokens only and price at read time).
    2. Restore cost blocks for the non-fable models in the bundled anthropic catalog.
    3. Consider surfacing "pricing unknown at bake time" as a warning instead of silently
      writing cost: 0 — this regression was invisible precisely because zero-cost baking
      is treated as success everywhere (health "ok", no logs).

    Happy to test a patch build against this host's data.

  4. steipete commented on Jul 27, 2026

    @steipete
    Contributor

    Thank you for the detailed follow-up isolating the actual pricing-resolution failure. Current main fixes zero-valued hosted-model usage through #114060 (5347285). The production resolver now sources bundled and centrally hosted model pricing before fallback, correctly records new model usage, and repairs confidently mispriced historical zero-cost totals without changing genuinely provider-billed zero. Regression coverage verifies hosted catalog prices, configured precedence, provider aliases, and historical-zero recovery; the merged proof validates 39 hosted providers and 212 priced models. The retired model_capability_cache is intentionally not recreated. Closing as completed on main.

  5. locked as resolved and limited conversation to collaborators on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions