Skip to content

perf: cache model cost indexes#86668

Merged
steipete merged 1 commit into
mainfrom
perf/cache-model-cost-index
May 25, 2026
Merged

perf: cache model cost indexes#86668
steipete merged 1 commit into
mainfrom
perf/cache-model-cost-index

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Summary

  • Cache configured model cost indexes per providers object, invalidated by a stable value fingerprint so in-place config changes still update pricing.
  • Make raw cost lookups skip manifest model-id normalization as well as runtime/plugin normalization, keeping direct pricing lookups off plugin metadata hot paths.
  • Add regressions for raw lookup avoiding manifest normalization and mutable config pricing updates after cache population.

Verification

  • node scripts/run-vitest.mjs src/utils/usage-format.test.ts
  • pnpm exec oxfmt --check src/utils/usage-format.ts src/utils/usage-format.test.ts
  • pnpm lint --threads=8
  • pnpm tsgo:core
  • /Users/steipete/Projects/agent-scripts/skills/autoreview/scripts/autoreview --mode local

Real behavior proof

Behavior addressed: CPU profile hotspots from repeated model cost index rebuilds and manifest/plugin metadata normalization during session usage cost lookup.
Real environment tested: local OpenClaw checkout on macOS with gateway CPU profiles from /Users/steipete/clawdbot/.artifacts/gateway-watch-profiles.
Exact steps or command run after this patch: focused usage-format Vitest, oxfmt check, oxlint shard lint, core tsgo, and autoreview.
Evidence after fix: focused usage-format tests passed 24 tests; lint, format, and core type gates passed; autoreview reported no accepted/actionable findings.
Observed result after fix: raw cost lookup returns configured pricing without calling manifest model normalization, and cached provider cost indexes observe in-place config pricing changes via value-fingerprint invalidation.
What was not tested: live gateway CPU profile comparison after this exact patch.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels May 25, 2026
@clawsweeper

clawsweeper Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: perf: cache model cost indexes This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15c1e25d95

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/utils/usage-format.ts
Comment on lines +238 to +242
const fingerprint = stableCostFingerprintValue(providers);
let cache = providerCostIndexByConfig.get(providers);
if (!cache || cache.fingerprint !== fingerprint) {
cache = { fingerprint };
providerCostIndexByConfig.set(providers, cache);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include plugin normalization state in cache key

getProviderCostIndex only invalidates on a fingerprint of providers, but the normalized index values also depend on runtime/manifest model-id normalization, which can change when plugin metadata snapshot changes (for example after plugin install/reload) without mutating config.models.providers. In that case the cached normalizedEntries map is reused with stale normalized keys, so resolveModelCostConfig can miss configured prices or return outdated mappings until process restart/reset.

Useful? React with 👍 / 👎.

@steipete steipete merged commit 068924e into main May 25, 2026
115 of 117 checks passed
@steipete steipete deleted the perf/cache-model-cost-index branch May 25, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant