Skip to content

fix(reports): allow local report commands to run without live pricing#375

Merged
junhoyeo merged 2 commits intojunhoyeo:mainfrom
IvGolovach:fix/offline-report-pricing
Apr 6, 2026
Merged

fix(reports): allow local report commands to run without live pricing#375
junhoyeo merged 2 commits intojunhoyeo:mainfrom
IvGolovach:fix/offline-report-pricing

Conversation

@IvGolovach
Copy link
Copy Markdown
Contributor

@IvGolovach IvGolovach commented Mar 30, 2026

Summary

  • keep local report commands usable when live pricing fetches fail by falling back to cached pricing or token-only output
  • add regression coverage for offline report paths and make affected CLI tests hermetic

Why

Local report commands currently abort when LiteLLM or OpenRouter pricing cannot be fetched, even though the underlying token and message data comes from local session files. That makes Tokscale unnecessarily fragile offline, behind strict firewalls, or during temporary network outages. This change keeps local reporting available without requiring live pricing.

Diff scope

  • reuse the existing tolerant pricing loader for local model and monthly reports
  • add a local-report graph path for CLI graph so it can degrade gracefully without live pricing
  • preserve the existing stricter graph-based paths used by submit and wrapped
  • add CLI regression tests for offline no-cache and stale-cache report behavior
  • make the affected CLI tests hermetic so they no longer depend on the real machine or network

Test proof

  • cargo test -p tokscale-core
    • 442 passed, 0 failed, 1 ignored
  • cargo test -p tokscale-cli
    • unit tests: 294 passed, 0 failed, 1 ignored
    • integration tests: 70 passed, 0 failed
  • cargo clippy -p tokscale-core --all-features -- -D warnings
    • passed
  • cargo clippy -p tokscale-cli --all-features -- -D warnings
    • passed
  • cargo fmt --all --check
    • passed
  • git diff --check
    • passed

Verification-pack proof

Not applicable - CLI/core local reporting change only.

Migration notes

Not applicable - no schema or data migration.

CI context confirmation

CI context names unchanged.

Rollback plan

  • if merged with a merge commit: git revert <merge_commit_sha>
  • if merged as a squash commit: git revert <squash_commit_sha>
  • no DB downgrade required

Known residual risks

  • this change does not introduce an explicit --offline or --no-pricing flag; it makes local report commands degrade gracefully when live pricing is unavailable
  • offline runs may still print pricing fetch warnings to stderr before falling back to cached pricing or token-only output
  • submit and wrapped intentionally keep their existing behavior in this PR scope

Related

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 30, 2026

@IvGolovach is attempting to deploy a commit to the Inevitable Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 3 files

…icing

# Conflicts:
#	crates/tokscale-cli/src/main.rs
#	crates/tokscale-cli/tests/cli_tests.rs
#	crates/tokscale-core/src/lib.rs
Copy link
Copy Markdown
Owner

@junhoyeo junhoyeo left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@junhoyeo junhoyeo merged commit 82cd4cf into junhoyeo:main Apr 6, 2026
13 of 14 checks passed
junhoyeo added a commit that referenced this pull request Apr 7, 2026
Add totalCost assertions to existing offline-no-cache tests,
stale-cache tests for monthly and graph commands, and a test
proving submit still fails offline with strict pricing guard.

Constraint: embedded costs from OpenCode fixtures (0.05+0.03+0.02=0.10) are preserved when pricing is None
Constraint: stale-cache pricing overrides embedded costs (totalCost=0.0209)
Confidence: high
Scope-risk: narrow
@IvGolovach IvGolovach deleted the fix/offline-report-pricing branch April 7, 2026 03:29
junhoyeo added a commit that referenced this pull request Apr 7, 2026
* test(cli): add missing offline report coverage from PR #375 review

Add totalCost assertions to existing offline-no-cache tests,
stale-cache tests for monthly and graph commands, and a test
proving submit still fails offline with strict pricing guard.

Constraint: embedded costs from OpenCode fixtures (0.05+0.03+0.02=0.10) are preserved when pricing is None
Constraint: stale-cache pricing overrides embedded costs (totalCost=0.0209)
Confidence: high
Scope-risk: narrow

* fix(test): assert submit offline test fails due to pricing, not bad args

The test was passing because --no-spinner is not a valid submit flag,
causing an argument parse error instead of a pricing failure.

Removed --no-spinner (submit doesn't have it), added stderr assertions
to verify failure is from pricing/network error path, not auth or args.

Confidence: high
Scope-risk: narrow
@junhoyeo
Copy link
Copy Markdown
Owner

junhoyeo commented Apr 7, 2026

@IvGolovach deployed in https://github.com/junhoyeo/tokscale/releases/tag/v2.0.20! thanks a lot 🎉

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