Skip to content

Conversation

@sentrivana
Copy link
Contributor

It looks like we're running into #4718 (and probably #4690) because the different agent runs are not properly isolated. This only seems to be a problem when multiple agent runs are awaited at once (e.g. via asyncio.gather) -- it seems that leads to some scope bleed.

import asyncio

import sentry_sdk
from agents import Agent, Runner
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration

sentry_sdk.init(...)

main_agent = Agent(
    name="main_agent",
    model="gpt-5",
)

async def run_agent() -> None:
    runner = await Runner.run(
        starting_agent=main_agent,
        input="How are you?",
    )
    print(runner.final_output)


async def main() -> None:
    await asyncio.gather(*[run_agent() for _ in range(2)])  # throws an error
    # await asyncio.gather(run_agent())  # works

@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 84.87%. Comparing base (28d0ddd) to head (23db0c8).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...y_sdk/integrations/openai_agents/patches/runner.py 92.30% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4720      +/-   ##
==========================================
+ Coverage   84.84%   84.87%   +0.03%     
==========================================
  Files         156      156              
  Lines       16109    16110       +1     
  Branches     2740     2740              
==========================================
+ Hits        13667    13673       +6     
+ Misses       1655     1650       -5     
  Partials      787      787              
Files with missing lines Coverage Δ
...dk/integrations/openai_agents/patches/agent_run.py 82.53% <ø> (ø)
...y_sdk/integrations/openai_agents/patches/runner.py 95.45% <92.30%> (+0.21%) ⬆️

... and 2 files with indirect coverage changes

@sentrivana sentrivana marked this pull request as ready for review August 25, 2025 14:40
@sentrivana sentrivana requested a review from a team as a code owner August 25, 2025 14:40
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@sl0thentr0py sl0thentr0py left a comment

Choose a reason for hiding this comment

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

change looks ok in itself, don't have context on the whole integration

@sentrivana sentrivana enabled auto-merge (squash) August 26, 2025 07:46
@sentrivana sentrivana merged commit eee4c4b into master Aug 26, 2025
138 checks passed
@sentrivana sentrivana deleted the ivana/isolate-openai-agents-runner branch August 26, 2025 07:53
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.

'Span' object has no attribute '_context_manager_state'

2 participants