fix(daemon): stop session flood and add session GC#1
Open
doyled-it wants to merge 1 commit into
Open
Conversation
Two defects let the session table grow without bound: - Indiscriminate adoption: every `claude` process that fired a SessionStart hook was adopted as a persistent dashboard row, including headless `claude -p` one-shots and scripted bursts. One worktree produced 3,267 rows (~28/min) this way. - No garbage collection: finished sessions and their events were never pruned, and sessions whose process died without a SessionEnd hook lingered as idle/working zombies forever. Defer wild adoption until a session shows real activity (first PreToolUse / PostToolUse), so start/stop-only invocations never create a row. Planned (wavecrest-launched) sessions still bind on SessionStart, unchanged. Add an hourly GC that reaps non-terminal sessions idle > 24h to 'finished' and deletes finished sessions older than 7 days (FK cascade clears their events/rollup/samples). Pinned sessions are exempt from both.
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.
Problem
The session table grew without bound, spawning thousands of dashboard rows. Traced from a live
~/.wavecrest/state.dbbackup (62 MB / 3,346 sessions / 19,874 events). Two distinct defects:claudeprocess that fired aSessionStarthook was adopted as a persistent session row, including headlessclaude -pone-shots and scripted bursts. One worktree produced 3,267 rows at ~28/min, each a short invocation that started and stopped with zero tool use (1PreToolUse/ 1PostToolUseacross all of them).finishedsessions and their events were never pruned, and sessions whose process died without aSessionEndhook lingered asidle/workingzombies forever.Fix
PreToolUse/PostToolUse). Start/stop-only invocations never create a row — this eliminates ~99% of the flood at the source. Planned (wavecrest-launched) sessions still bind onSessionStart, unchanged.src/daemon/gc.ts): reaps non-terminal sessions idle > 24h tofinished(clears zombies), and deletesfinishedsessions older than 7 days (FK cascade clears events/rollup/samples). Pinned sessions are exempt from both.Tests
http.test.ts) is pre-existing and fails identically onmain.gc.tsis type-clean).Out of scope (noticed separately)
claude(posix_spawnp failed, hundreds of consecutive failures) — opposite problem, worth a separate fix.