Skip to content

fix(media): add missing extensions to MEDIA delivery whitelist (#37318) - #37342

Closed
luoxiao6645 wants to merge 1 commit into
NousResearch:mainfrom
luoxiao6645:fix/37318-media-md-extension-whitelist
Closed

fix(media): add missing extensions to MEDIA delivery whitelist (#37318)#37342
luoxiao6645 wants to merge 1 commit into
NousResearch:mainfrom
luoxiao6645:fix/37318-media-md-extension-whitelist

Conversation

@luoxiao6645

Copy link
Copy Markdown

Problem

MEDIA:/path/to/file.md tags silently fail for common file types (.md,
.json, .yaml, .py, etc.) — the file is never delivered, send_message
returns misleading {success: true}.

Root Cause

Two of the three MEDIA regexes in the codebase used a stale
hardcoded extension list that never grew beyond the original
image/video/archive set. Only base.py's MEDIA_DELIVERY_EXTS had been
updated; run.py's _TOOL_MEDIA_RE and its inline clone at L17764
carried independent, narrower lists.

Changes

File Change
gateway/platforms/base.py Added 8 extensions: .markdown .toml .py .js .ts .sh .bash .zsh
gateway/run.py Replaced 2x hardcoded regex extension lists with _MEDIA_EXT_ALTERNATION from base.py

All three MEDIA regexes now share one source of truth (60 extensions),
so new extensions never need syncing across files again.

Platforms affected

Feishu, Telegram, and any platform using send_document via MEDIA: tags.

Fixes #37318

…esearch#37318)

Extensions like .md, .py, .json, .yaml were silently dropped
because extract_media() and _TOOL_MEDIA_RE used stale hardcoded
extension lists that didn't include common document/code types.

Changes:
- base.py: add .markdown, .toml, .py, .js, .ts, .sh, .bash, .zsh
  to MEDIA_DELIVERY_EXTS (now 60 extensions, was 52)
- run.py: replace two hardcoded extension regexes with
  _MEDIA_EXT_ALTERNATION imported from base.py, eliminating
  the duplicate maintenance that caused the mismatch

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have labels Jun 2, 2026

@tonydwb tonydwb 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.

Code Review Summary

Verdict: Approved ✅

Scope

Adds 8 missing extensions (.markdown, .toml, .py, .js, .ts, .sh, .bash, .zsh) to the MEDIA delivery whitelist and consolidates three separate regex lists into one shared source of truth.

Strengths

  • DRY refactor: Replaced two hardcoded inline regex copies in run.py with _MEDIA_EXT_ALTERNATION from base.py — future extensions only need one change location.
  • Good root cause analysis: Identified that only base.py had been updated while two regexes in run.py were independently stale.
  • Well-scoped: 7 additions, 10 deletions. Clean diff, single concern.
  • Correct by inspection: The approach (importing the shared alternation fragment) is syntactically and logically sound.

Minor Notes

  • No tests added for the new extensions — acceptable for a whitelist change this simple; regression test would be testing that a constant contains a string.

Reviewed by Hermes Agent

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for narrowing this to the remaining MEDIA extension drift.

Problems

  • Current main has only one live _TOOL_MEDIA_RE definition at gateway/run.py:1061; the PR's second replacement targets a duplicate that was removed. GitHub currently reports this branch as dirty, so that obsolete hunk should not be carried forward.
  • The PR adds no regression coverage. tests/gateway/test_platform_base.py:616-630 exercises the earlier .md/.json/.yaml class only, and tests/gateway/test_run_tool_media_re.py:23-32 reconstructs the old hardcoded regex.

Suggested changes

  • Salvage the current matcher replacement at gateway/run.py:1061 and drop the obsolete duplicate hunk.
  • Add behavior tests for the new extensions through BasePlatformAdapter.extract_media() and the auto-append path.

Current gateway/platforms/base.py:1463-1471 still lacks the requested .markdown, .toml, and script extensions, while extract_media() derives its matcher from that tuple at gateway/platforms/base.py:3641-3645; the underlying extension addition remains valid.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 13, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Closing as resolved on main: PR #65510 replaced the extension-allowlist approach with universal validated egress — ANY MEDIA: path (.py/.js/.ts/.sh/.toml and everything else) now delivers after passing validate_media_delivery_path. Verified live on main for your target extensions. Your idea of routing run.py's _TOOL_MEDIA_RE through the shared alternation is a reasonable residual improvement for the tool-result auto-append path — that narrow list is now only a secondary precision guard, but if you want to unify it, a focused PR for just that would be welcome. Thanks!

@teknium1 teknium1 closed this Jul 16, 2026
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 sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MEDIA: tag fails silently for .md files — extract_media() regex whitelist missing common extensions

4 participants