The stale session cleanup logic is only implemented in this package-level…
- User
The stale session cleanup logic is only implemented in this package-level LoadSessionState function, but not in StateStore.Load which is called directly by ManualCommitStrategy.loadSessionState(). This creates an inconsistency where stale sessions are cleaned up in some code paths but not others.
Consider adding the stale session check to StateStore.Load() in session/state.go instead, so all callers automatically benefit from stale session cleanup. This would make the behavior consistent across the codebase and ensure that ManualCommitStrategy.loadSessionState() (used in hooks and many other places) also returns nil for stale sessions.
Assistant
Let me understand the current code structure first.
Assistant
Now let me see how
ManualCommitStrategy.loadSessionState()works and find all callers of bothStateStore.Loadand the package-levelLoadSessionState.Assistant
Now let me check where
ManualCommitStrategy.loadSessionState()is called, to confirm the scope of the inconsistency.Assistant
Good,
loadSessionState()is called extensively in hooks and production code. Now let me check the existing stale session test to understand expectations.Assistant
Now I have a clear picture. Let me also look at the test for stale sessions in
StateStore.Listto see what exists there.Assistant
Let me check the
SessionStatetype in the strategy package to understand the relationship.Assistant
Good, it's a type alias. Now I have the full picture. Here's what I'll do:
StateStore.Load()— add stale session check + cleanup (the core fix)StateStore.List()— remove the now-redundant stale check (Load handles it)strategy.LoadSessionState()— remove the duplicate stale check (it reads files directly but can rely on the same pattern, or better yet, refactor to use StateStore)
Let me also check if
LoadSessionStatein strategy could be simplified to useStateStore.Assistant
Now I'll make the changes. Let me start with the core fix in
StateStore.Load(), then clean up the redundant checks.Assistant
Now remove the redundant stale check from
StateStore.List():Assistant
Now simplify
LoadSessionStatein the strategy package to useStateStoreinstead of duplicating file I/O:Assistant
Now let me clean up the unused imports in
strategy/session_state.go:Assistant
Now let me also check if there are unused imports after removing the
_ = ctxline:Assistant
Good — imports in
session/state.goare all still used (slogandloggingare used in the new stale check code). Now let me add a test forStateStore.Loadreturning nil for stale sessions.Assistant
Now let me add a test for
StateStore.Loaddirectly returning nil for stale sessions:Assistant
Now let me run the tests to make sure everything works.
Assistant
Now let me run the strategy tests that touch stale session behavior:
Assistant
All tests pass. Now let me run the full test suite as required before committing:
Assistant
The existing staticcheck issues are pre-existing. I just need to fix the two
testifylintissues in my new test:Assistant
Now let me run the full test suite:
- User
[Request interrupted by user for tool use]
- User
Commit with thorough message.
Assistant
Let me check the current state first.
Assistant
Committed. The change consolidates stale session cleanup into
StateStore.Load()so that all callers — includingManualCommitStrategy.loadSessionState()used in hooks, condensation, rewind, and git operations — automatically benefit. The redundant checks inStateStore.List()andstrategy.LoadSessionState()were removed, and the latter was simplified to delegate toStateStoreinstead of duplicating file I/O.