Skip to content

Conversation

@jmgilman
Copy link
Collaborator

@jmgilman jmgilman commented Jan 1, 2026

Summary

  • Fixes stale sessions appearing in hjk ps after a user exits (vs detaches) from a session
  • After AttachSession returns, checks if the session still exists in the multiplexer
  • If the session is gone (user exited), removes it from the catalog
  • Best-effort cleanup that won't fail the command on errors

Problem

When running hjk run and then exiting the session (typing exit or process terminates), the session remained in the catalog even though it no longer existed in the multiplexer. This caused hjk ps <branch> to show stale sessions.

Solution

Added cleanup logic to Manager.AttachSession() that runs after the multiplexer attach returns:

  1. Query the multiplexer for active sessions
  2. If our session isn't in the list, the user exited (not detached)
  3. Remove the session from the catalog

Test plan

  • Added test case for cleanup when user exits
  • Updated existing test to mock ListSessions
  • All existing tests pass
  • Manually verified the fix works

🤖 Generated with Claude Code

When a user exits a session (vs detaching), the multiplexer session is
terminated but the catalog entry was left behind. This caused `hjk ps`
to show stale sessions that no longer existed.

After AttachSession returns, we now check if the session still exists
in the multiplexer. If not, we remove it from the catalog. This is
best-effort cleanup that won't fail the command if it encounters errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jmgilman jmgilman merged commit edfa9b6 into master Jan 1, 2026
1 check passed
@jmgilman jmgilman deleted the fix/session-catalog-cleanup branch January 1, 2026 07:50
jmgilman added a commit that referenced this pull request Jan 3, 2026
Current behavior:
When a user exits a session (vs detaching), the multiplexer session is terminated but the catalog entry was left behind. This caused hjk ps to show stale sessions that no longer existed.

New behavior:
After AttachSession returns, we now check if the session still exists in the multiplexer. If not, we remove it from the catalog. This is best-effort cleanup that won't fail the command if it encounters errors.

Closes: #21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants