You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8b1ab15
Browse filesBrowse the repository at this point in the historyBrowse files
fix(claude-agent-sdk): keep backgrounded subagent spans open until task_notification
A foreground subagent moved to the background arrives as system/task_updated
with patch.is_backgrounded (sdk.d.ts:6059; task_id only), or follows an app
call to Query.backgroundTasks() (sdk.d.ts:3234). Both were ignored: the
subagent span ended at the "running in the background" tool_result and the
subagent's later turns were parented to an ended span.
- task_started records task_id -> tool_use_id; task_updated with
patch.is_backgrounded marks that subagent background.
- The Query proxy intercepts backgroundTasks(toolUseId?): matching open
foreground subagents are marked before the call is forwarded, and
unmarked if it rejects or resolves false. The caller gets the original
promise.
- A task_notification with status failed/stopped now makes the subagent
span ERROR in the foreground case too (it ended OK before when the
tool_result itself was not an error).
README documents background subagents.
approved: Nikhil 2026-10-03 blanket
Refs: TH-8235
Copy file name to clipboardExpand all lines: typescript/packages/traceai_claude_agent_sdk/README.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,10 @@ await shutdown(); // flush before a short script exits
67
67
68
68
One API response that the SDK splits over several assistant messages (same `message.id`) is one turn.
69
69
70
+
### Background subagents
71
+
72
+
A foreground subagent span ends with its `tool.Agent` / `tool.Task` result. A subagent that runs in the background stays open after that tool result (which is only the "running in the background" placeholder) until its `system/task_notification`, so its later turns and tools still nest under a live span. A subagent counts as background when the tool input has `run_in_background: true`, `task_started.is_backgrounded` is true, a later `task_updated` carries `patch.is_backgrounded: true`, or the app calls `Query.backgroundTasks()` (all foreground subagents, or the one whose `tool_use_id` it was given; undone if the call rejects or returns `false`). The subagent span is ERROR when the notification status is `failed` or `stopped` (`claude_agent.subagent.status` has the value). A background subagent with no notification by the time the query ends is closed as ERROR "Subagent span not completed". The subagent span can therefore end after its parent tool span.
73
+
70
74
| Field | Attributes | Source |
71
75
|---|---|---|
72
76
| Model |`gen_ai.request.model`, `claude_agent.model`|`options.model`, the init message, each assistant message |
0 commit comments