Skip to content

fix(claude): export background subagents, ignore api-request-blob, time model calls - #170

Open
sergioBMilan wants to merge 3 commits into
Arize-ai:mainfrom
BicicletasMilan:fix/claude-background-subagents
Open

sergioBMilan wants to merge 3 commits into
Arize-ai:mainfrom
BicicletasMilan:fix/claude-background-subagents

Conversation

@sergioBMilan

Copy link
Copy Markdown

Summary

Three fixes to the Claude Code high-fidelity export, all needed for sessions where subagents run in the background (the default Agent shape in recent Claude Code):

  1. Background subagents are exported under their launching Agent span. When a turn is exported, each async_launched Agent tool records its trace id and span id in session state (async_subagents). SubagentStop then renders the subagent transcript directly under that span, with its real SubagentStart..SubagentStop duration, even if no turn is open. A subagent that stops inside its launching turn keeps the existing foreground path (buffer + merge at Stop).
  2. api-request-blob records are ignored by the transcript parser. Only conversation records (type assistant / user, or no type) become events, so replayed tool blocks no longer duplicate every tool or create nameless Tool spans.
  3. Model calls start when their request went out: at the previous conversation record (the prompt, the last tool result or the previous response), instead of starting and ending at the response timestamp.

resolves #169

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other

How tested

  • New tests, each failing without its fix:
    • test_background_subagent_is_exported_under_its_launching_agent_span
    • test_background_subagent_that_stops_inside_its_turn_keeps_the_foreground_path
    • test_replayed_request_blobs_are_not_events
    • test_model_call_starts_at_the_record_that_sent_its_request
  • uv run pytest tests/ -m "not slow": 2741 passed, 3 skipped, 1 xfailed.
  • pre-commit run --all-files: clean.
  • End to end with Claude Code 2.1.301 and Phoenix Cloud: claude -p launching 3 background general-purpose subagents (wc, Read, a failing ls), with the main agent ending its turn before they finish. Every subagent arrives under its Agent span with its tools (the failing ls as ERROR) and model calls. Phoenix's cumulative token count on each subagent span matches the subagent transcript exactly, and model calls last 2-12 s instead of 0 s.

Checklist

  • Tests pass (uv run pytest tests/ -m "not slow")
  • Pre-commit clean (uv run pre-commit run --all-files)
  • Ran the code-review skill and addressed findings
  • Docs updated if needed (no user-facing setting changed)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Duy7FYPv9hkmbYZa3UXUao

sergioBMilan and others added 3 commits October 16, 2026 19:26
…span

A background subagent (Agent with run_in_background, the default shape in
recent Claude Code) returns async_launched at once and stops after the
launching turn was exported, often while no turn is open. SubagentStop
returned early (no current trace) or buffered a descriptor that no later
turn could correlate, so the subagent and every tool it ran were dropped.

The launching turn now records, per async launch, the trace and span id of
its Agent tool. SubagentStop exports the subagent tree directly under that
span, with its real SubagentStart..SubagentStop duration. Subagents that
stop inside their launching turn keep the existing foreground path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Duy7FYPv9hkmbYZa3UXUao
Claude Code 2.1.3xx writes the request it replays to the model as
api-request-blob records, with copies of earlier tool_use and tool_result
blocks. The parser read them as assistant/user messages, so every tool was
rendered twice: once complete, once pending under an empty model call, plus
nameless Tool spans for the replayed results. Only conversation records
(type assistant/user) are events now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Duy7FYPv9hkmbYZa3UXUao
The transcript stamps a model response only when it arrives, so every
model call span started and ended at the same instant (0 s). Its request
went out at the previous conversation record -- the prompt, the last tool
result or the previous response -- so the call now starts there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Duy7FYPv9hkmbYZa3UXUao
@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@sergioBMilan

Copy link
Copy Markdown
Author

Hi Arize team,

I'm contributing on behalf of my employer, BicicletasMilan, and our legal/management team would prefer to cover our contributions with a Corporate CLA rather than individual signatures. Section 4.1 of CLA.md mentions "a separate Corporate CLA with Arize AI", but I couldn't find that document in the repo.

Could you share the Corporate CLA and the process to sign it? Once it's signed, how should we get our contributors recognized by the CLA bot? Should each person still comment the sign phrase, or would you add them to the allowlist?

In the meantime, I'll hold off on signing the individual CLA for #170. Thanks, and thanks to @AlexZahar for the independent repro in #169.

This branch has not been deployed

No deployments
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.

[BUG]: Claude Code background subagents are dropped; api-request-blob records duplicate tools

1 participant