fix(llmobs): eagerly finalize stream to prevent nested agent spans#18247
Conversation
|
Codeowners resolved as |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 24f78a60e1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
sabrenner
left a comment
There was a problem hiding this comment.
code lgtm, i can QA in a bit but don't block on that. just one dumb question, and responding to codex's - i think we can ignore it for now, but if i'm reading it wrong, feel free to address it and i can re-review!
Description
The claude agent sdk closes async generators lazily which can lead to unwanted nested agent spans. This PR attempts to fix this by finishing the agent span when the
ResultMessagechunk is received.Testing
Repro script:
Before
The first agent span is left open indefinitely, leading to the second agent span being treated as its child (nested underneath it within the same trace).
After
Agent spans are eagerly closed when

ResultMessageis received, leading to two separate traces.Risks
Additional Notes