Repository navigation
feat(usage): add global usage dashboard and per-session usage panel - #500
chriswritescode-dev wants to merge 9 commits into
Conversation
PR Reviewer Guide 🔍(Review updated until commit dd60803)Since the last review — 1 finding was open on the previous HEAD
Here are some key observations to aid the review process:
✅ Resolved findingsfrontend/src/components/usage/UsageSessionsTable.tsx:123-127Heavy per-row fetching To show the Steps and Avg tokens/s columns, each visible row runs frontend/src/components/usage/UsageDashboard.tsx:61-66Saved filter wiped The pruning effect writes the reduced list back to storage through frontend/src/components/usage/UsageSessionsTable.tsx:42-44Range end ignored
|
|
Persistent review updated to latest commit 6d8be37 |
| const isAtSessionCap = sessions.length >= SESSION_CAP | ||
| const showsCapNote = isAtSessionCap && hasNextPage && isOldestLoadedInRange | ||
| const willLoadMoreSessions = | ||
| hasLoadedSessions && hasNextPage === true && !isError && !isAtSessionCap && isOldestLoadedInRange | ||
|
|
||
| useEffect(() => { | ||
| if (!willLoadMoreSessions || isFetchingNextPage) return | ||
| void fetchNextPage() | ||
| }, [fetchNextPage, isFetchingNextPage, sessions.length, willLoadMoreSessions]) |
There was a problem hiding this comment.
Unbounded auto-paging
The effect fetches the next page whenever willLoadMoreSessions is true and no fetch is running. The 500-session cap is based on sessions.length. If a page comes back empty (or adds no new sessions) but still has a next cursor, the count never grows. Each finished fetch toggles isFetchingNextPage, which runs the effect again, so the table keeps requesting pages from the server indefinitely. Consider capping by the number of pages fetched, or stopping when a page adds no sessions.
|
Persistent review updated to latest commit dd60803 |
User description
Summary
?usage=open, opened from the sidebar footer and the mobile More drawer: range selector (15m to all time plus custom), spend, tokens, prompts, steps, active days and streak, token composition, activity chart, models, tool reliability and sessions by spend, with a multi-select model filter that hides metrics that cannot be split per model.?panel=usage(and?dialog=usagefrom the mobile More drawer): spend, average tokens/s, tokens, steps, composition, models and tools, aggregated from the session's newest assistant steps.GET /api/experimental/session/statsthrough the existing/api/opencodeproxy, so the local and linked servers behave the same, with types from@opencode/clientand no new backend storage. The stats endpoint failing degrades to a "Usage unavailable" state.Closes #478
Validation
pnpm install --frozen-lockfile— passpnpm --filter frontend typecheck— passpnpm lint— passpnpm --filter frontend build— passPR Type
Enhancement, Tests
Description
Add full-screen global usage dashboard via
?usage=open.Add per-session usage panel at
?panel=usageand?dialog=usage.Filter usage by range and selected models, persisted locally.
Wire Usage entries into sidebar, mobile menus and tool rail.
Add usage data layer, aggregation helpers and extensive tests.
Diagram Walkthrough
File Walkthrough
27 files
Global usage dashboard with range and model filtersSession usage panel aggregating local assistant stepsSessions by spend table with paging and range filteringStats request and paged assistant message loaderUsage aggregation, tool stats and formatting helpersUsage range presets, resolution and validation schemaQuery hooks for stats and session usagePersist usage range and model filter preferencesURL-driven usage dialog open and closeFull-screen usage dialog with linked server switcherSession usage full-screen mobile dialog shellPreset and custom range selector inputsMulti-select model filter with overflow badgeDaily activity bar chart scaled by busiest dayModels table with steps, tokens, cost and shareTool reliability table with counts and P50Summary cards for spend, tokens, steps and throughputToken composition card with all token fieldsAdd Usage and Session usage navigation entriesOpen usage dialogs from mobile menu itemsAdd Usage entry to sidebar footerRegister session usage as a tool panelTreat usage as a valid panel toolAllow filtering session messages by typeMount global usage dialog in app shellRender session usage dialog when undockedRe-export usage stats and token types22 files
Test stats requests and assistant message pagingTest range presets, resolution and schema validationTest aggregation, throughput, tools and formattingTest usage query keys and fetch behaviorTest dialog URL state and history handlingTest persisted range and model preferencesTest dashboard metrics, filters and error statesTest session panel filtering, paging and errorsTest session ranking, paging, caps and linksTest global dialog opening and server scopingTest range preset and custom input behaviorTest model multi-select and badge renderingTest activity bars and zero-step handlingTest model rows, shares and empty statesTest tool rows, totals and missing P50Test summary card labels and optional statsTest token composition labels and valuesTest mobile usage entries and dialog openingTest desktop sidebar usage entry behaviorUpdate nav model expectations for usage itemsTest session usage tool for local and linked serversTest usage panel tool rewriting to dialog1 files