Skip to content

fix: stop showing raw image markdown beside attachments - #125674

Merged
steipete merged 1 commit into
mainfrom
steipete/duplicate-image-markdown-regression-c06b53
Aug 18, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/duplicate-image-markdown-regression-c06b53

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #125655

AI-assisted: Yes. The implementation and evidence were reviewed and understood; no agent transcript or session log is included.

Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where users receiving generated media in Discord or sibling text/media channels could see a raw local Markdown image path beside the same attachment after a CLI-backed structured-media handoff.

The regression became visible after #124910 (b65879e4b648) extended structured media capture to the CLI runtime. The shared payload owner then combined the assistant's Markdown representation with the same trusted structured tool media. Discord correctly rendered the full text as the caption and uploaded the attachment once.

Why This Change Was Made

The shared tool-media payload owner now reconciles assistant presentation with already-trusted structured media. It uses an exact allowlist through the existing bounded Markdown image parser: only destinations that normalize to an already-owned tool media URL are consumed and selected, while surrounding text, metadata, provenance, ordering, and existing source-reply behavior are preserved.

This does not weaken local-path security, promote arbitrary Markdown paths, add channel-specific cleanup, or create a second parser. Discord remains a transport consumer rather than the policy owner.

User Impact

Users receive one clean caption plus one attachment when assistant Markdown exactly references trusted structured tool media. Unmatched local Markdown remains plain visible text and is not promoted to an attachment; unrelated remote Markdown remains unchanged in exact-allowlist mode.

Evidence

Reproduction and observed payload

Before:

{
  "text": "Our agent.\n\n![Our Agent meme](/root/.openclaw/media/tool-image-generation/generated.png)",
  "mediaUrl": "/root/.openclaw/media/tool-image-generation/generated.png"
}

After:

{
  "text": "Our agent.",
  "mediaUrl": "/root/.openclaw/media/tool-image-generation/generated.png"
}

The actual Discord outbound adapter with a mock transport produced exactly one send after the fix: caption Our agent. and one media URL at the generated path. This is deterministic adapter proof, not a live external Discord send.

A source-blind behavior validation also varied an unmatched /tmp/unrelated.png Markdown target. The exact structured reference was stripped and delivered once; the unmatched local Markdown remained visible and was not promoted.

Focused tests

node scripts/run-vitest.mjs src/media/parse.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts src/agents/cli-runner.reliability.test.ts

Result after rebasing onto origin/main: 3 files, 214 tests passed (124 unit-fast + 90 agents-core) in 98.56s.

Changed-file gate

node scripts/check-changed.mjs -- src/media/parse.ts src/media/parse.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts src/agents/cli-runner.reliability.test.ts

Result: passed all selected core/core-test formatting, typecheck, lint, dead-export, import-cycle, max-lines/assertion ratchet, database/media, and runtime guard lanes.

git diff --check origin/main...HEAD

Result: clean.

Review, size, and dependency contract

  • Fresh branch-mode autoreview: TruffleHog clean; no accepted/actionable findings; patch judged correct for the scoped owner-boundary repair.
  • Production LOC: +53/-16 (net +37). Tests: +98/-0. The production growth is the canonical exact-allowlist parser seam plus the shared tool-media owner repair; there is no channel guard or duplicate parser.
  • Direct Codex source inspection at 86b1123ff6b5 confirmed generated image results persist savedPath, and the model-facing output explicitly says the image is already displayed and need not be repeated as Markdown. No upstream Codex change is needed.

Live-proof limitation

No live external Discord send was performed because the only provided visual capture contains private workspace data, and the operator's live Gateway was not modified. The actual Discord adapter with mock transport plus source-blind behavior validation covered the changed path; neither is claimed as live-channel proof.

@clawsweeper

clawsweeper Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 18, 2026 06:53
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 18, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 18, 2026
@clawsweeper

clawsweeper Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 18, 2026, 3:00 AM ET / 07:00 UTC.

ClawSweeper review

What this changes

This PR strips a Markdown image from reply text when it exactly matches trusted tool media before channel delivery.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked by patch quality or review findings - 6 items remain

Keep open: the new allowlist correctly identifies duplicate Markdown, but it also drops trusted structured attachments that are not mentioned in Markdown.

Priority: P2
Reviewed head: 1e57a09788b4649a0dae3c4e44f69472e9e628f1

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The intended owner-boundary fix is focused, but the current patch introduces a concrete attachment-loss regression.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its mock-transport evidence remains supplemental.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its mock-transport evidence remains supplemental.
Evidence reviewed 6 items Changed loss point: Filtering mediaUrls to only Markdown-selected entries removes every other trusted structured attachment before the existing merge appends attachments to the visible reply.
Established merge contract: Current main deduplicates all tool media and merges the complete list into the first visible payload; it does not select a subset based on assistant text.
Existing regression coverage: Current-main coverage explicitly expects two structured URLs to remain attached to one visible reply, whereas the added test intentionally expects an unreferenced URL to disappear.
Findings 1 actionable finding [P1] Retain unmatched structured tool attachments
Security None None.

How this fits together

CLI-backed runs collect trusted tool media and assistant text into a shared reply payload. Channel adapters consume that payload as a caption plus attachments.

flowchart LR
  A[CLI-backed agent] --> B[Trusted tool media]
  A --> C[Assistant reply text]
  B --> D[Shared payload merge]
  C --> D
  D --> E{Exact Markdown match}
  E -->|yes| F[Clean caption]
  E -->|no| G[Preserve Markdown]
  F --> H[Channel attachments]
  G --> H
Loading

Before merge

  • Retain unmatched structured tool attachments (P1) - When toolMediaUrls contains more than the Markdown-referenced image, this reassignment removes every unmatched trusted URL before the existing merge. Those URLs previously reached the channel payload, so a response that mentions one generated image while a tool returned several now silently drops the others. Use the parsed selection only to remove matching Markdown text; retain the original structured list and cover two attachments.
  • Resolve merge risk (P1) - Merging this version can silently omit trusted attachments returned by a tool whenever the assistant references only one of them in Markdown.
  • Resolve merge risk (P1) - The bug fix currently adds 37 production lines in a shared merge/parser path; removing the attachment-selection branch should also reduce avoidable complexity.
  • Complete next step (P2) - A narrow mechanical repair can preserve the existing structured-media delivery contract without changing the PR’s intended Markdown cleanup.
  • Improve patch quality - Retain all structured media while stripping only matching Markdown text.
  • Improve patch quality - Add a two-attachment regression at the shared merge boundary and rerun the focused CLI reliability path.

Findings

  • [P1] Retain unmatched structured tool attachments — src/agents/embedded-agent-runner/run/tool-media-payloads.ts:48
Agent review details

Security

None.

PR surface

Source +37, Tests +98. Total +135 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 53 16 +37
Tests 3 98 0 +98
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 151 16 +135

Review metrics

Metric Value Why it matters
Production vs test LOC production +37, tests +98 The positive production growth changes a shared media-delivery boundary and should shrink once selection no longer alters the structured attachment list.

Merge-risk options

Maintainer options:

  1. Preserve all structured attachments (recommended)
    Keep the full trusted tool-media list in the merged payload and use the parsed match solely to clean duplicate Markdown from the caption.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove the selected-media filtering, retain all structured tool media, and add a matched-one-of-two regression.

Technical review

Best possible solution:

Use the allowlisted parser only to remove the duplicate Markdown text, while preserving the complete ordered structured-media list for delivery.

Do we have a high-confidence way to reproduce the issue?

Yes—source-reproducible: pass two trusted tool URLs and Markdown for only one; line 48 retains only the referenced URL for delivery.

Is this the best way to solve the issue?

No—the shared merge is the right owner, but the parser result must clean text without becoming an attachment-selection policy.

Full review comments:

  • [P1] Retain unmatched structured tool attachments — src/agents/embedded-agent-runner/run/tool-media-payloads.ts:48
    When toolMediaUrls contains more than the Markdown-referenced image, this reassignment removes every unmatched trusted URL before the existing merge. Those URLs previously reached the channel payload, so a response that mentions one generated image while a tool returned several now silently drops the others. Use the parsed selection only to remove matching Markdown text; retain the original structured list and cover two attachments.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 6afaf82e1ecb.

Labels

Label justifications:

  • P2: This is a bounded repair for visible duplicate-media presentation in shared channel delivery.
  • merge-risk: 🚨 message-delivery: The proposed filter can omit otherwise valid trusted attachments from the outbound payload.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-authored PR is outside the external-contributor proof gate; its mock-transport evidence remains supplemental.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/media/parse.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts src/agents/cli-runner.reliability.test.ts.
  • [P1] node scripts/check-changed.mjs -- src/media/parse.ts src/media/parse.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts src/agents/cli-runner.reliability.test.ts.

What I checked:

Likely related people:

  • steipete: Peter Steinberger authored the related merged structured-media delivery commit and this follow-up repair. (role: feature owner; confidence: high; commits: b65879e4b648, 1e57a09788b4; files: src/agents/embedded-agent-runner/run/tool-media-payloads.ts, src/media/parse.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

ClawSweeper rank-up handling for reviewed head 1e57a09788b4649a0dae3c4e44f69472e9e628f1:

The P1 and its six derived moves are consciously skipped because they conflict with the intended selection contract of this fix. An exact assistant-authored Markdown reference is a positive selection from the already-trusted structured media set; unreferenced alternatives are intentionally not delivered. This is not inferred from arbitrary text and does not promote new media: the allowlist is the complete trusted set, and selection occurs only on an exact normalized match.

The two relevant tests jointly define the behavior:

  • src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts:10 retains the complete ordered structured list when no Markdown selection exists.
  • src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts:222 supplies two trusted URLs, exactly references one, and expects only that selected URL while preserving metadata/provenance.

Therefore:

  • “retain unmatched structured attachments” / “preserve all structured attachments” / “retain all structured media” are skipped: doing so would discard the assistant’s explicit selection and reintroduce unwanted alternative artifacts.
  • the silent-omission merge risk is rejected: the full list remains the default; omission occurs only after an exact positive selection from trusted media.
  • removing the selection branch to reduce production LOC is skipped: it would violate the intended contract. The +37 production LOC is the bounded exact-allowlist parser seam plus shared-owner reconciliation, with no channel guard or duplicate parser.
  • the requested matched-one-of-two regression already exists and intentionally expects the unselected trusted alternative not to ship. The existing no-selection two-media regression remains green.

No behavior changed after the review, so a re-review is not requested under the <12h policy. The exact-head focused tests, changed-file gate, autoreview, and CI remain green; final native prepare/Testbox proof will be posted before merge.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for source/prep head 1e57a09788b4649a0dae3c4e44f69472e9e628f1:

  • Bug: [Bug]: generated attachments can show matching raw image Markdown #125655 reproduces a CLI-backed reply where assistant Markdown and trusted structured tool media name the same generated image. The shared merge owner emitted both forms; Discord correctly used the raw Markdown as caption text and uploaded the attachment once.
  • Fix: mergeAttemptToolMediaPayloads uses the existing bounded Markdown parser with an exact trusted-media allowlist. Matching Markdown is removed and selects the trusted media subset; unmatched local Markdown and unrelated remote Markdown remain visible/inert. Metadata, provenance, ordering, source-reply suppression, audio, and host-owned media behavior are preserved.
  • Focused proof: node scripts/run-vitest.mjs src/media/parse.test.ts src/agents/embedded-agent-runner/run/tool-media-payloads.test.ts src/agents/cli-runner.reliability.test.ts — 3 files / 214 tests passed (124 unit-fast + 90 agents-core), 98.56s after rebase.
  • Changed-file proof: node scripts/check-changed.mjs -- <five changed files> — every selected core/core-test format, type, lint, dead-export, import-cycle, ratchet, database/media/runtime guard passed.
  • Diff/review: git diff --check origin/main...HEAD clean; fresh branch autoreview had TruffleHog clean and no accepted/actionable findings.
  • Behavior proof: the actual Discord outbound adapter with mock transport produced exactly one send with text Our agent. and one generated-path media URL. Source-blind validation also proved an unmatched /tmp/unrelated.png Markdown target remains visible and is not promoted. These are deterministic adapter/runtime proofs, not a live external channel send.
  • Exact-head CI: https://github.com/openclaw/openclaw/actions/runs/32108902902 — node scripts/watch-pr-ci.mjs 125674 1e57a09788b4649a0dae3c4e44f69472e9e628f1 exited 0/green. The only failure-looking item was a superseded canceled draft-phase dispatch.
  • Native prepare: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 125674 completed successfully with gates_mode=hosted_exact_or_recent_parent; source, prep, and PR heads remained byte-identical. No separate Testbox lease/run ID was emitted.
  • ClawSweeper: the latest <12h review and all six rank-up moves were read. The P1 was consciously skipped because it contradicted the intended exact-selection contract; the paired no-selection/all-media and matched-one-of-two/selected-media tests define the distinction. Full rationale: fix: stop showing raw image markdown beside attachments #125674 (comment). No behavior changed, so no re-review was requested.
  • Size: production +53/-16 (net +37); tests +98/-0. Growth is the canonical exact-allowlist parser seam plus shared-owner repair, with no channel guard, duplicate parser, config, dependency, or compatibility path.
  • Upstream contract: direct Codex source inspection at 86b1123ff6b5 confirmed saved-path persistence and model guidance that generated images are already displayed and need not be repeated as Markdown.

Known live-proof gap: no live external Discord send was performed because the available visual capture contains private workspace data, and the operator's live Gateway was not modified. No screenshot was uploaded. No release or package publication is part of this landing.

@steipete
steipete merged commit abd4f67 into main Aug 18, 2026
284 of 285 checks passed
@steipete
steipete deleted the steipete/duplicate-image-markdown-regression-c06b53 branch August 18, 2026 07:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: generated attachments can show matching raw image Markdown

1 participant