Skip to content

fix(openai): fix tracing exception in model response getting method when tracing is disabled #227

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

upphiminn
Copy link

This pull request addresses a possible issue in the OpenAIResponsesModel where an exception could occur during getting a response when tracing is disabled. When tracing is disabled there is no parent trace so withResponseSpan fails with not finding a context trace for the span it attempts to create. This leads to the whole getResponse failing. Fix found below copies the same style of span creation only when tracing is enabled as seen in getStreamedResponse method.

@upphiminn upphiminn marked this pull request as ready for review July 17, 2025 15:55
@seratch seratch added package:agents-openai bug Something isn't working labels Jul 17, 2025
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

This looks good to me; @dkundel-openai any concern?

@dkundel-openai
Copy link
Collaborator

This seems odd because if tracing is disabled there should still be a NoopTrace that this should get attached to?

@dkundel-openai
Copy link
Collaborator

The main thing is that not using withResponseSpan() means that we are not creating a new entry in the Async Context Store which could create race condition issues so we should avoid it wherever possible

@seratch
Copy link
Member

seratch commented Jul 25, 2025

@dkundel-openai thanks for the good point.
@upphiminn can you share what actually happens in this scenario? > When tracing is disabled there is no parent trace so withResponseSpan fails with not finding a context trace for the span it attempts to create.

If we figure the root cause out, the fix can be much simpler than rewriting a bunch of code.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

to avoid confusion, let me revert the approval for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working package:agents-openai
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants