Skip to content

Fix NameError in _handle_message_with_agent on already-sent media delivery - #72317

Closed
jorgeblanc9 wants to merge 1 commit into
NousResearch:mainfrom
jorgeblanc9:fix/telegram-history-media-paths-namerror
Closed

jorgeblanc9 wants to merge 1 commit into
NousResearch:mainfrom
jorgeblanc9:fix/telegram-history-media-paths-namerror

Conversation

@jorgeblanc9

Copy link
Copy Markdown

Summary

  • _history_media_paths was only defined inside the unrelated run_sync() closure (~line 21981), not in _handle_message_with_agent, so any already-streamed response that also needed to deliver media raised a NameError at the _deliver_media_from_response(...) call.
  • This surfaced on essentially every Telegram message as a second "Sorry, I encountered an unexpected error." reply following the normal streamed response.
  • Fix computes the same set from history, the pre-turn transcript already loaded earlier in _handle_message_with_agent, mirroring how run_sync derives agent_history for the same dedup purpose (so already-delivered media isn't double-counted, and media generated in the current turn is still delivered).

Traceback fixed

File "gateway/run.py", line 14561, in _handle_message_with_agent
    history_media_paths=_history_media_paths,
NameError: name '_history_media_paths' is not defined

Test plan

  • Reproduced live on a Telegram adapter instance: every message triggered the streamed reply followed by the generic error.
  • Applied fix, restarted the gateway process, confirmed the traceback no longer appears in gateway.log on subsequent messages.
  • Would appreciate a maintainer's eyes on whether history (vs. some other pre-turn history source) is the right dedup input in all call paths that reach this branch.

🤖 Generated with Claude Code

…already-sent responses

_history_media_paths was only defined inside the unrelated run_sync()
closure (line ~21981), not in _handle_message_with_agent, so any
already-streamed response that also needed to deliver media raised:

  File "gateway/run.py", line 14561, in _handle_message_with_agent
      history_media_paths=_history_media_paths,
  NameError: name '_history_media_paths' is not defined

This surfaced on every message to users on the Telegram adapter as a
second "Sorry, I encountered an unexpected error." reply following the
normal streamed response.

Fix computes the same set from `history`, the pre-turn transcript
already loaded earlier in this function (used identically to
run_sync's `agent_history` for the same dedup purpose).

Co-Authored-By: Claude Sonnet 5 <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 sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages duplicate This issue or pull request already exists labels Jul 27, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Duplicate of #72321: both replace the undefined _history_media_paths in the same post-stream delivery call with history-derived paths. #72321 also adds focused coverage that preserves prior-turn MEDIA deduplication.

@teknium1

Copy link
Copy Markdown
Collaborator

Fixed on main via PR #72341 (salvaged from #72321 by @TheEpTic, merge commit c2ee503). Your fix was character-for-character identical — same _collect_history_media_paths(history) approach — but #72321 arrived with a regression test covering the already_sent branch, so we salvaged that one. Earliest report credit goes to @Ieqzya in #72228. Thanks for the correct fix — closing as a duplicate.

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 duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants