-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When using Runner.run_streamed() with a session, if session.add_items() raises an exception, the stream_events() async generator hangs forever instead of propagating the error or terminating.
Debug information
openai 2.8.1
openai-agents 0.6.1
Python 3.13.0
Repro steps
MRE:
Run the following and the stream will hang...
from agents import Agent, Runner, SQLiteSession, set_default_openai_client
from openai import AsyncOpenAI
import asyncio
import os
set_default_openai_client(
AsyncOpenAI(
base_url="https://eu.api.openai.com/v1", api_key=os.environ["OPENAI_API_KEY"]
)
)
agent = Agent(
name="Assistant",
instructions="Reply very concisely.",
)
session = SQLiteSession("conversation_123")
async def _fake_add_items(**kwargs):
raise Exception("Simulated Exception in add_items")
session.add_items = _fake_add_items
async def main():
message = "What is the meaning of life?"
result = Runner.run_streamed(
agent,
input=message,
session=session,
)
async for event in result.stream_events():
print(type(event), event)
if __name__ == "__main__":
asyncio.run(main())Expected behavior
The exception should either:
• Be raised to the consumer iterating over stream_events()
• Be surfaced as an error event in the stream
• Cause the stream to terminate cleanly
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working