Skip to content

Conversation

@galkleinman
Copy link
Contributor

@galkleinman galkleinman commented Nov 26, 2025

When using ThreadPoolExecutor to run LLM calls concurrently with
guardrails, contextvars were not being propagated to the worker thread.
This caused issues with trace context and other context-dependent
functionality being lost across thread boundaries.

The issue broke the traces of: https://github.com/traceloop/openllmetry

Changes:

  • Use copy_context() before submitting tasks to ThreadPoolExecutor
  • Apply fix to chat.completions.create, responses.create, and responses.parse
  • Add tests to verify contextvars propagate correctly across threads
  • Add tests for single and multiple contextvars propagation

@gabor-openai
Copy link
Collaborator

@codex pls review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@gabor-openai
Copy link
Collaborator

Thanks so much for this @galkleinman ! Clean, succinct, and includes relevant testing. @steven10a to take a final look before we merge.

Copy link
Collaborator

@steven10a steven10a left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for catching this and providing the fix

@steven10a steven10a merged commit 0ec56d3 into openai:main Dec 2, 2025
3 checks passed
@galkleinman
Copy link
Contributor Author

Thanks for the quick turnaround @gabor-openai, @steven10a 🙌

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.

3 participants