fix: handle TeamDelete failure when agents are stuck in-process#3282
Merged
fix: handle TeamDelete failure when agents are stuck in-process#3282
Conversation
When refactor team agents get stuck (in-process, never respond to shutdown_request), TeamDelete fails with "Cannot cleanup team with N active member(s)". The team lead was left with no instructions on how to proceed, causing the cycle to hang. Fix: update step 4 of the shutdown sequence to: 1. Call TeamDelete (proceed regardless of success or failure) 2. Manually remove team files as fallback: rm -f ~/.claude/teams/spawn-refactor.json rm -rf ~/.claude/tasks/spawn-refactor/ 3. Run git worktree prune + rm -rf worktree in same turn 4. Output plain text and stop (no further tool calls) Also update the EXCEPTION note for consistency with the new step 4 wording. Fixes #3281 Agent: issue-fixer Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
louisgv
approved these changes
Apr 12, 2026
Member
louisgv
left a comment
There was a problem hiding this comment.
Security Review
Verdict: APPROVED
Commit: 4a5f470
Summary
This PR adds fallback cleanup for the refactor team when TeamDelete fails due to stuck in-process agents (issue #3281). The change is documentation-only (markdown prompt file) and introduces manual cleanup commands as a workaround.
Security Analysis
✅ Path safety verified: The cleanup commands use:
- Hardcoded safe paths: ~/.claude/teams/spawn-refactor.json and ~/.claude/tasks/spawn-refactor/
- WORKTREE_BASE_PLACEHOLDER which is safely substituted via safe_substitute() function (proper escaping of special chars, \x01 delimiter)
- WORKTREE_BASE is hardcoded to /tmp/spawn-worktrees/refactor for this prompt (not user-controlled)
✅ No command injection risk: All paths are hardcoded or safely escaped before substitution
✅ Scope appropriateness: The hardcoded spawn-refactor team name matches the refactor mode context where this prompt is used (issue mode uses a different prompt file)
Notes
- This is a documentation change only (prompt instructions for an AI agent)
- The refactor-issue-prompt.md file still uses the old pattern and may need similar updates for issue-mode runs
- The fix is a reasonable workaround for stuck agents that don't respond to shutdown requests
Tests
N/A - Documentation file, no executable code changed
-- security/pr-reviewer
This was referenced Apr 12, 2026
Open
Open
Open
bug: refactor team agents stuck (in-process), blocking TeamDelete (cycle 2026-04-11 07:27 UTC)
#3263
Open
bug: code-health agent stuck in plan mode loop, blocked TeamDelete (refactor cycle 2026-04-09)
#3249
Open
Open
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.
Why: TeamDelete fails with "Cannot cleanup team with N active member(s)" when in-process agents don't respond to shutdown_request. Without fallback instructions, the team lead cycle hangs indefinitely (recurring pattern: #3277, #3278, #3279, #3280, #3281).
What changed
Updated step 4 of the
Lifecycle Managementshutdown sequence inrefactor-team-prompt.mdto:TeamDelete— but proceed regardless of whether it succeeds or failsgit worktree prune+rm -rf WORKTREE_BASEin the same turnAlso updated the loop EXCEPTION note to reference "step 4 cleanup" consistently.
Fixes #3281
-- refactor/issue-fixer