Bug: Session files can become orphaned (exist but not in index) #66

Closed
opened 2026-04-01 07:46:45 +02:00 by shoko · 0 comments
Owner

Bug

Session files in ~/.kugetsu/sessions/ can become orphaned - they exist but are not tracked in ~/.kugetsu/index.json. This causes kugetsu destroy to fail:

Error: No session found for 'github.com/shoko/kugetsu#49'

Even though the session file exists:

~/.kugetsu/sessions/github.com-shoko-kugetsu-49.json  (file exists)
~/.kugetsu/index.json  (issue not tracked)

Root Cause

When kugetsu start creates a new session:

  1. Creates session file in ~/.kugetsu/sessions/
  2. Updates ~/.kugetsu/index.json with the issue mapping

But if step 1 succeeds and step 2 fails (e.g., crash, signal), the session file exists but index doesn't have it.

Impact

  • kugetsu destroy <issue> fails for orphaned sessions
  • kugetsu list shows incomplete state
  • Manual cleanup required (remove file + worktree manually)

Expected Behavior

kugetsu destroy should handle orphaned sessions gracefully:

  1. Check if session file exists even if not in index
  2. If orphaned, clean up session file AND worktree
  3. Update index to remove any stale entries

Possible Fixes

  1. On destroy: If issue not in index but session file exists, clean up anyway
  2. On start: Use atomic operations (write index first, then session file)
  3. Prune command: Already exists (kugetsu prune --force) but doesn't remove session files that ARE orphaned

Test Case

  1. Manually create orphaned session file
  2. Run kugetsu destroy <issue> - should succeed and clean up file
## Bug Session files in `~/.kugetsu/sessions/` can become orphaned - they exist but are not tracked in `~/.kugetsu/index.json`. This causes `kugetsu destroy` to fail: ``` Error: No session found for 'github.com/shoko/kugetsu#49' ``` Even though the session file exists: ``` ~/.kugetsu/sessions/github.com-shoko-kugetsu-49.json (file exists) ~/.kugetsu/index.json (issue not tracked) ``` ## Root Cause When `kugetsu start` creates a new session: 1. Creates session file in `~/.kugetsu/sessions/` 2. Updates `~/.kugetsu/index.json` with the issue mapping But if step 1 succeeds and step 2 fails (e.g., crash, signal), the session file exists but index doesn't have it. ## Impact - `kugetsu destroy <issue>` fails for orphaned sessions - `kugetsu list` shows incomplete state - Manual cleanup required (remove file + worktree manually) ## Expected Behavior `kugetsu destroy` should handle orphaned sessions gracefully: 1. Check if session file exists even if not in index 2. If orphaned, clean up session file AND worktree 3. Update index to remove any stale entries ## Possible Fixes 1. **On destroy:** If issue not in index but session file exists, clean up anyway 2. **On start:** Use atomic operations (write index first, then session file) 3. **Prune command:** Already exists (`kugetsu prune --force`) but doesn't remove session files that ARE orphaned ## Test Case 1. Manually create orphaned session file 2. Run `kugetsu destroy <issue>` - should succeed and clean up file
shoko closed this issue 2026-04-02 00:23:04 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/kugetsu#66