Skip to content

Conversation

@jmgilman
Copy link
Collaborator

@jmgilman jmgilman commented Jan 1, 2026

Summary

  • Extract common shutdown sequence into shutdownContainer helper method
  • Update Stop, Remove, and Recreate to use the unified helper
  • Improve error handling to report cleanup failures instead of silently ignoring them

Problem

The Remove method was silently ignoring container stop/remove errors, which could leave orphaned containers when multiplexer sessions were still active. This caused "Resource busy" errors that were never surfaced to the user.

Additionally, there was inconsistent behavior across Stop, Remove, and Recreate:

  • Stop and Recreate properly killed sessions before stopping containers
  • Remove did not, leading to the "Resource busy" failures

Solution

Created a shutdownContainer helper that encapsulates the common shutdown sequence:

  1. Kill all multiplexer sessions
  2. Remove session logs
  3. Wait for sessions to terminate
  4. Stop container with retry logic (handles transient "Resource busy" errors)
  5. Optionally remove the container

All three methods now use this helper, ensuring consistent behavior.

Additional Improvements

  • Create cleanup now uses stopContainerWithRetry and reports failures
  • CreateSession cleanup reports if session kill fails (prevents orphaned tmux sessions)
  • Remove now properly handles worktree removal errors (fails on real errors, ignores "not found")
  • All cleanup failures are included in error messages so users have visibility

Test plan

  • All existing tests pass (just check)
  • Manual end-to-end test: create instance with session, rm instance, verify both tmux session and container are cleaned up

🤖 Generated with Claude Code

Extract common shutdown sequence into shutdownContainer helper that:
- Kills all multiplexer sessions before stopping container
- Waits for sessions to terminate
- Removes session logs
- Uses retry logic for container stop (handles "Resource busy")
- Optionally removes container after stopping

Update Stop, Remove, and Recreate to use the new helper, ensuring
consistent behavior across all container lifecycle operations.

Also improve error handling throughout:
- Create cleanup now uses stopContainerWithRetry and reports failures
- CreateSession cleanup reports if session kill fails
- Remove now properly handles worktree removal errors
- All cleanup failures are included in error messages for visibility

Previously, Remove was silently ignoring container stop/remove errors,
which could leave orphaned containers when sessions were still active.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jmgilman jmgilman merged commit 1c149ec into master Jan 1, 2026
1 check passed
@jmgilman jmgilman deleted the fix/consistent-container-shutdown branch January 1, 2026 06:12
jmgilman added a commit that referenced this pull request Jan 3, 2026
…ources

Current behavior:
Container shutdown logic was inconsistent across Stop, Remove, and Recreate operations. Remove was silently ignoring container stop/remove errors, which could leave orphaned containers when sessions were still active. Cleanup error handling was inconsistent and some failures were ignored.

New behavior:
Extract common shutdown sequence into shutdownContainer helper that kills all multiplexer sessions before stopping container, waits for sessions to terminate, removes session logs, uses retry logic for container stop, and optionally removes container. All operations now use consistent shutdown logic with proper error handling and reporting of cleanup failures.

Closes: #19
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