Repository navigation
test(sdk): cover agent name cleanup for spans after an @agent - #4777
doronkopit5 wants to merge 1 commit into
Conversation
Adds regression tests for #4378, which #4405 fixed: a @task that runs after an @agent (inside a @workflow or standalone, sync and async) gets no gen_ai.agent.name, and the agent name is detached when the agent raises or a generator agent is closed early. The generator tests also assert the agent span has ended. Closes #4378 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What
Test-only PR. It closes #4378, which #4405 already fixed (released in traceloop-sdk 0.62.2):
_setup_spannow keeps the token returned byset_agent_name(), and_detach_tokensdetaches it on every exit path.These tests pin the reporter's cases so the leak can't come back. All of them are in
packages/traceloop-sdk/tests/test_agent_name_scope.py:@taskafter an@agentinside a@workflowkeepstraceloop.workflow.nameand gets nogen_ai.agent.name. The agent's own child span still carries the agent name.@taskafter a completed@agentgets no agent name, and the contextagent_nameis cleared.ERROR, and the agent name is detached before the next span.close()after one item ends the agent span and clears the context.aclosingtests now also assert that the agent span has ended.No production code changes. All 18 tests in the file pass on main, and ruff and mypy are clean.
Out of scope: the refactor proposed in the issue (one attach that carries the agent name in the span context). It isn't needed for the fix.
Closes #4378
🤖 Generated with Claude Code
Summary by CodeRabbit