[BUG] Stale shutdown_request in team message queue terminates newly spawned teammate
Description
When a shutdown_request is sent to a teammate agent via SendMessage, and the teammate is then re-spawned with the same name in the same team, the new agent immediately receives the old shutdown_request from the message queue and terminates itself.
Steps to Reproduce
- Create a team:
TeamCreate: name=my-team - Spawn a teammate:
Agent: name=committer, team_name=my-team - Send shutdown:
SendMessage: to=committer, message={type: "shutdown_request"} - Teammate shuts down
- Spawn a new teammate with the same name:
Agent: name=committer, team_name=my-team - Expected: New agent is ready and waiting for messages
- Actual: New agent immediately receives the old
shutdown_requestand terminates
Observed Behavior
// Step 5: spawn new committer
Spawned successfully. agent_id: committer@my-team
// Immediately after:
{"type":"idle_notification","from":"committer","idleReason":"available"}
{"type":"teammate_terminated","message":"committer has shut down."}
{"type":"shutdown_approved","requestId":"shutdown-1775755623068@committer"}
The requestId matches the previous shutdown request, confirming the new agent consumed a stale message.
Expected Behavior
- Shutdown requests should be scoped to a specific agent instance, not just the agent name
- When an agent is terminated and a new one spawned with the same name, the message queue should be cleared of stale messages from the previous instance
- Alternatively,
shutdown_responsemessages should include theagent_idand be validated against the current instance
Environment
- Claude Code version: 2.1.97
- OS: Windows 11
- Terminal: bash
Workaround
Currently the only workaround is to spawn the new agent with a different name (e.g., committer-2) or create an entirely new team, which is impractical for long-running workflows.
Impact
This makes it impossible to reliably restart a teammate agent within the same team. Any workflow that needs to stop and restart a specific agent role (e.g., a commit agent that is spawned per-session) is affected.
Related Issues
- #31788 — TeamDelete blocked by hung agent
- #34614 — Teammates silently exit after spawn
- #25254 — Messages not delivered, agent deadlock
- #24385 — Stale pane tracking after shutdown
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗