Hooks stop deleting live idle sessions - #2573
Merged
Merged
Conversation
listAllSessionStates deleted every non-active state with no shadow branch, no LastCheckpointID and no task records. That is the normal shape of a live session between turns — a read-only turn, or the turn right after a linked commit, when the commit removed the branch and turn-start cleared LastCheckpointID — and the store is listed by every worktree's hooks, so a commit in another worktree wiped the session and the next turn-start rebuilt it from zero, losing the transcript window, the owner and the home. One session in this clone was re-initialised 37 times in four days, and a commit made in the gap found no session at all. An IDLE never-condensed state is now an orphan only once its owner process is known to have exited. ENDED and legacy states keep the old rule; states with no recorded owner age out through the stale threshold instead. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Entire-Checkpoint: 01M2TZ1WNMFYDVGYVXYPYEA6FS
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
A critical cleanup race remains, alongside legacy-state behavior and platform-specific test issues.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Fixes hook-driven deletion of live idle sessions by making cleanup owner-aware.
Changes:
- Adds owner-liveness checks for orphan detection.
- Expands unit and integration coverage.
- Documents revised cleanup behavior.
| File | Description |
|---|---|
docs/development/checkpoint-implementation.md |
Documents orphan cleanup rules. |
cmd/entire/cli/strategy/manual_commit_test.go |
Expands cleanup behavior tests. |
cmd/entire/cli/strategy/manual_commit_session.go |
Implements owner-aware cleanup. |
cmd/entire/cli/integration_test/session_state_idle_survives_test.go |
Adds cross-worktree regression coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Entire-Checkpoint: 01M388GXJB5G8959MC2PN4HCBF
gtrrz-victor
previously approved these changes
Sep 24, 2026
gtrrz-victor
self-requested a review
September 24, 2026 12:34
Legacy records normalize to IDLE on list and isOrphanedSessionState never deletes IDLE, so they now remain until StaleSessionThreshold expiry. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01M39S21QM1G5K5G7EGNG5AKAZ
isOrphanedSessionState re-spelled "ended" as a phase check, so an IDLE state with EndedAt stamped was kept for 7 days (the finalizer skips it via IsEnded). Use the canonical predicate and drop test leftovers from the owner-liveness version. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01M39SKJBAWGZCRTKYPYZ8ZHP2
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01M39SWN2NJNA43TF5Z9P5457V
Soph
approved these changes
Sep 24, 2026
peyton-alt
added a commit
that referenced
this pull request
Sep 25, 2026
#2573 added an identical helper to the integration package. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 01M3CMXPNKPVD9XB99C1PHP9RF
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.


https://entire.io/gh/entireio/cli/trails/1413
Hooks stop deleting live idle sessions
Symptom. A session is re-initialised from scratch every few turns: transcript window, owner, and home reset, and a commit landing in the gap finds no session at all. In one clone a single session was re-initialised 37 times in four days.
Cause. The strategy's session listing, which every hook runs to match sessions, deletes any non-active state whose shadow branch is gone and whose checkpoint ID is empty. That is the normal shape of a healthy idle session right after a linked commit, or of a read-only session. Hooks in other worktrees list the same shared store, so any of them could delete it.
Fix. Orphan cleanup now deletes only finalized sessions (
State.IsEnded: ENDED phase orEndedAtstamped) that were never condensed and carry no task records. Unfinalized IDLE states are never deleted by the listing: a live idle session stays, and a dead-owner one is left forfinalizeExitedSessions, which marks it ENDED so the next listing clears it. Legacy empty-phase records normalize to IDLE, so — unlike before — they are kept until the 7-dayStaleSessionThresholdexpiry.entire statuswas already fixed to not delete on read (#2363); this covers the hooks.Tests. Integration: another worktree's commit hook no longer deletes an idle session. Unit: the cleanup table keeps idle-with-dead-owner, idle-with-unknown-owner and legacy-empty-phase, and deletes ENDED never-condensed and IDLE-with-
EndedAtstates.Follow-up. Hooks should not delete session state at all; deletion belongs to the sweeper, doctor and the 7-day expiry. That needs the orphan filter moved out of the shared listing and is tracked separately.
🤖 Generated with Claude Code
Note
Medium Risk
Changes shared hook-path session deletion logic for multi-worktree repos; incorrect owner liveness could retain stale state or still delete live sessions, but scope is narrowed and covered by new tests.
Overview
Fixes session re-initialization when git hooks in another worktree list the shared
.git/entire-sessions/store and treat a healthy IDLE session (no shadow branch yet, noLastCheckpointID) as orphaned.listAllSessionStatesnow routes shadow-branch-missing cleanup throughisOrphanedSessionState: IDLE states without checkpoint or task records are cleared only whenOwnerExited()is true. ENDED/legacy never-condensed cleanup is unchanged; idle sessions with a live or unknown owner are kept until stale expiry.Adds an integration test (linked worktree + parent commit hook) and expands unit tests for idle live/dead/unknown owner cases. Docs describe the new orphan rules.
Reviewed by Cursor Bugbot for commit 0f2dcb1. Configure here.