fix(openai-agents): Stop setting transaction status when child span fails#6303
Conversation
Codecov Results 📊✅ 282 passed | Total: 282 | Pass Rate: 100% | Execution Time: 42.46s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 1.28%. Project has 14920 uncovered lines. Files with missing lines (7)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 33.42% 33.37% -0.05%
==========================================
Files 190 190 —
Lines 22366 22392 +26
Branches 7594 7594 —
==========================================
+ Hits 7475 7472 -3
- Misses 14891 14920 +29
- Partials 744 744 —Generated by Codecov Action |
There was a problem hiding this comment.
No test validates that transaction status is not set when a child span fails
The PR's stated goal is to stop setting the transaction status when a child span (e.g. invoke_agent) fails, but there is no test verifying that the transaction status remains clean after a child-span failure on a successful overall run.
Evidence
set_span_erroredis removed from imports inrunner.py; it previously set both the span andcontaining_transactiontoINTERNAL_ERROR(seetracing_utils.py:1224).span.__exit__(*exc_info)in the new code (e.g.agent_run.py_run_single_turn) only sets the individual span's status, not the containing transaction.- The only
contexts["trace"]["status"]assertion intest_openai_agents.py(line 3123) covers a total-run-failure case, not the scenario where a child span errors but the overall workflow succeeds. - There is no test asserting
transaction["contexts"]["trace"]["status"] != "internal_error"(or== "ok") when a recoverable child-span error occurs, leaving the core behavioral change unvalidated.
Identified by Warden code-review
There was a problem hiding this comment.
Exception from original_run_single_turn is silently swallowed when span is unexpectedly None
In agent_run.py line 117–118, if not span: return inside the except Exception handler returns None from _run_single_turn instead of reaching the reraise(*exc_info) on line 124, discarding the original exception and letting the caller believe the call succeeded.
Evidence
agent_run.pyline 113: theexcept Exceptionblock capturesexc_infoand enterswith capture_internal_exceptions():.- Line 116 re-fetches
spanfromcontext_wrapper, which can beNoneif_AgentInvocationSpanContext.__exit__already ran (via_execute_handoffsor_execute_final_output) and calleddelattr(self._context_wrapper, '_sentry_agent_span'). - Line 118:
returninside thewithblock exits the entire coroutine — Python'sreturnis not caught bycapture_internal_exceptions(), soreraise(*exc_info)on line 124 is never reached. - The result is
Nonepropagated to the caller of_run_single_turn, hiding the underlying error.
Identified by Warden find-bugs
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2dc0251. Configure here.

Description
Stop modifying the transaction, since the transaction may not be managed by
openai-agents.Stop finishing spans inside
update_invoke_agent_span(). Change the function to accept aspanparameter and finish the span at the call site withSpan.__exit__(), passing in the exception tuple if relevant.Issues
Reminders
tox -e linters.feat:,fix:,ref:,meta:)