Repository navigation
fix(ai): track failed OpenAI Responses stream events - #1261
Open
Artyfowl1710 wants to merge 1 commit into
Open
Artyfowl1710 wants to merge 1 commit into
Artyfowl1710 wants to merge 1 commit into
Conversation
Prepared with OpenAI Codex assistance.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
An OpenAI Responses stream can return
response.failedas a terminal event over a successful HTTP connection. The Python SDK forwards that event to the caller but currently records the generation without$ai_is_error. Dashboards that use this field miss these failures.The sync and async Responses wrappers now record the terminal event through the existing streaming error path and continue forwarding it to callers. The existing privacy-mode formatter redacts the provider message. Exceptions raised during iteration retain their existing precedence.
💚 How did you test it?
httpx.MockTransportand an HTTP 200 SSE response. The tests verify the event delivered to callers, generation failure metadata, and provider error redaction in privacy mode.pytest -q -p no:cacheprovider --timeout=30 posthog/test/ai/openai posthog/test/ai/test_stream_midstream_error.py -k "openai or capture_streaming_event"with OpenAI 2.54.0 and Python 3.12 on Ubuntu. The result was 144 passed, 3 skipped, and 11 deselected.📝 Checklist
If releasing new changes
A patch changeset is included for
pypi/posthog.🤖 Agent context
Autonomy: Fully autonomous
OpenAI Codex identified the gap, prepared the change, and ran pytest and Ruff via the shell. The regression tests use the OpenAI SDK's streaming HTTP parser and cover both wrappers. The implementation uses the existing capture and redaction logic.