Skip to content

fix(gateway): unpack extract_media tuples in background task delivery#12091

Closed
truenorth-lj wants to merge 2 commits into
NousResearch:mainfrom
truenorth-lj:fix/bg-task-media-tuple-unpack
Closed

fix(gateway): unpack extract_media tuples in background task delivery#12091
truenorth-lj wants to merge 2 commits into
NousResearch:mainfrom
truenorth-lj:fix/bg-task-media-tuple-unpack

Conversation

@truenorth-lj

Copy link
Copy Markdown
Contributor

Summary

  • Fix _run_background_task and /btw handler to properly unpack (path, is_voice) tuples from extract_media() and route media files by extension (audio → send_voice, video → send_video, image → send_image_file, other → send_document)
  • Previously both handlers passed raw tuples into send_document/send_file, ignoring file type entirely
  • Aligns background task delivery with the correct routing already used in base.py._process_message_background and _deliver_streaming_media

Changes

  • gateway/run.py_run_background_task: replace flat send_document loop with extension-based routing matching base.py:1855-1888
  • gateway/run.py/btw handler: replace send_file (non-existent method) call with same extension-based routing
  • tests/gateway/test_background_command.py — add regression test verifying all four media types are routed to the correct send method

Test plan

  • New test test_media_files_routed_by_type passes — verifies .oggsend_voice, .mp4send_video, .pngsend_image_file, .pdfsend_document
  • All 20 existing test_background_command.py tests pass
  • Manual: trigger /background with a TTS prompt → voice message should arrive as voice bubble, not document

Closes #12064

🤖 Generated with Claude Code

truenorth-lj and others added 2 commits April 18, 2026 17:39
After the first compression, reduce head protection from protect_first_n
to 1 (system message only). Previously, the first N messages were
preserved verbatim across every compression cycle, causing "fossilized"
messages that survived indefinitely even after being summarized.

The system message (index 0) is always preserved. User/assistant messages
in positions 1..protect_first_n are only protected during the first
compression — subsequent compressions include them in the summarization
window since their content is already captured in the summary.

Closes NousResearch#11996

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
_run_background_task and the /btw handler were passing extract_media
tuples directly to send_document/send_file instead of routing by file
type. Now both consumers unpack (path, is_voice) and dispatch to the
correct send method (send_voice, send_video, send_image_file, or
send_document) based on file extension, matching the behavior in
base.py and _deliver_streaming_media.

Closes NousResearch#12064

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Apr 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing PRs: #12368 and #12172 address the same #12064 bug. All three fix background task media routing.

@teknium1

teknium1 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Merged via #37613 (commit 082025a on main).

Since this branch was filed, the tuple-unpacking bug and the send_file call you both fixed were resolved independently on main — the surviving gap was the type-routing in _run_background_task, which still forced everything through send_document. That's now reimplemented on current main (the branch here was too stale to cherry-pick cleanly), routing audio → voice bubble, video → send_video, image → send_image_file. Your authorship is preserved via a Co-authored-by trailer on the merge commit. Thanks!

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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Background task media delivery passes extract_media tuples into send_document()

3 participants