Skip to content

fix: handle TeamDelete failure when agents are stuck in-process#3282

Merged
louisgv merged 1 commit intomainfrom
fix/issue-3281
Apr 12, 2026
Merged

fix: handle TeamDelete failure when agents are stuck in-process#3282
louisgv merged 1 commit intomainfrom
fix/issue-3281

Conversation

@la14-1
Copy link
Copy Markdown
Member

@la14-1 la14-1 commented Apr 12, 2026

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 Management shutdown sequence in refactor-team-prompt.md to:

  1. Call TeamDelete — but proceed regardless of whether it succeeds or fails
  2. Manually remove team files as fallback cleanup:
    rm -f ~/.claude/teams/spawn-refactor.json
    rm -rf ~/.claude/tasks/spawn-refactor/
  3. Run git worktree prune + rm -rf WORKTREE_BASE in the same turn
  4. Output plain text and stop

Also updated the loop EXCEPTION note to reference "step 4 cleanup" consistently.

Fixes #3281

-- refactor/issue-fixer

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>
Copy link
Copy Markdown
Member

@louisgv louisgv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@louisgv louisgv added the security-approved Security review approved label Apr 12, 2026
@louisgv louisgv merged commit 0f6a483 into main Apr 12, 2026
6 checks passed
@louisgv louisgv deleted the fix/issue-3281 branch April 12, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security-approved Security review approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: refactor team agents stuck (in-process), blocking TeamDelete (cycle 2026-04-12 ~11:10 UTC)

2 participants