Skip to content

fix(pricing): skip unusable exact price entries - #658

Merged
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/pricing-safety-20260601
Jun 4, 2026
Merged

fix(pricing): skip unusable exact price entries#658
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/pricing-safety-20260601

Conversation

@IvGolovach

@IvGolovach IvGolovach commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Ignore exact pricing matches whose pricing object has no usable price fields, allowing a priced fallback source to win.
  • Keep explicit finite zero-price entries valid, so free or zero-base provider overrides are not accidentally rejected.
  • Prevent unknown future Claude 4.x minor variants from degrading to older Claude 4 pricing.

Why

Exact lookup paths could return a ModelPricing entry where every price field was None. That made the resolver stop early and report zero cost even when another pricing source had usable prices for the same model. The same resolver family also needed a guard against mapping unknown future Claude 4.x variants onto older lower-version Claude 4 rows, which can silently produce misleading cost estimates.

Related issues: #548, #631.

Diff scope

  • crates/tokscale-core/src/pricing/lookup.rs: filters exact and provider-prefixed direct matches through the existing usable-pricing rules before returning them.
  • crates/tokscale-core/src/pricing/lookup.rs: adds Claude 4.x minor-version guards so unrecognized future minor variants stay unknown instead of falling through to legacy lower-version pricing.
  • crates/tokscale-core/src/pricing/lookup.rs: adds regression coverage for unusable exact entries, provider-prefixed fallback behavior, valid zero-price entries, and unknown future Claude minor variants.

Branch integrity

  • Base branch: main.
  • Validated base SHA: a86e688d620939d2c973c6d5625baa815ea223d7.
  • Ahead/behind: 0 behind / 1 ahead against origin/main.
  • Merge base: a86e688d620939d2c973c6d5625baa815ea223d7.
  • Fast-forward safety: origin/main is an ancestor of this branch.

Commit integrity

  • Introduced commit: efcba6c32f1b7941f3b417e35a1eb5630431a5f0 fix(pricing): skip unusable exact price entries.
  • The PR contains one logical change scoped to pricing resolver safety and regression coverage.
  • Ledger: not applicable — not required for this change family.
  • Version: not applicable — release workflow owns package version bumps.

Diff hygiene

  • git diff --name-status origin/main...HEAD: only crates/tokscale-core/src/pricing/lookup.rs changed.
  • git diff --check origin/main...HEAD: PASS, no output.

Validation mode and proof

Mode 2 — narrow runtime change, because the diff changes localized pricing lookup behavior and focused tests without touching migrations, auth, deployment tooling, or external service contracts.

  • TDD red proof: the all-None exact shadowing case and unknown Claude minor fallback tests failed before the implementation.
  • cargo test -p tokscale-core pricing::lookup::tests -- --nocapture: PASS, 143 tests.
  • cargo fmt --all -- --check: PASS, no output.
  • git diff --check origin/main...HEAD: PASS, no output.
  • Not run: full workspace test suite — not required for selected validation mode; targeted pricing lookup tests cover the changed resolver behavior.

Required remote gates

Pending — GitHub Actions and mergeability checks will run after the PR is opened.

Migration notes

Not applicable — no database migration changed.

Runtime safety

The change narrows resolver acceptance for unusable exact rows and preserves the existing finite-price validation path. It does not add external I/O, persistent state, concurrency, or new pricing data sources. No invariant regression introduced.

Documentation integrity

Not applicable — no docs, commands, or runbooks changed.

Rollback plan

Rollback: revert this PR. DB downgrade: not applicable. Data repair: not applicable. Operational caveats: reverting would restore early returns for unusable exact pricing rows and the older Claude minor-version fallback behavior.

Known residual risks

Remote CI and GitHub mergeability are pending until the PR is opened. The resolver intentionally treats unknown future Claude minor versions as unknown pricing rather than estimating from older lower-version rows.


Summary by cubic

Skip exact and derived matches that have no usable price fields, so the resolver falls back to a priced source instead of reporting zero cost. Unknown Claude 4.x minor variants now stay unpriced instead of degrading to Claude 4; explicit 0.0 prices remain valid.

  • Bug Fixes
    • Filter exact, provider-prefixed, and model-part matches across LiteLLM, OpenRouter, and Cursor to only return usable pricing; otherwise allow fallback.
    • Prefer stripped/priced entries when a provider-exact row exists but has no prices.
    • Keep unknown Claude 4.x minor variants unknown and block numeric-suffix stripping that would map them to 4; no degradation across prefixes.
    • Added tests for unusable exact/model-part entries, stripped fallbacks, valid zero-price entries, and future Claude 4 minor variants.

Written for commit 5d657da. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview Jun 4, 2026 9:41pm

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

Validation
* Validation tier: Tier 2R - post-merge rebase correction for pricing lookup conflict with junhoyeo#614.
* git diff --check origin/main...HEAD: PASS.
* git diff --cached --check: PASS.
* cargo fmt --all -- --check: PASS.
* cargo test -p tokscale-core pricing::lookup::tests: PASS, 143 passed.
* cargo clippy -p tokscale-core --all-targets -- -D warnings: PASS.
* Ledger: not applicable - not required for selected validation tier/change family.
* Version: not applicable - release workflow owns package version bumps.
* Not run: full workspace cargo test - not required for selected validation tier; targeted lookup tests cover resolver behavior and mandatory remote CI will run on the final PR SHA.

Rollback
* git revert HEAD
@IvGolovach
IvGolovach force-pushed the codex/pricing-safety-20260601 branch from efcba6c to 5d657da Compare June 4, 2026 21:40
@IvGolovach
IvGolovach merged commit 5c1fe65 into junhoyeo:main Jun 4, 2026
14 checks passed
@IvGolovach
IvGolovach deleted the codex/pricing-safety-20260601 branch June 4, 2026 22:06
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.

2 participants