Skip to content

fix(openai-agents): Stop setting transaction status when child span fails#6303

Merged
alexander-alderman-webb merged 11 commits into
masterfrom
webb/openai-agents/transaction
May 20, 2026
Merged

fix(openai-agents): Stop setting transaction status when child span fails#6303
alexander-alderman-webb merged 11 commits into
masterfrom
webb/openai-agents/transaction

Conversation

@alexander-alderman-webb
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb commented May 20, 2026

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 a span parameter and finish the span at the call site with Span.__exit__(), passing in the exception tuple if relevant.

Issues

Reminders

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

Codecov Results 📊

282 passed | Total: 282 | Pass Rate: 100% | Execution Time: 42.46s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 1.28%. Project has 14920 uncovered lines.
❌ Project coverage is 33.37%. Comparing base (base) to head (head).

Files with missing lines (7)
File Patch % Lines
tracing_utils.py 25.99% ⚠️ 578 Missing and 24 partials
agent_run.py 4.20% ⚠️ 137 Missing
runner.py 0.00% ⚠️ 93 Missing
utils.py 13.86% ⚠️ 87 Missing
invoke_agent.py 0.00% ⚠️ 39 Missing
error_tracing.py 0.00% ⚠️ 27 Missing
__init__.py 40.00% ⚠️ 3 Missing
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

Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

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

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_errored is removed from imports in runner.py; it previously set both the span and containing_transaction to INTERNAL_ERROR (see tracing_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 in test_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

Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py Outdated
Comment thread sentry_sdk/integrations/openai_agents/spans/invoke_agent.py Outdated
Copy link
Copy Markdown
Contributor

@sentry-warden sentry-warden Bot left a comment

Choose a reason for hiding this comment

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

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.py line 113: the except Exception block captures exc_info and enters with capture_internal_exceptions():.
  • Line 116 re-fetches span from context_wrapper, which can be None if _AgentInvocationSpanContext.__exit__ already ran (via _execute_handoffs or _execute_final_output) and called delattr(self._context_wrapper, '_sentry_agent_span').
  • Line 118: return inside the with block exits the entire coroutine — Python's return is not caught by capture_internal_exceptions(), so reraise(*exc_info) on line 124 is never reached.
  • The result is None propagated to the caller of _run_single_turn, hiding the underlying error.

Identified by Warden find-bugs

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review May 20, 2026 08:44
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner May 20, 2026 08:44
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ 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.

Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py Outdated
Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py Outdated
Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py
@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft May 20, 2026 08:47
Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py
Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py
Comment thread sentry_sdk/integrations/openai_agents/patches/agent_run.py Outdated
Comment thread sentry_sdk/integrations/openai_agents/spans/invoke_agent.py Outdated
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review May 20, 2026 09:34
@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft May 20, 2026 09:39
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review May 20, 2026 09:43
@alexander-alderman-webb alexander-alderman-webb merged commit 46c6f01 into master May 20, 2026
148 of 151 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/openai-agents/transaction branch May 20, 2026 12:54
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.

2 participants