Skip to content

Background agent task-notifications silently dropped when multiple agents complete within seconds #45581

Closed

Description

@jungjoongi

Summary

When multiple background agents (run_in_background: true) complete within a narrow time window (< 30 seconds), some <task-notification> messages are silently dropped. The parent session never receives them. The agents themselves complete successfully (stop_reason: "end_turn"), produce all expected output files, and their output logs are written — but the orchestrating session is never notified.

This is distinct from #36690 (notifications arriving at wrong timing / racing with user questions). Here, notifications never arrive at all.

Reproduction

Setup

  • Claude Code v2.1.87, macOS, claude-opus-4-6
  • Orchestrator spawns N background agents simultaneously via Agent tool
  • Each agent writes files to disk upon completion

Steps

  1. Spawn 4–6 agents with run_in_background: true in a single message
  2. Wait for all agents to complete (they finish within ~30 seconds of each other)
  3. Observe that some <task-notification> messages never arrive

Observed behavior (2026-04-09 session)

Writer batch (4 agents, simultaneous spawn):

Agent Completed Notification
writer-batch-1 04:32:12 ✅ Received
writer-batch-2 04:32:20 ✅ Received
writer-batch-3 04:32:31 ✅ Received
writer-batch-4 04:32:40 ❌ Never received

Fact-checker batch (6 agents, simultaneous spawn):

Agent Completed Notification
fc-batch-1 07:49:46 ✅ Received
fc-batch-2 07:49:54 ✅ Received (delayed)
fc-batch-3 07:50:01 ✅ Received
fc-batch-4 07:50:09 ❌ Never received
fc-batch-5 07:50:15 ✅ Received
fc-batch-6 07:50:22 ✅ Received

Image-gen batch (3 agents, simultaneous spawn):

Agent Completed Notification
img-batch-1 08:16:55 ✅ Received
img-batch-2 08:17:01 ❌ Never received
img-batch-3 08:17:06 ✅ Received

Drop rate: 3/13 (23%)

Key evidence that agents completed successfully

  • All output files exist on disk with correct content
  • All agent output logs show stop_reason: "end_turn" (not crash/timeout)
  • Completion timestamps in output logs confirm work finished

Impact

  • Automated pipelines stall indefinitely — if no human is present to manually check file-based checkpoints, the orchestrator waits forever for a notification that will never come
  • Workaround required — timeout-based file checkpoint polling after last received notification (adds ~60s latency)
  • The system prompt states "you will be automatically notified when it completes — do NOT sleep, poll, or proactively check" — but this guarantee doesn't hold when agents complete near-simultaneously

Environment

  • Claude Code version: 2.1.87
  • Model: claude-opus-4-6 (orchestrator), claude-sonnet-4-6 + claude-opus-4-6 (agents)
  • Platform: macOS Darwin 25.2.0
  • Session type: Scheduled task (automated, no user present)

Related

Activity

  1. github-actions commented on Apr 9, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. Background Task Notifications Not Delivered When Multiple Agents Complete Simultaneously (v2.1.19) #20754
    2. [BUG] Bash run_in_background=true silently drops completion notifications for 2nd+ concurrent tasks #40235
    3. stream-json: background-task notification doesn't wake idle session (race in runAsyncAgentLifecycle) #39632

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  2. jungjoongi commented on Apr 9, 2026

    @jungjoongi
    Author

    Closing as duplicate. Root cause identified in #39632 (race in runAsyncAgentLifecycle where polling loop exits before enqueuePendingNotification fires). Added our production data (3/13 drops, 23% rate) as a comment there. Also 👍'd #20754.

  3. github-actions commented on Apr 17, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  4. locked as resolved and limited conversation to collaborators on Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:agentsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions