Conversation
Session state files (.git/entire-sessions/) accumulate over time. Sessions that ended more than 24 hours ago are no longer useful. This transparently deletes them during StateStore.List() and LoadSessionState() so stale sessions are invisible to all callers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 126847879a7e
PR SummaryLow Risk Overview This introduces Written by Cursor Bugbot for commit 37ea966. Configure here. |
There was a problem hiding this comment.
Pull request overview
This PR adds automatic cleanup of stale session state files under .git/entire-sessions/ so that ended sessions older than a threshold are deleted and become invisible to callers, addressing long-term accumulation and improving hook performance (Issue #437).
Changes:
- Add
IsStale()logic and aStaleSessionThresholdconstant to determine when sessions should be deleted. - Delete stale session state files during
StateStore.List()andstrategy.LoadSessionState(). - Add unit tests covering staleness detection and deletion behavior during load/list.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| cmd/entire/cli/session/state.go | Introduces staleness threshold + deletion of stale session files during StateStore.List() |
| cmd/entire/cli/session/state_test.go | Adds tests for State.IsStale() and stale deletion during StateStore.List() |
| cmd/entire/cli/strategy/session_state.go | Deletes stale session state files during LoadSessionState() |
| cmd/entire/cli/strategy/session_state_test.go | Adds test ensuring stale session files are deleted on LoadSessionState() |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This reverts commit 738a41c.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
bugbot run |
Previously, stale session detection was inconsistent: the package-level LoadSessionState() in strategy/ had its own stale check + file deletion, and StateStore.List() had a separate stale check, but StateStore.Load() did not. This meant ManualCommitStrategy.loadSessionState() — which calls StateStore.Load() directly and is used extensively in hooks, condensation, rewind, and git operations — never cleaned up stale sessions. Fix by adding the stale session check to StateStore.Load() itself, so all callers automatically benefit. Then: - Remove the duplicate stale check from StateStore.List() (it calls Load, which now handles it) - Simplify strategy.LoadSessionState() to delegate to StateStore instead of duplicating file I/O, unmarshaling, normalization, and stale checks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: aebb716f655b
Summary
Session state files (
.git/entire-sessions/) accumulate over time. Sessions that ended more than 24 hours ago are no longer useful. This PR transparently deletes them during load and list operations so stale sessions are invisible to all callers.As a side effect, this should fix #437 — we already aren't creating unnecessarily huge session files anymore (thanks to #426) but users with polluted
.git/entire-sessions/folders would still suffer from the issue. This will clean things up on an ongoing basis.What changed
State.IsStale()— new method on theStatestruct centralising the staleness check (ended > 24h ago; active sessions are never stale)StateStore.Load()— now checksIsStale()after loading; stale sessions are deleted from disk and(nil, nil)is returned. This is the core fix:ManualCommitStrategy.loadSessionState()callsStateStore.Load()directly, so hooks, condensation, rewind, and git operations now all benefit from stale session cleanup automatically.StateStore.List()— removed the duplicate stale-session check;Load()already handles it, soList()simply skipsnilreturns.strategy.LoadSessionState()— replaced duplicated file I/O, unmarshalling, normalisation, and stale-checking logic with a single call tosession.NewStateStore()+store.Load(). This centralises all session loading throughStateStore, eliminating the parallel code path that existed in thestrategypackage.The net effect is that all session loading/listing goes through
StateStoreand every caller — whether it's the package-levelLoadSessionState(),ManualCommitStrategy.loadSessionState(), orStateStore.List()— gets consistent stale-session cleanup.Test plan
TestStateStore_Load_DeletesStaleSession— verifiesLoad()returns nil and deletes the file for stale sessions, while still returning active sessions normallyTestStateStore_List_DeletesStaleSession— continues to pass (List delegates to Load)TestLoadSessionState_DeletesStaleSession— continues to pass via the simplified delegationTestState_IsStale— unit tests for the staleness predicate🤖 Generated with Claude Code