mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4745] [Engine] serve: keep the Monitor's token counts between starts #5157
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#5157
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/4745
Author: @au70ma70n
Created: 10/30/2026
Status: 🔄 Open
Base:
main← Head:engine-totals-persistence📝 Commits (2)
145e349[GUI] settings: let a long help line wrap instead of squeezing every field419a478[Engine] serve: keep the Monitor's token counts between starts📊 Changes
4 files changed (+212 additions, -3 deletions)
View changed files
📝
docs/DETAILS.md(+5 -1)📝
serve/server.py(+89 -0)➕
serve/test_totals.py(+113 -0)📝
serve/web/app.css(+5 -2)📄 Description
Draft — the costing story wants scope agreement first: #4742. It lands after #4743 (the layout fix, already open and standing on its own); merge order is #4743 → this one → #4746 → #4747, and until the branch before it merges this pull request's diff also shows those commits and shrinks on its own as they merge.
Branch
engine-totals-persistence, basemain.Problem and result
The counts the Monitor tab prints ("Since …: N requests · … input tokens read · … written") lived only in the process, so a restart lost them, and there was no way to close the window and read one session's totals on their own. Now they are kept in
<the run config's name>.totals.jsonbeside the run config, the way the shared Chat settings are kept: the file is read when the server starts and written when a request ends, so a restart or a crash loses no more than a request that never ended. The prompt and decode times travel with the counts, so the printed speeds stay averages of the whole window rather than of the last start.--totals-file none(oroff) keeps the old one-start counting, and--totals-file PATHnames the file.--totals-resetcloses the window: this start counts from zero and the window that ended is moved aside to<the same name>.prev.jsoninstead of being thrown away, so the session that just finished stays readable.Related discussion
#4742 — the scope thread for this story (this pull request and the two that price these counts).
#4631 — "[Engine] Monitor: Clear hides only the request rows; the totals can only be reset by restarting the server" (open, no labels, no linked pull request). It wants the totals zeroed without a restart and proposes
POST /metrics/resetbehind the API key, calling the Clear button. This answers the same problem from the other end — the window survives restarts, and a start with--totals-resetcloses it — but it does not add the button, so it does not close #4631. That issue also asks that/metrics/prometheusstay monotonic; worth settling in the same thread, because these counters come from the sametotals: after this PR they span every start the file remembers, and--totals-resetstarts them from zero (a reset Prometheus reads as a counter reset, not a regression). Scope for the persistence itself still needs a maintainer's yes.Approach
Five module-level helpers beside
slot_save_dir(totals_path_of,totals_load_file,totals_add_saved,totals_write_file,totals_reset_file) and aTOTALS_KEYSlist that names exactly what is kept. Writes go throughstrata_control.atomic(a neighbouring temporary file), so a reader never sees half a write. Only numbers are added: an unknown key or a bad value changes nothing, and a file that cannot be read is treated as a first start. A disk error prints once and turns the file off rather than costing an answer. The parser's shape diagnostics (tool_calls_from_reasoning,stray_think_closers,tool_args_repaired,tool_calls_unread) are deliberately not kept — they describe a reply, not a use to be counted.Validation
Passed:
.venv\Scripts\python.exe -m unittest serve.test_totalsat870aedd9+ this change on Windows 11 (NT 10.0.26200), Python 3.10.11, no GPU and no downloads: 32 tests OK, of which the 13 named above are this PR's (TotalsPath,TotalsFile,TotalsWindow) — they cover the path choice, a missing or broken file, adding a saved window and movingsinceback, the write/load round trip, two starts adding up, and the.prev.jsonmove.Failed: none observed.
Not run: the live
--totals-resetstart on the served model (the file moves and the printed line are covered by unit tests only); the Terminal suite, which needs pytest and is not installed in this venv; CUDA/HIP/SYCL builds are not needed but the app's ownnpm testwas not run here (no node).Limits
This changes a default — with a run config present, a new small file now appears beside it and the Monitor's window spans starts;
--totals-file noneis the way back to today's behaviour, and I can flip the default to opt-in if a maintainer prefers that. The window belongs to a run config, so two configs of the same model count separately; there is no reset from the page yet (#4631).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.