Skip to content

fix(gateway): terminate MEDIA: path at literal escape sequences - #41609

Closed
deacon-botdoctor wants to merge 1 commit into
NousResearch:mainfrom
Bot-Doctor-LLC:botdoctor/media-path-escape-upstream
Closed

fix(gateway): terminate MEDIA: path at literal escape sequences#41609
deacon-botdoctor wants to merge 1 commit into
NousResearch:mainfrom
Bot-Doctor-LLC:botdoctor/media-path-escape-upstream

Conversation

@deacon-botdoctor

Copy link
Copy Markdown
Contributor

Summary

Small models sometimes emit two-char escape sequences — a literal \n / \r\n (backslash + letter, not a real newline) — right after a MEDIA: path, e.g. MEDIA:/tmp/audio.mp3\n\nAnd more.

MEDIA_TAG_CLEANUP_RE's terminating lookahead did not treat a backslash as a path boundary, so the greedy \S+ swallowed the escape text, the extension lookahead failed, and the whole tag silently failed to match — the audio was dropped with no error.

  • add a literal backslash to the terminating lookahead character class so the path ends at its real extension
  • Windows backslash paths are unaffected: they terminate at the extension where the lookahead is already satisfied by end-of-string/whitespace (existing Windows-path tests stay green)

Validation

  • python3 -m py_compile gateway/platforms/base.py tests/gateway/test_platform_base.py
  • .venv/bin/python -m pytest tests/gateway/test_platform_base.py (150 passed, 2 skipped)
  • git diff --check

Scope check

  • rebuilt from fresh NousResearch/hermes-agent main
  • scanned staged diff for obvious secrets/private identifiers and downstream overlay markers

@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 Jun 8, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

Reviewed the regex change and test coverage — this looks solid.

Regex analysis: Adding \\ to the termination lookahead (?=[\s"',;:)]}\]|$) correctly handles models that emit literal escape sequences (\n, \r\n) after MEDIA: paths. The greedy \S+ followed by the extension backtracking ensures Windows backslash paths (C:\Users\file.mp3`) are still matched correctly — the extension is found before any trailing literal escape, so the lookahead fires on end-of-string or whitespace as before.

Test coverage: Both \n and \r\n literal sequences are covered. The file.pdf Windows test case continues to pass (existing test_media_tag_windows_backslash_path).

No issues found.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the focused regression fix. Current main still has the reported failure: gateway/platforms/base.py:1491-1496 does not treat a literal backslash as a valid terminator after a deliverable extension, while \S+ consumes the literal escape sequence. The proposed one-character lookahead expansion fixes that shared matcher, which is used by extraction (gateway/platforms/base.py:3645), streaming display cleanup (gateway/stream_consumer.py:892-911), and API media replacement (gateway/platforms/api_server.py:590-636). The added \n and \r\n regression cases are appropriate, and the existing Windows backslash-path coverage remains relevant.

Automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@deacon-botdoctor

Copy link
Copy Markdown
Contributor Author

Closing as part of open-PR prune.

Why: CONFLICTING MEDIA escape termination; cold companion to #41643; close with the media pair rather than leave half-dead.

If the need resurfaces on current main, open a fresh tip-based PR with current contracts covered — do not revive this stale conflicting head.

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:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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