Repository navigation
feat: add detailed token usage monitoring and cache write metrics - #354
Merged
Merged
Conversation
Sycun
marked this pull request as ready for review
October 11, 2026 14:48
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.
The dashboard previously showed only a token total and sent its token card to chat, while cache-write usage was lost between model responses and persisted summaries. This adds a Token Usage subsection in System Settings with 7/30/90-day ranges, input/output/cache-read/cache-write/reasoning counts, cache-read ratio, model shares, daily trends and recent run summaries. The dashboard card opens that subsection and shows a fixed seven-day total, with only cache hit rate in the subtitle (cache-read tokens divided by input tokens). Call counts and daily usage remain in the detail view.
The detail view now separates four primary metrics from secondary counters, adds an interactive daily chart (tokens, calls or cache-read ratio), and visualizes cached versus remaining input in a ring. Model rows show proportional bars, daily numerical details are collapsed by default, and recent runs use status badges. Charts expose exact values on hover or keyboard focus, support mobile/dark themes, and use the API's server-local day keys, filling only gaps between returned dates. Chart metric changes require no extra API request. The design uses publicly verifiable LiteLLM/Langfuse dashboard patterns and DeepSeek cache semantics; the research and limits are documented. It loads independently, supports manual refresh, project scoping and cancellation, and rejects stale responses after rapid period changes or navigation away. Selecting a period does not refresh the whole dashboard. The subsection supports direct links and page refresh through
#settings?section=token-usage, keyboard navigation, and Chinese/English/Russian labels. Dashboard polling and access filtering are retained.Upgrade Eino to stable v0.9.21 and the corresponding agentic model adapters to propagate
CacheWriteTokensthrough stream accumulation, SQLite persistence, APIs, chat summaries and WebShell timelines. Existing startup schema reconciliation adds the new column with a zero default. DeepSeek'sprompt_cache_hit_tokensis mapped to standard OpenAI cache-read details for JSON and SSE responses, preserving existing standard fields and raw JSON number precision. Cache details and reasoning are subsets and are never added again to the total; missing totals fall back to input plus output.The view is explicitly scoped to recorded Agent output usage, including collected sub-agent output. It is not a provider bill or a complete API-request ledger. Model grouping uses run configuration, so failover runs may contain mixed model usage. Unreported usage and internal calls without recorded output are excluded. Research, implementation details and follow-up directions are documented in
docs/zh-CN/token-usage-monitoring.md.Validation:
go test ./...passed for the backend changes.node --test web/static/js/*.test.cjs— 298 passing tests after the final UI changes.git diff --checkpassed for the changed files.The frontend cache-version assertions were updated for changed assets; an obsolete HITL migration assertion now checks the canonical schema definition. No runtime configuration, API keys, databases or production deployment changes are included.