-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ValueError during agents.tracing shutdown even when tracing is disabled #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for the bug report @cadenzadesigns. Not sure why, but I'm unable to reproduce this behavior. Would you be able to contribute a failing test case to the repo? Also, here's a potential fix: #503 |
Hi @rm-openai , Following up on the request to provide a failing test case for this issue (#502). I attempted to create a minimal test case within the
Outcome: However: Here are the environment details for my project where the error persists:
Conclusion: Let me know if there's any other way I can help test or provide more information. Thanks! |
When running tests involving the
openai-agents
SDK withpytest
, even after explicitly disabling tracing usingagents.set_tracing_disabled(True)
at the start of the test session,ValueError: I/O operation on closed file
errors occur during the final process shutdown. These errors originate fromagents.tracing.setup.shutdown
attempting to log debug messages after standard output/error streams appear to be closed.This occurs reliably after the pytest summary (e.g., "XXX passed, Y skipped...") is printed, so it doesn't seem to affect test results but creates noisy output in CI/test logs.
It seems
set_tracing_disabled(True)
prevents trace export but does not prevent the tracing components from initializing or attempting their shutdown logging.Debug information
Repro steps
openai-agents
,openai
, andpytest
.tests/test_agent_run.py
) that usesagents.Runner.run
orrun_sync
(even a simple "hello world" agent).tests/conftest.py
with the following hook to disable tracing programmatically:poetry run pytest tests/
.Expected behavior
When tracing is disabled using
set_tracing_disabled(True)
, no tracing-related shutdown logic should execute, or at least it should not attempt to log messages that causeValueError
after streams are closed. The test run should finish cleanly after the pytest summary.Actual behavior
The tests pass, but the following errors are printed to stderr after the pytest summary:
--- Logging error ---
Traceback (most recent call last):
File "/path/to/your/python/lib/python3.12/logging/init.py", line 1163, in emit
stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
File "/path/to/your/venv/lib/python3.12/site-packages/agents/tracing/setup.py", line 205, in shutdown
logger.debug("Shutting down trace provider")
Message: 'Shutting down trace provider'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
File "/path/to/your/python/lib/python3.12/logging/init.py", line 1163, in emit
stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
File "/path/to/your/venv/lib/python3.12/site-packages/agents/tracing/setup.py", line 206, in shutdown
self.multi_processor.shutdown()
File "/path/to/your/venv/lib/python3.12/site-packages/agents/tracing/setup.py", line 72, in shutdown
logger.debug(f"Shutting down trace processor {processor}")
Message: 'Shutting down trace processor <agents.tracing.processors.BatchTraceProcessor object at ...>'
Attempts to disable tracing via the
OPENAI_AGENTS_DISABLE_TRACING=1
environment variable orRunConfig(tracing_disabled=True)
also failed to prevent these specific shutdown errors in the test environment.Thanks for looking into this!
The text was updated successfully, but these errors were encountered: