Skip to content

fix(gateway): preserve media dedup after streamed replies (salvage #72321) - #72341

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-847fef33
Jul 27, 2026
Merged

teknium1 merged 1 commit into
mainfrom
hermes/hermes-847fef33

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Summary

Salvages PR #72321 by @TheEpTic: every streamed gateway reply crashed with NameError: name '_history_media_paths' is not defined after the model request already succeeded — the post-stream MEDIA-delivery branch in _handle_message_with_agent referenced a local that only exists inside _run_agent_inner (introduced in 83bba79). Users got the generic platform error on ordinary text replies as well as MEDIA-bearing ones.

Root cause: cross-function scope leak — the dedup set was bound in a different function's scope than the call site reading it (AST-verified: zero direct-scope assignments of _history_media_paths in _handle_message_with_agent).

Changes

  • gateway/run.py: derive the dedup set from the handler's own loaded transcript via _collect_history_media_paths(history) — same semantics as the original dedup contract, no empty-set fallback.
  • tests/gateway/test_42039_duplicate_user_message.py: regression test exercising the real already_sent branch, asserting prior-turn MEDIA paths reach _deliver_media_from_response.

Validation

Before (main) After
Streamed reply, already_sent=True NameError, generic platform error delivered normally
Regression test (sabotage run against main's line) FAILED with the exact NameError passes
scripts/run_tests.sh tests/gateway/test_42039_duplicate_user_message.py 4 passed / 1 failed 5 passed

Two independent production confirmations on the original PR thread (Fedora + macOS Telegram gateways) verified both the crash on current main and this fix.

Duplicate cluster: #72228 (@Ieqzya, earliest report — empty-set fallback drops dedup + unrelated desktop files), #72317 (@jorgeblanc9, same one-liner, no test), #72326 (@kylesteele-sudo, valid alternative placement + test). This salvage uses #72321's implementation; @TheEpTic's authorship preserved via cherry-pick.

Infographic

fix(gateway): preserve media dedup after streamed replies

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 2b17db0

ℹ️ Info

Desktop E2E visual evidence · View test artifacts · View job

1 visual diff.

inline evidence upload failed.

Failed to upload diff-665a0833239e-onboarding-overlay-diff.png with gh image (exit code 1): Error uploading /home/runner/work/_temp/e2e-evidence/diff-665a0833239e-onboarding-overlay-diff.png: step 0 (get upload token): uploadToken not found on repo page — do you have write access to NousResearch/hermes-agent? (or, if NousResearch enforces SAML SSO, authorize at https://github.com/orgs/NousResearch/sso)

@kandotrun

Copy link
Copy Markdown
Contributor

Reproduced this regression on a live Slack gateway: the streamed text was delivered, then _handle_message_with_agent raised NameError: name '_history_media_paths' is not defined while dispatching a MEDIA: attachment, producing the generic unexpected-error follow-up.

I independently verified this patch with a RED/GREEN full-handler regression that included both an echoed prior-turn MEDIA: tag and a newly generated image:

  • before the patch: the handler returned the generic unexpected-error response and delivered no attachment;
  • after the patch: the handler completed normally, filtered the prior attachment, and delivered only the new image.

Local verification: 203 related gateway/media tests passed; blocking ruff, git diff --check, and bytecode compilation passed. Recomputing from the pre-turn history here preserves the intended cross-turn deduplication and fixes the out-of-scope reference.

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 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.

4 participants