Skip to content

Studio: accept subtitle, caption and the rest of the common attachment formats - #9738

Merged
danielhanchen merged 46 commits into
mainfrom
studio/attachment-file-types
Sep 3, 2026
Merged

danielhanchen merged 46 commits into
mainfrom
studio/attachment-file-types

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

A user reported that Studio refuses .srt and .vtt when it should take them. It does, and the same gap covers a long tail of other formats.

What was wrong

.srt and .vtt are plain UTF-8, but neither was on any allowlist, so the file picker greyed them out and a native drag and drop was refused with "Unsupported attachment type". Chat attachments are gated by five separate hand-maintained lists (three in TypeScript, two in Rust), and they had drifted well behind what the pipeline can actually handle.

Kind Was Gap
Text and code 80 extensions No subtitles, no LaTeX, no Haskell/Elixir/Erlang/OCaml/F#/Fortran/COBOL/Zig/Nim, no CUDA, no shaders, no templating, no .jsonc/.json5
Audio wav, mp3, m4a, ogg, oga, flac No .aac, .opus, .aiff, .wma, .amr, even though the backend decodes all of them
Video mp4, mov, webm, mkv, avi No .m4v, .mpg, .wmv, .flv, .3gp, .ogv

What changed

Text: 80 extensions to 285. Subtitles (.srt .vtt .sbv .ass .ssa .sub .lrc), docs (.tex .bib .adoc .org .rmd .qmd), data (.jsonc .json5 .geojson .har .plist .avsc), localisation (.po .strings .resx .xliff .ics .vcf .eml), templates (.erb .ejs .hbs .jinja .twig .liquid .razor .pug), and around 120 more languages (.hs .ml .ex .erl .fs .clj .zig .nim .cr .cu .cuh .sol .cairo .mojo .f90 .cob .ada), plus shaders, shells and build files.

Audio: .opus .aac .aiff .aif .aifc .caf .wma .amr .mp2. Every one of these already decodes through libsndfile or the librosa/ffmpeg fallback in _decode_audio_mono, so the picker was stricter than the pipeline behind it. .webm and .mp4 deliberately stay off the extension list, since the audio adapter runs before the video adapter and would claim video files.

Video: .m4v .mpg .mpeg .wmv .flv .3gp .ogv, all of which ffmpeg reads. .ts and .mts stay off, since they are TypeScript here.

Deduplication. native_clipboard.rs carried a hand-copied 70-extension duplicate of the text list. It now falls back to TEXT_ATTACHMENT_EXTS, so it cannot drift again. The Rust and TypeScript lists are mirrored as before, and the existing parity tests keep them honest.

Syntax highlighting gains 167 shiki mappings so the new formats colour in the preview dialog instead of rendering flat. Unknown ids already degrade to plain text in code-plugin.ts, so this is safe either way.

What I deliberately left alone

Images stay at jpeg/png/webp/gif. Files go to the model as raw base64, and the external providers accept only those four, so adding .bmp/.heic/.tiff would fail at the model instead of at the picker, which is a worse experience than the current message. Doing it properly needs client side transcoding, and Chromium cannot decode HEIC or TIFF anyway.

Knowledge base uploads stay at the 7 RAG types. The native drop router treats "is a RAG type" as "index it rather than attach it inline", so widening that list would silently divert dropped source files into the knowledge base instead of the chat.

Testing

  • 5137 frontend tests pass, including the parity tests that assert the TypeScript and Rust lists agree.
  • 411 Rust tests pass, cargo check clean with no unreachable match arms.
  • tsc --noEmit clean, npm run build clean.
  • Verified the shipped bundle carries the new accept strings for all three adapters.

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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

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.

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.

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.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

This comment was marked as resolved.

Two limits bind a decode at once, the thirty-minute clock and a rate-independent
sample count, and the decode refuses at whichever is smaller. The buffer sizing
did not read the same bound. The initial allocation clamped only to the sample
count, so an 8 kHz file declaring three hours reserved 86.4M floats (330 MB) on
the way to being refused at 14.4M (55 MB), and the doubling that covers an
under-reported duration was not clamped at all: 48 kHz declaring twenty minutes
and holding twenty-one grew to 115.2M against an 86.4M limit, with the old
buffer still live for the copy.

_decoded_sample_ceiling is now the single source for all three, so the
allocation, the growth target and the refusal cannot drift apart. The growth
clamp cannot starve a write, since the sample count has already been checked
against that same ceiling.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@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: 7cfe5986c2

ℹ️ 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 +948 to +950
const decoder = new TextDecoder("windows-1252");
if (decoder.decode(bytes.subarray(0, 5)).toLowerCase() !== "<?xml") {
return null;

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 Detect BOM-less UTF-16 XML declarations

For a BOM-less UTF-16LE/BE XML attachment whose prolog explicitly declares that encoding, decoding the first five bytes as Windows-1252 produces interleaved NULs, so this check never recognizes <?xml. The file then falls through to strict UTF-8 decoding, which either rejects it when it contains non-ASCII text or sends NUL-padded gibberish when it is ASCII-only. Detect the standard UTF-16 byte patterns before scanning the prolog so these XML, plist, SVG, and project-file attachments use their declared encoding.

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.

Leaving this one: the input it describes is not well-formed XML.

XML 1.0 5th edition section 4.3.3 is explicit that entities encoded in UTF-16 MUST begin with the Byte Order Mark, and appendix F treats FE FF / FF FE as the autodetection signature precisely because the declaration cannot be read before the encoding is known. RFC 3023, restated in RFC 7303, is the other half: utf-16le and utf-16be MUST NOT carry a BOM and SHOULD carry an encoding declaration, but those are labels a transport applies, and there is no transport here. A file dropped onto the composer has only its bytes, so the only conforming way for it to be UTF-16 is to start with a BOM.

Both BOMs are already handled, ahead of the prolog scan, and they decode as strictly as everything else rather than being stripped and guessed at. So a conforming UTF-16 XML, plist, SVG or project file is read through its declared encoding today; what is being asked for is recovery of a file the spec says must not exist, and buying that means sniffing NUL interleaving on every text attachment, which is a guess that ASCII-with-embedded-NULs and some UTF-16 text both answer the same way.

The PyAV path was fixed to write each block into a single growing buffer, but
the soundfile path kept the branch that motivated it. When libsndfile reports
no usable frame count, or one past the ceiling, the declared length is dropped,
nothing is preallocated, and every block is held until a final concatenate
allocates a second copy of the recording. Measured with a source reporting zero
frames for a 30-minute 48 kHz decode: 592.6 MB peak against a 329.6 MB
waveform.

Now one append-only buffer that doubles when it runs short and is clamped to
_decoded_sample_ceiling: 352.0 MB for the same decode, with the returned array
byte-identical. An honest header is still only trusted once the decode has met
half of it, so it sizes the growth rather than buying an array up front, and
ordering is now correct by construction rather than by a latch.

Two tests asserted the old mechanism instead of the behaviour and were restated:
one required the final concatenate to happen, and one required no allocation at
all before the cap refuses, which a streaming buffer cannot promise. The
guarantee they were protecting, that nothing the header claims is allocated, is
now asserted directly against the ceiling.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: babe271195

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

Copy link
Copy Markdown
Member

Note on the red Frontend build + bundle sanity, since it is not this branch to fix.

The failing step is Startup bundle budget. I built three trees with the same node_modules and ran npm run bundle:check on each:

tree eager startup transfer vs the 1562.5 KB budget
origin/main alone 1566.2 KB over by 3.7 KB
origin/main merged with this branch 1572.8 KB over by 10.3 KB
this branch on its old merge base 1550.2 KB 12.3 KB to spare

So main is already over on its own, and CI agrees: the same step failed on main at 87ab4ed with over the startup budget: transfer 1568.0 KB > 1562.5 KB, no PR involved. This branch adds 6.6 KB on top of a baseline that already fails, which is why the check is red here and was green when the branch was cut.

That means it cannot be cleared from this branch. Taking the attachment work to zero bytes still leaves main 3.7 KB over, and raising BUDGET belongs with whatever crossed the line on main, since the check asks for it to be raised in the same PR as the measurement that justifies it.

The 6.6 KB this branch adds is real and worth trimming separately. The charset detection and the five binary sniffers in text-attachment-accept.ts are only needed once a file is actually attached, but they are pulled onto the startup path because the composer imports the accept string from the same module. Splitting the accept data from the decode and sniff half would move most of it off the first screen.

@danielhanchen

Copy link
Copy Markdown
Member

CI has finished on babe27119: 54 pass, 6 red, none of the six caused by this branch. Checked each against main rather than assuming, since two of them do sit in areas this branch touches.

red check cause checked against main
Repo tests (CPU) test_context_dependent_unsloth_zoo_findings_are_digest_pinned; the pinned sha256 for the unsloth_zoo/compiler.py scanner finding drifted same single failure, 15824 passed
workflow-trigger lint same digest-pin test failure on main at 4792f9bb2
Frontend build + bundle sanity Startup bundle budget, detailed above failure on main at 87ab4ed7c, 1568.0 KB > 1562.5 KB
Build PR AppImage sha256 mismatch on the downloaded linuxdeploy-plugin-appimage.AppImage reproduces on the staging repo too; main last built clean at 05:30
Core (HF=4.57.6 + TRL<1) The operation was canceled not a test failure
Chat UI Tests (banner) The operation was canceled not a test failure

The Repo tests (CPU) run is the useful signal: 15824 passed, including the studio backend suite, so the audio decode work on this branch is green in CI and the one failure is the pin that also breaks main.

The digest pin and the AppImage checksum should clear on their own once someone updates them on main. The bundle budget will not, for the reason in the previous comment.

Separately, a cross-platform replication of this branch ran on a staging repo to keep it off the org queue: 15 green, 4 red, and the 4 are the same pre-existing set (Backend CI and Frontend CI fail identically on staging main, plus the AppImage checksum and the same unsloth_zoo pin). The Windows leg of that run did find two real problems in this branch own tests, both fixed in c81f628ad: read_text() followed the cp1252 locale and raised UnicodeDecodeError on the parity test, and five tests imported torch directly rather than skipping where it is absent.

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