Repository navigation
Say why a request has no price, and mark estimates in sessions - #27
Merged
Merged
Conversation
"No price" was counted four different ways, and none matched what the interface says. The dashboard's note reads "these models are not in the price list", but the summary counted every row without a cost on per-token billing: each failed request, and each response that never reported usage. Time buckets, cost groups and sessions counted every null cost, subscription calls included. The pricing page, which exists to say "configure a price for these models", listed failures and missing usage too, and a price fixes neither. Two predicates now define it, and every query uses them: - no price: the usage is known and the model has no price. Configuring a price fixes it. - no usage: a response the upstream accepted (a 2xx, a WebSocket 101, or a cancellation) arrived without usage. The money is missing from the total, and no price can fix it. A failure without usage is neither: a request that failed before any response is not billed, and one that failed midway carries its usage since #26. A 4xx response is not billed either. Subscription calls stay outside both, as the summary already had them. Summary, CostBucket and CostGroup gain `no_usage_requests`, and the pricing page lists only models a price would fix. Sessions could present an estimate as exact. TurnView had no `cost_estimated`, so the waterfall showed a cancelled turn's lower bound exactly like a measured amount, and SessionView's total mixed the two. TurnView gains `cost_estimated`. SessionView gains `cost_micros_estimated`, and `priced_turns` and `no_usage_turns`, so the desktop app stops deriving "no turn had a price" from `turns - unpriced_turns`, a subtraction that is wrong once failures and subscription turns no longer count as unpriced. Workspace version 0.1.2, for the release the desktop app will pin. Each new test was run against the broken version it guards: the summary's old predicate counts a failure as unpriced; counting a 4xx as missing usage, buckets counting subscription rows, the pricing page's old filter, and a session hiding its estimated part each fail their test. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Fixes the last two gaps listed in #24, and bumps the workspace to 0.1.2 for
the release the desktop app will pin.
What "no price" means. Two SQL predicates in
tw-store/src/db.rsarenow shared by every query that counts cost states:
NO_PRICENO_USAGENeither predicate counts:
a failure without usage, which is not billed before a response and
carries usage when it fails midway (A stream that fails midway keeps the usage the upstream billed #26);
a 4xx response, which is not billed;
subscription calls, whose cost is not a price at all.
Summary,CostBucket,CostGroupgainno_usage_requests.unpriced_requestseverywhere isNO_PRICE.unpriced_recent, which backs the pricing page's list, counts onlyNO_PRICErows.SessionViewgainscost_micros_estimated,priced_turnsandno_usage_turns.unpriced_turnsisNO_PRICE.TurnViewgainscost_estimated.Why
The counts were wrong in four different ways.
list". The count behind it was every per-token row with no cost, which
included each failure and each response that never reported usage.
cost, so subscription calls were included too.
yet it listed failures and missing usage, which a price cannot fix.
Why "no usage" is its own count rather than dropped. A response without
usage (a relay that strips it, a cancellation before the first frame, a
WebSocket session) usually cost money that is missing from the total.
Removing it from "no price" without counting it elsewhere would make the
total quietly low with nothing to signal it. It is counted separately
because the interface has to say something different about it.
Why sessions needed estimates. Since #24, a cancelled turn's cost is a
lower bound, and since #26 so is a failed stream's.
TurnViewhad nocost_estimated, so the waterfall showed those amounts exactly likemeasured ones, and the session total mixed both.
Why
priced_turns. The desktop app decided "no turn had a price" bycomputing
turns - unpriced_turns. Once failures and subscription turnsstop counting as unpriced, that subtraction is wrong, so the count now
comes from the query.
How it was checked
New tests in
db.rs:no usage in the summary, buckets and groups, and a 400 counts as neither;
no-usage turns, and each turn's
cost_estimated.The existing three-state tests still pass unchanged.
Each new test was run against the broken version it guards, and each
fails:
Gates:
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(1,163 passed),./scripts/smoke.sh(48 passed; thememory warning read 37 MB, under the 40 MB regression line).
🤖 Generated with Claude Code