claude-code - 💡(How to fix) Fix [BUG] CLI emits task_notification before subagent's ResultMessage — causes premature completion signal in multi-agent pipelines

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

In a multi-agent pipeline using claude_agent_sdk, the CLI emits task_notification (status=completed) for a subagent before the subagent has finished executing its tool calls and sending its ResultMessage. This causes the orchestrating (lead) agent to act on a false completion signal — dispatching downstream tasks that depend on the subagent's output files, which don't exist yet.

Observed behavior (from trace msg logs with timestamps):

10:07:11 [TASK_START] R1 researcher 10:08:36 Lead receives Agent R1 completed 10:08:36 Lead dispatches Reviewer-1 (trusting the notification) 10:08:36 R1 TASK_PROG: last_tool=WebSearch, tools=23 ← STILL RUNNING 10:09:29 R1 TASK_PROG: last_tool=WebSearch, tools=31 ← STILL RUNNING 10:12:36 R1 TASK_PROG: last_tool=Write, tools=38 ← ACTUALLY writes file now (4 min later)

The lead agent receives task_notification at tools=23, but the researcher continues to execute 15 more tool calls over 4 minutes before actually writing its output file.

Broader impact across 5 parallel researchers:

ResearcherNotification timeActual Write timeGap
R110:08:36 (tools≈23)10:12:36 (tools=38)+4 min
R210:08:39 (tools≈17)10:14:27 (tools=40)+5.8 min
R310:09:02 (tools≈13)Never (tools=61+)

[Reference:]https://github.com/anthropics/claude-agent-sdk-python/issues/882

Root Cause

In a multi-agent pipeline using claude_agent_sdk, the CLI emits task_notification (status=completed) for a subagent before the subagent has finished executing its tool calls and sending its ResultMessage. This causes the orchestrating (lead) agent to act on a false completion signal — dispatching downstream tasks that depend on the subagent's output files, which don't exist yet.

Observed behavior (from trace msg logs with timestamps):

10:07:11 [TASK_START] R1 researcher 10:08:36 Lead receives Agent R1 completed 10:08:36 Lead dispatches Reviewer-1 (trusting the notification) 10:08:36 R1 TASK_PROG: last_tool=WebSearch, tools=23 ← STILL RUNNING 10:09:29 R1 TASK_PROG: last_tool=WebSearch, tools=31 ← STILL RUNNING 10:12:36 R1 TASK_PROG: last_tool=Write, tools=38 ← ACTUALLY writes file now (4 min later)

The lead agent receives task_notification at tools=23, but the researcher continues to execute 15 more tool calls over 4 minutes before actually writing its output file.

Broader impact across 5 parallel researchers:

ResearcherNotification timeActual Write timeGap
R110:08:36 (tools≈23)10:12:36 (tools=38)+4 min
R210:08:39 (tools≈17)10:14:27 (tools=40)+5.8 min
R310:09:02 (tools≈13)Never (tools=61+)

[Reference:]https://github.com/anthropics/claude-agent-sdk-python/issues/882

Fix Action

Fix / Workaround

Summary

In a multi-agent pipeline using claude_agent_sdk, the CLI emits task_notification (status=completed) for a subagent before the subagent has finished executing its tool calls and sending its ResultMessage. This causes the orchestrating (lead) agent to act on a false completion signal — dispatching downstream tasks that depend on the subagent's output files, which don't exist yet.

10:07:11 [TASK_START] R1 researcher 10:08:36 Lead receives Agent R1 completed 10:08:36 Lead dispatches Reviewer-1 (trusting the notification) 10:08:36 R1 TASK_PROG: last_tool=WebSearch, tools=23 ← STILL RUNNING 10:09:29 R1 TASK_PROG: last_tool=WebSearch, tools=31 ← STILL RUNNING 10:12:36 R1 TASK_PROG: last_tool=Write, tools=38 ← ACTUALLY writes file now (4 min later)

Setup: A lead agent spawns researcher subagents via the Task tool. Each researcher performs web searches, then writes a file to disk as its final step. A reviewer subagent is dispatched only after the corresponding researcher "completes."

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Summary

In a multi-agent pipeline using claude_agent_sdk, the CLI emits task_notification (status=completed) for a subagent before the subagent has finished executing its tool calls and sending its ResultMessage. This causes the orchestrating (lead) agent to act on a false completion signal — dispatching downstream tasks that depend on the subagent's output files, which don't exist yet.

Observed behavior (from trace msg logs with timestamps):

10:07:11 [TASK_START] R1 researcher 10:08:36 Lead receives Agent R1 completed 10:08:36 Lead dispatches Reviewer-1 (trusting the notification) 10:08:36 R1 TASK_PROG: last_tool=WebSearch, tools=23 ← STILL RUNNING 10:09:29 R1 TASK_PROG: last_tool=WebSearch, tools=31 ← STILL RUNNING 10:12:36 R1 TASK_PROG: last_tool=Write, tools=38 ← ACTUALLY writes file now (4 min later)

The lead agent receives task_notification at tools=23, but the researcher continues to execute 15 more tool calls over 4 minutes before actually writing its output file.

Broader impact across 5 parallel researchers:

ResearcherNotification timeActual Write timeGap
R110:08:36 (tools≈23)10:12:36 (tools=38)+4 min
R210:08:39 (tools≈17)10:14:27 (tools=40)+5.8 min
R310:09:02 (tools≈13)Never (tools=61+)

[Reference:]https://github.com/anthropics/claude-agent-sdk-python/issues/882

What Should Happen?

Expected behavior

task_notification with status=completed should only be emitted after the subagent's ResultMessage has been written to the transport stream — i.e., after the subagent has fully finished execution (all tool calls completed, final response generated).

Actual behavior

task_notification is emitted while the subagent subprocess is still actively executing tool calls. The Python SDK relays it immediately (confirmed by SDK maintainer in anthropics/claude-agent-sdk-python#882).

Steps to Reproduce

Environment

  • Claude Code version: v2.1.92
  • claude-agent-sdk-python: 0.1.56
  • OS: Linux (WSL2, kernel 5.15.167.4-microsoft-standard-WSL2)
  • Python: 3.10
  • Architecture: Lead agent (sonnet4.6) → 5 parallel researcher subagents → reviewer subagents

Reproduction

Setup: A lead agent spawns researcher subagents via the Task tool. Each researcher performs web searches, then writes a file to disk as its final step. A reviewer subagent is dispatched only after the corresponding researcher "completes."

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

v2.1.92

Platform

Other

Operating System

Ubuntu/Debian Linux

Terminal/Shell

WSL (Windows Subsystem for Linux)

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

task_notification with status=completed should only be emitted after the subagent's ResultMessage has been written to the transport stream — i.e., after the subagent has fully finished execution (all tool calls completed, final response generated).

Actual behavior

task_notification is emitted while the subagent subprocess is still actively executing tool calls. The Python SDK relays it immediately (confirmed by SDK maintainer in anthropics/claude-agent-sdk-python#882).

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] CLI emits task_notification before subagent's ResultMessage — causes premature completion signal in multi-agent pipelines