fix: estimate cost when stored zero is placeholder#4
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a cost-reporting edge case where OpenCode stores cost: 0 as a placeholder despite nonzero token usage, causing oc-stats to display $0 everywhere by always trusting stored costs. It introduces a default behavior to estimate costs when a stored zero looks like a placeholder, with an opt-out CLI flag to preserve the previous “trust stored zero” behavior.
Changes:
- Add
ZeroCostBehaviorand centralizedupdate_price_summaryhelper to resolve stored-vs-estimated cost consistently. - Thread
zero_cost_behaviorthrough analytics snapshot + UI app wiring, and add--keep-zeroCLI flag. - Add/adjust tests and document the new default + opt-out behavior in the README.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/pricing.rs | Introduces ZeroCostBehavior and update_price_summary with unit tests for placeholder-zero handling. |
| src/ui/app.rs | Stores and propagates zero_cost_behavior into snapshot recomputation. |
| src/main.rs | Adds --keep-zero flag and maps it to ZeroCostBehavior passed into the app. |
| src/analytics/model_stats.rs | Switches model/provider cost accumulation to the shared update_price_summary helper. |
| src/analytics/mod.rs | Updates snapshot building to use update_price_summary and threads zero_cost_behavior through chart builders; updates/adds tests. |
| README.md | Documents the new default estimation behavior and the --keep-zero opt-out. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
There's a clear counterexample: model calls under OpenAI Codex subscription. They would have issues with this strategy. When using OAuth to log into Codex, all cost values for openai provider model calls (like gpt-5.4) are correctly recorded as 0. Treating 0 as a placeholder would fallback to models.dev's OpenAI API-based pricing logic. The result would be a discrepancy exactly matching my Codex usage cost compared to what I'm curious what you mean specifically by "some OpenCode setups store zero cost for nonzero-token responses". The previous default behavior should display something like |
|
My motivation was using this with my OpenAI Codex subscription. I wanted to estimate how much it would have cost me if I didn't have the subscription. That being said, I agree that a more consistent design would be the current behavior by default but add an |
Preserve existing behavior by default and add --ignore-zero for setups that write placeholder zero costs. Reuse the same pricing path in daily aggregation so analytics views stay consistent.
# Conflicts: # src/main.rs
|
I'm sorry for the delay. I changed it to default Keep Zero, and then optionally ignore Zero. |
Why: some OpenCode setups store zero cost for nonzero-token responses, which makes oc-stats show zero cost everywhere because it always trusts stored cost values. Fix: estimate pricing when stored cost is zero on nonzero-token events by default, add a --keep-zero flag to preserve the original behavior, and cover the new behavior with tests and docs.