Skip to content

refactor: dedup identical opus-tier rates in modelPricing EXACT_RATES (#4163) - #4259

Merged
atomantic merged 2 commits into
mainfrom
claim/issue-4163
Aug 15, 2026
Merged

refactor: dedup identical opus-tier rates in modelPricing EXACT_RATES (#4163)#4259
atomantic merged 2 commits into
mainfrom
claim/issue-4163

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

All five claude-opus-* rows in EXACT_RATES (server/lib/modelPricing.js) carried the same hand-copied [5.0, 25.0] literal, and the { test: /opus/i, rateModel: 'claude-opus-5' } entry in FAMILY_RULES had to be re-pointed at the newest id on every opus bump — migration 206 and every bump before it — purely to relabel the reported rateModel, since every opus row already resolved to the same numbers.

The tier now owns one OPUS_TIER_RATES pair plus a newest-first OPUS_MODEL_IDS list that generates its EXACT_RATES rows, and the family rule takes its pointer from the head of that list. An opus bump is now a one-line prepend — no second edit site.

Which fix shape, and why

The issue offered two shapes. I took shape 1 (shared constant, pointer derived rather than hand-written) instead of shape 2 (a family rule yielding rates inline), because rateModel is load-bearing downstream and shape 2 could not preserve it:

  • client/src/pages/UsagePage.jsx prints Priced as ${m.rateModel} in the per-model tooltip.
  • attributedModel() in server/services/usageReconciler.js compares two ids' resolved rateModel to decide whether a recorded launch model and a transcript model are the same family, and deliberately treats null as "not recognized, therefore not a match".

An inline-rates rule would have to report rateModel: null (breaking that comparison outright) or a synthetic label like claude-opus (which would stop matching the exact-table label, so opus and claude-opus-5 would no longer reconcile as one model). Keeping the pointer a real EXACT_RATES key avoids both while still retiring the per-bump edit — and it now cannot go stale or dangle, since it is derived from the list rather than typed.

No pricing or behavior change. A differential run of resolveModelRates and isFreeModelId over 954 provider/model pairs (every listed id, CLI shorthands, Bedrock-prefixed and suffixed variants, unlisted opus generations, local family:tag ids, and the fallback paths) returns byte-identical results before and after. No client mirror of this module exists — it is server-only.

Tests

server/lib/modelPricing.test.js gains an opus tier block pinning the three properties that made the hand-maintained pointer safe:

  • every listed opus generation bills at the same tier rates (matched: 'exact');
  • an opus id the table has never heard of (claude-opus-9, global.anthropic.claude-opus-7-…-v1:0) still prices at $5/$25 without a pointer bump — the invariant this refactor exists to guarantee;
  • the reported family label is itself a non-null, exactly-resolvable table id at the same rates, and every opus id agrees on it — the property usageReconciler and the usage tooltip depend on.

The existing opus shorthand assertion now checks the rates rather than hardcoding claude-opus-5, so the suite needs no edit at the next bump either; the new label test covers what that assertion used to.

Test plan

  • cd server && NODE_ENV=test npx vitest run lib/modelPricing.test.js services/usageReconciler.test.js — 89 passed.
  • cd server && NODE_ENV=test npm test — 29127 passed. Four files reported failures under this run, all pre-existing load flakes from concurrent suites (a different, non-overlapping set failed on a second run); services/loras.test.js, services/imageGenQuota.test.js, routes/settings.secretsStrip.test.js, and routes/imageGen.watermark.test.js all pass in isolation (93 passed) and none touch pricing.
  • Differential harness comparing pre- and post-change resolveModelRates/isFreeModelId across 954 pairs: 0 mismatches.

Closes #4163

…#4163)

All five claude-opus-* rows carried the same [5.0, 25.0] literal, and the
/opus/i FAMILY_RULES entry had to be re-pointed at the newest id on every
opus bump (migration 206 and every bump before it) purely to relabel the
reported rateModel — zero behavioral effect, two edit sites.

The tier now owns one OPUS_TIER_RATES pair and a newest-first
OPUS_MODEL_IDS list that generates its EXACT_RATES rows; the family rule
takes its pointer from the head of that list. An opus bump is a one-line
prepend.

The pointer stays a real EXACT_RATES key rather than becoming inline
rates on the family rule, because rateModel is load-bearing downstream:
UsagePage prints "Priced as <rateModel>", and usageReconciler compares
two ids' rateModel to decide whether a recorded and a transcript model
are the same family (a null or synthetic label would make 'opus' and
'claude-opus-5' stop matching). A differential run of resolveModelRates
and isFreeModelId over 954 provider/model pairs before and after returns
byte-identical results.
…ghten the family-label assertion

Sharing one OPUS_TIER_RATES array across all five keys meant a future edit
to a single opus row would silently rewrite the whole tier; each row now
owns its pair, matching the hand-written rows around it.

The family-label test asserted only expect.any(String); it now shape-matches
/^claude-opus-\d/ rather than hardcoding the current head id, which would
have reintroduced the per-bump edit this change removes.
@atomantic

Copy link
Copy Markdown
Owner Author

Review log — antigravity (agy), 2 rounds

Round 1 — 2 findings, both applied in e790d69:

  1. Shared array reference. Object.fromEntries(OPUS_MODEL_IDS.map((id) => [id, OPUS_TIER_RATES])) handed all five opus keys a reference to one array, so a future edit to a single opus row would have silently rewritten the whole tier. Each row now clones the pair, matching the hand-written rows around it.
  2. Weak test assertion. The family-label test asserted only expect.any(String). Tightened — but to toMatch(/^claude-opus-\d/) rather than the suggested hardcoded toBe('claude-opus-5'), since hardcoding the current head id would reintroduce exactly the per-bump edit this PR removes. The exact-resolution assertion immediately after is what actually pins the pointer to a real table key.

Round 2 — NO FINDINGS on the updated diff.

Re-verified after the fixes: lib/modelPricing.test.js, services/usageReconciler.test.js and lib/index.test.js pass (94 tests), and the differential harness still reports 0 mismatches across 954 provider/model pairs.

@atomantic
atomantic merged commit a38fbb8 into main Aug 15, 2026
7 checks passed
@atomantic
atomantic deleted the claim/issue-4163 branch August 15, 2026 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dedup identical opus-tier rate rows in modelPricing.js EXACT_RATES

1 participant