Skip to content

Studio: accept the standard input_audio message part - #10255

Merged
Imagineer99 merged 13 commits into
unslothai:mainfrom
NilayYadav:fix-content-part-input-audio
Sep 7, 2026
Merged

Imagineer99 merged 13 commits into
unslothai:mainfrom
NilayYadav:fix-content-part-input-audio

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

Sending audio the way the OpenAI SDK documents it fails right away with a validation error about the tag name, before any model runs. The content part list was closed to six types and input_audio was not one of them. This happens even when the loaded model can take audio, and llama-server accepts that exact part already, so people have to find the non standard audio_base64 field instead.

This adds input_audio to the accepted parts and maps it onto the same audio path that field uses. It also adds a catch all for part types we do not model, so an unknown type gets a clear message naming it rather than a raw validation dump.

Tested on a live server with a real wav file. Before, the request fails with messages.0.content.str: Input should be a valid string. After, the model receives the audio and transcribes it.

@NilayYadav

NilayYadav commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

GitHub Actions reproduction + fix verification

Pinned head: 54dcda70906a4019bf61544716d0930d976356d8. Three probes, one dependency set, one ubuntu-latest image — the legs differ only in the unsloth tree they import (run). Every probe POSTs to the real routers through a TestClient; only the auth dependency is stubbed. Leg D merges the head onto today's main first, so it also proves the branch still applies cleanly.

The defect. On main, the part the OpenAI SDK documents is rejected at body validation, before any model runs:

POST /v1/chat/completions  {"type":"input_audio","input_audio":{"data":<b64>,"format":"wav"}}
main 8e26d2c2b  ->  422  union_tag_invalid
    Input tag 'input_audio' ... does not match any of the expected tags:
    'text', 'image_url', 'input_document', 'reasoning', 'image_generation_call', 'compaction'

On the head it clears validation and reaches model resolution — a later, different error — and lands where the audio path reads it:

[step2] validated; content part types = ['text', 'input_audio']
[step2] after lift: audio_base64 = 'UklGRiQAAABXQVZF'

Every shape, with its real status. Leg B is the first commit, before review; leg C is the converged head. Same probe, same runner.

request A main B first commit C converged head
local: text + audio 422 400 no model loaded 400 no model loaded (accepted)
external: text + audio 422 200 — request sent, recording stripped 400 Audio input is only supported on a local model with audio support.
external: unknown part 422 200 server_error 400 Message content parts of type 'file' are not supported.
audio on an assistant turn 422 400 no model loaded (part deleted) 400 Audio input is supported on a user message, not on a 'assistant' one.
two recordings 422 400 no model loaded (second discarded) 400 Only one audio recording per request is supported, and this one carries 2.
empty data: "" 422 400 no model loaded (part deleted) 422
malformed type 422 500 Internal Server Error 422
/chat/count_tokens: audio part 422 503 No GGUF model loaded — audio refusal bypassed 503 Cannot count tokens for messages containing audio.
/audio/generate: audio part 422 400 no model loaded 400 Audio input is not supported here; this route speaks the message text.
durable run: audio part 422 202 queued; blob persisted: True 400 Media chat runs use the legacy streaming path

Column B is what the first commit shipped: opening the tagged union let the two new part types reach five routes that share ChatCompletionRequest but never learned about them. The two rows that matter most are the ones that answer rather than refuse — the external provider sends the request with the recording stripped, so the model answers a question about audio it never received, and the durable-run sanitizer persists the base64 into request_json for the life of the thread, which is exactly what its own comment forbids. malformed type -> 500 is reachable by any client: a list type is unhashable against the tag set.

Column C answers every one of those with a typed error naming the cause, and the local path still takes the part.

Regression tests: studio/backend/tests/test_chat_input_audio_part.py — 7 on leg B, 24 on legs C and D, all passing on the runner.

Legs A and D also pin the boundary: the defect still reproduces on today's main, and the fix holds when the branch is merged onto it (aa7aaa5b8).

The Studio UI is unaffected either way — the frontend sends audio_base64, never input_audio, and declines to count when audio is present. The five request shapes it does send to /chat/count_tokens return byte-identical responses before and after.

Known limitation, deliberate: audio_base64 holds one recording and _inject_audio_part appends it to the last user message, so a recording replayed from an earlier turn is attached to the latest one. Carrying several recordings with their turn association is a larger change; a second recording is refused rather than silently reduced to one.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 3, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 4, 2026
@NilayYadav
NilayYadav force-pushed the fix-content-part-input-audio branch from 54dcda7 to 3cd1d58 Compare September 4, 2026 15:36
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 3cd1d584e7

ℹ️ 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".

@Imagineer99

Copy link
Copy Markdown
Member

This fixes a real validation issue. A/B checks at base e8a8854 and PR head 3cd1d58 show standard input_audio failing before inference on base and reaching the audio path on this PR. Adjacent regression tests pass: 636 on base and 660 on the PR, with the same three skips.

One change before merge: audio from an earlier user turn moves onto the latest user turn, changing the model's input. The independent probe observes audio moving from turn 0 to turn 2 through _normalise_chat_content_parts and _inject_audio_part. Reject earlier-turn audio explicitly until its original position can be preserved. Real model transcription and the full OS/GPU matrix remain unverified.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

Done in 21a57997c — earlier-turn audio is now refused rather than moved.

POST /v1/chat/completions
  [user: "transcribe this" + input_audio], [assistant: ...], [user: "who is in the background?"]

before  ->  accepted; audio authored on turn 0 ends up on turn 2
after   ->  400  Audio input is supported on the latest user message, and this one carries it
                 on an earlier turn. Re-send the recording on the current turn.

The request no longer reaches _inject_audio_part at all, so there is no path left on which the recording moves. The two shapes that must keep working are unaffected: a recording on the latest user turn is still lifted and lands on the turn it was authored on, and the single-turn documented shape is unchanged.

You are right that this is the correct interim. audio_base64 holds one recording and _inject_audio_part appends it to the last user message, so the field simply cannot express which turn a recording came from — every option short of refusing either moves it, drops it silently, or leaves it where no capability check, size bound, decoder or /chat/count_tokens refusal can see it. Preserving the original position needs that field to become a list carrying turn association, which is a change of a different size and belongs in its own PR. The docstring now records that rather than leaving it implicit.

test_a_recording_carried_on_an_earlier_turn_is_refused covers it, and test_a_recording_on_the_latest_user_turn_is_still_lifted guards the refusal from over-reaching. 25 tests in the file, 139 across it plus the durable-run and preview suites, added-line coverage 59/59.

On the two gaps you name — both are real and I have not closed either. Every probe here drives the real routers through a TestClient with only the auth dependency stubbed, so what is proven is that the part validates, reaches model resolution, and lands on audio_base64. No real audio model has transcribed a real clip on this branch, and the evidence run is ubuntu-latest only, so the OS/GPU matrix is unverified. Happy to stage a GGUF audio-model run if you want that before merge.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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.

Reviewed commit: 21a57997cc

ℹ️ 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".

path = _resolve_or_4xx(run, checkpoint)
# Before the lock and the load: openai_chat_completions refuses these too, but only after a
# checkpoint load that can evict the resident model on its way to the same 400.
_reject_unsupported_content_parts(payload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate audio-part placement before loading previews

When a preview request contains multiple input_audio parts, places one on a non-user role, or carries it on an earlier user turn, this call does not reject it because it only checks UnknownContentPart. The route therefore acquires the preview lock and calls load_model_for_preview, after which the delegated completion rejects the request in _normalise_chat_content_parts. These payloads previously failed validation before entering the route, so they can now trigger an expensive checkpoint load and evict the resident model despite always returning 400; run the audio-part normalization checks before loading the preview checkpoint.

Useful? React with 👍 / 👎.

return await _proxy_to_external_provider(payload, request, current_subject)

# Local path only: the lift targets audio_base64, which the proxy never reads.
_normalise_chat_content_parts(payload)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject audio when the transformers model cannot consume it

When the resident non-GGUF model has has_audio_input false and no compatible auto-switch occurs, this lift removes the input_audio part and sets audio_base64, but the transformers branch only handles that field inside if payload.audio_base64 and model_info.get("has_audio_input"); otherwise it falls through to ordinary text generation. Thus a newly accepted standard audio request can receive a plausible response based only on its text while the recording is silently ignored. Add a capability rejection for payload.audio_base64 when the selected transformers model lacks audio input support.

Useful? React with 👍 / 👎.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: df49628a20

ℹ️ 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".

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: e3cd1e9d32

ℹ️ 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".

@Imagineer99

Copy link
Copy Markdown
Member

The earlier-turn audio issue is fixed, and 666 regression tests pass. Real-model checks through Chromium, Firefox and WebKit also return the same correct transcript for both input_audio and audio_base64. Looks good to merge.

@Imagineer99
Imagineer99 merged commit e1f8d0c into unslothai:main Sep 7, 2026
48 checks passed
danielhanchen pushed a commit that referenced this pull request Sep 8, 2026
…them

The refusal added here answered input_file and file_id images, but only on a user
turn and only for those two shapes. Four ways of losing an attachment in silence
were left:

- system, developer and assistant turns each return via `continue` before the
  parts loop, so an attachment on those turns was still dropped;
- an input_image with neither image_url nor file_id was dropped;
- an input_image whose detail falls outside the documented set fails its typed
  variant, degrades to the catch-all, and took a servable url down with it;
- an unmodelled part was dropped, which is what /chat/completions stopped doing
  in #10255.

_responses_tool_output_content had already written the first three rules for the
same shapes arriving as a tool result, so this reuses its wording rather than
inventing a second vocabulary for one question. The attachment refusal is hoisted
above the role branches; the generic "parts of type 'X' are not supported" stays
on the user branch so an assistant replay turn keeps its lenient text flatten and
a client round-tripping prior output is not made to fail.

An image carrying image_url and file_id together still resolves from the url on
both paths: file_id means "instead of a url", not "in addition to one".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants