Background Task Notifications Not Delivered When Multiple Agents Complete Simultaneously (v2.1.19)
Bug Description
When running multiple background agents (run_in_background: true) in parallel, completion notifications are not consistently delivered to the main session. Only 1 out of 3 agents sent a notification upon completion.
Environment
- Claude Code Version: 2.1.19
- OS: macOS Sequoia 15.2 (Darwin 25.2.0)
- Model: claude-opus-4-5-20251101
- Terminal: iTerm2
Steps to Reproduce
- Launch 3 background agents simultaneously:
Task({
subagent_type: "general-purpose",
description: "Task 1",
prompt: "...",
run_in_background: true
})
// Repeat for Task 2 and Task 3
- While agents are running, send a user message (e.g., "checking status")
- Wait for all agents to complete
Expected Behavior
All 3 agents should deliver <task-notification> messages upon completion.
Actual Behavior
- Agent 1 (a34bb07): ✅ Notification received
- Agent 2 (a0fc025): ❌ No notification (but completed successfully)
- Agent 3 (a194492): ❌ No notification (but completed successfully)
All agents completed successfully (verified via tail on output files), but only 1 notification was delivered to the main session.
Evidence
Output files confirm completion:
$ grep -c "stop_reason" ~/.claude/projects/.../subagents/agent-*.jsonl
agent-a0fc025.jsonl:22 # Completed
agent-a194492.jsonl:41 # Completed
agent-a34bb07.jsonl:42 # Completed (notification received)
Suspected Cause
Race condition in notification queue processing:
- Multiple agents complete around the same time
- User sends a message while notifications are queued
- Queue processing is interrupted or notifications are "swallowed"
Workaround
Manually check agent output files:
tail -20 /private/tmp/claude/-Users-*/tasks/*.output
Or wait a few seconds after agents complete before sending any messages.
Impact
- Users cannot reliably track background task completion
- Workflow automation based on notifications becomes unreliable
- Parallel agent execution loses observability
Related
This may be related to the notification queue handling introduced in v2.1.16+ with the new task management system.
---
Thank you for looking into this! Happy to provide additional logs or context.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗