Skip to content

Background task media delivery passes extract_media tuples into send_document() #12064

@NewTurn2017

Description

@NewTurn2017

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions