Repository navigation
fix(openai): preserve audio data in provider responses - #2029
Merged
hassiebp merged 1 commit intoOct 21, 2026
Merged
Conversation
|
|
Collaborator
|
Thanks a lot for your contribution, @HuaTNA ! |
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.
What does this PR do?
Fixes langfuse/langfuse#19094.
OpenAI chat-completion audio tracing replaces the provider's
audio.datastring with aLangfuseMediaobject because extraction modifies the original audio object's__dict__. The response returned to application code then fails base64 decoding or JSON serialization.Copy the audio dictionary before converting its data for tracing. The provider response stays unchanged, while the exported generation still contains the media reference and transcript. The source change is one line; a single regression exercises the instrumented public chat-completion call with an actual OpenAI SDK response object and the shared in-memory exporter. Provider HTTP and media uploads are mocked.
Type of change
Verification
Locked environment on macOS arm64, Python 3.13.13, OpenAI 2.29.0, Pydantic 2.14.0 and OpenTelemetry SDK 1.45.0:
uv sync --locked uv run --frozen pytest tests/unit/test_openai.py::test_chat_completion_audio_preserves_provider_response -q uv run --frozen pytest tests/unit/test_openai.py tests/unit/test_media.py tests/unit/test_openai_prompt_extraction.py -q LANGFUSE_PUBLIC_KEY=unit-test-public-key LANGFUSE_SECRET_KEY=unit-test-secret-key LANGFUSE_BASE_URL=http://127.0.0.1:3000 uv run --frozen pytest -n auto --dist worksteal tests/unit uv run --frozen ruff check . uv run --frozen mypy langfuse --no-error-summary uv run --frozen ruff format --check langfuse/openai.py tests/unit/test_openai.py uv run pre-commit run --files langfuse/openai.py tests/unit/test_openai.py git diff --checkThe regression fails on unchanged main with
PydanticSerializationErrorand passes after the fix. Related tests pass 81/81. The full unit suite passes 949 tests, with 2 skipped. Repository lint, mypy, changed-file formatting, configured hooks and diff checks pass.The first full-suite attempt had setup errors from missing dummy Langfuse credentials and sandbox-blocked loopback HTTP fixtures. The passing rerun supplied dummy local configuration and allowed loopback fixtures. No real Langfuse server, provider credentials or paid calls were used.
Whole-repository
ruff format --check .reports an existing formatting issue in untouchedlangfuse/_client/resource_manager.py. Its bytes match main, and formatting a copy from main fails identically; this PR leaves it unchanged. No e2e/live-provider tests, actual audio generation/playback, persisted backend behavior, other Python versions or OSes were tested.Found through code analysis and reproduced locally with Codex assistance. Codex also assisted with implementation and test execution; this does not claim production usage or independent human review.
Checklist
code_review.md..env.templateneeded changes; this preserves the existing response contract.

Confidence Score: 5/5
This PR appears safe to merge.Summary
Copies the audio dictionary before replacing its data for tracing. This keeps the provider response unchanged while preserving the recorded media reference and transcript.
Reviews (1) · Last reviewed commit: "fix(openai): preserve audio data in prov..." · Reviewed by Greptile