Skip to content

fix(gateway): sync MEDIA: directive extension whitelist with extract_local_files - #33522

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/media-directive-extension-whitelist
Closed

fix(gateway): sync MEDIA: directive extension whitelist with extract_local_files#33522
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:fix/media-directive-extension-whitelist

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

Summary

gateway/platforms/base.py has two independent file-extension whitelists used for media routing:

  1. extract_media() — parses explicit MEDIA:<path> directives from the model
  2. extract_local_files() — finds bare local paths in response text

These whitelists had drifted out of sync. extract_local_files accepts .html, .json, .svg, .md, .tar, .gz, .bmp, .tiff, and many more — but the regex in extract_media did not. When the model emitted MEDIA:/path/file.html, the regex didn't match, the file was silently dropped, and send_message reported success: true. Silent data loss with no log output.

Fix

Synced the extract_media regex extension group with _LOCAL_MEDIA_EXTS by adding all missing extensions:

  • Images: bmp, tiff, svg
  • Documents: odt, rtf, md
  • Spreadsheets/data: xls, ods, tsv, json, xml, yaml, yml
  • Presentations: ppt, odp, key
  • Archives: tar, gz, tgz, bz2, xz
  • Web: html, htm

Kept existing extras not in _LOCAL_MEDIA_EXTS (epub, opus, apk, ipa) since they're valid media types.

Testing

  • All 14 existing TestExtractMedia tests pass
  • All 44 test_extract_local_files tests pass
  • Added 2 regression tests covering the newly-recognized extensions

Code Intelligence

  • Analyzed: gateway/platforms/base.py extract_media() (line ~2416) and _LOCAL_MEDIA_EXTS (line ~2458)
  • Blast radius: LOW — regex change only, no control flow modification
  • Related patterns: extract_local_files() uses the same conceptual whitelist; the two must stay in sync

Fixes #31137

…local_files

The extract_media() regex in base.py only recognized a subset of file
extensions (images, video, audio, common docs), while extract_local_files()
accepted a much broader set including .html, .json, .svg, .md, .tar, .gz,
and many others. When the model emitted MEDIA:/path/file.html, the regex
didn't match, the file was silently dropped, and send_message reported
success — causing silent data loss with no log output.

This fix syncs the two whitelists by adding the missing extensions to the
extract_media regex: bmp, tiff, svg, odt, rtf, md, xls, ods, tsv, json,
xml, yaml, yml, ppt, odp, key, tar, gz, tgz, bz2, xz, html, htm.

Fixes NousResearch#31137
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels May 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #29609 (preferred approach: dynamically derive extension set from SUPPORTED_DOCUMENT_TYPES). This static whitelist expansion is the same approach as #31138, #32995, and #33089. The underlying issue is #31137.

@liuhao1024

Copy link
Copy Markdown
Contributor Author

Closing as duplicate per triage.

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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gateway): MEDIA: directive silently drops .html and other extensions due to regex/whitelist drift

2 participants