perf: cache model cost indexes#86668
Conversation
|
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. |
There was a problem hiding this comment.
💡 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".
| const fingerprint = stableCostFingerprintValue(providers); | ||
| let cache = providerCostIndexByConfig.get(providers); | ||
| if (!cache || cache.fingerprint !== fingerprint) { | ||
| cache = { fingerprint }; | ||
| providerCostIndexByConfig.set(providers, cache); |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
Verification
node scripts/run-vitest.mjs src/utils/usage-format.test.tspnpm exec oxfmt --check src/utils/usage-format.ts src/utils/usage-format.test.tspnpm lint --threads=8pnpm tsgo:core/Users/steipete/Projects/agent-scripts/skills/autoreview/scripts/autoreview --mode localReal 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.