fix(gateway): cross-turn media dedupe, spaced/GIS MEDIA paths, code-block-safe display strip - #72193
Merged
Conversation
…/tool output The model sometimes echoes a previous MEDIA:path tag or bare file path in a later response. Previously both streaming delivery and non-streaming delivery would re-send those files, causing duplicate documents/images on later turns. Changes: - _collect_history_media_paths now also scans assistant messages for MEDIA: tags, not just tool results. - _deliver_media_from_response accepts pre-computed history_media_paths and filters extracted media/local files. - BasePlatformAdapter gains _history_media_paths_for_session for non-streaming dedup.
… display strip Follow-up wave to #72170 resolving the remaining open MEDIA-delivery gaps: - #24032: add .kmz/.kml/.geojson/.gpx to MEDIA_DELIVERY_EXTS, and recover unknown-extension paths containing spaces via _match_extensionless_path — validation-gated forward extension across single spaces (bounded at 8 tokens, stops at newline / next MEDIA: keyword). The regex itself stays non-greedy and whitespace-bounded so the #68773 absorption bug class cannot return; the on-disk file check is the oracle. - #16434 (streaming half): _strip_media_tag_directives now uses the same mask-as-locator pattern as extract_media, so MEDIA tags inside fenced code blocks, inline-code examples, and JSON string values survive in streamed display text instead of being mangled. Display and delivery now agree on every protected-span rule. - Updated three stream_consumer display expectations that pinned the old inconsistent behavior (backtick/double-quote tags stripped from display while delivery never attempted them).
Collaborator
Contributor
૮ >ﻌ< ა ci reviewran on 165b076 ℹ️ InfoDesktop E2E visual evidence · View test artifacts · View job1 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) |
This was referenced Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the three MEDIA-delivery gaps left open after PR #72170: cross-turn duplicate re-delivery, GIS/spaced-path extraction, and streaming display mangling MEDIA examples inside code blocks.
Changes
Salvaged (cherry-picked, authorship preserved):
gateway/run.py+gateway/platforms/base.py: cross-turn media dedupe —_collect_history_media_pathsnow also scans assistant messages, and both the non-streaming and post-stream delivery paths filter extracted files against history, so a model echoing last turn'sMEDIA:tag no longer re-uploads the same file (fix(gateway): deduplicate repeated media tags against prior assistant/tool output #53586, @dhruvkej9). Salvage adjustments: rebased around the bug(gateway): post-stream media delivery can upload bare local paths not intentionally present in the visible reply #20834 explicit-only post-stream rule (dropped the PR'sextract_local_filesre-introduction on that path), fixed the adapter-side helper to map gatewaysession_key→ transcriptsession_idviapeek_session_id, and repaired the commit's broken author identity (ubuntu@ip-...internal→ the contributor's GitHub noreply).Our fixes:
gateway/platforms/base.py:.kmz/.kml/.geojson/.gpxadded toMEDIA_DELIVERY_EXTS, and unknown-extension paths containing spaces (MEDIA:/data/map data.kmz,C:\...\My Documents\x.log) now deliver via_match_extensionless_path— validation-gated forward extension across single spaces, bounded at 8 tokens, stopping at newline / the nextMEDIA:keyword. The regex stays non-greedy so the Agent fails to append separators after MEDIA tags, URLs, and file paths, causing cascading delivery and truncation failures #68773 absorption bug class cannot return; the file-exists check is the oracle ([BUG] extract_media regex truncates Windows spaced paths and rejects GIS extensions (.kmz/.kml/.geojson/.gpx) #24032).gateway/platforms/base.py:_strip_media_tag_directives(streaming display path) now uses the same mask-as-locator pattern asextract_media, so MEDIA tags inside fenced code blocks / inline-code examples / JSON string values survive in streamed display text (Gateway should not treat MEDIA examples or missing files as attachments #16434 streaming half). Display and delivery now agree on every protected-span rule.stream_consumerdisplay tests that pinned the old inconsistent behavior (tags stripped from display that delivery never attempted).Validation
MEDIA:/data/map data.kmz(spaced, GIS)MEDIA:/x/my server.log(spaced, unknown ext)MEDIA:example in fenced code block (streaming)MEDIA:/aMEDIA:/bextensionless pairInfographic