Skip to content

fix(gateway): add video_generate to auto-append media allowlist#43065

Open
srojk34 wants to merge 1 commit into
NousResearch:mainfrom
srojk34:fix/video-generate-auto-append-media
Open

fix(gateway): add video_generate to auto-append media allowlist#43065
srojk34 wants to merge 1 commit into
NousResearch:mainfrom
srojk34:fix/video-generate-auto-append-media

Conversation

@srojk34

@srojk34 srojk34 commented Jun 9, 2026

Copy link
Copy Markdown

Problem

video_generate was missing from _AUTO_APPEND_MEDIA_TOOL_NAMES in
gateway/run.py. The gateway's auto-append logic is gated on that set,
so it never ran for video tool results — video files were only delivered
if the model happened to restate the path in its reply text.

image_generate received the symmetric fix in #42616, but video_generate
was not included in the same change. This PR closes the remaining gap.

Root cause

video_generate returns {"success": true, "video": "/abs/path.mp4", ...}
with no MEDIA: tag in its result string. Without an entry in
_AUTO_APPEND_MEDIA_TOOL_NAMES, _collect_auto_append_media_tags() never
inspects the result, so no MEDIA: tag is appended to the gateway reply.

Fix

  1. Add "video_generate" to _AUTO_APPEND_MEDIA_TOOL_NAMES.
  2. Add _JSON_VIDEO_TOOL_PATH_FIELD = "video" constant (mirrors
    _JSON_MEDIA_TOOL_PATH_FIELDS for the image path).
  3. Add a handler block in _collect_auto_append_media_tags() that
    JSON-parses the tool result, reads the "video" field, and appends a
    MEDIA: tag when _TOOL_MEDIA_RE.fullmatch() passes (local-path guard).

Remote CDN URLs (HTTPS) are not matched by _TOOL_MEDIA_RE and still
require model restatement — identical scope to the image_generate fix.

Fixes #19105 (video path).

Test plan

  • Existing tests/gateway/test_media_extraction.py — 13/13 pass
  • video_generate with a local-file backend: MEDIA:/abs/path.mp4
    appended automatically, video delivered without model restatement
  • video_generate with a CDN-URL backend (FAL, xAI): no MEDIA: tag
    injected (URL not matched by _TOOL_MEDIA_RE), behaviour unchanged
  • image_generate path unaffected — no regression

video_generate returns its artifact as JSON ({"success": true, "video":
"/abs/path.mp4"}) with no MEDIA: tag, so the gateway auto-append path
(which was gated on _AUTO_APPEND_MEDIA_TOOL_NAMES) never ran for it —
video delivery depended on the model restating the path in its reply.

Add video_generate to the allowlist and extract its local-file path from
the "video" field, mirroring the existing image_generate handler that
reads from ("host_image", "image", "agent_visible_image"). The same
_TOOL_MEDIA_RE guard applies: remote CDN URLs (which lack a local-path
prefix) are not matched and still require model restatement; local-path
backends benefit immediately.

Symmetric with the image_generate fix from NousResearch#42616.

Fixes NousResearch#19105 (video path)
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery tool/vision Vision analysis and image generation labels Jun 9, 2026
@Julientalbot

Copy link
Copy Markdown
Contributor

@srojk34 nice — this is the earlier and correct fix; I closed my dup #45786 in its favor. Two optional add-ons from that branch if useful: collapsing the image/video branches into a single per-tool field map (drops the duplicated handler block), and 5 video_generate tests (structured path, URL-rejected, failure-ignored, history-dedup, look-alike-tool guard). Happy to send them as a follow-up PR on top of this once it lands, or you can lift the test file from fix/media-autoappend-producer-tools — whichever you prefer.

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

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WhatsApp media delivery fails for generated images, videos, and tool-created media outputs

3 participants