mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2979] [Engine] Durable opt-in lifetime token counters in Monitor #4377
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4377
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2979
Author: @Zcg2021
Created: 10/17/2026
Status: 🔄 Open
Base:
main← Head:codex/usage-stats-reliability📝 Commits (10+)
3664ba0serve: lifetime token statistics, kept across restarts, with time-window viewsbdb9a1ddocs: the usage_stats key, the usage view on /metrics, and the Usage panel007819aserve: Usage panel - opens on the 7-day view, and the browser remembers the choice7d76f60docs: the Usage panel's default view and the browser memory for the choicedc2a649serve: the edge cases that came out of testing the Usage panel65f8120serve: the Usage range buttons wrap on a phonebfc9f1bfix(monitor): preserve lifetime usage across restarts and show all-time outputa62e6bdfix(monitor): keep live metrics first and document lifetime usage validationc7df4b9fix(usage): release ledger ownership when beta server returnse4ff9b2docs(usage): record beta persistence and HTTP revalidation📊 Changes
38 files changed (+7583 additions, -13 deletions)
View changed files
📝
docs/DETAILS.md(+38 -0)➕
docs/images/usage-stats/desktop.png(+0 -0)➕
docs/images/usage-stats/usage-bottom.png(+0 -0)➕
docs/usage-stats-validation.md(+91 -0)➕
docs/usage-v020/README.md(+78 -0)➕
docs/usage-v020/check_http.py(+89 -0)➕
docs/usage-v020/http-mac.txt(+9 -0)➕
docs/usage-v020/http-windows.txt(+9 -0)➕
docs/usage-v020/lifecycle-after.txt(+6 -0)➕
docs/usage-v020/lifecycle-before.txt(+36 -0)➕
docs/usage-v020/mac-missing-dependency.txt(+2033 -0)➕
docs/usage-v020/mac-tests.txt(+566 -0)➕
docs/usage-v020/mac-upstream-control.txt(+39 -0)➕
docs/usage-v020/monitor-top.png(+0 -0)➕
docs/usage-v020/usage-bottom.png(+0 -0)➕
docs/usage-v020/windows-tests.txt(+529 -0)➕
docs/usage-v029/README.md(+92 -0)➕
docs/usage-v029/browser-load.txt(+6 -0)➕
docs/usage-v029/browser-usage.txt(+8 -0)➕
docs/usage-v029/check_evidence.py(+31 -0)...and 18 more files
📄 Description
Problem and result
Monitor's session counters reset on restart, hiding how much work a local installation has produced. This opt-in feature retains request/token totals across restarts and shows an all-time output headline in a Usage card at the bottom of Monitor. Speed, hardware and cache remain first. Disabled mode creates no ledger/lock, adds no usage metrics and shows no card.
Related discussion
Builds on @wokhouse's #2370, retaining its six original commits and authorship. Related proposals: #2400 and #2204. Draft pending maintainer agreement on scope/consolidation; this update does not claim that scope was approved. Reliability changes can be separated if that is preferred.
Approach
Save once per settled request: temporary snapshot, flush/fsync, atomic replacement. A cross-process writer lock prevents simultaneous servers overwriting one store (
msvcrton Windows,flockon POSIX). Failed writes remain visible and retry without double counting; corrupt files are preserved. Shutdown and startup-failure paths release ledger ownership. Hourly buckets are bounded to 31 days.Only counters/timestamps are stored: no prompts, answers, tool arguments or credentials. Undated log imports are labelled, added only to the headline, and excluded from date-window totals and speed averages. Sequential model profiles may share a file; simultaneous servers need separate stores.
Enable with
"usage_stats": trueorserve/server.py --usage-stats; optionally setusage_stats_path/STRATA_USAGE_STATS. Keep the ledger across upgrades; its parent directory must exist.Updated against v0.2.9 main
c62d5e3a: preserve upstream's asynchronous language/chat startup and load/unload stale-response guard. Manual date refreshes share that guard without spawning an extra polling loop. Documentation follows the current main structure. No native source, model, scheduler or cache-format changes. This is the Pythonserve/webMonitor, not the separate desktop/TUI interface.Validation
Server/UI revision
33b9c6241862ea0e32c841a1e94d234ed090b0e9, merging upstreamc62d5e3a15b40ea51c96aae9e8d36928965f53ab. Browser regression tests:b37a743d. Evidence/docs:df0f7583. Tested November 2, 2026. Isolated directories and mock engines; no production restart, upgrade or test inference.Passed:
python -m unittest serve.test_server serve.test_usage serve.test_usage_durability serve.test_monitor serve.test_prometheus serve.test_runconfig -q— 412 tests, OK, 3 Unix-signal skips, 152.171 s. Covers abrupt exit, writer ownership, failed persistence/retry, corrupt-file preservation, disconnect/tool accounting and lifecycle cleanup.python docs/usage-v020/check_http.py— eight requests each across enabled/disabled statistics and streaming/non-streaming Chat Completions/Responses. Both arms produce 72 mock tokens; persisted/API/session totals, reload and custom range match; normalized reply payloads match. Disabled mode creates no ledger/metrics field.node tools/webtest/usage_test.mjs: 7 browser checks;node tools/webtest/browser_test.mjs 'load/unload:': 5 upstream browser checks. Both useWEBTEST_MODULES=<puppeteer-core installation>, Chromium, Node 24.3.0. Covers custom-date startup, stale response rejection, no duplicate polling, disabled/error states, layout order and load/unload including phone header.node serve/test_web_*.jsfiles,node --check serve/web/app.js,git diff origin/main --check.python docs/usage-v029/check_evidence.py: published aggregate sums and two temporary-store load/save/reload cycles preserve exact values.Failed:
python -m unittest discover -s serve -p 'test_*.py' -q— 1,326 tests, 1 failure, 21 skips, 427.109 s.test_gpu_roles_server.Roles.test_every_card_offexpectsSystemExit, while upstream explicitly allows this case on Darwin. The exact failure reproduces on an unmodifiedc62d5e3aarchive. That function is unchanged here; the full Mac run is not reported green.Not run:
Native CUDA/HIP/SYCL/Metal builds or inference (native code unchanged), physical power loss, a new persistence latency benchmark, or separate desktop/TUI statistics UI. Historical beta/native results are dated separately and not substituted for this validation.
Full v0.2.9 report, commands, sanitized logs and evidence.
Field evidence and limits
A read-only snapshot from our existing deployment, taken November 2 at 11:06:10 UTC, records 22,020,156 output tokens across 23,837 requests:
Allowlisted aggregate JSON. Reused prompt tokens are counted separately and are not generated output. These are historical implementation data, not v0.2.9 production burn-in or a performance/quality benchmark. They may aggregate sequential models, development work and tests. No per-request data or date buckets are published; the snapshot alone cannot prove zero lost counts or zero overhead.
The earlier screenshot below shows 20,097,558, before that snapshot, and illustrates the headline/import/range distinction. Metadata was removed with decoded pixels verified identical. Requests killed before settlement remain excluded; undated imports must not duplicate already-counted work.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.