Skip to content

Studio: attach video to a chat, and say why when it is unavailable - #9057

Merged
danielhanchen merged 13 commits into
studio/desktop-drag-drop-9036from
studio/chat-video-attachments
Aug 19, 2026
Merged

danielhanchen merged 13 commits into
studio/desktop-drag-drop-9036from
studio/chat-video-attachments

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

Stacked on #9056. Review that one first, this branch targets it so the diff stays clean.

Why

We could not attach or drop a video in chat, even though llama.cpp has supported it for a while. It takes video through its OpenAI-compatible chat endpoint as an input_video content part:

{"type": "input_video", "input_video": {"data": "<base64>"}}

The catch is that it accepts one only when three things line up: the mmproj declares video, the binary was built with video support, and ffmpeg and ffprobe are installed on the machine. It reports that verdict at GET /props under modalities.video. Nothing about the GGUF alone can tell us, so that is what we read rather than guessing.

Frontend

  • Video joins the native drop classifier and gets its own pending queue beside images and audio, so a dropped clip survives a chat re-key the same way the other two do.
  • VideoAttachmentAdapter takes one clip per message, from the picker or from a drop. More than one is refused up front: llama-server expands a clip into a run of frames, so a batch would blow the context before reaching the model.
  • When the model cannot take video, the adapter names all three possible causes. The server does not say which one it is, and a bare "video input is not supported" is not much help to anyone.

Backend

  • video_base64 on the chat request is forwarded whole as an input_video part. llama-server owns the frame sampling, so unlike audio there is nothing useful to transcode here.
  • has_video_input is read from the /props modalities at load and rides the same path out to the model row that has_audio_input already takes.

What is deliberately left out

Compare mode. video_base64 targets the single loaded GGUF, so at most one side of a compare could answer. Dropping a clip there now says that instead of ignoring the file.

Size caps line up across the three hops, 64 MB in the desktop reader, in the composer and in the route, so no hop accepts what the next one refuses.

Testing

  • npm run typecheck clean, npm test 2946 passing
  • pytest tests/test_video_attachment_part.py 7 passing, covering the part shape and the /props capability read
  • cargo check clean
  • Verified against a local Studio that openapi.json now carries ChatCompletionRequest.video_base64, InferenceStatusResponse.has_video_input and LoadResponse.has_video_input

End to end generation needs a video-capable mmproj plus ffmpeg on the box, which I did not have here, so that part rests on the wire shape and the capability gate rather than a live run.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@shimmyshimmer
shimmyshimmer force-pushed the studio/chat-video-attachments branch from 36c94c7 to a325f99 Compare August 17, 2026 03:12
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Good catch, that one is real. parkIfWaitingOnAttachments only chose between "images" and "audio", so a video still registering fell to the "audio" arm and the parked-send toast read "Waiting for dropped audio".

Fixed in a325f99: enqueueSend takes a "video" state with its own title, and the caller now picks by what is actually materializing rather than treating audio as the fallback.

While rebasing this onto the updated #9056 I also fixed two things on that branch that are worth flagging here, since both were mine:

  • Keeping the window-wide drop listener on outside single chat also handed it model drops, so a GGUF dropped on a compare or project view would have loaded and replaced the active model. Nothing happened there before, so that was not a change this should make. The refusal now covers every kind the handler acts on, models included.
  • The recipe seed route had moved its extension check after the read, so a rejected 500 MB upload was pulled into memory first. Back to validating the filename before reading a byte.

@shimmyshimmer
shimmyshimmer force-pushed the studio/chat-video-attachments branch from a325f99 to d3d8059 Compare August 17, 2026 03:14
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@shimmyshimmer
shimmyshimmer force-pushed the studio/chat-video-attachments branch from d3d8059 to 78637fe Compare August 17, 2026 03:37
@shimmyshimmer

Copy link
Copy Markdown
Member Author

All three were right. Fixed in 78637fe.

Capability never copied into the row. This was the serious one: syncModelCapabilities declared has_video_input but never wrote hasVideoInput, and /api/models/list omits it for the active GGUF row, so the adapter read false after every load and status hydration. Video would have been refused even on a model whose /props reported support, which means the feature did not work in its main path at all. Copied through now.

Tool and response_format passthrough. Confirmed the branch returns well before the injection, and _build_openai_passthrough_body forwards an explicit field list, so video_base64 went nowhere and the model answered without the clip. Refused there now with the same wording the audio path uses.

Base64 ceiling. Confirmed the arithmetic: a 64 MiB file encodes to 4 * ceil(67108864 / 3) = 89478488 characters, and the floored cap allowed 89478485, so a clip of exactly the size the composer accepts came back 413. Also moved the measurement after the data URI header is stripped, since the header is not payload. Both now use the padded ceiling.

Tests added for the last two, and I checked they fail against the old code before keeping them.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

shimmyshimmer and others added 3 commits August 17, 2026 00:15
llama.cpp takes video through its OpenAI-compatible chat endpoint as an
`input_video` content part, but only when the mmproj declares video, the
binary was built with video support and ffmpeg is installed. It reports
that verdict at /props under modalities.video. Nothing about the GGUF
alone can tell us, so that is what Studio now reads.

Frontend: video joins the drop classifier and its own pending queue
beside images and audio, and a VideoAttachmentAdapter takes one clip per
message from the picker or a drop. When the model cannot take video the
adapter names all three possible causes instead of letting llama-server
refuse the request later.

Backend: video_base64 on the chat request is forwarded whole as an
input_video part, since llama-server owns the frame sampling and there is
nothing useful to transcode. has_video_input rides the same path as
has_audio_input out to the model row.

Compare mode is left out on purpose: video_base64 targets the single
loaded GGUF, so at most one side could answer. Dropping a clip there now
says so rather than ignoring the file.

Size caps line up across the three hops (64 MB in the desktop reader, in
the composer and in the route) so no hop accepts what the next refuses.
… path

Three review findings, all correct.

syncModelCapabilities took has_video_input but never copied it into the
row, and /api/models/list omits it for the active GGUF, so the adapter read
false after every load and refused video even when /props reported it. The
feature did not work in its main path.

The tool and response_format passthrough returns before the injection and
forwards an explicit field list, so a clip rode along nowhere and the model
answered without it. Refused now, the way audio already is there.

The size cap floored the base64 inflation, so a clip of exactly the size
the composer allows was refused with a 413, and the data URI header was
counted against the payload. Padded ceiling, measured after stripping.
…here it cannot be served

Three separate places map backend capability flags onto a model row and
each one dropped the video flag: the direct status adoption, the queued-run
capability Pick, and (fixed earlier) syncModelCapabilities. The adapter
reads that row, so any of them leaves video refused on a model that
supports it. Covered by a rule rather than three spot checks.

Injection lives in the GGUF branch, so an external provider or a local
transformers model answered as if no clip were attached. Both now refuse,
as does token counting, which cannot inject the frames it would need to
count. The size check also moved ahead of the automatic model switch so an
oversized clip does not evict a working model before the 413, and video now
votes in the pre-switch projector requirement alongside audio.

The video drain's read-failure toast said 'audio', inherited from the
audio drain it was cloned from.
@shimmyshimmer
shimmyshimmer force-pushed the studio/chat-video-attachments branch from cb6c49e to 57d819a Compare August 17, 2026 07:16
@shimmyshimmer

Copy link
Copy Markdown
Member Author

All four correct. One of them turned out to be broader than reported.

Status adoption drops the video capability (correct, and there was a third site). ensureActiveModelInStoreList copied only the audio fields and its own comment notes that adoption never calls syncModelCapabilities, so a server-adopted GGUF got a row without the flag. Rather than patch the second site and wait for a third, I wrote the invariant as a test: every module that assigns hasAudioInput must assign hasVideoInput. It immediately found one more, QueuedModelCapabilities in queued-model-capabilities.ts, a Pick that omitted the field. Its index < 0 branch builds a fresh row from that Pick alone, so a queued run against a model not in the catalog would have refused video too. All three fixed in 57d819a.

Video before automatic model switching (correct). The size check is a target-independent length check, exactly like the audio one directly above it, so it had no business running after a model load. Moved ahead of the switch, and video now votes in the projector requirement alongside audio. Both checks call one _video_b64_rejection helper so the pre-switch and post-load rules cannot drift, which is the failure mode that would reintroduce the load.

Attachment surviving a model change (correct). Confirmed both halves: _proxy_to_external_provider returns at the top of the handler, and injection is inside if using_gguf, so an external provider and a local transformers model each answered as though nothing were attached. Both now return 400 rather than a silent answer. I put the gate in the backend rather than the composer so it covers API clients too, and the same pass caught /count-tokens, which refuses images and audio but was quietly undercounting a turn carrying a clip.

Video drain toast says audio (correct). Straight inheritance from the audio drain it was cloned from, on the one path whose whole job is explaining why a dropped video did not attach.

Each of the six new tests was confirmed to fail against the pre-fix tree. Full run: 2952 frontend tests pass, 907 backend tests across the inference suites pass (the 6 failures in test_audio_type_inconclusive.py are an _MLXTrainerAdapter attribute error present on a clean checkout of main), typecheck and cargo check clean.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Adding video to require_vision made the shared rejection reachable for a
request carrying only a clip, but its text is fixed at 'image or audio
input', so the user who attached a video was told about modalities the
request never carried. The label now follows what is attached, and defaults
to the existing wording so the image-only callers are unchanged.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Correct, and it is a regression I introduced in the previous round.

Adding payload.video_base64 to require_vision made that rejection reachable for a request carrying only a clip, but its text is fixed at "image or audio input", so the one user who most needs the explanation gets told about two modalities their request never carried.

modality_label now names what is actually attached and defaults to the existing wording, so the image-only callers (/messages, /responses) are byte-for-byte unchanged. Fixed in adc01c1.

Worth noting what the fix caught on the way in: the existing test_chat_audio_input_guards_target_before_switch stubs _maybe_auto_switch_model with a hand-written signature, so the new keyword broke it. That is the test doing its job, and I extended it to assert the label rather than just tolerate it, which is what pins the audio-only request to "audio" rather than the union the hook guards.

Four tests, three of which fail against the pre-fix tree:

  • a video-only request labels the refusal "video", driven end to end through the handler
  • a mixed request lists every modality attached
  • a caller passing no label still gets the old wording (a contract test, so it passes either way by design)

Backend run over the inference, auto-switch, audio, token-count and video suites: 1530 passed against 1526 on a clean checkout, same 18 pre-existing failures either side (the text-to-video generation suites and test_audio_type_inconclusive.py, neither touched by this PR).

chatgpt-codex-connector[bot]

This comment was marked as resolved.

… recount

The /props probe went out without an Authorization header, so under
UNSLOTH_DIRECT_STREAM=1 llama-server answered 401 and video capability
never came back. Context recount already bails on images and audio
because toOpenAIMessages has no branch for them; video has the same
property and was missing the bail, so the usage bar priced a text-only
prompt and stringified megabytes of base64 on the UI thread.
@danielhanchen

Copy link
Copy Markdown
Member

Review summary

Verdict: useful, merge it. Nine review items triaged, four fixes pushed as 60009e088, 3,957 tests across three suites with no regression I could find.

Before / after, with the screenshot

Before, dropping or picking an .mp4 in chat did nothing visible - assistant-ui rejected it on the accept string inside an unawaited promise, so the file vanished with no toast and no explanation. After, video is a first-class attachment on a video-capable GGUF, and every path that cannot serve it says why.

video refusal

BEFORE 06c90fd3c (this PR's merge base, which is #9056's head, deliberately not main) vs AFTER 0a9d93c22. The AFTER home was rebuilt because its stamp still read adc01c14b, so no stale side was photographed. Facts moved with the picture: accept tokens 100 -> 110, accept_video_tokens [] -> the five video MIME types, toast_count 0 -> 1, and the console error went from File type video/mp4 is not accepted to the explanation on screen.

Two traps were hit and are recorded rather than papered over: a port collision with another Studio on this box (caught by the identity check), and host noise that read exactly like a PR effect - the welcome greeting is pickRandom() and the llama.cpp update banner had been answered on one side only. Both are now suppressed on both sides. Not covered by this pair: the <Model> cannot accept video toast, the size and one-clip refusals, and any real video inference - all need a loaded video-capable GGUF. Composite and facts: outputs/ui_diff_9057/.

Item verdicts

Seven of nine were correct when written (02:42-08:05 on 2026-08-17) and had already been fixed by 39a8fa135 / 57d819a00 / adc01c14b, so they get a thumbs up and no further action:

id verdict
3793514622 genuine, fixed - syncModelCapabilities writes hasVideoInput
3793610899 genuine, fixed - passthrough now rejects rather than dropping the clip
3793610902 genuine, fixed - 4*ceil(64MiB/3) = 89478488; the old floor gave 89478485, three bytes short, so an exactly-64-MiB file 413'd. Arithmetic checked against the real encoder
3793669125 genuine, fixed - video joins _needs_vision, size check runs pre-switch
3793686247 rejected - see the thread
3793686249 genuine, fixed - ensureActiveModelInStoreList copies has_video_input
3793686253 genuine, fixed - toast now reads "Could not attach dropped video"
3794475015 genuine, fixed - modality_label names the attached modality in the refusal
3794717067 genuine, fixed by me in 60009e088

Is the issue real

Yes, and the before-side console says so literally. Worth noting the design call at the centre of it: the feature hinges on llama-server's /props modalities.video, which is the only thing that knows whether the mmproj, the build flags and ffmpeg all line up - none of which the GGUF alone reveals. That is the right source of truth.

Does it break anything

Purely additive: a new optional Pydantic field, a new adapter inserted into a composite, new refusal branches. I measured that adding the video adapter steals no pre-existing attachment type - identical dispatch for png/gif/wav/mp3/ogg/flac/webm-audio/m4a/txt/md/html/pdf with and without it.

Old llama.cpp builds, the case you asked about: a build too old to report modalities omits the key entirely, isinstance(modalities, dict) is False, the flag stays False, and video is refused with an explanation. Verified across 8 malformed /props shapes, 5 non-object bodies and 5 HTTP error codes - none crash, none falsely claim video. Old persisted chats have no video parts and read back identically. ChatCompletionRequest is extra: "allow", so an older backend ignores the new field rather than 422-ing every message.

Simulation

789 new lines of tests, run against real code rather than mocks. 590 backend + 2996 frontend + 371 Rust, 0 failures.

area result
base64 ceiling vs the real encoder, 12 sizes PASS, measured
exactly-64-MiB clip admitted, +1 char 413s PASS, measured
data-URI strip, 5 containers + 4 malformed PASS, measured
old llama.cpp with no modalities key PASS, measured
8 malformed modalities shapes, no crash PASS, measured
5 non-object /props bodies, 5 HTTP errors PASS, measured
capability not inherited across a model swap PASS, measured
/props auth header present / absent PASS, measured (after the fix)
has_video_input really reaches the wire PASS, measured
injection across 7 message shapes incl. tool turns PASS, measured
5 refusal paths + pre-switch ordering PASS, measured
isVideoFile x 4 engines x 5 containers PASS, simulated MIME tables
adapter dispatch order, no type stolen PASS, measured with the real fileMatchesAccept
size boundary, frontend/backend caps agree PASS, measured
clip extraction across 9 thread shapes PASS, measured on lifted source
legacy thread unaffected PASS, measured

Cross-platform and cross-browser. All five containers simulated as reported by Chrome/Edge, Firefox, Safari, and a Windows box with no codec pack - including the cases that return an empty MIME type (.mkv on Firefox and Safari, everything on bare Windows). The extension fallback covers all of them, which is why VIDEO_ACCEPT carries both MIME and extension tokens. crypto.randomUUID is guarded for non-secure contexts (Safari over a LAN IP). The Rust MIME table and the frontend accept list are held in parity by the PR's own tests, and the Rust suite passes on the macOS and Windows runners in CI plus 371/371 locally.

Fixes pushed in 60009e088

  1. /props readback sent no Authorization. Under UNSLOTH_DIRECT_STREAM=1 that 401s, so video capability never came back. Pre-existing on the merge base, and the env var defaults to "0" and is set nowhere in the repo, installers, Tauri or docs - so lower severity than filed, but wrong either way.
  2. The context-usage recount did not decline a video turn. refresh-context-usage.ts bails on images and on audio, with a comment stating exactly why: toOpenAIMessages has no branch for them, so counting prices a text-only prompt. Video has the identical property and had no bail. A user on an 8k model would watch the bar read ~1k/8192 while the real prompt already overflowed, then get an exceed_context_size 400 against a bar that said there was room. It also pushed ~85 MB of base64 through branchSignature's synchronous JSON.stringify on the UI thread twice per recount - precisely the cost the image bail exists to avoid. Two regression tests added.
  3. test_video_attachment_part.py used .read_text() with no encoding, which is what reddened test_source_read_encoding.py.
  4. Two new simulation files (444 + 345 lines).

Two things left for you

  • _has_video_input goes stale on the diffusion load path. The clear sits inside the llama-server spawn block and load_model returns earlier on the diffusion branch. _is_vision and _has_audio_input have the identical pre-existing hole at the same early return, so fixing video alone would be inconsistent and fixing all three is outside this PR. Flagging it because the PR's own comment claims the clear covers "a swap into a model without video", and it does not cover this one.
  • video_base64 is forwarded verbatim. llama.cpp's handle_media branches on string_starts_with(url, "http") before decoding, so an authenticated API client posting video_base64: "http://..." makes llama-server fetch that URL. audio_base64 cannot do this because it is decoded locally first. Not reachable from the Studio UI and below the bar I was working to, but a one-line guard in _video_b64_rejection closes it. Your call.

(Not a defect: audio tokens are filtered out of the file picker when no audio model is loaded, while video tokens are always offered. That asymmetry is the PR's stated purpose - explain unavailability rather than hide the affordance.)

CI

  • Rust/Tauri on all three OSes: green, 371/371 locally across 5 consecutive clean runs.
  • Repo tests (CPU): two failures, one PR-caused. test_source_read_encoding.py was ours and is fixed above. test_multi_chat_prompt_queue_contract.py is not - the handleSubmit to stopQueue slice is byte-identical (6552 chars) at head, at the merge base and on origin/main, and lacks the token in all three. Pre-existing main red.
  • Python 3.10 / 3.11 and one Chat UI Tests: not failures, 30-minute job timeouts (timeout-minutes: 30; runtimes 30m11s, 30m11s, 30m25s, reported as cancelled). Python 3.12 (24m29s) and 3.13 (26m44s) passed on identical code, and the other Chat UI Tests passed in 21m45s. Queue congestion.
  • The 86 test_video_* failures I hit locally are the diffusion video subsystem, unrelated - identical 86-fail/251-pass at head and at the merge base.

One caveat stated plainly: no real video ever went through a real video-capable GGUF. Everything above is stubbed /props, lifted source, and an 8 KB synthetic MP4 that nothing decodes. The wire shape is pinned against llama.cpp's source rather than against a live server.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

The accept list carries extensions as well as mime types because the
browser's answer is unreliable for mkv and some mov files, and the
picker takes those files on the extension. Only an empty type was being
replaced, so a clip the browser called application/octet-stream kept
that type into the attachment, and the request builder recognises a file
part only when its mimeType matches ^video/. The clip was attached, sent
and dropped, and the model answered as though nothing were there, which
is the silent drop this PR exists to remove. The table mirrors the one
in native_intents.rs, so a clip read by the desktop reader and one
picked in the browser reach the route the same way.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 54e81ddf90

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

@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: 5a3f14663c

ℹ️ 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 +1525 to +1526
const base64 = extractVideoPartBase64(part);
if (base64) return base64;

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 Reject empty video payloads instead of dropping them

When a user selects a zero-byte video, the attachment adapter accepts it because the size check only enforces the maximum, and fileToBase64 produces a data URI with an empty payload. extractVideoPartBase64 then returns "", but this truthiness check treats that as no video, so video_base64 is omitted and the model answers the text prompt without showing the intended “Could not read” error. Reject zero-byte files when adding them, or preserve the empty payload so the backend can return its explicit 400.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit bf2e3bb into studio/desktop-drag-drop-9036 Aug 19, 2026
39 of 43 checks passed
@danielhanchen
danielhanchen deleted the studio/chat-video-attachments branch August 19, 2026 12:10
danielhanchen added a commit that referenced this pull request Aug 19, 2026
* Desktop: make every drop zone take a drop again (#9036)

Tauri delivers OS file drops window-wide and suppresses the webview's own
drop events, so a zone wired only to `onDrop` does nothing in the desktop
app: no drag-over border, and the file is silently ignored.

Native drop routing (#8265) was only ever adopted by the shared image
picker and the create-project dialog. Every other file drop zone still
relied on HTML5 handlers that never fire, which is why this reads as
intermittent: the same file works when it lands on the chat, covered by
the window-wide handler, and does nothing anywhere else.

Adds `useNativeFileDrop`, which claims the native drop for an element and
returns drag-over state plus the HTML5 handlers the web build still needs,
then adopts it in the zones that were dead:

- Projects -> Sources, which also had no drag-over styling at all
- Data Recipes unstructured seed
- Diffusion training images
- Video and audio reference pickers

Documents upload by lease rather than an inline read, since the native
reader only serves media inline, so the recipe seed route now accepts
`nativePathLease` the way the RAG upload routes already do. The native
path policy accepts video containers so the reference picker can register
what it is given.

Also stops two silent discards with the same symptom: a claimed zone that
refused a drop while disabled, and compare mode disabling the window-wide
handler outright. Both now say what happened.

`native-dropzone-coverage.test.ts` walks src/ and fails if a zone reads
files from a drag payload without either claiming the native drop or
explicitly deferring to the window handler.

* Desktop: refuse a dropped model in compare too, and validate before reading

Two things the first pass got wrong.

Keeping the window-wide listener on outside single chat also handed it
model drops, so a GGUF dropped on a compare or project view would load
and replace the active model. Nothing happened there before, so that is
not a change this should be making. The refusal now covers every kind the
handler would act on, models included.

The recipe seed route also moved its extension check after the read, so a
rejected 500 MB upload was pulled into memory first. Back to validating
the filename before reading a byte, as it was.

* Desktop: size the native video cap to the largest client-side limit

64 MB sat under the reference picker's own 72 MB, so a clip the picker
accepts was refused on drop. The cap is a backstop; callers keep theirs.

* Desktop: drop the diffusion zone from this pass, and bound the native read

Two review findings, both correct.

The diffusion dataset zone accepts .bmp, .m4v, .caption and .jsonl, which
the chat attachment policy rejects outright, and .txt, which registers but
cannot be read inline. Captions beside images are the documented workflow
there, so wiring that zone to the attachment path would have uploaded the
images and silently lost the captions. It needs its own registration and
upload policy, which is more than this belongs to, so it goes back to the
picker it had.

The recipe seed route also read a dropped path in full before checking any
limit, so a multi-gigabyte local file went into backend memory before the
413. It now refuses on the stat and bounds the read by what the block has
left, in case the file grows in between.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Desktop: keep a busy drop zone hit-testable, and size the video cap to the raw limit

A disabled seed zone carried pointer-events-none, which takes it out of
elementFromPoint, so nativeDropTargetAt could not find the target it had
just registered. The disabled message was unreachable and the drop fell
through to the window handler instead.

MAX_NATIVE_VIDEO_BYTES was set to the reference picker's 96 MiB, but that
cap bounds the data URL, not the file: the picker's own raw limit is
75497280 bytes. Rust was reading and base64-encoding up to 96 MiB, 128 MiB
across the bridge, for clips the picker then rejected.

* Match the document-refusal test to the message it now returns

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: attach video to a chat, and say why when it is unavailable (#9057)

* Studio: attach video to a chat, and say why when it is unavailable

llama.cpp takes video through its OpenAI-compatible chat endpoint as an
`input_video` content part, but only when the mmproj declares video, the
binary was built with video support and ffmpeg is installed. It reports
that verdict at /props under modalities.video. Nothing about the GGUF
alone can tell us, so that is what Studio now reads.

Frontend: video joins the drop classifier and its own pending queue
beside images and audio, and a VideoAttachmentAdapter takes one clip per
message from the picker or a drop. When the model cannot take video the
adapter names all three possible causes instead of letting llama-server
refuse the request later.

Backend: video_base64 on the chat request is forwarded whole as an
input_video part, since llama-server owns the frame sampling and there is
nothing useful to transcode. has_video_input rides the same path as
has_audio_input out to the model row.

Compare mode is left out on purpose: video_base64 targets the single
loaded GGUF, so at most one side could answer. Dropping a clip there now
says so rather than ignoring the file.

Size caps line up across the three hops (64 MB in the desktop reader, in
the composer and in the route) so no hop accepts what the next refuses.

* Studio: carry the video capability through, and cover the passthrough path

Three review findings, all correct.

syncModelCapabilities took has_video_input but never copied it into the
row, and /api/models/list omits it for the active GGUF, so the adapter read
false after every load and refused video even when /props reported it. The
feature did not work in its main path.

The tool and response_format passthrough returns before the injection and
forwards an explicit field list, so a clip rode along nowhere and the model
answered without it. Refused now, the way audio already is there.

The size cap floored the base64 inflation, so a clip of exactly the size
the composer allows was refused with a 413, and the data URI header was
counted against the payload. Padded ceiling, measured after stripping.

* Studio: carry the video capability through every hop, and refuse it where it cannot be served

Three separate places map backend capability flags onto a model row and
each one dropped the video flag: the direct status adoption, the queued-run
capability Pick, and (fixed earlier) syncModelCapabilities. The adapter
reads that row, so any of them leaves video refused on a model that
supports it. Covered by a rule rather than three spot checks.

Injection lives in the GGUF branch, so an external provider or a local
transformers model answered as if no clip were attached. Both now refuse,
as does token counting, which cannot inject the frames it would need to
count. The size check also moved ahead of the automatic model switch so an
oversized clip does not evict a working model before the 413, and video now
votes in the pre-switch projector requirement alongside audio.

The video drain's read-failure toast said 'audio', inherited from the
audio drain it was cloned from.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Studio: name the attached modality in the pre-switch refusal

Adding video to require_vision made the shared rejection reachable for a
request carrying only a clip, but its text is fixed at 'image or audio
input', so the user who attached a video was told about modalities the
request never carried. The label now follows what is attached, and defaults
to the existing wording so the image-only callers are unchanged.

* Match the document-refusal test to the message it now returns

* Send the API key on the /props readback and skip video in the context recount

The /props probe went out without an Authorization header, so under
UNSLOTH_DIRECT_STREAM=1 llama-server answered 401 and video capability
never came back. Context recount already bails on images and audio
because toOpenAIMessages has no branch for them; video has the same
property and was missing the bail, so the usage bar priced a text-only
prompt and stringified megabytes of base64 on the UI thread.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Send a picked clip under the container its extension names

The accept list carries extensions as well as mime types because the
browser's answer is unreliable for mkv and some mov files, and the
picker takes those files on the extension. Only an empty type was being
replaced, so a clip the browser called application/octet-stream kept
that type into the attachment, and the request builder recognises a file
part only when its mimeType matches ^video/. The clip was attached, sent
and dropped, and the model answered as though nothing were there, which
is the silent drop this PR exists to remove. The table mirrors the one
in native_intents.rs, so a clip read by the desktop reader and one
picked in the browser reach the route the same way.

---------

Co-authored-by: shimmyshimmer <[email protected]>
Co-authored-by: Unsloth <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: shimmyshimmer <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Unsloth <[email protected]>
Co-authored-by: Daniel Han <[email protected]>
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 11, 2026
Fixes unslothai#17062

## Why

Chat refused any video over 64 MB, which is roughly 50 seconds of 720p.
That number was picked when video input landed (unslothai#9057) so the composer,
the route and the desktop reader agreed with each other. Nothing in the
model path needs it:

- llama-server picks frames by duration (fps sampling with per-model
frame clamps), not by file size, so a bigger file does not mean more
context.
- Studio already re-encodes any clip larger than 640x360 to 640x360 at 4
fps before llama-server sees it. A 3 minute 720p clip at 8 Mbps (180
MiB) comes out at about 19 MiB.

The real ceiling is llama-server's HTTP layer, which refuses request
bodies over 100 MB (`CPPHTTPLIB_PAYLOAD_MAX_LENGTH` in its vendored
cpp-httplib). The clip travels as base64 in JSON, so anything above
about 74 MB that reaches llama-server untouched would fail there.

## What changes

- The composer and the chat route accept clips up to 256 MB. Its base64
(about 341M characters) stays under the browser's maximum string length,
and the request stays under Studio's default 500 MB body cap.
- The pre-llama transcode also runs when a clip is larger than 64 MB,
even if its frames are already small, so llama-server never gets a body
near its 100 MB limit. Clips at or under 64 MB take exactly the same
path as before.
- After transcoding, the video payload going to llama-server (all clips
in the request together) is checked against that 64 MB budget. A clip
that could not be brought under it (failed or timed out transcode, or a
very long clip) gets a clear 413 asking for a shorter clip instead of an
opaque llama-server error. Anything that was valid on main (64 MB total)
still fits.
- A size-only re-encode (frames already small, frame rate already low)
runs without a video filter, since ffmpeg refuses an empty `-vf`. Every
refusal on this path also finalizes the API monitor entry.
- The 413 messages and the tests that pinned 64 MB are updated, and
tests cover a small-frame clip over the forward budget being transcoded,
a clip still over budget after transcoding, and several clips over
budget together.

Nothing else in the UI or the flow moves: same attach button, same
toasts, same one clip per message. Desktop drag-and-drop keeps its
native reader cap (about 72 MB, shared with the video generation
reference picker); the attach button in Desktop uses the webview picker
and gets the new limit.

## Evidence

Route functions (`_video_b64_rejection`, then `_shrink_clip_for_llama`)
on synthetic clips, main vs this branch:

| Clip | main | this branch |
|---|---|---|
| 180 MiB, 180 s, 1280x720 | 413 `Video file is too large (max 64 MB).`
| accepted, forwarded 18.9 MiB (about 25 MiB of JSON) in 20 s |
| 99 MiB, 20 s, 640x360 at 40 Mbps | 413 | accepted, transcoded to 13.9
MiB (without the new trigger it would have gone to llama-server as about
132 MB of JSON) |
| 297 MiB, 60 s, 640x360 | 413 | 413 `Video file is too large (max 256
MB).` |

The synthetic clips are noise-heavy, so real footage shrinks further.

## Testing

- `node --test` on the video, native drop and reference size suites: 232
passing; `tsc --noEmit` clean
- Backend: `test_video_pr9057_simulation.py` 68,
`test_video_attachment_part.py` 32,
`test_video_chat_completions_behaviour.py` 80,
`test_llama_video_frame_budget.py` 41, `test_llama_video_ffmpeg.py` 20
(2 skipped, same as main), media decode suites 54, all passing
- The new transcode test fails on main (the 99 MiB-style small-frame
clip is forwarded untouched) and passes here

## Before / after

A 99 MiB clip attached in the chat composer (no model loaded, so only
the size check runs). Before: refused with a 64MB toast. After: it sits
in the composer as an attachment.

![Composer before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/17400/pr17400_ba-aa9467180174.png)
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