Skip to content

feat(usage): add thread and subagent breakdown - #9016

Closed
saphid wants to merge 5 commits into
pingdotgg:mainfrom
saphid:saphid/usage-thread-breakdown
Closed

saphid wants to merge 5 commits into
pingdotgg:mainfrom
saphid:saphid/usage-thread-breakdown

Conversation

@saphid

@saphid saphid commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

The Usage page shows which projects, providers and models spent tokens, but not which conversation spent them, so an unexpected cost can't be traced back to a thread.

What changed

  • Thread breakdown. A new server.getUsageThreadBreakdown RPC returns per-thread token and cost totals, with expandable subagent rows and daily cost components. The Usage page loads it on demand when the Thread breakdown is selected.
  • Attribution. The server maps provider sessions and dedicated worktrees (deepest claimed ancestor) to T3 threads. It uses one project snapshot per request and applies the same environment, project and provider-ownership filters as the summary. Unknown attribution, such as Grok sessions with no cwd, never counts as "Outside projects".
  • Bounds. Each environment returns at most 40 thread rows, and each row at most 40 agents. The rest roll up into "Other threads" and "Other subagents" rows that keep the totals. Exact-time windows longer than 24 hours are rejected before any transcript scan. Attribution read failures come back as typed errors instead of invented rows.
  • Clients. Web and desktop render the table; client-runtime adds the thread query atom, refreshed when prices change. Mobile has no thread view yet. docs/user/usage.md covers the new view.

Stack

Depends on #9015, which depends on #9014. The branch is #9014's three commits, #9015's commit (dcbaf50868), then this PR's single commit d41a62aaca. Review only the thread increment. Merge #9014 and #9015 first.

Rebuilt 2026-09-25 on current main (66129c6fd5). The previous head (c329b6d7d9) squashed an older, wider version of the stack. This head keeps only the thread breakdown. Dropped, as #9014 and #9015 already did:

  • the short-lived source-snapshot scan cache and the refreshToken contract field (the thread RPC now walks sources like the summary, and the file cache keeps the second walk warm)
  • the "segmented" Input variant and the refresh-lifecycle rewrite (retained statuses, refresh error toasts/alerts)
  • summary aggregator and scan-cache dedupe changes that belong to fix(usage): correct Claude cost accounting #9019's Claude accounting fix
  • the extra contract versions: this PR is v6 → v7 (thread-breakdown RPC only)

Kept from main: #12304's saved totals after transcript cleanup (the thread view folds the same retained files as the summary, so both reconcile after cleanup) and #11485's per-account scan directories and per-directory session counting. ProjectionThreadRepository.listByProjectId was removed as unused in #9917 and is restored here for worktree attribution. UsageThreadTable.test.tsx rendered static markup, which main no longer allows (#13104), so it was dropped. The subagent badges lost their font-normal/muted classes to satisfy the new shadcn(no-restyle) lint rule, arbitrary text sizes use the text-2xs/text-3xs/rounded-xs tokens, and the unused UsageThreadDailyChart export is now module-private (knip).

Verification

At head d41a62aaca:

  • vp test run on server usage + persistence repositories, web usage components and state, shared usageMerge/usageFormat, client-runtime state and contracts: 92 files, 1307 of 1309 passed. The two failures (uses explicit account settings…, does not share an in-flight scan…) fail identically on unmodified main on macOS and pass in CI.
  • Typecheck passed for t3, @t3tools/web, @t3tools/shared, @t3tools/contracts, @t3tools/client-runtime and @t3tools/mobile.
  • vp lint and vp fmt on the changed files pass.

UI

Before: main exposes model/day breakdowns

After: thread breakdown with daily cost and subagent rows

Breakdown recording: project → thread → expand → collapse

These captures were taken on 2026-09-05 from the integrated usage stack (#9308 at 7e24802) with synthetic data. They show this PR's thread table and expand/collapse behavior but were not re-captured at the rebuilt head. A fresh capture is still pending.

Coordination trace: T3 thread b9fe71d2-8f1e-4170-aa28-e6972b3797bf

Rebased and updated with Claude Opus 5 in Claude Code (T3 Code harness). Earlier revisions: GPT-6 and GPT-5.6 Sol in the Codex harness.

Closes discussions

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ 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.

2 participants