Skip to content

fix(openaichat): send audio input as input_audio parts - #2951

Open
mtmcp wants to merge 1 commit into
stacklok:mainfrom
mtmcp:fix/openaichat-audio-input
Open

mtmcp wants to merge 1 commit into
stacklok:mainfrom
mtmcp:fix/openaichat-audio-input

Conversation

@mtmcp

@mtmcp mtmcp commented Nov 23, 2026

Copy link
Copy Markdown

Summary

The Chat Completions adapter refused every audio part before sending, so a
custom provider with api_flavor: openai-chat-completions could not send audio
even to a model that hears it. Chat Completions defines an input_audio user
content part, and llama.cpp's llama-server accepts it for models with an
audio projector.

  • Map inline audio parts to input_audio, with the format taken from the MIME
    type, ignoring case and parameters. Only audio/mpeg is IANA-registered; WAV
    has no registered type, so each toolchain uses its own name:
    • audio/wav: Go's MIME table
    • audio/wave: WHATWG sniffing, so http.DetectContentType and mecatui
    • audio/x-wav: Python mimetypes, libmagic, Linux /etc/mime.types
    • audio/vnd.wave: freedesktop shared-mime-info, so GIO and xdg-mime
    • audio/mpeg and audio/mp3 map to mp3; Chromium and shared-mime-info
      both recognize audio/mp3 as an alias of audio/mpeg.
  • Refuse URL-sourced audio and other audio types with an error naming the
    cause, since input_audio carries only inline wav or mp3 data.
  • Report Audio: true from Capabilities(). As in the Responses adapter, the
    bit describes what the wire can carry; per-model gating stays with
    composition's model metadata and the server hosting the model.
  • Correct the stale audio comments in internal/app and the multimodal input
    user documentation.

Issue relationship

Fixes #2949

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

Baseline checks

  • Linting (task lint)
  • Fast offline test suite (task test)
  • Pre-review race suite (task test:race)
  • Offline demo (go run ./cmd/mecademo)
  • Markdown changed: docs generation/link checks (task docs)
  • User docs/user-facing behavior changed: site build (task site:build)
  • Guarded engine API affected: compatibility check (task api:check)
  • Intentional engine API change: task api:update + engine/CHANGELOG.md

task site:build (needs Node 24 and pnpm) and the docs:grpc-ref step of
task docs (needs buf; no protobuf changes) were not run locally; left to CI.
No engine API change, so task api:check and task api:update do not apply.

Manual verification

Against llama.cpp llama-server (build b12633) serving
unsloth/gemma-4-E4B-it-GGUF:Q4_K_M, using the steps in #2949: before,
mecatui refuses the attachment; after, WAV and MP3 reach the model and it
answers questions about the clip. An audio/ogg part is refused before sending.

mecatl-local-audio-fixed

Changes

File Change
provider/openaichat/request.go Map audio parts to input_audio; MIME-to-format table; refusals
provider/openaichat/openaichat.go Capabilities() reports Audio: true; comment states the transmit-authority rule
provider/openaichat/multimodal_test.go New, like the openai and anthropic adapters' files: the image test (moved from request_test.go, renamed TestBuildParamsImagePart), tests for each MIME alias, the refusals, the request body on the wire, and the capability
provider/openaichat/request_test.go Image test moved out; its audio half became the tests above. New TestBuildParamsToolResultDropsMedia pins that tool messages stay text-only although Capabilities() now reports audio
provider/openaichat/session_header_test.go Extract drainStream so the new wire test reuses the stream-draining helper
internal/app/capability.go, capability_test.go, registry.go Correct stale comments that assumed no adapter carries audio
user-docs/features/sessions/multimodal-input.md Describe where audio input is available and the WAV/MP3 limit

User-facing change

Sessions on a custom provider with api_flavor: openai-chat-completions
advertise audio input, and mecatui lets users attach WAV and MP3 files. A
model that cannot hear is refused by its server. Responses and Messages
sessions are unchanged.

Special notes for reviewers

API compatibility: no break. No contract fields change. The existing
session_capabilities.audio flag reports true for sessions on Chat
Completions providers (see the opencode note below); mecatui and ACP already
handle that value. A newly enabled capability is a discoverable addition under
the wire API policy, so no major or feature-identifier change is needed. No
stored-data or Go API change.

opencode: the built-in provider uses the same adapter, so its sessions
can advertise audio until its model listing loads; the listing declares text
and image input, which then removes audio. Default and ACP sessions compute
capabilities before discovery runs, so with opencode as the default provider
they advertise audio. Its server refuses audio a model cannot take. This is the
same rule the fix applies everywhere: the adapter reports what the wire can
carry, and the model's server decides.

provider/openaichat is published independently; this changes its behavior,
not its exported API.

Map inline WAV and MP3 audio parts to Chat Completions input_audio and
report Audio: true, leaving per-model gating to composition and the
server. Refuse URL-sourced and other audio types with a clear error.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blkt blkt assigned blkt and unassigned blkt Nov 26, 2026

@rdimitrov rdimitrov left a comment

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.

The mapping itself is correct and matches the design in #2949: the format table, case and parameter handling, and the "adapter reports what the wire can carry" rule are consistent with the Responses adapter. The OpenCode note also holds, since openCodeLister declares ["text","image"].

I'm requesting changes for one reason: an audio part that the adapter or the server refuses now permanently breaks the session, and mecatui and ACP can reach that state for the first time.

How I tested

I built this branch and ran mecated serve against a local fake Chat Completions server over HTTPS, then drove it through the HTTP API.

  • Normal use works. audio/wave, AUDIO/X-WAV; rate=16000, audio/mpeg and audio/mp3 all reached the server as input_audio with the right format. A 960 KB, 30-second WAV went through, and earlier clips were replayed correctly on later turns.
  • Tests pass: provider/openaichat with -race, the internal/app capability tests, internal/adapter/acp and cmd/mecatui/client.
  • Compaction strips media before summarizing, and tool results still drop audio through the fixed text-only caps, so neither path regresses.

1. A refused audio part permanently breaks the session (blocking)

recordPrompt saves the user message to history before the adapter builds the request, and every request replays the full history. A part that fails is therefore resent on every later turn:

Case First prompt Plain-text follow-up /retry
audio/aiff (mecatui's http.DetectContentType sniff produces this, and audio/midi) openaichat: unsupported audio MIME type same error –
HTTPS URL audio (the TS SDK audioPart({ url }) allows it) openaichat: audio part must be inline data, not a URL same error –
WAV sent to a model that can't hear (server returns 400) provider request failed (400 Bad Request) same 400 failed-step retry is not eligible

The only way out is to clear the session or start a new one. The server's 400 reason never reaches the user or the server log either.

HTTP API callers could already hit this on main, but mecatui and ACP couldn't, because they gate on audio: false. With this PR they pass the gate. The codebase already guards against this kind of replay breakage for empty text blocks (the empty-render rule in engine/port/toolresult_route.go).

Suggested fix in this PR: refuse URL audio and anything other than WAV or MP3 before the prompt is saved. That could be a check in the server's prompt path, or mecatui staging only wav/mp3 types. That covers the two deterministic cases.

The server-rejection case also applies to images on non-vision models, so I think it's better as a follow-up issue than as part of this PR.

2. Existing users can't turn audio off

Custom openai-chat-completions providers (Ollama, vLLM, LM Studio, hosted Chat Completions APIs) rarely declare input in /v1/models, and their models aren't in the catalog. So every one of their sessions now reports audio: true. I confirmed this after discovery had finished, not just before it. settings.yaml has no per-model setting to narrow it.

That also applies to ACP's initialize handshake, including with opencode as the default provider (acknowledged in the description). Combined with finding 1, a text-only model plus an audio attachment now produces a broken session where it used to produce a clear local refusal. The description says a model that can't hear "is refused by its server", which understates what happens.

3. Docs

user-docs/features/sessions/multimodal-input.md: "If Mecatl offers audio for a model that cannot hear, the model's server rejects it" should say the session can't continue afterwards and how to recover, unless finding 1 is fixed.

This branch has not been deployed

No deployments
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.

openaichat refuses audio input that Chat Completions servers accept

3 participants