Skip to content

read: audio files are rejected as binary, so multimodal models never receive them #54491

Open

Description

@Te-River

Description

The read tool cannot read audio files, so a multimodal model with audio input can never receive one.

packages/core/src/tool/read-filesystem.ts gates media on a fixed set:

export const MEDIA_MIMES = new Set(["image/png", "image/jpeg", "image/gif", "image/webp", "application/pdf"])

Mime.detect (packages/core/src/mime.ts) sniffs magic bytes for PNG, JPEG, GIF, BMP, PDF, WEBP and AVIF only — there is no audio signature. An .mp3 (or .wav, .m4a, .ogg, .flac) therefore detects as application/octet-stream, misses MEDIA_MIMES, and falls through to the text path, where the first NUL byte rejects it:

if (first.bytes.includes(0)) return yield* new BinaryFileError({ resource })

So read on an audio file fails with BinaryFileError.

The rest of the pipeline already supports audio. packages/core/src/session/model-request.ts classifies a file part's mime into a modality and checks it against the model's declared capabilities:

const mimeToModality = (mime: string) => {
  if (mime.startsWith("image/")) return "image"
  if (mime.startsWith("audio/")) return "audio"
  if (mime.startsWith("video/")) return "video"
  if (mime === "application/pdf") return "pdf"
}

read is the only place that excludes audio, and the tool's own description says "Supports text files, images, and PDFs".

Two related gaps in the same set:

  • Video has the same problem: mimeToModality handles video/, but MEDIA_MIMES and Mime.detect do not.
  • Mime.detect returns image/bmp and image/avif, which are not in MEDIA_MIMES either, so those are rejected as binary too.

Plugins

none

OpenCode version

2.0.26

Steps to reproduce

  1. Ask the agent to read an audio file, e.g. read ./clip.mp3, with a model whose capabilities.input includes audio.
  2. The tool fails with BinaryFileError instead of presenting the file to the model.

Screenshot and/or share link

n/a

Operating System

Windows 11

Terminal

n/a (desktop app)

Activity

  1. opencode-agent commented on Oct 11, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed write-up! You're asking for the read tool to attach audio files (and also video, BMP and AVIF) when the model's capabilities.input supports them. Right now read only attaches PNG, JPEG, GIF, WebP and PDF. Everything else is detected as binary and rejected, even though the rest of the request pipeline already handles audio/ and video/ parts.

    That matches the tool's current design, which supports text, images and PDFs, so we're treating this as a feature request. Maintainers will consider it.

    Related items:

  2. Te-River commented on Oct 11, 2026

    @Te-River
    Author

    Cross-referencing the siblings, since they are one change in read:

    So the gap is one set: MEDIA_MIMES in packages/core/src/tool/read-filesystem.ts and the magic-byte sniffing in packages/core/src/mime.ts both stop at images and PDF, while mimeToModality in packages/core/src/session/model-request.ts already routes audio/ and video/ parts. Fixing one without the other leaves the same class of file rejected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions