Skip to content

fix: correct concurrent subagent trace parenting#302

Merged
Kyle-Verhoog merged 2 commits intomasterfrom
kyle/fix-concurrent-subagent-parenting
Mar 16, 2026
Merged

fix: correct concurrent subagent trace parenting#302
Kyle-Verhoog merged 2 commits intomasterfrom
kyle/fix-concurrent-subagent-parenting

Conversation

@Kyle-Verhoog
Copy link
Member

@Kyle-Verhoog Kyle-Verhoog commented Mar 16, 2026

Summary

  • When Claude Code spawns multiple concurrent subagents (parallel Task tool calls), the LIFO agent_span_stack caused spans to get parented to the wrong subagent
  • Fix SubagentStart to use the parent_id captured at PreToolUse time, add LLM-to-agent mappings in the link tracker, and prompt-based agent matching for first LLM calls
  • Add active_agents dict to SessionState for concurrent subagent resolution
  • Add test test_concurrent_subagents_parent_correctly

Test plan

  • All 20 existing tests pass unchanged
  • New concurrent subagent test verifies both subagents are parented to root

Claude session: 290749d0-c759-42b7-8d1b-d4edb76c65d3
Resume: claude --resume 290749d0-c759-42b7-8d1b-d4edb76c65d3

🤖 Generated with Claude Code

@Kyle-Verhoog Kyle-Verhoog force-pushed the kyle/fix-concurrent-subagent-parenting branch from 2118af4 to 3cf7a0e Compare March 16, 2026 13:40
Copy link
Contributor

@sabrenner sabrenner left a comment

Choose a reason for hiding this comment

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

lgtm! just a couple small non-blocking nits but 🚢

Kyle-Verhoog and others added 2 commits March 16, 2026 19:44
When Claude Code spawns multiple concurrent subagents (parallel Task
tool calls), the LIFO agent_span_stack caused spans to get parented to
the wrong subagent. Fix by using the parent_id captured at PreToolUse
time, tracking LLM-to-agent mappings in the link tracker, and adding
prompt-based agent matching for first LLM calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…_prompt

Address review nit — build request_text via direct string concatenation
instead of accumulating into a list and joining.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Kyle-Verhoog Kyle-Verhoog force-pushed the kyle/fix-concurrent-subagent-parenting branch from f7742f7 to 5601412 Compare March 16, 2026 23:45
@Kyle-Verhoog Kyle-Verhoog added the no-releasenote This PR does not require a releasenote entry label Mar 16, 2026
@Kyle-Verhoog Kyle-Verhoog merged commit c777599 into master Mar 16, 2026
18 of 19 checks passed
@Kyle-Verhoog Kyle-Verhoog deleted the kyle/fix-concurrent-subagent-parenting branch March 16, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-releasenote This PR does not require a releasenote entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants