Skip to content

Fix CI: propagate bg logger across threads for openai-agents >= 0.8#1344

Open
clutchski wants to merge 1 commit intomainfrom
matt/fix-ci
Open

Fix CI: propagate bg logger across threads for openai-agents >= 0.8#1344
clutchski wants to merge 1 commit intomainfrom
matt/fix-ci

Conversation

@clutchski
Copy link
Collaborator

Summary

  • Root cause: _override_bg_logger was threading.local(), which doesn't propagate to child threads. openai-agents 0.8.0 runs sync @function_tool functions via asyncio.to_thread(), so spans created in tool worker threads logged to the wrong (real HTTP) logger instead of the test memory logger.
  • Changed _override_bg_logger from threading.local() to ContextVar so it propagates via asyncio.to_thread() while remaining isolated per-context
  • Added setup_threads() call in BraintrustTracingProcessor.__init__() to propagate ContextVar context across ThreadPoolExecutor worker threads
  • Added test_openai_agents nox session with version matrix (latest, 0.8.0, 0.7.0) for independent agents SDK version testing

Test plan

  • test_agents_tool_openai_nested_spans passes (was failing)
  • All 41 OpenAI wrapper tests pass
  • All 104 logger tests pass
  • Core tests pass (343 passed, pre-existing teardown issues excluded)
  • CI runs test_openai_agents(latest), test_openai_agents(0.8.0), test_openai_agents(0.7.0) sessions

🤖 Generated with Claude Code

…ai-agents >= 0.8

openai-agents 0.8.0 runs sync @function_tool functions via asyncio.to_thread(),
which copies ContextVar context but not threading.local() state. The background
logger override (_override_bg_logger) was threading.local(), so spans created in
tool worker threads logged to the wrong (real HTTP) logger instead of the test
memory logger -- causing test_agents_tool_openai_nested_spans to fail.

Changes:
- Change _override_bg_logger from threading.local() to ContextVar so it
  propagates via asyncio.to_thread() while remaining isolated per-context
- Call setup_threads() in BraintrustTracingProcessor.__init__() to propagate
  ContextVars across ThreadPoolExecutor worker threads
- Add test_openai_agents nox session with version matrix (latest, 0.8.0, 0.7.0)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant