Skip to content

fix(mattermost): unnamed media uploads lose file extensions - #119535

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/mattermost-upload-filename
Aug 5, 2026
Merged

vincentkoc merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/mattermost-upload-filename

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Mattermost uploads without a source filename were sent as the extensionless name upload, even when their MIME type identified the file format.

Why This Change Was Made

Unnamed Mattermost media now uses the shared extensionForMime mapping, matching the established Slack upload behavior from #119399. Explicit source filenames remain unchanged.

User Impact

Mattermost clients receive useful names such as upload.png for unnamed media, so file type handling does not depend only on the MIME header.

Evidence

$ PNPM_CONFIG_VERIFY_DEPS_BEFORE_RUN=false pnpm exec tsx proof-live.ts
before: base a1249667 emitted filename="upload" for unnamed image/png
after: head 8fd66335 emitted filename="upload.png" for unnamed image/png
negative-control: both emitted filename="operator-name.bin" for explicitly named image/png
proof-live.ts
import { createServer } from "node:http";
import { registerHooks } from "node:module";
import { createPluginRuntimeMock } from "openclaw/plugin-sdk/plugin-test-runtime";
import { setMattermostRuntime } from "./extensions/mattermost/src/runtime.js";

registerHooks({
  resolve(specifier, context, nextResolve) {
    if (
      specifier === "./runtime-api.js" &&
      context.parentURL?.endsWith("/extensions/mattermost/src/mattermost/send.ts")
    ) {
      const source = `export async function loadOutboundMediaFromUrl(mediaUrl) {
        return {
          buffer: Buffer.from("image-bytes"),
          contentType: "image/png",
          kind: "image",
          ...(mediaUrl.endsWith("/named") ? { fileName: "operator-name.bin" } : {}),
        };
      }`;
      return { url: `data:text/javascript,${encodeURIComponent(source)}`, shortCircuit: true };
    }
    return nextResolve(specifier, context);
  },
});

const { sendMessageMattermost } = await import(
  "./extensions/mattermost/src/mattermost/send.js"
);

const CHANNEL_ID = "aaaaaaaaaaaaaaaaaaaaaaaaaa";
const uploadBodies: string[] = [];
const server = createServer((request, response) => {
  let body = "";
  request.setEncoding("utf8");
  request.on("data", (chunk) => {
    body += chunk;
  });
  request.on("end", () => {
    if (request.url === "/api/v4/files") {
      uploadBodies.push(body);
      response.writeHead(201, { "content-type": "application/json" });
      response.end(JSON.stringify({ file_infos: [{ id: "file-proof" }] }));
      return;
    }
    response.writeHead(201, { "content-type": "application/json" });
    response.end(JSON.stringify({ id: "post-proof", channel_id: CHANNEL_ID }));
  });
});

await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
try {
  const address = server.address();
  if (!address || typeof address === "string") {
    throw new Error("loopback server did not expose a port");
  }
  setMattermostRuntime(createPluginRuntimeMock());
  for (const mediaUrl of ["fixture://media/unnamed", "fixture://media/named"]) {
    await sendMessageMattermost(`channel:${CHANNEL_ID}`, "", {
      cfg: {
        channels: {
          mattermost: {
            botToken: "loopback-proof",
            baseUrl: `http://127.0.0.1:${address.port}`,
            network: { dangerouslyAllowPrivateNetwork: true },
          },
        },
      },
      mediaUrl,
      requireMediaUpload: true,
    });
  }
  console.log(
    JSON.stringify(
      uploadBodies.map((body) => ({
        filename: body.match(/filename="([^"]+)"/)?.[1],
        contentType: body.match(/Content-Type: ([^\r\n]+)/)?.[1],
      })),
    ),
  );
} finally {
  await new Promise<void>((resolve, reject) =>
    server.close((error) => (error ? reject(error) : resolve())),
  );
}

AI-assisted: built with Codex

Punchcard-Session: clear-orchard-lantern-bc

@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: S labels Aug 5, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 3:27 AM ET / 07:27 UTC.

ClawSweeper review

What this changes

The PR derives a MIME-based extension for unnamed Mattermost media uploads while preserving loader-provided filenames.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still gives unnamed Mattermost uploads the fallback name upload; this PR applies the existing public MIME mapping at the correct plugin-owned upload boundary and adds a multipart loopback regression without introducing a correctness or security finding.

Priority: P2
Reviewed head: 8fd663357cdc3113c88da6901b86705bf3cc07ab

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with boundary-level regression coverage and credible after-fix multipart evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.
Evidence reviewed 7 items Current-main behavior: Current main still uses the extensionless fallback when the media loader provides no filename, so the central behavior is not already implemented.
Correct owner boundary: The PR changes the plugin-owned filename argument immediately before the Mattermost upload call, preserving explicit filenames and retaining upload for absent or unknown MIME values.
Shared SDK contract: The public plugin SDK facade exports extensionForMime; its implementation normalizes MIME parameters and aliases and returns an extension only for known values.
Findings None None.
Security None None.

How this fits together

The Mattermost plugin loads outbound media, chooses its multipart filename, uploads it to Mattermost, and then posts the resulting file in a channel. The selected fallback filename affects how receiving clients recognize the attachment.

flowchart LR
  A[Outgoing media URL] --> B[Media loader]
  B --> C[Mattermost send path]
  C --> D[Filename fallback]
  D --> E[Multipart file upload]
  E --> F[Channel post]
  F --> G[Mattermost client]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed: the source review found no actionable patch defect, leaving only normal maintainer merge gating.
Agent review details

Security

None.

PR surface

Source +1, Tests +70. Total +71 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 71 1 +70
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 73 2 +71

Review metrics

Metric Value Why it matters
Production vs test LOC production +2/-1; tests +71/-1 The small production change reuses an existing public SDK contract, while the test expansion covers the action-to-multipart boundary.

Stored data model

Persistent data-model change detected: serialized state: extensions/mattermost/src/channel.send-loopback.test.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep the plugin-local fallback and land it through normal exact-head merge gates; a new cross-channel filename-policy abstraction would add unnecessary SDK surface.

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

Yes—current main’s identified fallback emits upload for absent loader filenames, and the supplied loopback path shows that the same upload boundary emits upload.png after the change.

Is this the best way to solve the issue?

Yes—the transport owns multipart filename selection, while the existing SDK owns MIME normalization; the patch preserves named files and unknown-MIME behavior without creating duplicate shared policy.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3faa2b088823.

Labels

Label changes:

  • add P2: This is a bounded attachment-presentation defect in one bundled channel plugin.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.

Label justifications:

  • P2: This is a bounded attachment-presentation defect in one bundled channel plugin.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from the real Mattermost send and multipart path against a localhost API, including before/after output and an explicit-filename control; it does not overclaim a live Mattermost service.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Commit 56a7000 introduced Mattermost attachment upload routing, and current fallback lines blame to the later reconstructed-file commit fd1662f. (role: attachment-upload path introducer and recent area contributor; confidence: medium; commits: 56a7000b3efa, fd1662f49cc3; files: extensions/mattermost/src/mattermost/send.ts, extensions/mattermost/src/mattermost/client.ts)
  • steipete: The merged Slack sibling uses the same MIME-to-extension owner-boundary pattern and provides the closest established precedent. (role: adjacent upload-pattern owner; confidence: medium; commits: 847e6eea8e94; files: extensions/slack/src/client-delivery.ts, extensions/slack/src/send.upload.test.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.

@vincentkoc vincentkoc self-assigned this Aug 5, 2026
@vincentkoc
vincentkoc merged commit a7ad4f7 into openclaw:main Aug 5, 2026
105 of 111 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

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

Labels

channel: mattermost Channel integration: mattermost P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

2 participants