Skip to content

test + fix attempt - #2352

Open
Pedro Mora (stretpjc) wants to merge 1 commit into
mainfrom
Claude-Agent-SDK-subagent-tool-spans-issue
Open

test + fix attempt#2352
Pedro Mora (stretpjc) wants to merge 1 commit into
mainfrom
Claude-Agent-SDK-subagent-tool-spans-issue

Conversation

@stretpjc

@stretpjc Pedro Mora (stretpjc) commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes a race where local Claude Agent SDK tool spans could be parented to the root span before stream consumption.
Correlates Agent/Task and subagent lifecycle hooks using the real tool-use ID, then records tool parenting during PreToolUse. Adds a hermetic regression test covering execution before and after stream consumption.

Relevant internal linear SDK-222
Test:
3.21.0:
Screenshot 2026-08-11 at 12 02 50 PM

Proposed change:
Screenshot 2026-08-11 at 12 03 06 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de9a5c60c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

Comment on lines +756 to +760
const pendingIndex = pendingSubAgentToolUseIds.findIndex(
(pendingToolUseId) =>
subAgentDetailsByToolUseId.get(pendingToolUseId)?.agentType ===
input.agent_type,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correlate concurrent subagents by a unique identifier

When two pending Agent/Task calls use the same subagent_type and their SubagentStart callbacks arrive in a different order, this findIndex assigns each agent_id to the first queued delegation rather than its actual delegation. Subsequent local-tool PreToolUse hooks then record the wrong toolUseToParent relationship, corrupting both subagents' span trees; the correlation needs an identifier or ordering guarantee that distinguishes same-type concurrent agents.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant