fix(store): add 14-day retention for the sessions/ directory (#949) - #970
Open
hakanbaysal wants to merge 2 commits into
Open
fix(store): add 14-day retention for the sessions/ directory (#949)#970hakanbaysal wants to merge 2 commits into
hakanbaysal wants to merge 2 commits into
Conversation
) content/ has pruned stale per-project DBs at 14 days since day one, but sessions/ had no retention path at all: per-session stats-*.json files (one per server process, never reread once the session ends) and idle per-project session DBs accumulate without bound. A two-month heavy install reached 5,294 files / ~331MB in sessions/ while content/ stayed bounded at ~52MB (mksglu#949). Add cleanupStaleSessionFiles(sessionsDir, maxAgeDays) and run it in the same one-time startup cleanup cycle as the content/ pruning, with the same 14-day window. Retention is purely mtime-based: every hook write refreshes the DB mtime, so a file untouched for 14 days cannot belong to a live session. Deliberately no WAL-staleness liveness guess — that heuristic can delete files under a live handle (mksglu#880) — and unknown file types in the directory are never touched.
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.
What / Why / How
Fixes #949.
content/has pruned stale per-project DBs at 14 days since day one, butsessions/had no retention path at all: per-sessionstats-*.jsonfiles(one per server process, never reread once the session ends) and idle
per-project session DBs accumulate without bound. The issue reports a
two-month heavy install at 5,294 files / ~331MB in
sessions/whilecontent/stayed bounded at ~52MB.Fix: add
cleanupStaleSessionFiles(sessionsDir, maxAgeDays)next tocleanupStaleContentDBsand run it in the same one-time startup cleanup cycle,with the same 14-day window.
Two deliberate design points:
untouched for 14 days cannot belong to a live session. No WAL-staleness
liveness guess — that heuristic can delete files under a live handle ([Bug]: cleanupStaleContentDBs race with parallel Pi MCP servers poisons ContentStore singleton (permanent disk I/O error) #880),
so the sessions variant does not inherit it.
*.db(with their-wal/-shmsiblings) and
stats-*.jsonare considered; unknown file types in thedirectory are never touched.
Note: pruning old
stats-*.jsonslightly reduces the Pi lifetime byteaggregation (
patchPiLifetimeFromStatsFilessums all stats files) — the sameclass of trade-off the existing 14-day
content/pruning already makes.Affected platforms
Test plan
stats removed while fresh files and unknown types are kept; a fresh DB with
a stale-looking WAL is kept (no WAL heuristic, regression guard for the [Bug]: cleanupStaleContentDBs race with parallel Pi MCP servers poisons ContentStore singleton (permanent disk I/O error) #880
class); missing directory returns 0.
npx vitest run tests/store.test.ts→ 126 passed;npx vitest run tests/core/server.test.ts→ 499 passed.npx tsc --noEmit→ clean.Checklist
npm testpasses (store + server suites; full build requires Node >=22.5)npm run typecheckpassesjoin()throughout, no hardcoded separators)nextbranch