Skip to content

fix(usage): model shares and order follow the selected metric - #11391

Merged
maria-rcks merged 1 commit into
pingdotgg:mainfrom
flamboh:t3code/add-usage-share-column
Oct 4, 2026
Merged

maria-rcks merged 1 commit into
pingdotgg:mainfrom
flamboh:t3code/add-usage-share-column

Conversation

@flamboh

@flamboh flamboh commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Note

🤖 Claude Opus 5.5 on behalf of Oliver

Problem

The Usage page's metric toggle switches provider shares between cost and tokens, but model shares always showed cost shares. ModelTotals only carried costShare. In Tokens mode the web model table's Share column showed each model's share of cost, for example 50.8% next to a model holding a fifth of the tokens. Mobile's "By model" list always showed "% of cost" and kept its cost ordering.

Fix

  • mergeUsage now derives tokenShare for each model, matching ProviderTotals.
  • Web: a small modelShare(model, metric) helper in usageBreakdown.ts picks the share for the selected metric. The table already sorts by tokens in Tokens mode (feat(usage): show cost by token type, speed, and model detail #15108), so only the Share column changes. Cost mode still leaves the share blank for a model with unknown cost. In Tokens mode an unpriced model shows its real token share.
  • Mobile: "By model" takes the metric. It orders by that metric, as the provider rows already do, and shows tokens and "% of tokens" in Tokens mode. Cost mode is unchanged.

Before / After

Web Usage page, Tokens metric, Model breakdown (real local usage history):

Before: Share is cost share, so it jumps around in a list sorted by tokens.
Before: model Share column shows cost shares in Tokens mode

After: Share is token share and falls down the list. The unpriced codex-auto-review shows its 1.7%.
After: model Share column shows token shares in Tokens mode

Mobile was not captured. It uses the same shared tokenShare and the existing provider-row pattern.

Verification

  • vp test run packages/shared/src/usageMerge.test.ts apps/web/src/components/usage/usageBreakdown.test.ts: model token shares are independent of cost shares, and modelShare follows the metric, including unpriced models.
  • Lint and fmt on the changed files; tsc --noEmit for packages/shared, apps/web, apps/mobile.
  • Web checked by hand in a dev server against real provider history.

Rebuilt from scratch on current main. The previous version conflicted after #15108 and the v2 merge, and used renderToStaticMarkup tests.

Made by Claude Opus 5.5 in Claude Code (via T3 Code).

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 12, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 12, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 5ea5b5b

Macroscope's review found this PR approvable — This is a narrowly scoped usage-display fix that derives token shares and keeps model shares, values, and mobile ordering aligned with the selected metric. The shared change is additive, existing cost behavior is preserved, and targeted tests cover the new calculations.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 57d04f88-4836-4c2b-b279-da6a09a49084
📥 Commits

Reviewing files that changed from the base of the PR and between 773d9fe and 5ea5b5b.

📒 Files selected for processing (6)
  • apps/mobile/src/features/usage/UsageRouteScreen.tsx
  • apps/web/src/components/usage/UsagePage.tsx
  • apps/web/src/components/usage/usageBreakdown.test.ts
  • apps/web/src/components/usage/usageBreakdown.ts
  • packages/shared/src/usageMerge.test.ts
  • packages/shared/src/usageMerge.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Model totals now include token shares. The web and mobile usage breakdowns select model shares, values, and ordering according to the active cost or token metric. The mobile view retains its unpriced display in cost mode.

Changes

Usage metric reporting

Layer / File(s) Summary
Token share aggregation
packages/shared/src/usageMerge.ts, packages/shared/src/usageMerge.test.ts
Model totals now include token share, calculated as the model’s tokens divided by merged total tokens, or zero when the total is zero. A test checks that token and cost shares can differ.
Web metric breakdown
apps/web/src/components/usage/usageBreakdown.ts, apps/web/src/components/usage/UsagePage.tsx, apps/web/src/components/usage/usageBreakdown.test.ts
The web breakdown selects token share or cost share according to the active metric. Cost share is unavailable for models with unknown cost; token share remains available.
Mobile metric breakdown
apps/mobile/src/features/usage/UsageRouteScreen.tsx
The mobile models section receives the selected metric, sorts models by that measure with the other measure as a tie-breaker, and displays the matching values and shares. Unknown-cost models retain their unpriced display in cost mode and show token data in token mode.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: t3dotgg

Merge Risk: ⚪ Minimal · up to 5ea5b

The metric-specific model shares appear ready to merge after normal checks. Mobile simulator rendering remains unverified, but no concrete rendering failure is established.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 5ea5b

The change is focused on percentage calculation and display. No expansion of data access or permissions was identified. Integration risk is limited to the shared value and its consumers.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — For the inspected changes, exposure remains within usage information already supplied to the selected views. Selecting token shares does not add environment targets, service calls, credentials, or authority to the rendering path.

Trust Boundaries and Controls

  • inferred — Usage-summary values flow through existing aggregation into numeric share selection and formatted display. The changed selectors do not convert summary content or metric choice into an identity, authorization, or privileged-operation decision. This conclusion does not establish the security of the underlying usage service.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the problem, the web and mobile changes, and focused verification. It does not provide the required scope-and-approval information, and it notes that mobile screenshots were n… Add the triaged issue or maintainer approval comment that establishes the change's scope. If this is an obvious bug fix that needs no prior approval, explain why. Add clear before-and-after screenshots for the mobile UI, or state why screen…
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Issue #14427 requires model shares to use cost in Cost mode and tokens in Tokens mode. packages/shared/src/usageMerge.ts derives tokenShare from model tokens and merged total tokens. `apps/web/src…
Out of Scope Changes check ✅ Passed All changes support issue #14427: shared token-share calculation, web and mobile metric-aware model breakdowns, and focused regression tests. The diff shows no unrelated changes.
Title check ✅ Passed The title clearly and concisely describes the main change: model shares and ordering follow the selected metric.
Full details: Description check

Explanation

The description explains the problem, the web and mobile changes, and focused verification. It does not provide the required scope-and-approval information, and it notes that mobile screenshots were not captured despite changes to the mobile UI.

Resolution

Add the triaged issue or maintainer approval comment that establishes the change's scope. If this is an obvious bug fix that needs no prior approval, explain why. Add clear before-and-after screenshots for the mobile UI, or state why screenshots cannot be provided and include suitable evidence of the change.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@greatitself

Copy link
Copy Markdown

Independent validation of e794fe6b3220e217922eb427ee5a7fd2ed05a164 (merge-base ca6416ec2d1d).

Checked 36 usage combinations with two distinct transcript sources plus a duplicate of the first source. The token-share denominator stayed deduplicated; unpriced model tokens retained their share independently of cost; zero-token cases returned finite zero shares. The same model aggregated correctly across distinct sources. This tests the shared merge logic only, not the web/mobile presentation.

Reproduction scripts and recorded results — second.mjs; the numbered metadata file pins this PR’s tested revisions.

Model: GPT-6. Harness: Codex.

@juliusmarminge juliusmarminge linked an issue Sep 30, 2026 that may be closed by this pull request
2 tasks done
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 1, 2026 — with ChatGPT Codex Connector
@flamboh
flamboh force-pushed the t3code/add-usage-share-column branch from 773d9fe to 5ea5b5b Compare October 4, 2026 01:35
@macroscopeapp
macroscopeapp Bot dismissed their stale review October 4, 2026 01:35

Dismissing prior approval to re-evaluate 5ea5b5b

@flamboh flamboh changed the title fix(usage): make model shares follow the selected metric fix(usage): model shares and order follow the selected metric Oct 4, 2026
@maria-rcks
maria-rcks merged commit 0c81120 into pingdotgg:main Oct 4, 2026
33 checks passed
github-actions Bot added a commit to davidvanderklay/t3code-flake that referenced this pull request Oct 4, 2026
## What's Changed
* feat(web): Nightly tells you to get the beta mobile app by @t3dotgg in pingdotgg/t3code#15070
* test(server): ACP adapter tests no longer race the prompt settle by @t3dotgg in pingdotgg/t3code#15330
* feat(usage): fold preview model IDs into the model they belong to by @t3dotgg in pingdotgg/t3code#15333
* refactor(server): check RPC scopes in group middleware by @juliusmarminge in pingdotgg/t3code#15324
* feat(mobile): beta Working section hides busy threads until they need you by @t3dotgg in pingdotgg/t3code#15346
* fix(settings): symlinked settings files stay linked when saved by @yordis in pingdotgg/t3code#15009
* fix(server): Stop ends a dev server left running before a provider switch by @t3dotgg in pingdotgg/t3code#15355
* fix(server): merged threads settle even after the agent wakes on its own by @t3dotgg in pingdotgg/t3code#15388
* fix(web): no-project drafts can switch machines by @maria-rcks in pingdotgg/t3code#15356
* fix(web): highlight tool inputs and remove nested work log indentation by @Yash-Singh1 in pingdotgg/t3code#15384
* fix(server): restarts keep delegated tasks, queued threads, and stops intact by @maria-rcks in pingdotgg/t3code#15323
* fix(web): sending past the resume banner compacts first by @maria-rcks in pingdotgg/t3code#15290
* fix(codex): resume archived native sessions by @maria-rcks in pingdotgg/t3code#15389
* feat(web): morph composer and panel action icons by @jakeleventhal in pingdotgg/t3code#14924
* fix(web): subagents sent a follow-up show as running in Lineage by @scratchyone in pingdotgg/t3code#15334
* fix(web): clear stale chat action shortcuts by @maria-rcks in pingdotgg/t3code#15394
* fix(orchestration-v2): restore earlier app agent transcript pages by @Bil0000 in pingdotgg/t3code#14104
* fix(web): remove the square thread info panel shadow by @PixPMusic in pingdotgg/t3code#15069
* fix(mobile): Android usage widget no longer sticks on "Loading widget" in release builds by @tris203 in pingdotgg/t3code#15142
* fix(web): size the model picker to its content by @saphid in pingdotgg/t3code#15152
* test(server): replay checks a Claude subagent's thread takes its reported model by @juliusmarminge in pingdotgg/t3code#15022
* fix(web): subagent finish notifications look like subagent cards by @flamboh in pingdotgg/t3code#15281
* fix(web): thread status dot has an accessible name by @ryanilano in pingdotgg/t3code#14587
* fix(web): legacy sidebar options button has a label by @ryanilano in pingdotgg/t3code#14602
* fix(web): imported themes keep switches and focus rings visible by @flamboh in pingdotgg/t3code#14498
* fix(web): links to issues no longer strand the pull request viewer by @flamboh in pingdotgg/t3code#14242
* fix(web): repo/task breadcrumb no longer bounces when the sidebar collapses by @flamboh in pingdotgg/t3code#15046
* fix(web): Pull request panel entry works for linked PRs by @flamboh in pingdotgg/t3code#15061
* fix(web): add context menu to draft threads in the sidebar by @flamboh in pingdotgg/t3code#10637
* fix(web): keep sidebar branding and build pills from clipping at varying font sizes and zoom levels by @flamboh in pingdotgg/t3code#12141
* fix(usage): model shares and order follow the selected metric by @flamboh in pingdotgg/t3code#11391
* feat(web): sweep sidebar buttons to settle, un-settle, and wake threads by @argofowl in pingdotgg/t3code#14768
* feat: retry a failed workspace preparation by @juliusmarminge in pingdotgg/t3code#15326

## New Contributors
* @argofowl made their first contribution in pingdotgg/t3code#14768

**Full Changelog**: pingdotgg/t3code@v0.0.46-nightly.20261003.2638...v0.0.46-nightly.20261004.2644

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.46-nightly.20261004.2644
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Oct 4, 2026
## What's Changed
* feat(web): Nightly tells you to get the beta mobile app by @t3dotgg in pingdotgg/t3code#15070
* test(server): ACP adapter tests no longer race the prompt settle by @t3dotgg in pingdotgg/t3code#15330
* feat(usage): fold preview model IDs into the model they belong to by @t3dotgg in pingdotgg/t3code#15333
* refactor(server): check RPC scopes in group middleware by @juliusmarminge in pingdotgg/t3code#15324
* feat(mobile): beta Working section hides busy threads until they need you by @t3dotgg in pingdotgg/t3code#15346
* fix(settings): symlinked settings files stay linked when saved by @yordis in pingdotgg/t3code#15009
* fix(server): Stop ends a dev server left running before a provider switch by @t3dotgg in pingdotgg/t3code#15355
* fix(server): merged threads settle even after the agent wakes on its own by @t3dotgg in pingdotgg/t3code#15388
* fix(web): no-project drafts can switch machines by @maria-rcks in pingdotgg/t3code#15356
* fix(web): highlight tool inputs and remove nested work log indentation by @Yash-Singh1 in pingdotgg/t3code#15384
* fix(server): restarts keep delegated tasks, queued threads, and stops intact by @maria-rcks in pingdotgg/t3code#15323
* fix(web): sending past the resume banner compacts first by @maria-rcks in pingdotgg/t3code#15290
* fix(codex): resume archived native sessions by @maria-rcks in pingdotgg/t3code#15389
* feat(web): morph composer and panel action icons by @jakeleventhal in pingdotgg/t3code#14924
* fix(web): subagents sent a follow-up show as running in Lineage by @scratchyone in pingdotgg/t3code#15334
* fix(web): clear stale chat action shortcuts by @maria-rcks in pingdotgg/t3code#15394
* fix(orchestration-v2): restore earlier app agent transcript pages by @Bil0000 in pingdotgg/t3code#14104
* fix(web): remove the square thread info panel shadow by @PixPMusic in pingdotgg/t3code#15069
* fix(mobile): Android usage widget no longer sticks on "Loading widget" in release builds by @tris203 in pingdotgg/t3code#15142
* fix(web): size the model picker to its content by @saphid in pingdotgg/t3code#15152
* test(server): replay checks a Claude subagent's thread takes its reported model by @juliusmarminge in pingdotgg/t3code#15022
* fix(web): subagent finish notifications look like subagent cards by @flamboh in pingdotgg/t3code#15281
* fix(web): thread status dot has an accessible name by @ryanilano in pingdotgg/t3code#14587
* fix(web): legacy sidebar options button has a label by @ryanilano in pingdotgg/t3code#14602
* fix(web): imported themes keep switches and focus rings visible by @flamboh in pingdotgg/t3code#14498
* fix(web): links to issues no longer strand the pull request viewer by @flamboh in pingdotgg/t3code#14242
* fix(web): repo/task breadcrumb no longer bounces when the sidebar collapses by @flamboh in pingdotgg/t3code#15046
* fix(web): Pull request panel entry works for linked PRs by @flamboh in pingdotgg/t3code#15061
* fix(web): add context menu to draft threads in the sidebar by @flamboh in pingdotgg/t3code#10637
* fix(web): keep sidebar branding and build pills from clipping at varying font sizes and zoom levels by @flamboh in pingdotgg/t3code#12141
* fix(usage): model shares and order follow the selected metric by @flamboh in pingdotgg/t3code#11391
* feat(web): sweep sidebar buttons to settle, un-settle, and wake threads by @argofowl in pingdotgg/t3code#14768
* feat: retry a failed workspace preparation by @juliusmarminge in pingdotgg/t3code#15326

## New Contributors
* @argofowl made their first contribution in pingdotgg/t3code#14768

**Full Changelog**: pingdotgg/t3code@v0.0.46-nightly.20261003.2638...v0.0.46-nightly.20261004.2644

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.46-nightly.20261004.2644
ohbentos pushed a commit to ohbentos/t3code that referenced this pull request Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Usage Tokens view calculates Share using cost instead of token count

4 participants