openclaw - ✅(Solved) Fix [Bug]: MEDIA directive parser can include trailing serialized JSON in local file path [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#75182Fetched 2026-05-01 05:37:15
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
2
Author
Timeline (top)
cross-referenced ×2commented ×1

A MEDIA directive containing a local image path followed by serialized tool-result JSON can be parsed as one polluted file path, causing outbound media delivery to fail with ENOENT.

Error Message

Observed failed path shape:

/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}

Observed error:

ENOENT: no such file or directory, open '/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}'

The same image delivered successfully when resent as:

MEDIA:/path/to/image.png

A local defensive patch that trims known media extensions before trailing serialized JSON also made this polluted test directive deliver successfully:

MEDIA:/path/to/image.png"}],"details":{"test":"polluted-media-path"}

Root Cause

Severity: Medium to high for image/file delivery workflows, because generated images may fail to send even though the file exists.

Fix Action

Fix / Workaround

A local defensive patch that trims known media extensions before trailing serialized JSON also made this polluted test directive deliver successfully:

Temporary workaround: send the media path as a clean standalone directive, for example MEDIA:/path/to/image.png, without any adjacent metadata or serialized tool result text.

PR fix notes

PR #75202: fix(media): strip trailing serialized JSON from MEDIA directive local paths

Description (problem / solution / changelog)

Summary

When image generation appends tool-result JSON on the same line as a MEDIA: directive (e.g. MEDIA:/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2"}), MEDIA_TOKEN_RE absorbs the full line and cleanCandidate's trailing-char strip does not remove the embedded JSON noise, producing an ENOENT-causing polluted path.

Root cause: cleanCandidate strips outer punctuation chars from start/end, but " appears inside the path after the extension — cleanCandidate never reaches it.

Fix: Add TRAILING_JSON_AFTER_EXT_RE as a second pass in cleanCandidate: after the standard strip, if a file extension is followed by any JSON boundary character ("'{}[]|,), truncate at the extension boundary.

Test: Added regression case in the accepted-path table:

MEDIA:/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2"}
→ /path/to/image.png  ✓

53/53 tests pass.

Fixes #75182.

Changed files

  • src/media/parse.test.ts (modified, +7/-0)
  • src/media/parse.ts (modified, +8/-1)

PR #68338: Parse multiline MEDIA directives

Description (problem / solution / changelog)

Summary

  • Parse empty MEDIA: directives whose media path appears on the following line.
  • Preserve ordered text/media segments when consuming the continuation path.
  • Keep the change scoped to media output parsing only; no delivery, routeReply, prompt, config, or secret changes.

Tests

  • PATH=/opt/node-v22.22.0/bin:$PATH corepack pnpm exec vitest run --config vitest.config.ts src/media/parse.test.ts --reporter=dot --silent=passed-only
  • PATH=/opt/node-v22.22.0/bin:$PATH node scripts/run-tsgo.mjs
  • PATH=/opt/node-v22.22.0/bin:$PATH node scripts/run-oxlint.mjs
  • PATH=/opt/node-v22.22.0/bin:$PATH corepack pnpm format:check src/media/parse.ts src/media/parse.test.ts
  • git diff --check
  • PATH=/opt/node-v22.22.0/bin:$PATH corepack pnpm check:no-conflict-markers

Changed files

  • src/media/parse.test.ts (modified, +25/-0)
  • src/media/parse.ts (modified, +40/-2)

Code Example

Observed failed path shape:

/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}

Observed error:

ENOENT: no such file or directory, open '/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}'

The same image delivered successfully when resent as:

MEDIA:/path/to/image.png

A local defensive patch that trims known media extensions before trailing serialized JSON also made this polluted test directive deliver successfully:

MEDIA:/path/to/image.png"}],"details":{"test":"polluted-media-path"}
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

A MEDIA directive containing a local image path followed by serialized tool-result JSON can be parsed as one polluted file path, causing outbound media delivery to fail with ENOENT.

Steps to reproduce

  1. Generate or otherwise produce a local image file path, for example /path/to/image.png.
  2. Send an assistant reply containing a MEDIA directive where serialized metadata is appended after the image path, for example: MEDIA:/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2"}
  3. Deliver the reply through a channel that opens/uploads local MEDIA paths.
  4. Observe that the channel attempts to open the polluted path including the trailing JSON.

Expected behavior

The MEDIA parser should extract only the valid media source /path/to/image.png, or reject/sanitize the malformed token before passing it to channel delivery.

Actual behavior

The parsed media path can include trailing serialized JSON such as "}],"details":{...}. The channel then attempts to open that polluted path and fails with ENOENT.

OpenClaw version

2026.4.26

Operating system

Ubuntu 24.04 / Linux 6.17.0-22-generic x64

Install method

npm global / systemd user service

Model

openai-codex/gpt-5.5 with image generation via openai/gpt-image-2

Provider / routing chain

OpenClaw assistant reply -> MEDIA directive parsing -> channel outbound media delivery.

Observed with the openclaw-weixin channel, but the parsing issue appears to be in the shared MEDIA directive handling before channel delivery.

Additional provider/model setup details

The issue was observed after image generation returned a local image path plus structured metadata. The generated image file existed and could be delivered successfully when resent as a clean single-line MEDIA directive.

Logs, screenshots, and evidence

Observed failed path shape:

/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}

Observed error:

ENOENT: no such file or directory, open '/path/to/image.png"}],"details":{"provider":"openai","model":"gpt-image-2",...}'

The same image delivered successfully when resent as:

MEDIA:/path/to/image.png

A local defensive patch that trims known media extensions before trailing serialized JSON also made this polluted test directive deliver successfully:

MEDIA:/path/to/image.png"}],"details":{"test":"polluted-media-path"}

Impact and severity

Affected: Channels that support local MEDIA path delivery, observed with openclaw-weixin.

Severity: Medium to high for image/file delivery workflows, because generated images may fail to send even though the file exists.

Frequency: Reproduced with polluted MEDIA paths; clean MEDIA paths work.

Consequence: Users see failed media delivery and must ask the assistant to resend the same file using a clean path.

Additional information

Temporary workaround: send the media path as a clean standalone directive, for example MEDIA:/path/to/image.png, without any adjacent metadata or serialized tool result text.

Suggested fix:

  • Harden the shared MEDIA directive parser so a local path ending in a known media extension is not allowed to absorb trailing serialized JSON.
  • Add boundary validation in channel outbound media adapters before file I/O: sanitize or reject polluted media paths, and log both the raw and sanitized media source.

extent analysis

TL;DR

The most likely fix is to modify the MEDIA directive parser to extract only the valid media source by trimming known media extensions before trailing serialized JSON.

Guidance

  • Verify that the issue is caused by the polluted media path by checking the error message for ENOENT and the attempted file path.
  • Implement a temporary workaround by sending the media path as a clean standalone directive, without any adjacent metadata or serialized tool result text.
  • To permanently fix the issue, harden the shared MEDIA directive parser to prevent local paths from absorbing trailing serialized JSON.
  • Add boundary validation in channel outbound media adapters to sanitize or reject polluted media paths and log both the raw and sanitized media source.

Example

No code snippet is provided as the issue does not specify the programming language or the exact code responsible for parsing the MEDIA directive.

Notes

The suggested fix may require modifications to the OpenClaw codebase, specifically the MEDIA directive parser and channel outbound media adapters. The exact implementation details will depend on the programming language and framework used.

Recommendation

Apply the workaround of sending the media path as a clean standalone directive until a permanent fix can be implemented, as this will allow for successful media delivery while the issue is being addressed.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

The MEDIA parser should extract only the valid media source /path/to/image.png, or reject/sanitize the malformed token before passing it to channel delivery.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: MEDIA directive parser can include trailing serialized JSON in local file path [2 pull requests, 1 comments, 2 participants]