Skip to content

fix(gateway): resolve adapter before _deliver_media_from_response - #2432

Closed
MacroAnarchy wants to merge 1 commit into
NousResearch:mainfrom
MacroAnarchy:fix/unbound-adapter-streaming-media
Closed

fix(gateway): resolve adapter before _deliver_media_from_response#2432
MacroAnarchy wants to merge 1 commit into
NousResearch:mainfrom
MacroAnarchy:fix/unbound-adapter-streaming-media

Conversation

@MacroAnarchy

Copy link
Copy Markdown
Contributor

Bug

When streaming is enabled (already_sent=True), _handle_message_with_agent calls _deliver_media_from_response(response, event, adapter) at line 2321 — but adapter is only assigned conditionally earlier in the method (first-message home-channel hint or Discord voice context).

On the normal Telegram/Slack/etc streaming path, adapter is never bound, causing:

UnboundLocalError: cannot access local variable 'adapter' where it is not associated with a value

This crashes every streamed response that contains media files.

Fix

Resolve adapter from self.adapters.get(source.platform) immediately before the call, with a None guard so media delivery degrades gracefully instead of crashing the entire message handler.

Testing

Verified on a live Telegram gateway — streamed responses now complete without errors.

The 'adapter' variable in _handle_message_with_agent is only assigned
conditionally (first-message home-channel hint or Discord voice context),
so it is unbound on the normal streaming path when already_sent is True.

This causes an UnboundLocalError on every streamed response:

    UnboundLocalError: cannot access local variable 'adapter'
    where it is not associated with a value

Resolve the adapter from self.adapters just before the call and guard
against None so media delivery degrades gracefully instead of crashing
the entire message handler.
@42-evey

42-evey commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Duplicate of #2424

@MacroAnarchy

Copy link
Copy Markdown
Contributor Author

Didn't see #2424 — same fix. Closing as duplicate. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants