Skip to content

Say why a request has no price, and mark estimates in sessions - #27

Merged
fylorn merged 1 commit into
mainfrom
fix/say-why-there-is-no-price
Sep 16, 2026
Merged

fylorn merged 1 commit into
mainfrom
fix/say-why-there-is-no-price

Conversation

@fylorn

@fylorn fylorn commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

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.rs are
now shared by every query that counts cost states:

Meaning Fix
NO_PRICE usage known, the model has no price configure a price
NO_USAGE a response the upstream accepted (2xx, WebSocket 101, or a cancellation) without usage none; the money is missing

Neither 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, CostGroup gain no_usage_requests.
    unpriced_requests everywhere is NO_PRICE.

  • unpriced_recent, which backs the pricing page's list, counts only
    NO_PRICE rows.

  • SessionView gains cost_micros_estimated, priced_turns and
    no_usage_turns. unpriced_turns is NO_PRICE.

  • TurnView gains cost_estimated.

Why

The counts were wrong in four different ways.

  • Dashboard summary. The note says "these models are not in the price
    list". The count behind it was every per-token row with no cost, which
    included each failure and each response that never reported usage.
  • Time buckets, cost groups and sessions. These counted every null
    cost, so subscription calls were included too.
  • Pricing page. It exists to say "configure a price for these models",
    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. TurnView had no
cost_estimated, so the waterfall showed those amounts exactly like
measured ones, and the session total mixed both.

Why priced_turns. The desktop app decided "no turn had a price" by
computing turns - unpriced_turns. Once failures and subscription turns
stop counting as unpriced, that subtraction is wrong, so the count now
comes from the query.

How it was checked

New tests in db.rs:

  • a failure without usage is neither;
  • a midway failure with an unknown model is still unpriced;
  • a 200 without usage, an early cancellation and a WebSocket 101 count as
    no usage in the summary, buckets and groups, and a 400 counts as neither;
  • a subscription row is neither in buckets, groups or sessions;
  • the pricing page lists only a model with usage and no price;
  • a session reports its estimated part, priced turns, unpriced and
    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:

  • the summary's old predicate, which counts a failure as unpriced;
  • a 4xx counted as missing usage;
  • buckets counting every null cost;
  • the pricing page's old filter;
  • a session hiding its estimated part.

Gates: cargo fmt --check, cargo clippy --workspace --all-targets -D warnings,
cargo test --workspace (1,163 passed), ./scripts/smoke.sh (48 passed; the
memory warning read 37 MB, under the 40 MB regression line).

🤖 Generated with Claude Code

"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>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit 1ee6946 into main Sep 16, 2026
2 checks passed
@fylorn
fylorn deleted the fix/say-why-there-is-no-price branch September 16, 2026 15:24
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