← Back to PRs

#14794: fix: parse inline MEDIA: tokens in agent replies

by explainanalyze open 2026-02-12 16:58 View on GitHub →
stale size: S
## Problem Fixes #13790 When an agent reply contains an inline `MEDIA:` tag (e.g. `Here is your audio: MEDIA:/tmp/voice.opus`), it was not detected and delivered as an attachment on Telegram. The literal text path was sent instead. ## Root Cause `splitMediaFromOutput` in `src/media/parse.ts` had an early-return guard that skipped any line where `MEDIA:` didn't appear at the start of the line (after trimming). This meant inline `MEDIA:` tokens were never matched by the regex. ## Fix Removed the `trimmedStart.startsWith("MEDIA:")` guard so the `MEDIA_TOKEN_RE` regex runs on every line, catching both line-start and inline tokens. ## Tests - Added regression test in `src/media/reproduce_issue.test.ts` covering inline MEDIA tokens - Test fails on `main` (confirms it catches the bug), passes with the fix - All 59 existing media tests continue to pass <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Changes update `splitMediaFromOutput` to scan every line for `MEDIA:` tokens (not just lines that start with `MEDIA:`), enabling inline tokens like `Here is your audio: MEDIA:/tmp/voice.opus` to be extracted into `mediaUrls` and removed from the rendered text. A small guard was also added to avoid the "path with spaces" fallback when the token is inline (to reduce accidental capture of trailing prose). A new regression test file exercises inline tokens, spacing after the colon, quoted paths with spaces, and confirms fenced code blocks are not parsed for media tokens. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge and appears to fix the reported Telegram attachment parsing issue. - The change is localized to media token parsing, includes targeted regression tests (including inline-token coverage), and existing behavior around fenced code blocks and audio tags remains intact based on code review. The only notable risk area is the semantics of extracting inline `MEDIA:` sequences in prose, but that concern is already tracked in prior review threads for this PR. - src/media/parse.ts (token syntax/edge-case semantics) <sub>Last reviewed commit: 2a9824d</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs