Skip to content

Studio: keep earlier messages when you send audio - #12244

Merged
Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:keep-history-on-audio-turns
Sep 29, 2026
Merged

Lyxot merged 3 commits into
unslothai:mainfrom
NilayYadav:keep-history-on-audio-turns

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

With a safetensors audio model (transformers on an NVIDIA GPU, or MLX on a Mac), a message with a recording was answered as if it were the first message of the chat, so every earlier turn was dropped. On the GPU path a recording sent without typed text was also paired with the last question you typed, so the model answered that old question instead of listening.

Audio turns now keep the earlier conversation, as image turns already do since #10944 and as GGUF always has. A recording sent on its own is read as "Please transcribe this audio." on both backends.

Gemma's template refuses turns that do not alternate, so, much like the text path, empty replies and tool turns are left out and when two messages from the same side follow each other only the later one is kept, so a question that never got a reply gives way to the recording. Text, image and GGUF turns behave as before.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Codex review coverage

Mirror: NilayYadav#136, pinned to upstream head 1ab98be3b3dd7db0b8b57827eca510a1147f0163 (same commit and tree 150be7cd on the mirror and on this PR).

Rounds: 2. Converged because Codex approved the current head: "Didn't find any major issues" on 1ab98be3b3 (comment).

Items:

  • Round 1, P1, "Append audio after a trailing assistant turn": rejected. On main both backends already caption the recording with that same last user text (inference.py falls back to the newest non-empty user message; MLX took the newest user text), so the recording was bound to that question before this PR too. The Studio UI never sends a trailing assistant turn with audio, continue_final_message is refused on the audio route, and the image path attaches media the same way.

Also fixed during review (found by hand, not by Codex): the reply to an earlier recording was paired with the typed question before it, because the empty recording turn was dropped and the later reply replaced the earlier one. Fixed in 1ab98be3b3.

Final Codex result on 1ab98be3b3: no major issues.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review + reproduction evidence

Pinned review: 1ab98be3b3dd7db0b8b57827eca510a1147f0163. 1 finding, fixed in 1ab98be3b3 (the reply to an earlier recording was re-paired with the typed question before it).

I reproduced the chat flow on fresh upstream main (ca5e2fd) and on the PR with Studio installed by install.sh --local on Linux with an NVIDIA L4, gemma-3n-E2B-it loaded from the picker, recordings attached from the composer, Chromium 1440x900:

  • main: after typing "My name is Nilay and my favourite colour is teal", a recording asking "What is my name?" gets a reply saying it does not have a name (no earlier turn reaches the model). A bare recording of "Please count from one to five." sent after "Write a haiku about the sea." gets another haiku ("Blue waves crash and foam, Salty air and sunlit spray, Deep secrets reside.").
  • PR head: the same steps give "Nilay." and "Please count from one two five.". A second recording, "What was the poem you wrote for me? Please say it again.", gets the earlier haiku back word for word.
  • PR as first submitted (c9fe6b6): that second recording got a brand new haiku. The browser sends an earlier recording as an empty user turn; the helper dropped it and then let the next reply replace the real one. 1ab98be3b3 drops that reply together with its recording, with tests on both backends.

PR 12244 before/after

  • Test A/B on Modal (the GitHub Actions mirrors head and fix reverted sat queued for over 90 minutes and never started): with the fix reverted, test_the_reply_to_an_earlier_recording_stays_off_the_question_before_it and test_mlx_generate_audio_input_deltas_and_reject fail; on the head, test_generation_budget.py is 18 passed (6 fixed vs main) and the CPU run of test_generation_budget.py, test_mlx_inference_backend.py and test_vision_client_tools.py is 7 fixed, 312 unchanged, 0 failing. The one red upstream check (workflow-trigger lint) is red on main at ca5e2fd and 501b15f too.

  • Unchanged paths: an image turn ("The number in the picture is 42. Your name is Nilay.") and a single audio turn over /v1/chat/completions (222 prompt tokens) are identical on both sides; an API request with a system message and an unanswered user turn returns 200 on both. Whisper, GGUF audio and text turns do not reach this code.

  • Speed, 3 warm runs each: a single audio turn is 5.70 s on main and 5.58 s on the PR. With history the prompt grows by the history only (224 to 243 tokens here).

  • MLX was checked through the tests above and the mlx-vlm 0.4.4 to 0.7.1 prompt builder, not on a Mac by hand.

Left as a suggestion: on MLX a whitespace-only caption sent through the raw API no longer falls back to "Please transcribe this audio." (the UI trims input, so only API callers can hit it).

Conclusion: real bug, fixed on both backends; with 1ab98be3b3 the audio turn keeps the chat and pairs every earlier reply with the right question.

…istory

An earlier recording or picture sent without text replays as an empty user turn. Dropping it together with its reply meant a voice-only conversation still lost every earlier exchange; the reply is kept, with the empty turn, as the GGUF path already does. Turns after the newest user turn are left out, as before the branch, and a recording turn whose text is only whitespace is captioned with the transcribe default on MLX, as the structured CUDA render already appends it.
@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Pushed 3ecf5767ce on top of 1ab98be3b3:

  • An earlier recording or image-only turn is now kept as an empty user turn together with its reply, instead of both being dropped. The UI replays every earlier recording that way, so a voice-only chat still lost every earlier exchange. Keeping the empty turn also keeps each reply paired with the turn it answered, which was the concern behind 1ab98be3b3, and matches what GGUF sends. On Gemma 4 E2B (MLX), a recording asking about something said in an earlier recording now answers "Teal" where it answered "Blue" before.
  • Turns after the newest user turn are left out again, as they were before this PR, so the recording is always the last turn.
  • On MLX, a recording turn whose text is only whitespace gets "Please transcribe this audio." again (the suggestion from the review above).
  • Tests for the typed text on the recording turn, the whitespace case and the trailing-turn case.

The branch is 9 commits behind main with no conflicts, so I did not merge main. The two red checks on 1ab98be3b3 (workflow-trigger lint and Repo tests (CPU, studio)) both fail on playwright_user_message_time.py not being wired into CI, which is red on main too.

@Lyxot

Lyxot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Codex review and CI on 3ecf5767ce (current head), via a staging copy whose diff is exactly this PR (Lyxot#110):

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Audio turns now keep the earlier conversation on both safetensors backends, and a recording sent without text is no longer paired with an older question. Codex converged and CI is green apart from the Playwright-registration check that is red on main too.

@Lyxot
Lyxot merged commit 90946aa into unslothai:main Sep 29, 2026
43 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants