fix(tools): forward media args through live adapter - #23770
Conversation
teknium1
left a comment
There was a problem hiding this comment.
Thanks for isolating the live-adapter media gap. The current patch needs a different dispatch layer before it can provide the intended behavior.
Problems
tools/send_message_tool.py:464-465passesmedia_filesandforce_documenttoadapter.send(). The adapter contract atgateway/platforms/base.py:2889-2895accepts onlychat_id,content,reply_to, andmetadata; QQBot's concretesend()has the same shape atgateway/platforms/qqbot/adapter.py:2430-2436. This makes the live path fail with unsupported kwargs rather than upload an attachment.- The added mock accepts arbitrary kwargs, so it does not cover that production contract or establish that a native media method was invoked.
Suggested changes
- Follow the current live Matrix pattern in
tools/send_message_tool.py:1725-1760: send text normally, then selectsend_image_file,send_video,send_voice, orsend_documentfor each attachment and propagate failures. - Test against an adapter with the real
send()signature and assert the selected media method is awaited.
Automated hermes-sweeper review.
| result = await adapter.send( | ||
| chat_id=chat_id, | ||
| content=chunk, | ||
| media_files=media_files, |
There was a problem hiding this comment.
BasePlatformAdapter.send() and QQBot's concrete send() do not accept media_files or force_document; this call will fail with unexpected keyword arguments. Dispatch each attachment through send_image_file / send_video / send_voice / send_document after the text send instead.
| SimpleNamespace(extra={}), | ||
| "chat-1", | ||
| "hello", | ||
| media_files=[("/tmp/report.pdf", False)], |
There was a problem hiding this comment.
This mock accepts arbitrary kwargs, so the test cannot detect that real adapters' send() methods reject media_files and force_document. Use a contract-shaped send(chat_id, content, reply_to=None, metadata=None) plus a media method, and assert the media method is awaited.
What does this PR do?
Fixes the live in-process
_send_via_adapter()path so gateway adapters receivemedia_filesandforce_documentjust like the existing standalone sender path. Before this change, attachments could silently disappear whenever the gateway runner and adapter lived in the current process.Related Issue
Fixes #23760
Type of Change
Changes Made
media_filesandforce_documentthrough the liveadapter.send(...)call in/tools/send_message_tool.py/tests/tools/test_send_message_tool.pythat exercises the live in-process adapter path and asserts both kwargs are preservedHow to Test
uv run --frozen pytest -q -o addopts='' tests/tools/test_send_message_tool.py -k TestSendViaAdapterStandaloneFallbacktest_live_adapter_forwards_media_kwargspassesuv run --frozen ruff check tools/send_message_tool.py tests/tools/test_send_message_tool.pyChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
uv run --frozen pytest -q -o addopts='' tests/tools/test_send_message_tool.py -k TestSendViaAdapterStandaloneFallback->6 passeduv run --frozen ruff check tools/send_message_tool.py tests/tools/test_send_message_tool.py-> passed