Repository navigation
fix: four small SDK fixes (OpenAI spans, transport errors, scope transaction, pydantic) - #7857
intertermux-code wants to merge 4 commits into
Conversation
…aths The pydantic v1 .dict() API emits PydanticDeprecatedSince20 on pydantic v2, which breaks anyone running with DeprecationWarnings as errors. Every supported openai/openai-agents version requires pydantic v2, so model_dump() is a drop-in replacement here. Fixes getsentry#7827.
The span setter copied a Transaction's name into _transaction but never cleared it, so after a top-level transaction finished (span restored to None) later events on the same scope kept the stale transaction name. The clear only happens on None: a finishing child span restores the transaction itself, so a live transaction's name is preserved. Also resets the stale _transaction_info, matching Scope.clear(). Fixes getsentry#7774.
The four streaming chunk iterators only finished the gen_ai.chat / gen_ai.responses span in the code after their iteration loop. Closing the stream early, leaving a `with` block after one chunk, or losing the connection skipped that code, so the span was never finished and got dropped from the transaction. Wrap the loop and post-loop bookkeeping in try/finally so the span is always finished (errored on connection errors), and patch Stream.close / AsyncStream.close to finish the span too, mirroring the Anthropic integration. The span is attached to the stream and detached on finish so it is finished exactly once no matter which path runs first. Fixes getsentry#7847.
HttpTransportCore._handle_response logged unexpected non-2xx statuses (e.g. 403/404 from a network middlebox) and recorded the loss, but never raised, so custom/wrapper transports calling the synchronous send path had no way to detect the failed delivery and trigger failover routing. Raise TransportResponseError after recording the loss, so a failed delivery surfaces as an exception like network errors already do. 429 keeps its rate-limit handling and 413 its deliberate-drop semantics; neither raises. Fixes getsentry#7844.
|
Hi @intertermux-code. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e1146fe. Configure here.
| try: | ||
| return f(self) | ||
| finally: | ||
| _finish_stream_span(self, sys.exc_info()) |
There was a problem hiding this comment.
Stream close marks spans as errors
Medium Severity
_finish_stream_span is given sys.exc_info(), so close() and the iterator finally can pass GeneratorExit or an exception from the caller's except/finally into span.__exit__. That marks the gen_ai span as failed even when the OpenAI stream itself succeeded, including early close(), with-block exit, and abandoned iterators.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit e1146fe. Configure here.


Following up on your note about consolidating — this is a single PR containing all four fixes from #7850, #7851, #7852 and #7853, which you closed this morning.
Four separate commits, one per issue:
fix: use model_dump() instead of deprecated dict() in OpenAI output paths(fixes OpenAI Agents integration emitsPydanticDeprecatedSince20on tool calls -_set_output_datacallsdict()#7827) — pydantic v1.dict()emits PydanticDeprecatedSince20 on pydantic v2, breaking runs with DeprecationWarnings as errors.model_dump()is a drop-in replacement in the OpenAI integration paths.fix: clear Scope._transaction when the span is unset(fixes Scope._transaction not cleared when span is set to None #7774) — the span setter copied the transaction name into_transactionbut never cleared it (or the stale_transaction_info) when the span was unset, so later events on the same scope kept a finished transaction's name/source.fix(openai): finish streaming gen_ai span on early stream close(fixes OpenAI integration: streamed gen_ai.chat/gen_ai.responses span is lost when the stream is closed early or errors #7847) — the streaming chunk iterators only finished the gen_ai span after the loop; early close,with-block exit or connection drop dropped the span. Now wrapped in try/finally, plus Stream.close/AsyncStream.close patched to finish it, mirroring the Anthropic integration.fix(transport): raise TransportResponseError on unexpected HTTP status(fixes[HTTPTransport]Non-2xx HTTP responses treated as success and redundant fallback retries on blocked routes #7844) —_handle_responselogged unexpected non-2xx and recorded the loss but never raised, so wrapper transports had no failure signal for failover. Now raises after recording the loss; 429 and 413 keep their existing semantics.All covered by regression tests (each commit includes them), and the affected suites pass locally.