Skip to content

fix(wecom): add MEDIA file support to send_message tool#37370

Closed
changyinhui wants to merge 5 commits into
NousResearch:mainfrom
changyinhui:fix/wecom-send-message-media
Closed

fix(wecom): add MEDIA file support to send_message tool#37370
changyinhui wants to merge 5 commits into
NousResearch:mainfrom
changyinhui:fix/wecom-send-message-media

Conversation

@changyinhui

Copy link
Copy Markdown

Summary

Fixes #37364 — WeCom send_message silently drops MEDIA file attachments when the gateway is running.

Root Cause

  1. No media branch: _send_to_platform() had no dedicated WeCom media branch. Files fell through to the "Non-media platforms" catch-all (line 825) and were silently dropped.

  2. WebSocket conflict: The standalone _send_wecom() creates a new WeComAdapter and attempts a fresh WebSocket connection. WeCom enforces single-connection-per-bot (errcode 846609: "aibot websocket not subscribed"), so this fails when the gateway already holds the connection.

Changes

  1. _send_via_adapter() — Add media_files handling with send_document / send_image_file dispatch. Temporarily clear _last_chat_req_ids so the adapter uses proactive send mode; restore afterwards so the gateway's own response delivery is unaffected.

  2. _send_to_platform() — Add Platform.WECOM and media_files branch (before the "Non-media platforms" fallback) that routes through _send_via_adapter(), reusing the gateway's live WebSocket connection.

  3. _send_wecom() — Add media_files parameter and handling for the standalone fallback path.

Testing

Verified on live WeCom deployment: send_message(target="wecom", message="...MEDIA:/tmp/test.md") successfully delivers .md file as native attachment.

Closes #37364

teknium1 and others added 2 commits June 2, 2026 14:55
…wn-ext black hole (NousResearch#34517) (NousResearch#34844)

MEDIA:<path> tags for .md/.json/.yaml/.xml/.html and other document
extensions were silently dropped. extract_media() carried a narrow
extension allowlist that omitted them, while extract_local_files()
had a broad one. The dispatch sites then ran an unconditional
re.sub(r'MEDIA:\\s*\\S+', '') that stripped the tag from the body even
when extract_media had not matched it — so extract_local_files (broad
list) ran on text where the path was already gone, and the file was
delivered by neither path.

- Add MEDIA_DELIVERY_EXTS in gateway/platforms/base.py as the single
  source of truth; extract_media and extract_local_files both derive
  their extension set from it (no more drift).
- Replace the loose MEDIA cleanup at the non-streaming dispatch site
  (base.py) and the streaming consumer (stream_consumer.py) with the
  shared, extension-anchored MEDIA_TAG_CLEANUP_RE. A MEDIA: tag with an
  unknown extension is left in the body so the bare-path detector can
  still pick it up instead of being black-holed.
- Chain cleaned text through extract_media -> extract_images ->
  extract_local_files in run.py's post-stream media delivery (it was
  dropping the cleaned text and rescanning raw text with MEDIA: tags).
- Regression tests covering both halves: previously-dropped extensions
  now extract, and unknown-ext paths survive the cleanup.

Consolidates the MEDIA extension-allowlist PR cluster.

Co-authored-by: Bartok9 <259807879+Bartok9@users.noreply.github.com>
Co-authored-by: banditburai <123342691+banditburai@users.noreply.github.com>
Co-authored-by: Kyzcreig <9063726+Kyzcreig@users.noreply.github.com>
Three changes to fix WeCom media delivery in send_message:

1. _send_via_adapter(): Add media_files handling with send_document /
   send_image_file dispatch. Save/restore _last_chat_req_ids so the
   adapter uses proactive send mode for media instead of consuming the
   gateway's reply slot.

2. _send_to_platform(): Add Platform.WECOM + media_files branch that
   routes through _send_via_adapter() — reuses the gateway's live
   WebSocket connection instead of creating a duplicate connection
   that would fail with WeCom errcode 846609.

3. _send_wecom(): Add media_files parameter for standalone path
   (non-live-adapter fallback).

Closes NousResearch#37364
@alt-glitch alt-glitch added type/bug Something isn't working platform/wecom WeCom / WeChat Work adapter comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 2, 2026
Resolved merge conflict in gateway/platforms/base.py — upstream changes
(Windows path support, media path masking, _strip_media_directives refactor)
are orthogonal to the WeCom send_message MEDIA fix.

Our key changes in tools/send_message_tool.py (WeCom media branch at L820,
_send_via_adapter reply context handling) are unaffected.
Add TestSendWecomMedia with 4 unit tests:
- WeCom + media_files routes to _send_via_adapter
- WeCom text-only still uses legacy _send_wecom
- Single chunk passes media_files through
- Error from _send_via_adapter propagates

Closes NousResearch#37364
@changyinhui changyinhui closed this Jun 8, 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 P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[WeCom] send_message MEDIA files silently dropped — no media branch in _send_to_platform

3 participants