Skip to content

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

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

feat(usage): add thread and subagent breakdown#9016
saphid wants to merge 69 commits into
pingdotgg:mainfrom
saphid:saphid/usage-thread-breakdown

Conversation

@saphid

@saphid saphid commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

What Changed

The Usage page can drill a project, provider, or model total down to its originating threads and expandable subagent rows, including daily cost components. The server maps provider sessions and dedicated worktrees to T3 threads, keeps final progressive snapshots, and returns typed failures when attribution data cannot be read instead of inventing rows.

Why

Aggregate spend identifies what was used but not which conversation produced it. Thread attribution makes unexpected cost traceable while preserving project boundaries, platform-specific path behavior, row caps, and the same immutable records and read time used by the summary.

Stack and Review Scope

This PR is cumulative and lands after #9015. Review the thread/subagent increment; later PRs include this stack.

Verification

Current candidate a67d8f25442c06f9caec12d6173d96256a6130e6 includes upstream main 39802c06117fae0b3da43624b0d54309c5437c72. The focused UsageService and chart-gesture suites passed (36 tests), and the server package typecheck passed. Repository failure doubles follow the current imported-transcript interface. Earlier evidence below retains its stated revision and scope; integrated web evidence and its attribution limits are described below.

A direct Claude Opus 5 high review attempt for this integration batch exited 1 because OAuth expired; no Claude review occurred.

Candidate: c3dab9986a533784af56cfca5ebd3f381b21cd25, including upstream main 82c2b7ffb4d450572f5baf9a70693f1e25cfdfed.

  • The full focused contribution check at ba873b8 passed 171 tests across 12 files, plus the affected package typechecks.
  • The final 82c2b7f delta removes an unused pricing helper: 7 pricing tests, server typecheck, Knip and git diff --check passed on the pre-repair main composition. The chart/runtime contribution was unchanged by that final delta.
  • The chart merge preserves upstream's live column builder and this PR's daily/hourly and range behavior. Fresh independent source review of the shared resolution found no actionable issues.
Focused commands
vp test run apps/server/src/usage/UsageService.test.ts apps/server/src/usage/usageAggregation.test.ts apps/server/src/usage/usagePaths.test.ts apps/server/src/usage/usageScanCache.test.ts apps/server/src/usage/usageThreads.test.ts apps/server/src/usage/usageTranscriptReader.test.ts apps/web/src/components/usage/UsagePage.test.tsx apps/web/src/components/usage/UsageThreadTable.test.tsx apps/web/src/state/usage.test.ts packages/shared/src/usageMerge.test.ts apps/web/src/components/usage/UsageProviderChart.test.ts
vp run --filter t3 typecheck
vp run --filter @t3tools/web typecheck
vp run --filter @t3tools/client-runtime typecheck
vp run --filter @t3tools/contracts typecheck
vp run --filter @t3tools/shared typecheck
vp test run apps/server/src/usage/usagePricing.test.ts
vp run --filter t3 typecheck

Refresh correctness checks

The refresh repair passed the focused UsageService suite (16 tests), 3 chart-gesture regression tests, and 8 web usage-state tests. After the final thread-cache guard, 2 affected service tests were rerun and passed; the earlier full-suite count is not presented as a new full-suite run. The optional thread-refresh contract passed 2 schema tests and the contracts package typecheck. Server and web package typechecks, changed-file formatting/lint and diff checks passed. Independent source review found no actionable issue in this frozen repair.

These repairs cancel a chart gesture if its date window changes, let each environment progress after its own pricing request, and coalesce concurrent tokened summary scans. Thread-enabled branches await their environment summary before refreshing thread rows. The source-scan revision guard prevents older aggregation from pruning files discovered by a newer scan. Integrated web evidence and remaining client limits are described below.

UI Changes

The thread breakdown lists three conversations, expands checkout into daily cost and the accessibility subagent, and collapses back to summary rows. The integration retains this PR’s open-row/toggle behavior; later stack changes add navigation controls and cache-write columns.

Before: upstream main 39802c06117fae0b3da43624b0d54309c5437c72. After: cumulative #9308 integration 7e248026469ec7be6d5c2bdaccf86f380e0c2476, captured in an isolated web preview with two synthetic projects, three conversations and generated transcripts. This reuses the retained feature in the integrated stack; it is not a separate capture of this PR’s individual head. Focused tests above were run on the individual published head. The 30-day preset ends at the last complete day on the integration; main includes the current day. Both captures contain the same fourteen days of synthetic usage.

Before: main exposes model/day breakdowns

After: integrated coverage and cache-write breakdown controls

Clean breakdown recording · Annotated breakdown recording. This shows project → thread → expand → collapse; idle time is trimmed from 109.7 s to 12.57 s, without a performance claim.

Limits: The fixture uses a single environment. Cross-environment attribution, truncation and failure paths remain covered by focused tests rather than this recording. No React Native or SwiftUI mobile capture is represented here. Clean/annotated packet validation passed; uploaded derivatives were retrieved and hash-verified.

Checklist

  • The intended increment is focused; its cumulative dependencies are identified above.
  • I explained what changed and why.
  • Integrated before/after screenshots are attached and their revisions are identified.
  • Integrated thread expansion/collapse recording is attached; source attribution and limits are stated.

Implemented and reviewed with GPT-6 and GPT-5.6 Sol in the Codex harness. A direct Claude Opus 5 high availability attempt exited 1 because OAuth had expired; no Opus review occurred.

Note

Add thread, subagent, and project breakdowns to usage tracking

  • Adds readThreadBreakdown to UsageService and server.getUsageThreadBreakdown RPC to return per-thread and subagent token/cost totals.
  • Adds project attribution to usage aggregation and the UsagePage UI to filter usage by specific projects or outside-project usage.
  • Tracks cwd in UsageRecord and the usage scan cache to support project resolution. Bumps USAGE_CONTRACT_VERSION to 9.
  • Adds custom date ranges up to 90 days and pointer-drag zoom to the daily UsageProviderChart.
  • Risk: USAGE_SCAN_CACHE_VERSION bump to 4 invalidates older usage scan caches. dedupeWithinFile logic changed to retain the final record per key instead of the first, altering token counts for mixed progressive/complete transcripts.

Macroscope summarized a67d8f2.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL 1,000+ changed lines (additions + deletions). labels Sep 1, 2026
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from 45cd1b2 to 13df108 Compare September 1, 2026 07:35
Comment thread apps/server/src/server.ts Outdated
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
Comment thread apps/server/src/usage/usageTranscriptReader.ts Outdated
Comment thread apps/server/src/usage/usageThreads.ts
Comment thread apps/web/src/components/usage/UsageProviderChart.tsx Outdated
Comment thread apps/web/src/components/usage/UsagePage.tsx
Comment thread apps/server/src/usage/usageScanCache.ts
Comment thread apps/server/src/usage/UsageService.ts Outdated
Comment thread apps/server/src/usage/UsageService.ts Outdated
Comment thread apps/server/src/server.ts Outdated
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from 13df108 to df71e4e Compare September 1, 2026 10:28
Comment thread apps/server/src/usage/usageTranscriptReader.test.ts Outdated
Comment thread apps/web/src/components/usage/UsageProviderChart.tsx
Comment thread apps/server/src/usage/UsageService.ts
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from df71e4e to da3b431 Compare September 1, 2026 11:12
Comment thread apps/server/src/usage/UsageService.ts
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
Comment thread apps/server/src/usage/usageTranscripts.ts
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from da3b431 to fbffad8 Compare September 1, 2026 11:27
Comment thread apps/server/src/usage/UsageService.test.ts Outdated
Comment thread apps/web/src/state/usage.ts Outdated
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
saphid and others added 4 commits September 1, 2026 21:39
The usage window was locked to four presets, so a spike on the chart
could not be inspected without eyeballing dates. Dragging across any
daily chart now commits the selection as the date window, double-click
returns to the preset, and date fields beside the presets accept any
custom range directly. The server already accepted arbitrary day
windows; this is web-only.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Cap custom windows before enumeration, keep date controls reachable in compact layouts, and complete brush gestures synchronously through pointer capture.
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from fbffad8 to 46d852c Compare September 1, 2026 11:48
Comment thread apps/web/src/components/usage/UsagePage.tsx Outdated
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from 46d852c to 60afb41 Compare September 1, 2026 11:56
Comment thread apps/server/src/usage/UsageService.ts Outdated
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch from 60afb41 to 5428268 Compare September 1, 2026 12:10
Comment thread apps/server/src/usage/UsageService.ts Outdated
Comment thread packages/shared/src/usageMerge.ts
Comment thread apps/web/src/components/usage/UsageThreadTable.tsx Outdated
@saphid
saphid force-pushed the saphid/usage-thread-breakdown branch 2 times, most recently from 7cc8b55 to bb9504a Compare September 1, 2026 12:29

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread apps/mobile/src/features/usage/UsageRouteScreen.tsx Outdated
Comment thread apps/mobile/src/state/usage.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4b516fe. Configure here.

Comment thread apps/mobile/src/features/usage/UsageRouteScreen.tsx Outdated
Comment thread apps/server/src/usage/UsageService.ts
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.

1 participant