Skip to content

fix(media): preserve correct filenames for transparent image attachments - #128902

Merged
steipete merged 1 commit into
mainfrom
codex/qa-transparent-image-output-filename-20260824
Aug 25, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-transparent-image-output-filename-20260824

Conversation

@steipete

Copy link
Copy Markdown
Contributor
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 sending transparent WebP images would receive attachments with a misleading .webp filename after OpenClaw resized and converted the actual image bytes to PNG. The incorrect filename reached both Telegram multipart uploads and Discord attachments.

Why This Change Was Made

The shared image loader now derives attachment extensions from the actual encoded image MIME type across both direct-buffer and file-loading paths. It generalizes the existing private JPEG filename helper without changing image admission, security policy, public types, configuration, or production line count.

User Impact

Transparent WebP images converted to PNG arrive as correctly named .png attachments. Existing JPEG .jpg naming, original mixed-case PNG filenames, unchanged WebP images, nameless attachments, GIF passthrough, and SVG rejection are preserved.

Evidence

  • Added a regression using genuine transparent WebP bytes produced by the existing Rastermill image processor. It first failed with expected "portrait.png", received "portrait.WebP", then passed across both image-loading paths.
  • Ran the exact committed owner, Rastermill adapter, and canonical MIME suites: 285 tests passed. Independent review ran four owner/sibling suites: 289 tests passed.
  • Exercised real transparent WebP-to-PNG conversion through actual Telegram InputFile and Discord multipart attachment construction, verifying PNG bytes, preserved alpha, dimensions, and the .png filename.
  • Verified opaque JPEG conversion, uppercase PNG preservation, unchanged WebP, missing filenames, GIF passthrough, SVG rejection, typed lint, formatting, assertion safety, and the maximum-lines ratchet.
  • Production change is size-neutral: 7 lines added, 7 removed.
  • Local full core and owner-test typechecks encounter existing stale shared-install Google, markdown-it, and TUI dependency diagnostics; neither changed file produces a type error.

@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 24, 2026
@steipete
steipete marked this pull request as ready for review August 24, 2026 23:39
@clawsweeper clawsweeper Bot added mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 24, 2026, 7:46 PM ET / 23:46 UTC.

ClawSweeper review

What this changes

This PR makes optimized image attachment filenames match the emitted image MIME type and adds transparent-WebP-to-PNG coverage.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main can emit PNG bytes for transparent images while retaining the source WebP filename in both optimized-image owners; this PR repairs both paths with one shared mapper and focused direct/local coverage. No blocking patch defect found; the maintainer label and exact-head CI/rebase state require normal human landing review.

Priority: P2
Reviewed head: 8908a87a2769b2812c9efe7ef782ae531cd60711

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused owner-level repair and regression are sound; exact-head validation remains before merge.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-labeled PR is exempt from the external-contributor proof gate; its body describes after-fix transport checks but no linked artifact was independently inspected.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-labeled PR is exempt from the external-contributor proof gate; its body describes after-fix transport checks but no linked artifact was independently inspected.
Evidence reviewed 7 items Current-main failure boundary: The optimizer selects PNG for transparent output, but both current-main result owners only rewrote filenames for JPEG, leaving a resized transparent WebP with a WebP filename.
Shared local-file owner: The local/URL loader uses the same optimizer and had the same JPEG-only filename rewrite at its final result boundary.
Canonical MIME extension contract: Media Core maps image/jpeg, image/png, and image/webp to .jpg, .png, and .webp; the PR reuses this canonical mapping instead of adding a parallel table.
Findings None None.
Security None None.

Live Verification

Command: pnpm test src/media/web-media.test.ts --reporter=verbose

Result: PASS (completed)

pnpm test src/media/web-media.test.ts --reporter=verbose
runner@runnervm76f27:/tmp/clawsweeper-live-proof-128902-TpUNcg/target$ pnpm test src/media/web-media.test.ts --reporter=verbose
$ node --import tsx scripts/test-projects.mts src/media/web-media.test.ts --reporter=verbose
pnpm test src/media/web-media.test.ts --reporter=verbose
[test] starting test/vitest/vitest.media.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128902-TpUNcg/target

 ✓  media  src/media/web-media.test.ts › loadWebMedia › 'allows localhost file URLs for local …' 59ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › 'rejects remote-host file URLs before …' 2ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › 'rejects remote-host file URLs with th…' 1ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › 'rejects Windows network paths before …' 1ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › loads browser-style canvas media paths as managed local files 2ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › keeps trying hosted media resolvers after one throws 2ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › surfaces Rastermill decode failures when image optimization cannot produce a JPEG 1ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › uses model metadata-aware image compression grids 1ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › adapts automatic image compression for many-image turns 0ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › preserves in-limit GIF buffers when optimizing direct image buffers 1ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › does not bypass model dimensions for GIF buffers 0ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › renames opaque PNGs converted to JPEG across direct and local image owners 17ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › renames transparent WebP images converted to PNG across direct and local image owners 7ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › applies model image maxBytes to the effective image cap 2ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › uses the strictest model image maxBytes across fallback candidates 0ms
 ✓  media  src/media/web-media.test.ts › loadWebMedia › downscales oversized JPEGs to the resolved model side limit before returning media 369ms



























Assertions:

  • PASS expect_output: renames transparent WebP images converted to PNG across direct and local image owners

How this fits together

The shared web-media loader accepts direct buffers and local files, optimizes images, and returns bytes, MIME type, and filename to channel adapters. Telegram uses that filename for multipart uploads, while Discord uses it as the attachment name.

flowchart LR
  A[Direct buffer or local file] --> B[Web media loader]
  B --> C[Image optimization]
  C --> D[Output MIME and filename]
  D --> E[Telegram multipart upload]
  D --> F[Discord attachment]
  E --> G[Visible attachment]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - GitHub reports the branch behind main with incomplete checks; rebase or inspect the real merge result and require green exact-head CI before landing.
  • Resolve merge risk (P1) - The read-only checkout has no installed Rastermill package, so the focused suite was not independently executed here; rerun it on the rebased head.
  • Complete next step (P2) - The maintainer label keeps this PR in human landing review; refresh the behind branch and validate the exact merge head.
Agent review details

Security

None.

PR surface

Source 0, Tests +29. Total +29 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 7 7 0
Tests 1 30 1 +29
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 37 8 +29

Review metrics

Metric Value Why it matters
Production versus test LOC production +7/-7 (net 0); tests +30/-1 (net +29) The bug fix absorbs the behavior into the existing owner without production growth, while the new test covers both direct and local input paths.

Stored data model

Persistent data-model change detected: serialized state: src/media/web-media.test.ts. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

A Telegram Desktop upload can directly show that converted transparent WebP media now carries a .png attachment filename. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis telegram desktop proof: verify that a transparent WebP resized to PNG is sent with a .png attachment filename.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one MIME-derived filename mapper at the shared media owner, retain the direct/local regression, and land only after a fresh exact-head validation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one MIME-derived filename mapper at the shared media owner, retain the direct/local regression, and land only after a fresh exact-head validation.

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

Yes in source: current main produces transparent PNG output but retains the source WebP filename in both optimized-image result paths; the PR adds a direct/local regression for that case.

Is this the best way to solve the issue?

Yes: moving filename selection to one shared MIME-based mapper repairs the owner boundary and avoids channel-specific duplicate policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1edbbc9dd72c.

Labels

Label changes:

  • add P2: This corrects user-visible attachment metadata on a bounded optimized-image path without broader availability or security impact.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-labeled PR is exempt from the external-contributor proof gate; its body describes after-fix transport checks but no linked artifact was independently inspected.
  • add mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. Telegram forwards the shared loader filename into InputFile, so the corrected PNG filename is visible in a short Telegram Desktop proof.

Label justifications:

  • P2: This corrects user-visible attachment metadata on a bounded optimized-image path without broader availability or security impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-labeled PR is exempt from the external-contributor proof gate; its body describes after-fix transport checks but no linked artifact was independently inspected.
  • mantis: telegram-visible-proof: Mantis should capture Telegram visible proof. Telegram forwards the shared loader filename into InputFile, so the corrected PNG filename is visible in a short Telegram Desktop proof.

Evidence

What I checked:

  • Current-main failure boundary: The optimizer selects PNG for transparent output, but both current-main result owners only rewrote filenames for JPEG, leaving a resized transparent WebP with a WebP filename. (src/media/web-media.ts:918, 1edbbc9dd72c)
  • Shared local-file owner: The local/URL loader uses the same optimizer and had the same JPEG-only filename rewrite at its final result boundary. (src/media/web-media.ts:1057, 1edbbc9dd72c)
  • Canonical MIME extension contract: Media Core maps image/jpeg, image/png, and image/webp to .jpg, .png, and .webp; the PR reuses this canonical mapping instead of adding a parallel table. (packages/media-core/src/mime.ts:18, 8908a87a2769)
  • Repair and regression coverage: The PR applies the MIME-based mapper at both owner boundaries and tests genuine transparent WebP bytes through direct-buffer and local-file paths, asserting PNG MIME and filename. (src/media/web-media.test.ts:491, 8908a87a2769)
  • Channel consumer path: Telegram loads media through the shared loader and passes the returned filename to InputFile; Discord uses the returned filename as its attachment name. (extensions/telegram/src/outbound-media.ts:96, 1edbbc9dd72c)
  • History provenance: Blame ties the current optimizer and both JPEG-only filename return paths to Peter Steinberger's current-main media work; the feature history also includes the earlier attachment-format repair. (src/media/web-media.ts:997, 053b89d80f6b)

Likely related people:

  • steipete: Owns the current optimized-media filename paths and the earlier attachment-format work in this area. (role: recent media feature owner; confidence: high; commits: 053b89d80f6b, b186d81c46d4; files: src/media/web-media.ts, src/media/web-media.test.ts)
  • vincentkoc: Recently maintained the local media-read boundary that feeds the shared optimizer. (role: adjacent media contributor; confidence: medium; commits: fa13cf4f2f00; files: src/media/web-media.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase or inspect the actual merge result, then obtain green exact-head CI.
  • Capture a redacted Telegram Desktop attachment proof if maintainers want channel-visible confirmation.

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.

@openclaw-mantis

openclaw-mantis Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Mantis Telegram proof — PASS

Summary: A real Telegram user invoked the same fixture-plugin command against exact main and candidate SUTs. Main converted a genuine transparent WebP to PNG bytes and image/png while retaining the stale wide-transparent.WebP filename; the candidate returned the same PNG bytes and MIME with the corrected wide-transparent.png filename. The pull request fixes the reported filename/encoded-byte mismatch.

  • Scenario: In each exact SUT, an identical fixture plugin registered /webmedia_probe. The command loaded the same genuine 2500x100 transparent WebP through the public outbound-media SDK with a 4096-byte cap, forcing the real shared WebMedia image optimizer to resize and encode it. A real Telegram user invoked the command, and the bot visibly returned the resulting content type, filename, first eight encoded bytes, and PNG-signature check. The candidate also ran the focused committed WebMedia regression inside the isolated SUT.
  • Trigger: clawsweeper_label
  • Run: https://github.com/openclaw/openclaw/actions/runs/32791437515
  • Artifact: https://github.com/openclaw/openclaw/actions/runs/32791437515/artifacts/9543817716
  • Baseline: pass at 4c8c22867ebb6a838b4648f9193919b3d72fa3be — The exact baseline SHA completed the real Telegram command. Its bot reply recorded contentType=image/png, fileName=wide-transparent.WebP, first8Hex=89504e470d0a1a0a, and pngMagic=true.
  • Candidate (PR merged onto main): pass at 73b2f08ea8705c9dbb097f4bd5fac276ffe05084 — The exact candidate SHA completed the identical real Telegram command. Its bot reply recorded contentType=image/png, fileName=wide-transparent.png, first8Hex=89504e470d0a1a0a, and pngMagic=true. The focused transparent-WebP WebMedia regression passed in the isolated candidate SUT.
  • Differential (trusted facts): Both lanes used the same plugin, source image, public SDK call, byte cap, and Telegram command. The encoded MIME and PNG signature were identical; only the stale filename changed from wide-transparent.WebP on main to the MIME-correct wide-transparent.png on the candidate. This isolates the pull request's intended fix and proves it at the shared media-owner boundary reached from a real Telegram interaction.
  • Overall: pass
Before — current main After — this PR
baseline previewGifCropped candidate previewGifCropped

Motion-trimmed clips:

Raw QA files: https://artifacts.openclaw.ai/mantis/telegram-visible/pr-128902/run-32791437515-1/index.json

@steipete
steipete merged commit ee4bb5f into main Aug 25, 2026
303 checks passed
@steipete
steipete deleted the codex/qa-transparent-image-output-filename-20260824 branch August 25, 2026 00:04
@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

maintainer Maintainer-authored PR mantis: telegram-visible-proof Mantis should capture Telegram visible proof. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant