Fix /status reporting sessions as zero - #2248
Merged
Merged
Conversation
The /status `sessions` field almost always read 0. The 60s cleanup added to bound memory called `verifiedTokens.clear()` on the whole set, wiping the count every minute, so it only showed a value when a search happened to land in the current window. Bound memory with a per-token idle TTL instead of a full wipe, and track distinct sessions with a monotonic counter decoupled from the expiring cache, restoring the since-restart meaning that pairs with the search counters it is averaged against.
felladrin
marked this pull request as ready for review
July 29, 2026 10:49
/status reporting sessions as zero
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.
Fixes the
/statusendpoint always reportingsessions: 0.Currently, the memory-bounding cleanup added in #2157 calls
verifiedTokens.clear()on the whole set every 60 seconds. That wipes the count every minute, sogetVerifiedTokensAmount()only returns a non-zero value if a search happens to land in the current 60-second window. Before #2157 the set was never cleared, sosessionsmeant "distinct sessions since restart", which is the basis it shares withtextualSearches/graphicalSearcheswhen computing the per-session averages.This PR keeps memory bounded without destroying the metric: it evicts idle tokens with a per-token TTL instead of a full wipe, and tracks distinct sessions with a monotonic counter kept separate from the expiring cache, so the count stays on the "since restart" basis.
What changed
server/verifiedTokens.tsSet->Map<token, lastSeen>; cleanup evicts only entries idle longer than 30 min;sessionsnow comes from a monotonicsessionCountthat survives evictionserver/verifyTokenAndRateLimit.tsserver/verifiedTokens.test.tsHow to test
npx vitest run server/verifiedTokens.test.ts server/verifyTokenAndRateLimit.test.ts(20 tests pass)./status:sessionsreads 1 and stays there past the 60-second mark (before this change it dropped back to 0).