feat(usage): add thread and subagent breakdown - #9016
Open
saphid wants to merge 69 commits into
Open
Conversation
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 07:35
45cd1b2 to
13df108
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 10:28
13df108 to
df71e4e
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 11:12
df71e4e to
da3b431
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 11:27
da3b431 to
fbffad8
Compare
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
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 11:48
fbffad8 to
46d852c
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 11:56
46d852c to
60afb41
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
from
September 1, 2026 12:10
60afb41 to
5428268
Compare
saphid
force-pushed
the
saphid/usage-thread-breakdown
branch
2 times, most recently
from
September 1, 2026 12:29
7cc8b55 to
bb9504a
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
❌ 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.
# Conflicts: # apps/server/src/usage/UsageService.test.ts # apps/server/src/usage/UsageService.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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
a67d8f25442c06f9caec12d6173d96256a6130e6includes upstream main39802c06117fae0b3da43624b0d54309c5437c72. 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 main82c2b7ffb4d450572f5baf9a70693f1e25cfdfed.ba873b8passed 171 tests across 12 files, plus the affected package typechecks.82c2b7fdelta removes an unused pricing helper: 7 pricing tests, server typecheck, Knip andgit diff --checkpassed on the pre-repair main composition. The chart/runtime contribution was unchanged by that final delta.Focused commands
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 integration7e248026469ec7be6d5c2bdaccf86f380e0c2476, 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.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
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
readThreadBreakdowntoUsageServiceandserver.getUsageThreadBreakdownRPC to return per-thread and subagent token/cost totals.UsagePageUI to filter usage by specific projects or outside-project usage.cwdinUsageRecordand the usage scan cache to support project resolution. BumpsUSAGE_CONTRACT_VERSIONto 9.UsageProviderChart.USAGE_SCAN_CACHE_VERSIONbump to 4 invalidates older usage scan caches.dedupeWithinFilelogic changed to retain the final record per key instead of the first, altering token counts for mixed progressive/complete transcripts.Macroscope summarized a67d8f2.