test + fix attempt - #2352
Conversation
There was a problem hiding this comment.
💡 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".
| const pendingIndex = pendingSubAgentToolUseIds.findIndex( | ||
| (pendingToolUseId) => | ||
| subAgentDetailsByToolUseId.get(pendingToolUseId)?.agentType === | ||
| input.agent_type, | ||
| ); |
There was a problem hiding this comment.
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 👍 / 👎.
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:
Proposed change:
