Repository navigation
A stream that fails midway keeps the usage the upstream billed - #26
Merged
Merged
Conversation
A stream the upstream breaks, or the tool firewall cuts, has usually been billed by then: the full input as soon as the upstream started answering, and the output up to the cut. RequestFailed carried none of it, so the recorder wrote the row without tokens or cost, and the money was never in the totals. RequestFailed gains optional `bytes`, `duration_ms` and `usage`. The ending fills them from what it has seen: bytes once the response headers have arrived (a failure before them received nothing, and 0 would read as an empty response), the elapsed time for every failure, and the sniffed usage. The recorder now writes failures through the same path as the other two endings, so a failure with usage gets tokens and a price, marked estimated for the same reason as a cancellation: the output count is cut short. It still counts as failed. A stream cut by the tool firewall reported source `upstream`. It now reports the error's own source, `denied`, like the WebSocket cut: the upstream did not break, a policy stopped it. Checked against the broken versions: a failure without usage, a cut reported as `upstream`, a failure priced as exact, and the recorder dropping a failure's usage each fail their tests. The smoke script's firewall stream now reports input usage in message_start, and the cut request must reach /history with those tokens and an estimated cost. 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. |
fylorn
added a commit
that referenced
this pull request
Sep 16, 2026
) "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>
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 fourth gap listed in #24. A stream the upstream breaks, or the
tool firewall cuts, now records the usage that was already billed, with a
price.
RequestFailedgains optionalbytes,duration_msandusage, all#[serde(default, skip_serializing_if = "Option::is_none")]:bytes: present once the response headers have arrived.duration_ms: present for every failure.usage: whatever the sniffer saw before the failure.usage gets tokens and a cost marked estimated, and still counts as failed.
RequestPricedis reported for failures too.denied, notupstream, matching the WebSocket cut from Every request that starts reports how it ended #25.Why
By the time a stream breaks midway, the upstream has usually billed the
full input (
message_startarrives first) and the output up to the break.RequestFailedcarried no usage, so the recorder wrote failures withouttokens or cost, and that money never appeared in any total.
Why the cost is estimated. It is the same reason as a cancellation: the
cumulative output count arrives only at the end of the stream, so the
amount at a break is a lower bound.
Why
bytesis absent before the response headers. A failure beforethem received no response at all; reporting 0 would read as an empty
response.
Why a firewall cut is
denied. The upstream did not break; a policystopped the response. The stream now reports the error's own source, the
same change #25 made for requests every upstream refused.
How it was checked
tests/endings.rs:RequestFailedcarries the bytes and the 5,000 inputtokens from
message_start.curl | shtool call reportsdeniedand keeps itsusage.
estimated cost.
scripts/smoke.sh: the fake upstream's firewall stream now reports inputusage in
message_start, and the cut request must reach/historywiththose tokens and an estimated cost.
Each test was run against the broken version it guards, and each fails:
upstream;Gates:
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(1,157 passed),./scripts/smoke.sh(48 passed; thememory warning read 36 MB this run).
🤖 Generated with Claude Code