Repository navigation
fix(anthropic): honor configured model pricing - #117275
Conversation
ab2c5a4 to
70b4ad6
Compare
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 12:46 PM ET / 16:46 UTC. ClawSweeper reviewWhat this changesThe PR changes Anthropic model normalization so a matching Merge readinessThis PR is still necessary and appears correct: current main passes configured models through Anthropic’s provider-owned normalizer, where known Claude catalog prices currently replace an explicit configured cost. The branch adds the narrow owner-local precedence guard, preserves unconfigured catalog pricing and provider-billed totals, and supplies credible after-fix runtime proof. Likely related person: Priority: P2 Review scores
Verification
How this fits togetherOperator model configuration enters agent model discovery and is passed to the Anthropic provider normalizer before the shared AI layer computes estimated usage cost. Provider-reported billed totals remain authoritative after that estimate is calculated. flowchart LR
A[Operator model configuration] --> B[Agent model discovery]
B --> C[Anthropic provider normalization]
D[Claude catalog defaults] --> C
C --> E[Shared usage calculator]
E --> F[Usage estimates]
G[Provider-billed total] --> H[Authoritative total]
H --> F
Before merge
Agent review detailsSecurityNone. PR surfaceSource +5, Tests +65. Total +70 across 2 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the provider-local precedence repair with its two-model regression coverage; configured Anthropic costs should win only for the matching configured model, while unconfigured catalog rates and provider-billed totals remain unchanged. Do we have a high-confidence way to reproduce the issue? Yes. Current main sends configured models through the Anthropic provider normalizer, whose known-Claude catalog branch replaces Is this the best way to solve the issue? Yes. This is the best fix: it corrects precedence at the Anthropic provider that owns the catalog defaults, instead of changing generic session accounting or usage formatting after the wrong cost has already been produced. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ea2e7f46a697. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
70b4ad6 to
e0d28b5
Compare
Maintainer real Anthropic-owner verificationRetargeted the original @synthalorian contribution to the actual Anthropic model-normalization owner for #116714, reported by @1Vision365-PeterTijsma. The previous plugin-runtime/usage-format changes are completely removed; authoritative provider-reported billed totals are unchanged. Exact real production provider registration, model normalization, usage-cost calculation, context/default/Claude-CLI controls, and provider-billed authority proof: node --import tsx --input-type=module -e 'const {buildAnthropicProvider}=await import("./extensions/anthropic/register.runtime.ts");const {calculateCost,applyProviderReportedUsageCost}=await import("./packages/ai/src/model-utils.ts");const configuredCost={input:777,output:888,cacheRead:999,cacheWrite:666};const provider=buildAnthropicProvider();const results=[];for(const modelId of ["claude-sonnet-5","claude-opus-5"]){const configuredContext=321000;const config={models:{providers:{anthropic:{baseUrl:"https://api.anthropic.com",models:[{id:modelId,name:modelId,reasoning:true,input:["text","image"],cost:configuredCost,contextWindow:configuredContext,maxTokens:128000}]}}}};const discovered=provider.resolveDynamicModel({config,provider:"anthropic",modelId,modelRegistry:{find:()=>null}});if(!discovered)throw new Error("missing discovered "+modelId);const configuredModel={...discovered,cost:configuredCost,contextWindow:configuredContext,contextTokens:configuredContext};const normalized=provider.normalizeResolvedModel({config,provider:"anthropic",modelId,model:configuredModel})??configuredModel;const usage={input:1000,output:1000,cacheRead:1000,cacheWrite:1000,totalTokens:4000,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}};calculateCost(normalized,usage);const estimate={...usage.cost};applyProviderReportedUsageCost(usage,42);const defaultModel=provider.normalizeResolvedModel({provider:"anthropic",modelId,model:configuredModel})??configuredModel;const cliInput={...configuredModel,provider:"claude-cli",cost:{input:0,output:0,cacheRead:0,cacheWrite:0}};const cliModel=provider.normalizeResolvedModel({provider:"claude-cli",modelId,model:cliInput})??cliInput;results.push({modelId,configuredRate:configuredCost,normalizedRate:normalized.cost,calculated:estimate,configuredContext:normalized.contextWindow,defaultInputRate:defaultModel.cost.input,claudeCliInputRate:cliModel.cost.input,providerBilled:{total:usage.cost.total,totalOrigin:usage.cost.totalOrigin}})}process.stdout.write(JSON.stringify({results})+"\n")'Current main, before: [{"model":"claude-sonnet-5","configuredInput":777,"actualInput":2,"estimatedTotal":0.014700000000000001,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}},{"model":"claude-opus-5","configuredInput":777,"actualInput":5,"estimatedTotal":0.036750000000000005,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}}]Exact contributor head e0d28b5, after: [{"model":"claude-sonnet-5","configuredInput":777,"actualInput":777,"cost":{"input":0.777,"output":0.888,"cacheRead":0.9990000000000001,"cacheWrite":0.666,"total":3.33},"configuredContext":321000,"defaultInput":2,"claudeCliInput":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}},{"model":"claude-opus-5","configuredInput":777,"actualInput":777,"cost":{"input":0.777,"output":0.888,"cacheRead":0.9990000000000001,"cacheWrite":0.666,"total":3.33},"configuredContext":321000,"defaultInput":5,"claudeCliInput":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}}]Both model families now retain configured 777/888/999/666 rates and calculate total 3.33; configured context, catalog defaults, Claude CLI, and authoritative provider-billed total 42 remain unchanged. OPENCLAW_VITEST_FS_MODULE_CACHE_PATH=/private/tmp/openclaw-vitest-s02-117275-70b4ad6d node scripts/run-vitest.mjs extensions/anthropic/index.test.ts51/51 owner tests passed. Identical patch additionally passed Blacksmith Testbox production and test extension typechecks, formatting, and all 51 tests (lease tbx_01kyyqv92jdej6v1e11hpy4rkc); fresh Codex Sol xhigh autoreview is clean. Exactly two Anthropic plugin files changed; production delta is +5 lines. The earlier ClawSweeper wrong-layer, changed-surface-proof, and provider-billing compatibility findings are resolved. |
|
Merged via squash.
|
* origin/main: (44 commits) fix(plugins): compare authoring metadata by canonical JSON semantics (openclaw#117486) fix(doctor): reject contradictory lint check selectors (openclaw#117495) fix(anthropic): honor configured model pricing (openclaw#117275) refactor(plugins): reuse scoped loader for capability discovery (openclaw#117373) refactor(test): derive changed tooling routes (openclaw#117407) fix(kova): clarify extension memory attribution (openclaw#117500) fix(imessage): sanitize private context on every outbound path (openclaw#117501) fix(ci): align release validation fixtures (openclaw#117494) fix(talk): preserve owner authorization in realtime consults (openclaw#114163) fix(ui): surface aborted-run diagnostics (openclaw#117497) perf(models): skip Ollama row runtime loading (openclaw#117465) fix(cli): report user profile command outcomes (openclaw#117466) fix(active-memory): detect Chinese recall intent in escalate mode (openclaw#117338) (openclaw#117419) fix(workboard): ignore caller-supplied archivedAt when creating a card (openclaw#116412) fix(models): avoid waiting on promotions before listing models (openclaw#117322) refactor(plugins): inherit shared package boundary settings (openclaw#117474) fix(systemd): parse all inline environment assignments (openclaw#117484) feat(web-fetch): add tools.web.fetch.headers for operator request headers (openclaw#115545) fix(qa): Slack progress lane misses successful delivery (openclaw#117391) refactor: deduplicate Codex prompt snapshot fixtures (openclaw#117476) ...
* origin/main: (41 commits) fix(plugins): compare authoring metadata by canonical JSON semantics (openclaw#117486) fix(doctor): reject contradictory lint check selectors (openclaw#117495) fix(anthropic): honor configured model pricing (openclaw#117275) refactor(plugins): reuse scoped loader for capability discovery (openclaw#117373) refactor(test): derive changed tooling routes (openclaw#117407) fix(kova): clarify extension memory attribution (openclaw#117500) fix(imessage): sanitize private context on every outbound path (openclaw#117501) fix(ci): align release validation fixtures (openclaw#117494) fix(talk): preserve owner authorization in realtime consults (openclaw#114163) fix(ui): surface aborted-run diagnostics (openclaw#117497) perf(models): skip Ollama row runtime loading (openclaw#117465) fix(cli): report user profile command outcomes (openclaw#117466) fix(active-memory): detect Chinese recall intent in escalate mode (openclaw#117338) (openclaw#117419) fix(workboard): ignore caller-supplied archivedAt when creating a card (openclaw#116412) fix(models): avoid waiting on promotions before listing models (openclaw#117322) refactor(plugins): inherit shared package boundary settings (openclaw#117474) fix(systemd): parse all inline environment assignments (openclaw#117484) feat(web-fetch): add tools.web.fetch.headers for operator request headers (openclaw#115545) fix(qa): Slack progress lane misses successful delivery (openclaw#117391) refactor: deduplicate Codex prompt snapshot fixtures (openclaw#117476) ...
* origin/main: (44 commits) fix(plugins): compare authoring metadata by canonical JSON semantics (openclaw#117486) fix(doctor): reject contradictory lint check selectors (openclaw#117495) fix(anthropic): honor configured model pricing (openclaw#117275) refactor(plugins): reuse scoped loader for capability discovery (openclaw#117373) refactor(test): derive changed tooling routes (openclaw#117407) fix(kova): clarify extension memory attribution (openclaw#117500) fix(imessage): sanitize private context on every outbound path (openclaw#117501) fix(ci): align release validation fixtures (openclaw#117494) fix(talk): preserve owner authorization in realtime consults (openclaw#114163) fix(ui): surface aborted-run diagnostics (openclaw#117497) perf(models): skip Ollama row runtime loading (openclaw#117465) fix(cli): report user profile command outcomes (openclaw#117466) fix(active-memory): detect Chinese recall intent in escalate mode (openclaw#117338) (openclaw#117419) fix(workboard): ignore caller-supplied archivedAt when creating a card (openclaw#116412) fix(models): avoid waiting on promotions before listing models (openclaw#117322) refactor(plugins): inherit shared package boundary settings (openclaw#117474) fix(systemd): parse all inline environment assignments (openclaw#117484) feat(web-fetch): add tools.web.fetch.headers for operator request headers (openclaw#115545) fix(qa): Slack progress lane misses successful delivery (openclaw#117391) refactor: deduplicate Codex prompt snapshot fixtures (openclaw#117476) ...
* origin/main: (27 commits) fix(plugins): compare authoring metadata by canonical JSON semantics (openclaw#117486) fix(doctor): reject contradictory lint check selectors (openclaw#117495) fix(anthropic): honor configured model pricing (openclaw#117275) refactor(plugins): reuse scoped loader for capability discovery (openclaw#117373) refactor(test): derive changed tooling routes (openclaw#117407) fix(kova): clarify extension memory attribution (openclaw#117500) fix(imessage): sanitize private context on every outbound path (openclaw#117501) fix(ci): align release validation fixtures (openclaw#117494) fix(talk): preserve owner authorization in realtime consults (openclaw#114163) fix(ui): surface aborted-run diagnostics (openclaw#117497) perf(models): skip Ollama row runtime loading (openclaw#117465) fix(cli): report user profile command outcomes (openclaw#117466) fix(active-memory): detect Chinese recall intent in escalate mode (openclaw#117338) (openclaw#117419) fix(workboard): ignore caller-supplied archivedAt when creating a card (openclaw#116412) fix(models): avoid waiting on promotions before listing models (openclaw#117322) refactor(plugins): inherit shared package boundary settings (openclaw#117474) fix(systemd): parse all inline environment assignments (openclaw#117484) feat(web-fetch): add tools.web.fetch.headers for operator request headers (openclaw#115545) fix(qa): Slack progress lane misses successful delivery (openclaw#117391) refactor: deduplicate Codex prompt snapshot fixtures (openclaw#117476) ...
* origin/main: (41 commits) fix(plugins): compare authoring metadata by canonical JSON semantics (openclaw#117486) fix(doctor): reject contradictory lint check selectors (openclaw#117495) fix(anthropic): honor configured model pricing (openclaw#117275) refactor(plugins): reuse scoped loader for capability discovery (openclaw#117373) refactor(test): derive changed tooling routes (openclaw#117407) fix(kova): clarify extension memory attribution (openclaw#117500) fix(imessage): sanitize private context on every outbound path (openclaw#117501) fix(ci): align release validation fixtures (openclaw#117494) fix(talk): preserve owner authorization in realtime consults (openclaw#114163) fix(ui): surface aborted-run diagnostics (openclaw#117497) perf(models): skip Ollama row runtime loading (openclaw#117465) fix(cli): report user profile command outcomes (openclaw#117466) fix(active-memory): detect Chinese recall intent in escalate mode (openclaw#117338) (openclaw#117419) fix(workboard): ignore caller-supplied archivedAt when creating a card (openclaw#116412) fix(models): avoid waiting on promotions before listing models (openclaw#117322) refactor(plugins): inherit shared package boundary settings (openclaw#117474) fix(systemd): parse all inline environment assignments (openclaw#117484) feat(web-fetch): add tools.web.fetch.headers for operator request headers (openclaw#115545) fix(qa): Slack progress lane misses successful delivery (openclaw#117391) refactor: deduplicate Codex prompt snapshot fixtures (openclaw#117476) ...
Fixes #116714
Original contributor: @synthalorian. Original issue reporter: @1Vision365-PeterTijsma.
What Problem This Solves
Explicit operator pricing under
models.providers.anthropic.models[].costwas silently overwritten by the Anthropic provider normalizer for both Claude Sonnet 5 and Claude Opus 5. The documented configured rates therefore never reached real assistant-usage cost calculation.Why This Change Was Made
The actual producer is
extensions/anthropic/register.runtime.ts:normalizeAnthropicResolvedModelreapplied Sonnet/Opus catalog pricing after an explicitly configured model rate was already present. Generalize its existing configured-model override detector from context alone to context or cost, and skip provider-default repricing only for an explicitly configured cost on that same provider/model.This maintainer takeover deliberately removes the original broad
src/plugins/runtime/runtime-llm.runtime.tsandsrc/utils/usage-format*changes. Provider-reported billed totals remain authoritative; this PR does not replace, hide, or reinterpret them. The fix stays entirely inside the Anthropic pricing owner, adds only five net production lines, and introduces no config options, dependencies, or migrations.User Impact
Configured per-million input, output, cache-read, and cache-write rates now determine estimated usage for both affected Anthropic model families. Unconfigured catalog defaults, the Sonnet promotional-price cutoff, explicit context overrides, Claude CLI pricing, and authoritative provider-billed totals keep their existing behavior.
Evidence
Actual production
buildAnthropicProvider().normalizeResolvedModelandcalculateCost, with 1,000 tokens in each category:Before, current main:
{"results":[{"modelId":"claude-sonnet-5","configuredRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"normalizedRate":{"input":2,"output":10,"cacheRead":0.2,"cacheWrite":2.5},"calculated":{"input":0.002,"output":0.01,"cacheRead":0.0002,"cacheWrite":0.0025,"total":0.014700000000000001},"configuredContext":321000,"defaultInputRate":2,"claudeCliInputRate":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}},{"modelId":"claude-opus-5","configuredRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"normalizedRate":{"input":5,"output":25,"cacheRead":0.5,"cacheWrite":6.25},"calculated":{"input":0.005,"output":0.025,"cacheRead":0.0005,"cacheWrite":0.00625,"total":0.036750000000000005},"configuredContext":321000,"defaultInputRate":5,"claudeCliInputRate":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}}]}After, exact contributor PR head
e0d28b5f115486555aea56623bd2562d988bee5d:{"results":[{"modelId":"claude-sonnet-5","configuredRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"normalizedRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"calculated":{"input":0.777,"output":0.888,"cacheRead":0.9990000000000001,"cacheWrite":0.666,"total":3.33},"configuredContext":321000,"defaultInputRate":2,"claudeCliInputRate":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}},{"modelId":"claude-opus-5","configuredRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"normalizedRate":{"input":777,"output":888,"cacheRead":999,"cacheWrite":666},"calculated":{"input":0.777,"output":0.888,"cacheRead":0.9990000000000001,"cacheWrite":0.666,"total":3.33},"configuredContext":321000,"defaultInputRate":5,"claudeCliInputRate":0,"providerBilled":{"total":42,"totalOrigin":"provider-billed"}}]}Both Sonnet and Opus preserve the configured
777/888/999/666rates and calculate0.777 + 0.888 + 0.999 + 0.666 = 3.33. The same production run also proves configured context remains321000, catalog defaults remain2/5, Claude CLI remains0, and a real provider-reported billed total remains42with originprovider-billed.Native focused owner test:
Result: 1 file passed; 51 tests passed, including both new real-plugin-plus-cost-calculator regressions.
The exact identical two-path patch was also validated on trusted Blacksmith Testbox lease
tbx_01kyyqv92jdej6v1e11hpy4rkc:node scripts/crabbox-wrapper.mjs run --provider blacksmith-testbox --id tbx_01kyyqv92jdej6v1e11hpy4rkc --timing-json -- bash -lc 'pnpm format:check extensions/anthropic/index.test.ts extensions/anthropic/register.runtime.ts && pnpm tsgo:extensions && pnpm tsgo:extensions:test && pnpm test extensions/anthropic/index.test.ts'Formatting, production extension typecheck, test extension typecheck, and all 51 tests passed; remote timing JSON reports
exitCode=0. The newly added two model regressions were also observed failing before the production fix. Fresh Codex Sol xhigh autoreview reports no accepted or actionable findings.The earlier ClawSweeper wrong-owner finding is resolved by deleting the plugin-runtime and usage-format patch entirely; the missing changed-surface proof is resolved by actual provider registration, normalization, cost calculation, both model-family regressions, and the before/after runtime transcripts above. No provider-billed compatibility change remains.