Skip to content

Studio: accept multiple audio files per message - #12267

Merged
danielhanchen merged 9 commits into
mainfrom
studio/multi-audio-input
Sep 30, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
studio/multi-audio-input

Conversation

@shimmyshimmer

@shimmyshimmer shimmyshimmer commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Audio-input models like Gemma 4 E4B accept several audio clips in one message, but Studio only allowed one. Seven separate checks enforced that: the composer adapter, native drops, the Compare composer, and the chat route. The request also had a single audio_base64 field, and each backend received a single waveform.

This PR lets a message carry up to 8 audio files while keeping the per-message resource cost the same as a single maximal clip.

Changes

Request and validation

  • New extra_audio_base64: list[str] field for clips after the first. audio_base64 is always the first clip, so existing capability, routing and auto-switch checks still see the audio.
  • Several OpenAI style input_audio parts on the latest user message are now lifted in order instead of rejected. Clips on earlier turns are still refused.
  • The 25 MB size cap and 30 minute duration cap now apply to all clips together. A count cap of 8 bounds per-clip decode cost.

Serving paths

  • GGUF (llama.cpp): one input_audio part per clip, in upload order. wav/mp3 pass through; other formats are transcoded to WAV and share the remaining byte budget, so several clips never forward more than one maximal clip could. KV admission charges each clip.
  • Transformers: one audio item per clip in the processor chat template. Whisper transcribes each clip in turn.
  • MLX: still one clip per message. mlx-vlm drops extra clips unless the processor opts in, so the route returns a clear 400 instead of answering from the first clip only.
  • The inference worker now receives clips as raw float32 bytes instead of tolist(). For a 60 s clip this is 3.8 MB instead of 8.6 MB pickled, and about 0.2 ms instead of about 20 ms to encode and decode.

Frontend

  • The composer adapter tracks count and combined size instead of refusing a second clip. A shared toast id keeps an oversized batch to one message.
  • The request builder sends extra_audio_base64 from the current turn only. It stays undefined for text turns so they remain on the durable run path.
  • The send-time media gate refuses several clips on an MLX model that was loaded after attaching.
  • Native drops accept up to 8 audio files.
  • Compare holds a list of clips with one chip each, and its audio picker allows multiple files.

Testing

  • Backend: new tests in test_chat_input_audio_part.py for clip order, the count cap, the combined size and duration caps, and the shared GGUF WAV budget. Existing preflight tests are updated for the clip list. Audio related test files match main (the few failures there also fail on an unmodified checkout).
  • Frontend: npm run typecheck and npm test pass (9356 tests), including new tests for the caps and the MLX gate.
  • Manual: ran gemma-4-E2B-it GGUF on Studio's llama.cpp build with two spoken clips (one wav, one m4a). Asked for the number in one and the colour in the other, it answered "The secret number is 42, and the favourite colour is purple.", which needs both clips. Prompt tokens went from 65 for one clip to 121 for two.

UI before and after

Two WAV files picked at once in the chat composer (no model loaded), merge base b8440cc vs head ed8896d. Before: one chip and "Only one audio file can be attached per message.". After: both clips attach.

Composer with two audio files, before and after

Audio-input models such as Gemma 4 can take several clips in one
message, but Studio refused a second clip in the composer, native
drops, Compare, and the chat route.

- Add extra_audio_base64 and lift several input_audio parts from the
  latest user turn, up to 8 clips.
- Keep the 25 MB and 30 minute caps across all clips together.
- GGUF sends one input_audio part per clip; transcoded clips share
  the remaining byte budget.
- Transformers passes one audio item per clip; Whisper transcribes
  each in turn.
- MLX keeps one clip and refuses more, since mlx-vlm drops extras.
- Send clips to the inference worker as raw float32 bytes instead of
  Python lists.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T13:11:00.907970Z c522140 Manual request
🔒 Security Review ✅ Completed 2026-09-29T11:10:13.400078Z 7b9f25d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@danielhanchen

Copy link
Copy Markdown
Member

The "(Python 3.13, l-r)" failures come from this PR, not main; they pass on main. The existing single-file audio tests still pin the old contract:

  • test_mlx_inference_backend.py now hits "This MLX model takes one audio file per message."
  • test_openai_tool_passthrough.py::TestApiMonitorAudioInput fails with object of type 'object' has no len(), because its fakes pass one audio object where the code now expects a list.

Updating those tests to the multi-file shape, or accepting a single object alongside a list in the new code, should clear them.

The "Repo tests (CPU, studio)" and "workflow-trigger lint" failures are a separate issue on main that #12255 fixed; a rerun will clear them.

- Decode each clip within the duration the earlier clips left, so a
  later clip can no longer allocate a full 30 minutes on its own.
- Refuse several clips for a non-GGUF target on an MLX host before
  the model switch, instead of after loading it.
- Compare: count clips that are still being read, so overlapping
  pastes or drops cannot exceed the per-message caps.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

- Pass extra clips as extra_audio_arrays instead of overloading
  audio_array with a list, which misread a plain list of samples as
  many one-sample clips. The keyword is only passed when there are
  extra clips.
- Decode the first clip exactly as before; the combined budget only
  applies to later clips.
- Native drops: keep attaching the rest of the batch after one clip
  is refused, since a later smaller clip may still fit.
- Compare: use the non-secure-context safe id helper for clip ids.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Thanks, both were real regressions from this PR. Fixed in 131280b:

  • Extra clips now travel in a separate extra_audio_arrays keyword that is only passed when there is more than one clip, so audio_array keeps its old meaning and a plain list of samples is one waveform again. test_mlx_inference_backend.py passes.
  • A single clip is decoded exactly as before, without the combined budget check, so the opaque fakes in TestApiMonitorAudioInput and test_active_generations.py pass again.

Also added worker level tests for the single clip and multi clip shapes.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

An equal split of the WAV budget made the result depend on attachment
order: a long m4a followed by a short clip got half the budget and
fell under the 8 kHz floor, although both fit together.

Decode the transcoded clips first, then give every clip the highest
shared sample rate that fits the budget; clips already below it are
left alone. Held clips now share one decoded sample ceiling, so peak
memory stays at the single clip bound. A single clip still gets the
whole budget, as before.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

# Conflicts:
#	studio/backend/core/inference/inference.py
- Pick the shared WAV rate from the resampler's own output length and
  resample to it directly. Rebuilding the rate from a floored byte cap
  gave 7999 Hz at the 8 kHz floor and refused a request that fits.
- Compare: block sending until a selected batch is fully read, so a
  slow later clip cannot miss the message.
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 7b9f25d118

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

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7b9f25d118

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

# Conflicts:
#	studio/frontend/src/features/chat/shared-composer.tsx
@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Failed to set up container
ℹ️ 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".

@danielhanchen danielhanchen self-assigned this Sep 30, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 30, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 30, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 30, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 30, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 30, 2026
@unslothai unslothai deleted a comment from shimmyshimmer Sep 30, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

4 similar comments
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@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: c5221400c7

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

Comment on lines +1145 to +1149
const addError = getAudioAddError(
counted.length,
counted.reduce((total, size) => total + size, 0),
file.size,
);

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 Apply the MLX clip limit in compare mode

When either Compare pane targets an MLX-served model, this call omits the maxFiles argument and therefore allows up to eight clips. Sending two or more clips then starts the comparison and may load the model, only for the backend to reject the request with _MLX_MULTI_AUDIO_DETAIL; the regular composer avoids this by calling maxAudioFilesFor. Derive the limit from the selected comparison targets or reject the multi-clip draft before starting the comparison.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a bug: Compare panes send through createOpenAIStreamAdapter (runtime-provider.tsx pairId adapter), whose send-time attachedMediaUnavailableReason gate gets audioCount and the pane model's isMlx, so a multi-clip MLX pane is refused before any request; the backend switch preflight also refuses on an MLX host before loading. Only the moment of the message differs (send vs attach).

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: c5221400c7

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

@danielhanchen
danielhanchen merged commit ba64bcb into main Sep 30, 2026
51 of 59 checks passed
@danielhanchen
danielhanchen deleted the studio/multi-audio-input branch September 30, 2026 13:18
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.

2 participants