Skip to content

Avoid fabricated costs for unknown models - #429

Merged
tuo-lei merged 5 commits into
mainfrom
fix/unknown-model-cost-fidelity
Aug 7, 2026
Merged

tuo-lei merged 5 commits into
mainfrom
fix/unknown-model-cost-fidelity

Conversation

@tuo-lei

@tuo-lei tuo-lei commented Aug 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add non-fallback pricing lookup and cost-estimation APIs
  • omit replay and dashboard cost estimates when any model price is unknown
  • preserve existing legacy pricing APIs and known-model behavior
  • surface a data-quality explanation when tokens exist but cost cannot be estimated
  • reject unknown future Opus/Haiku minor versions instead of applying stale family rates

Why

Unknown OpenCode, Hermes, local, and future model IDs were silently priced at Sonnet rates. This produced a precise-looking dollar value with no evidence that the rate was applicable.

Compatibility

  • existing getModelPricing, estimateCost, and estimateCostSimple behavior is unchanged
  • new safe APIs are additive
  • replay/provider schemas are unchanged
  • known Claude and GPT-5.x cost estimates remain identical
  • token usage remains available when cost pricing is unknown

Validation

  • pnpm lint:check
  • pnpm typecheck
  • pnpm test
  • pnpm --filter @vibe-replay/provider-hermes test
  • pnpm test:cloudflare
  • pnpm build

Summary by CodeRabbit

  • Bug Fixes
    • Improved cost reporting for sessions using unknown or unsupported models.
    • Preserved token usage while leaving cost estimates unavailable when pricing cannot be determined.
    • Added clear data-quality notes when costs are unknown or cannot be attributed.
  • Tests
    • Added coverage for unknown models, partial pricing data, and local-model sessions.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 163cb426-f0ae-4518-980b-6d170cc7b651

📥 Commits

Reviewing files that changed from the base of the PR and between 6de2087 and 220cf34.

📒 Files selected for processing (2)
  • packages/replay-core/src/pricing.ts
  • packages/replay-core/test/pricing.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/replay-core/test/pricing.test.ts
  • packages/replay-core/src/pricing.ts

📝 Walkthrough

Walkthrough

The change adds known-only pricing APIs, preserves token usage when pricing is unavailable, and records standardized data-quality notes in scanner and viewer results.

Changes

Pricing quality

Layer / File(s) Summary
Known pricing resolution
packages/replay-core/src/pricing.ts, packages/replay-core/test/pricing.test.ts
Known-model lookup returns undefined for unsupported models and versions. Strict cost estimators return undefined for unknown or empty usage. Legacy Sonnet fallback behavior remains available through getModelPricing.
Scan cost-quality propagation
packages/replay-core/src/transform.ts, packages/cli/src/scanner.ts, packages/replay-core/test/transform-comprehensive.test.ts, packages/cli/test/scanner.test.ts
Transform and scanner paths use known-only estimators. Results preserve token usage and add an unknown-cost note when estimation is unavailable.
Viewer data-quality display
packages/viewer/src/components/DataQualityIndicator.tsx, packages/viewer/src/components/__tests__/data-quality-indicator.test.ts
The viewer reports unavailable cost estimates when a model exists without known pricing or attribution.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SessionScanner
  participant PricingHelpers
  participant ScanResult
  participant DataQualityIndicator
  SessionScanner->>PricingHelpers: Estimate cost from token usage
  PricingHelpers-->>SessionScanner: Known cost or undefined
  SessionScanner->>ScanResult: Preserve usage and add quality note
  ScanResult->>DataQualityIndicator: Provide model and cost metadata
  DataQualityIndicator-->>ScanResult: Display unavailable-cost note
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preventing fabricated cost estimates for unknown models.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/unknown-model-cost-fidelity

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Claude encountered an error after 0s —— View job


I'll analyze this and get back to you.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/replay-core/src/pricing.ts`:
- Around line 107-121: Reject versioned future major model IDs before the
generic family fallbacks in the pricing resolver, while preserving supported and
legacy Claude 3/4 IDs; update the version parsing or allowlist around the Opus,
Sonnet, and Haiku handling in packages/replay-core/src/pricing.ts:107-121. Add
assertions covering claude-opus-5, claude-sonnet-5, and claude-haiku-5 in
packages/replay-core/test/pricing.test.ts:107-114, expecting undefined pricing.

In `@packages/viewer/src/components/DataQualityIndicator.tsx`:
- Around line 36-37: Update DataQualityIndicator so the unavailable-cost note is
added whenever token usage exists and meta.stats.costEstimate is undefined,
regardless of whether meta.model is present. Add a corresponding test case in
packages/viewer/src/components/__tests__/data-quality-indicator.test.ts lines
56-64 covering token usage with no model and no cost estimate.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 18fe41d0-afe1-4fff-9363-d280966a20d0

📥 Commits

Reviewing files that changed from the base of the PR and between 13cd08f and 24f162e.

📒 Files selected for processing (8)
  • packages/cli/src/scanner.ts
  • packages/cli/test/scanner.test.ts
  • packages/replay-core/src/pricing.ts
  • packages/replay-core/src/transform.ts
  • packages/replay-core/test/pricing.test.ts
  • packages/replay-core/test/transform-comprehensive.test.ts
  • packages/viewer/src/components/DataQualityIndicator.tsx
  • packages/viewer/src/components/__tests__/data-quality-indicator.test.ts

Comment thread packages/replay-core/src/pricing.ts Outdated
Comment thread packages/viewer/src/components/DataQualityIndicator.tsx Outdated

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/replay-core/src/pricing.ts`:
- Around line 106-124: Update the Claude pricing selection logic around
hasUnsupportedClaudeMajor and the Opus, Sonnet, and Haiku branches to parse
complete version tokens in both family-first and major-first naming forms.
Reject any minor version greater than 6 before matching supported 4-5/4-6
pricing, using token-bounded matches so values such as 4-60 are not treated as
4-6. Add regression tests covering unsupported minors and both identifier
formats for each Claude family.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 22aa4267-fee3-451b-b73e-063a2082aa8d

📥 Commits

Reviewing files that changed from the base of the PR and between 24f162e and 2e07830.

📒 Files selected for processing (5)
  • packages/cli/src/scanner.ts
  • packages/replay-core/src/pricing.ts
  • packages/replay-core/test/pricing.test.ts
  • packages/viewer/src/components/DataQualityIndicator.tsx
  • packages/viewer/src/components/__tests__/data-quality-indicator.test.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/viewer/src/components/DataQualityIndicator.tsx
  • packages/replay-core/test/pricing.test.ts
  • packages/viewer/src/components/tests/data-quality-indicator.test.ts
  • packages/cli/src/scanner.ts

Comment thread packages/replay-core/src/pricing.ts Outdated

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/replay-core/src/pricing.ts`:
- Around line 141-145: Update the version parsing logic around the minorToken
handling to distinguish dated release suffixes from numeric minor versions,
rejecting numeric minor values above 6 rather than silently omitting them.
Ensure inputs such as 4-100 and another three-digit minor value are rejected and
cannot fall through to legacy Opus pricing, while preserving valid minor-version
and dated-suffix behavior; add regression coverage for both cases.
- Around line 112-117: Update the Sonnet pricing branch in the
version-resolution logic to use sonnetVersion?.major === 4 after the existing
4.5/4.6 special case, so major-first IDs such as claude-4-1-sonnet select
MODEL_PRICING["sonnet-4"] instead of the generic sonnet pricing.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3df04a32-ff7b-40df-a5ac-030890473418

📥 Commits

Reviewing files that changed from the base of the PR and between 2e07830 and 6de2087.

📒 Files selected for processing (2)
  • packages/replay-core/src/pricing.ts
  • packages/replay-core/test/pricing.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/replay-core/test/pricing.test.ts

Comment thread packages/replay-core/src/pricing.ts
Comment on lines +141 to +145
const minorToken = match[2];
return {
major: Number(match[1]),
...(minorToken && minorToken.length <= 2 ? { minor: Number(minorToken) } : {}),
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Reject numeric minor versions with three or more digits.

Line 144 discards a numeric minor token when it has more than two digits. claude-opus-4-100 then has no minor version, bypasses Line 107, and receives legacy Opus pricing at Line 110.

Distinguish dated release suffixes from numeric minor versions. Reject every numeric minor version above 6. Add regression coverage for 4-100 and another three-digit minor value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/replay-core/src/pricing.ts` around lines 141 - 145, Update the
version parsing logic around the minorToken handling to distinguish dated
release suffixes from numeric minor versions, rejecting numeric minor values
above 6 rather than silently omitting them. Ensure inputs such as 4-100 and
another three-digit minor value are rejected and cannot fall through to legacy
Opus pricing, while preserving valid minor-version and dated-suffix behavior;
add regression coverage for both cases.

@tuo-lei

tuo-lei commented Aug 7, 2026

Copy link
Copy Markdown
Owner Author

Final validation complete:

  • CodeRabbit: all three review rounds completed; every actionable comment is addressed; final incremental review reported no actionable comments
  • Required CI: lint, test, and build passed
  • Additional CI: E2E, Windows smoke, and audit passed
  • Local clean-environment full E2E passed on the final commit
  • Existing legacy pricing APIs remain unchanged; strict pricing APIs are additive
  • Public replay/provider schemas: unchanged
  • Known-model costs remain covered; unknown/future model costs are omitted with a data-quality explanation
  • Security scan of the diff: no credential patterns found

@tuo-lei
tuo-lei merged commit 787ac0d into main Aug 7, 2026
7 checks passed
@tuo-lei
tuo-lei deleted the fix/unknown-model-cost-fidelity branch August 7, 2026 07:56
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.

1 participant