Summary
The background-task delivery path treats extract_media() results as plain file paths, but extract_media() returns (path, is_voice) tuples. This causes _run_background_task() to pass tuples into send_document() instead of strings.
Affected code
- Producer:
gateway/platforms/base.py:1198-1237
- Consumer:
gateway/run.py:5441-5478
- Existing extraction tests:
tests/gateway/test_platform_base.py:258-323
- Existing
_run_background_task() coverage does not exercise media output: tests/gateway/test_session_model_override_routing.py:138-153
Why this is a bug
extract_media() explicitly returns:
Tuple[List[Tuple[str, bool]], str]
For example:
BasePlatformAdapter.extract_media('[[audio_as_voice]]\nMEDIA:/tmp/audio.ogg')
# -> ([('/tmp/audio.ogg', True)], '')
But _run_background_task() does:
media_files, response = adapter.extract_media(response)
...
for media_path in (media_files or []):
await adapter.send_document(chat_id=source.chat_id, file_path=media_path)
Each loop item is a tuple, not a path string.
Minimal reproduction / evidence
Observed directly on main:
media, cleaned = BasePlatformAdapter.extract_media('[[audio_as_voice]]\nMEDIA:/tmp/audio.ogg')
print(media)
# [('/tmp/audio.ogg', True)]
That tuple shape is then forwarded unmodified by the background-task loop.
Expected behavior
Background-task media delivery should either:
- unpack
(path, is_voice) and route voice/document appropriately, or
- use a helper that already understands the tuple format.
Actual behavior
send_document() receives a tuple like ('/tmp/audio.ogg', True) as file_path.
Suggested investigation
Unpack the tuple in _run_background_task() and preserve the is_voice flag instead of treating media_files as List[str]. A regression test that exercises a background-task response containing [[audio_as_voice]] + MEDIA: would lock this down.
Summary
The background-task delivery path treats
extract_media()results as plain file paths, butextract_media()returns(path, is_voice)tuples. This causes_run_background_task()to pass tuples intosend_document()instead of strings.Affected code
gateway/platforms/base.py:1198-1237gateway/run.py:5441-5478tests/gateway/test_platform_base.py:258-323_run_background_task()coverage does not exercise media output:tests/gateway/test_session_model_override_routing.py:138-153Why this is a bug
extract_media()explicitly returns:For example:
But
_run_background_task()does:Each loop item is a tuple, not a path string.
Minimal reproduction / evidence
Observed directly on
main:That tuple shape is then forwarded unmodified by the background-task loop.
Expected behavior
Background-task media delivery should either:
(path, is_voice)and route voice/document appropriately, orActual behavior
send_document()receives a tuple like('/tmp/audio.ogg', True)asfile_path.Suggested investigation
Unpack the tuple in
_run_background_task()and preserve theis_voiceflag instead of treatingmedia_filesasList[str]. A regression test that exercises a background-task response containing[[audio_as_voice]]+MEDIA:would lock this down.