Skip to content

feat: count a session's subscription turns, and say how each turn was billed - #49

Merged
fylorn merged 1 commit into
mainfrom
feat/subscription-turns
Sep 19, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/subscription-turns

Conversation

@fylorn

@fylorn fylorn commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Groundwork for the desktop's sessions page, which labels a session served entirely by a subscription upstream (Codex on a ChatGPT account, say) as "cannot be priced", while the overview reports the same requests as subscription usage.

Why the page could not do better

The session aggregation already kept subscription rows out of the money: a_subscription_row_is_neither_anywhere checks that such a row is neither priced, unpriced nor no-usage. But SessionView had no fourth count, so a session made only of subscription turns came back as priced_turns = unpriced_turns = no_usage_turns = 0, which is the same shape as a session where nothing could be priced. TurnView had the same gap one level down: a subscription turn has cost_micros: None, and nothing else on the turn said why.

What changes

  • SessionView.subscription_turns: turns served by a subscription upstream. It does not overlap the three existing counts (those only count per-token rows) and counts the same rows as the overview's subscription_requests. Both queries now share one SUBSCRIPTION predicate, the way NO_PRICE and NO_USAGE are shared, so the two numbers cannot drift apart.
  • TurnView.billing: same vocabulary as HistoryRow.billing (per-token / subscription / free / unknown).

Both fields are required on the wire, with no serde(default), because nothing reads an older shape.

Tests

  • tw-store: a_session_counts_its_subscription_turns_as_what_they_are covers a session mixing subscription turns (including one that broke mid-stream), a priced turn and an unpriced one. Each lands in exactly one count, the session's subscription count equals the overview's, and every turn carries its billing.
  • tw-control: new tests/sessions.rs checks the JSON the desktop receives from /sessions and /sessions/{id}, both for an all-subscription session and for a mixed one.

fmt, clippy -D warnings, cargo test --workspace and ./scripts/smoke.sh (51 passed; the 36 MB memory note is reported by smoke as over target but not a regression) all pass locally.

Releasing is a separate step. The desktop change that renders these fields will pin whichever tag includes this.

🤖 Generated with Claude Code

… billed

A session served entirely by a subscription upstream (Codex on a ChatGPT
account, say) came back with zero priced, zero unpriced and zero no-usage
turns, and SessionView had no fourth number. The desktop could not tell it
from a session where nothing could be priced, so it said "cannot be
priced" while the overview reported the same requests as subscription
usage.

- SessionView carries subscription_turns. It is disjoint from the three
  existing counts (those only count per-token rows) and counts the same
  rows as the overview's subscription_requests: both now use one
  SUBSCRIPTION predicate, the way NO_PRICE and NO_USAGE are shared, so the
  two numbers cannot drift apart.
- TurnView carries billing, in the same vocabulary as HistoryRow.billing.
  A subscription turn has no cost_micros either, and the amount alone
  cannot tell it from a turn without a price.

Both fields are required on the wire; nothing reads an older shape.

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 20e5b6b into main Sep 19, 2026
2 checks passed
@fylorn
fylorn deleted the feat/subscription-turns branch September 19, 2026 17:43
@fylorn fylorn mentioned this pull request Sep 20, 2026
fylorn added a commit that referenced this pull request Sep 20, 2026
Sessions report how many of their turns a subscription upstream served,
and each turn says how it was billed (#49). The desktop needs the tag to
pin: until now a session served entirely by a subscription was
indistinguishable, in the protocol, from one where nothing could be
priced, and the sessions page called it "cannot be priced".

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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