Repository navigation
Stats: a Reset totals button, and POST /v1/stats/reset behind it - #640
Conversation
The saved totals only ever grow, so wrong ones stay wrong: builds before the provider usage fix added leftover memory to them, and the Stats tab kept showing billions after the fix. There was no way back short of deleting files by hand. Reset totals on the Stats tab asks first, then sets every saved counter to zero. Conversations are kept. - POST /v1/stats/reset: the gateway's endpoint buckets hold counters only and are deleted; a conversation has its stats block emptied and the rest of its file left alone. /v1/stats answers with the new totals at once (its five-second cache is dropped). Behind the gateway token like the rest of /v1, and refused from another site's page on a token-less gateway. - A conversation with a turn running on the gateway is skipped, not waited for, and the reply says how many were; the tab passes that on. - ResetSessionStats (session store): rewrites one session without its counters. Transcript, tool details, title, updated_at and transcript log stay; a session with no recorded location is not stamped with the caller's workspace, as Save would stamp it; nothing is written when there is nothing to clear. There is no lock across processes, so the new record replaces the file only if the file still holds what was read, and it starts over when it does not. - TSession.Save is split into the record builder and the write so the reset can build the same record; the files it writes are unchanged. Tests: session_stats_tests.pas (the store routine, a save landing mid-reset included) and stats_reset_e2e.py (the real gateway: totals to zero at once, conversations as they were, a session in use skipped and cleared by a second reset, a GET and a cross-site POST refused). gateway_token_tests pins the route as token-gated. Each behaviour, reverted alone, fails one of them. The button itself was checked in a browser, not by a committed test. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3ba834943
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| GStatsCacheLock.Enter; | ||
| try | ||
| GStatsCacheUntil := 0; | ||
| GStatsCacheBody := ''; |
There was a problem hiding this comment.
Prevent in-flight stats reads from restoring the old cache
If a concurrent GET /v1/stats misses the cache and reads the sessions before the reset finishes, it can publish its pre-reset totals after this invalidation. HandleStats performs ListSessions(True) outside GStatsCacheLock and later unconditionally assigns GStatsCacheBody, so clearing the cache here does not prevent that stale result from being cached again. The reset button's immediate refresh can consequently show the old totals despite a successful reset, and subsequent reads can receive them for another five seconds. Use a cache generation checked before publishing, or coordinate aggregation with reset, so an in-flight pre-reset aggregation cannot repopulate the invalidated cache.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. Fixed in 3d8b58f on claude/pasclaw-desktop-plan-uapzcp (this PR had already merged): the cache now has a generation that goes up when a reset drops it, and an answer is stored only if the cache has not been dropped since the request started. The Stats tab also draws only its newest request's answer, so a poll sent before the reset cannot put the old totals back on screen.
Generated by Claude Code
…s back Review finding on #640. POST /v1/stats/reset cleared the cached /v1/stats answer, but a /v1/stats request already reading the sessions at that moment stored its pre-reset answer afterwards, and the old totals were served for another five seconds. - The cache has a generation that goes up when it is dropped. An answer is stored only if the cache has not been dropped since the request started (StatsCacheGet / StatsCachePut / StatsCacheDrop). - The Stats tab draws only the newest request's answer. A poll sent just before the reset could answer after the reset's own refresh and put the old totals back on screen until the next poll. Tests: gateway_stats_buckets_tests pins the cache (an answer from before a drop is refused, one from after is kept); removing the generation check fails it. The page's ordering was checked in a browser with a held request: with the check the totals stay at zero, without it the old ones come back. No committed test for the page. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYD1zZPD7GuM8pF1btwi2U
Builds on #639 (the stats fix). Until that merges, this PR's diff also shows its commit; the change here is the second commit,
d3ba834.Why
The saved totals only ever grow, so wrong ones stay wrong. Builds before #639 added leftover memory to them, and the Stats tab keeps showing billions after the fix. The only way back was deleting files by hand.
What it does
Reset totals on the Stats tab asks first, then sets every saved counter to zero. Conversations are kept.
One web UI conversation, with the counts the provider reported:
The conversation was unchanged on screen, on disk and after a page reload.
Changes
POST /v1/stats/reset/v1/statsanswers with the new totals at once: its five-second cache is dropped./v1/*, and a token-less gateway refuses it from another site's page.ResetSessionStats(session store) rewrites one session without its counters.updated_atand transcript log stay.Savewould stamp it.TSession.Saveis split into the record builder and the write so the reset can build the same record. The files it writes are unchanged: the same turns through the previous build and this one give identical session files.Limits
prompt_cache_warm_pingscounts since the gateway started and is not reset.Tests
make test-session-stats: the store routine, including a save that lands mid-reset and a file that keeps changing.make test-stats-reset-e2e: the real gateway against a fake provider. Totals go to zero at once, conversations are as they were, a session in use is skipped and cleared by a second reset, and a GET and a cross-site POST reset nothing.gateway_token_testspins the route as token-gated.make testpasses on FPC 3.2.2. Not built with Delphi.Generated by Claude Code