Repository navigation
feat: metrics page backed by a durable usage rollup - #165
Merged
Merged
Conversation
Two tables written in the transaction that finalises an entry: usage (requests, tokens by type, reasoning, cost by type, response time and a duration histogram per UTC hour, thread, provider, model and thinking level) and tally (user messages and tool calls that ran). Rows carry the session and project they were written for and no foreign key, so they outlive a deleted session. Aborted requests are billed and counted but never timed. A migration backfills from existing entries with the same code as the live path. Sync.usage reads both tables by revision for a follower. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
usage.sync streams the usage rollup in revision order, then live, as running totals a client replaces by key. It is a stream of its own so a client that predates it is unaffected. server.info gains an optional host name: the macOS computer name, else the hostname. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…serve metrics The app server follows usage.sync for each machine into its own usage and tally tables, keyed by machine and store so history survives a recreated store, and keeps working against a server without the stream. A machine's name is now the one its server reports; the name typed in Settings is an optional override, and the built-in server is no longer seeded as CodeWork. metrics.usage and metrics.hours read the mirror by calendar day and hour in a given time zone, with machine and project filters. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A Metrics page beside Settings in the sidebar: cost, tokens and sessions for a period; a 12-month activity calendar by prompts, sessions, tokens or cost with a per-day view; tokens or cost over time by model or provider; projects, models, response time, weeks, tool calls, thinking levels, cache and top sessions. It reads one year of usage and refreshes as usage syncs. The server name in Settings is optional and shows the machine's own name when empty. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ross navigation Tooltips live in their own store, so following the pointer re-renders only the tooltip; the calendar is sized before its first paint and keeps its scroll on a refresh. The year's read outlives the page for a minute and the period and filters persist across navigation, a removed machine's filter falling back to every machine. Change badges carry direction in the arrow, the cache badge shows points, and a model id shared by two providers is labelled provider first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…server's usage Each open of the harness database records a boot with the revision it opened at. usage.sync takes the client's last boot and, when the store left that line (a restored backup), reads from zero with reset; a read from zero replaces the store's mirrored rows in one transaction. The app server keys usage by store with no foreign key to machine, so a removed server's history stays and the server added again replaces it rather than adding to it. Metrics also refresh on index changes, for session titles and deletions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…achines seed.ts writes a history of sessions, models and tools through the thread store; the live suite checks the metrics reads against each machine's own totals across live turns, app and machine restarts, a paused machine, a network cut, a restored backup, a server removed and added again, and a recreated store. The fixture model can stamp replies with the real time (CODEWORK_FIXTURE_NOW=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The machine suites run it inside each OrbStack machine by path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
A Metrics page in the desktop app (chart button beside Settings in the sidebar), backed by usage the harness now records durably and the app server mirrors per machine.
How it fits together
usage: per UTC hour × thread × provider × model × thinking level — requests, tokens by type, reasoning tokens, cost by type, summed response time and a fixed-edge duration histogram.tally: per hour × thread — user messages and tool calls that ran, by name.Rows copy the session and project ids and have no foreign key, so they outlive a deleted session. A migration backfills existing entries with the same code as the live path.
usage.sync(revision order, then live; running totals a client replaces by key) and reports the machine's own name inserver.info.usage.syncper machine into its own tables, keyed by machine and store, so history also survives a recreated harness database. It servesmetrics.usageandmetrics.hoursby calendar day and hour in a given time zone, with machine and project filters.Also in this PR
Correctness notes
usage.syncis a stream of its own rather than newindex.syncvariants, so a desktop that predates it keeps syncing; an app server talking to an older CodeWork server simply shows no usage for that machine.Testing
vp run typecheckandvp check: clean.packages/harness658 passed / 34 skipped;packages/codework159 passed / 19 skipped;apps/serverall non-live tests passed.usage.machines.live6/6 (new),sync.machines.live12/12,daemon.machines.live1 passed / 1 skipped,recovery.machines.live5/5.Known limits
reads.test.ts"each read's topics fire…" times out intermittently, with or without this change.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.