Repository navigation
fix(swarm): stop deleting teams and task lists when the CLI process exits - #213
Conversation
…xits init() registered a shutdown hook that removed every team created in the session (team directory, task directory) unless TeamDelete had run. The server stops the CLI on Stop, /clear, restart and app quit, so a stop lost the whole team. Delete teams only through TeamDelete. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
# Conflicts: # CHANGELOG.md
GoDiao
left a comment
There was a problem hiding this comment.
Thanks @pcbeingused333! This is the fix #199 proposed: no shutdown hook, so teams go away only on an explicit TeamDelete. We ran the new test against main's init.ts and it fails there (the team directory is gone); with your change it passes, also in random order with the swarm and teams tests.
We pushed a merge of main and a small commit on top: your CHANGELOG entry had landed in the 0.6.1 section, so it now sits under [Unreleased] with a thanks line; we removed the added comments (we keep new code comment-free); and we fixed two existing comments in teamHelpers.ts and state.ts that said teams are cleaned up on exit.
We left cleanupSessionTeams and the session tracking in place, as you did: what to do with teams nobody deletes is the separate decision #199 leaves open. Approving and merging. Thanks again!
Fixes #199
When the CLI process of a session that created a team exits, the team directory and its task list were deleted.
init()registered a shutdown hook (cleanupSessionTeams) that removed every team created in the session unlessTeamDeletehad run. The server stops the CLI in many ordinary situations (Stop after the 3 s interrupt window,/clear, a session restart, the disconnect timeout, an idle prewarmed session, quitting the app, rewinding a session), so each of them lost the team, its members' messages and all tasks.This removes that hook. Teams are now deleted only when the user or the lead runs
TeamDelete, and a restarted or resumed session finds its team and task list on disk. The session-team tracking andcleanupSessionTeamsstay in place and are no longer called on exit; what to do with teams that are never deleted is the separate decision the issue leaves open.One behaviour to be aware of: the removed hook also killed teammates' tmux/iTerm2 panes when the leader exited. That no longer happens, so pane-backed teammates are left running, in line with keeping the team available to the next session.
Test:
src/entrypoints/init.teamCleanup.test.tscreates a team and task list on disk, marks the team as created by the session, runs the realinit()and the registered shutdown cleanups, and asserts both still exist. It fails on currentmainand passes with this change;src/utils/swarmandsrc/server/__tests__/teams.test.tsstill pass (37 tests, bun 1.4). The CHANGELOG has a line under Unreleased. The full type check and lint were not run, and this was not tried against a live tmux session.This change was made with Claude Code.