Skip to content

fix(gateway): handle quoted MEDIA paths consistently across streaming and final deliveryy#12179

Open
Ruzzgar wants to merge 1 commit into
NousResearch:mainfrom
Ruzzgar:fix/gateway-quoted-media-paths
Open

fix(gateway): handle quoted MEDIA paths consistently across streaming and final deliveryy#12179
Ruzzgar wants to merge 1 commit into
NousResearch:mainfrom
Ruzzgar:fix/gateway-quoted-media-paths

Conversation

@Ruzzgar

@Ruzzgar Ruzzgar commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes a gateway parsing mismatch for MEDIA: directives when the file path is quoted or contains spaces.

The adapter-side media parser already supported outputs like:

  • MEDIA: '/tmp/my image.png'
  • MEDIA: "/tmp/my image.png"
  • MEDIA: `/tmp/my image.png`

But gateway-side handling still used simpler MEDIA:(\S+) / MEDIA:\s*\S+ patterns in a few places. That caused inconsistent behavior across delivery paths:

  • gateway/run.py could truncate the path at the first space during history/media dedupe
  • gateway/stream_consumer.py could leave trailing path fragments visible in streamed text
  • end-of-stream fallback could miss the unsent tail if the final edit was still rate-limited

What changed

  • Added a shared MEDIA: path parser helper in gateway/platforms/base.py
  • Reused that parser in gateway/run.py for history scanning and final-response media extraction
  • Reused the same parser in gateway/stream_consumer.py so quoted/spaced MEDIA: directives are stripped consistently from visible streamed text
  • Hardened the end-of-stream fallback path so that if the final streaming edit still fails due to flood control/backoff, the missing tail is sent once instead of being dropped

Why this is a bug

BasePlatformAdapter.extract_media() already treated quoted/spaced MEDIA: paths as valid. The gateway had drifted from that behavior, so the same tool output could work in one path and break in another. This patch brings the gateway paths back into alignment with the existing adapter contract.

Regression coverage

Added tests for:

  • stripping quoted/spaced MEDIA: directives from streamed visible text
  • parsing quoted/spaced MEDIA: paths as a single path in gateway media extraction logic

Test plan

Using the repo's Windows virtualenv at .venv:

  • tests/gateway/test_platform_base.py
  • tests/gateway/test_stream_consumer.py
  • tests/gateway/test_media_extraction.py

Result:

  • 145 passed, 4 warnings in 1.63s

Also ran related gateway media tests:

  • tests/gateway/test_send_image_file.py
  • tests/gateway/test_signal.py

Result:

  • 85 passed, 4 warnings in 1.42s

@Ruzzgar Ruzzgar force-pushed the fix/gateway-quoted-media-paths branch from e877d2b to 382d899 Compare April 18, 2026 14:45
@Ruzzgar Ruzzgar changed the title fix(gateway): handle quoted MEDIA paths consistently across streaming and final delivery fix(gateway): handle quoted MEDIA paths consistently across streaming and final deliveryy Apr 18, 2026
@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 Apr 23, 2026
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 type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants