Skip to content

fix(clickclack): preserve MIME extension for unnamed uploads - #119646

Merged
Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
sunlit-deng:codex/fix/clickclack-upload-filename
Aug 5, 2026
Merged

Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
sunlit-deng:codex/fix/clickclack-upload-filename

Conversation

@sunlit-deng

Copy link
Copy Markdown
Contributor

What Problem This Solves

Unnamed ClickClack media uploads currently use the generic filename attachment even when the media loader provides a useful MIME type such as image/png. That loses the file extension in the upload and in the media-only message body, making downloaded attachments and previews less consistent.

Why This Change Was Made

When no explicit or loader-provided filename exists, derive the filename as attachment${extensionForMime(contentType) ?? ""} through the public openclaw/plugin-sdk/media-mime helper. Existing filenames still win, known MIME types gain their extension, unknown MIME types stay on the generic attachment fallback, and missing MIME metadata still defaults to application/octet-stream.

This follows the recent MIME-derived filename precedent in Alix-007's merged Slack upload change and Mattermost upload change, adapted to ClickClack's upload-first delivery path.

User Impact

ClickClack users receive unnamed image uploads as attachment.png instead of attachment, while named files, unknown MIME types, durable retries, upload ordering, and attachment association remain unchanged.

Evidence

  • Focused validation: node scripts/run-vitest.mjs extensions/clickclack/src/outbound.test.ts --reporter=verbose — 28 tests passed.
  • Static validation: node scripts/run-oxlint.mjs extensions/clickclack/src/outbound.ts extensions/clickclack/src/outbound.test.ts and git diff --check passed.
  • Same temporary proof script, production sendClickClackMedia, real loopback ClickClack HTTP API, synthetic image bytes with no filename, empty media text, and upload/message/attachment requests:
    • Base 36ee98d815dbffdb233205278e91e2db86cebb88: upload filename remained generic and media-only body was not attachment.png.
    • Candidate 981da82a77708e877364592a89ed7ed842387cf9: multipart filename was attachment.png and media-only body was attachment.png.
  • Negative controls: explicit viewer-proof.ts remains unchanged; unknown and missing MIME types retain attachment; durable upload/message retry cases pass.
$ node_modules/.bin/tsx proof-live.ts
base 36ee98d815dbffdb233205278e91e2db86cebb88: {"uploadStatus":200,"uploadFilenameIsPng":false,"uploadFilenameIsGeneric":true,"messageStatus":200,"mediaOnlyBodyIsPng":false,"attachmentStatus":200}
head 981da82a77708e877364592a89ed7ed842387cf9: {"uploadStatus":200,"uploadFilenameIsPng":true,"uploadFilenameIsGeneric":false,"messageStatus":200,"mediaOnlyBodyIsPng":true,"attachmentStatus":200}
negative-control: 28 tests passed; explicit viewer-proof.ts retained; unknown and missing MIME retained generic attachment; durable retry coverage passed
proof-live.ts
import { createServer, type IncomingMessage, type ServerResponse } from "node:http";
import { sendClickClackMedia } from "./extensions/clickclack/src/outbound.ts";
import type { CoreConfig } from "./extensions/clickclack/src/types.ts";

const PNG_BYTES = Buffer.from(
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO7Z0nQAAAAASUVORK5CYII=",
  "base64",
);

async function readBody(request: IncomingMessage): Promise<Buffer> {
  const chunks: Buffer[] = [];
  for await (const chunk of request) {
    chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
  }
  return Buffer.concat(chunks);
}

function respond(response: ServerResponse, status: number, payload: unknown): void {
  const body = JSON.stringify(payload);
  response.writeHead(status, {
    "content-type": "application/json",
    "content-length": Buffer.byteLength(body),
  });
  response.end(body);
}

let uploadBody = Buffer.alloc(0);
let messageBody: string | undefined;
let uploadStatus = 0;
let messageStatus = 0;
let attachmentStatus = 0;

const server = createServer(async (request, response) => {
  if (request.method === "GET" && request.url === "/media/") {
    response.writeHead(200, {
      "content-type": "image/png",
      "content-length": PNG_BYTES.length,
    });
    response.end(PNG_BYTES);
    return;
  }

  const body = await readBody(request);
  if (request.method === "POST" && request.url?.startsWith("/api/uploads?")) {
    uploadBody = body;
    uploadStatus = 200;
    const multipart = body.toString("latin1");
    const filename = /filename="attachment\.png"/u.test(multipart)
      ? "attachment.png"
      : "attachment";
    respond(response, uploadStatus, {
      upload: {
        id: "upl_proof",
        workspace_id: "wsp_1",
        owner_id: "bot_proof",
        filename,
        content_type: "image/png",
        byte_size: PNG_BYTES.length,
        width: 1,
        height: 1,
        duration_ms: 0,
        created_at: "2026-08-05T00:00:00Z",
      },
    });
    return;
  }

  if (request.method === "POST" && request.url === "/api/channels/chn_general/messages") {
    messageBody = JSON.parse(body.toString("utf8")).body;
    messageStatus = 200;
    respond(response, messageStatus, { message: { id: "msg_proof" } });
    return;
  }

  if (request.method === "POST" && request.url === "/api/messages/msg_proof/attachments") {
    attachmentStatus = 200;
    respond(response, attachmentStatus, { ok: true });
    return;
  }

  respond(response, 404, { error: "not found" });
});

await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
const address = server.address();
if (!address || typeof address === "string") {
  throw new Error("loopback server did not expose a port");
}

try {
  const baseUrl = `http://127.0.0.1:${address.port}`;
  const cfg = {
    channels: {
      clickclack: {
        enabled: true,
        baseUrl,
        apiBaseUrl: baseUrl,
        token: "synthetic-clickclack-token",
        workspace: "wsp_1",
      },
    },
  } as CoreConfig;

  await sendClickClackMedia({
    cfg,
    to: "channel:chn_general",
    text: "",
    mediaUrl: "",
    mediaLocalRoots: "any",
    mediaReadFile: async () => PNG_BYTES,
  });

  const multipart = uploadBody.toString("latin1");
  const uploadFilenameIsPng = /filename="attachment\.png"/u.test(multipart);
  const uploadFilenameIsGeneric = /filename="attachment"/u.test(multipart);
  console.log(
    JSON.stringify({
      uploadStatus,
      uploadFilenameIsPng,
      uploadFilenameIsGeneric,
      messageStatus,
      mediaOnlyBodyIsPng: messageBody === "attachment.png",
      attachmentStatus,
    }),
  );
} finally {
  await new Promise<void>((resolve, reject) => server.close((error) => (error ? reject(error) : resolve())));
}

Tested head SHA: 981da82.
Canonical precedent: recent Alix-007 MIME-derived upload filename PRs #119399 and #119535 use the same narrow filename-fallback treatment; this candidate applies it to ClickClack's upload and media-only message path.

AI-assisted: built with Codex

@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, 11:15 AM ET / 15:15 UTC.

ClawSweeper review

What this changes

The PR derives a MIME-based extension for unnamed ClickClack uploads while preserving supplied filenames and generic fallbacks for unknown MIME types.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR is still necessary: current main sends unnamed ClickClack uploads as attachment. The plugin-local fallback is the best fix, has no actionable review findings, and is supported by focused tests plus an after-fix transport-boundary proof.

Priority: P2
Reviewed head: 981da82a77708e877364592a89ed7ed842387cf9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary fix with suitable regression coverage and a recorded real transport-path result.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body records an after-fix loopback ClickClack API run through the production sender and multipart client, with before/after filename and message-body results plus negative controls.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records an after-fix loopback ClickClack API run through the production sender and multipart client, with before/after filename and message-body results plus negative controls.
Evidence reviewed 6 items Current-main defect: Current main falls back to the extensionless attachment when media has no filename; fetched media can legitimately have MIME metadata without a filename.
Owner-boundary repair: The PR computes the normalized content type and derives the fallback name before the existing upload and media-only message flow, leaving durable upload recovery intact.
Shared SDK contract: The public plugin SDK MIME helper normalizes MIME values and returns extensions only for known types, so unknown and absent MIME values retain the generic fallback.
Findings None None.
Security None None.

How this fits together

The ClickClack channel plugin loads outbound media, uploads it through the ClickClack API, then creates a channel message and attachment association. The selected upload filename is also used for media-only message text.

flowchart LR
  A[Outbound media request] --> B[Media loader]
  B --> C[ClickClack filename fallback]
  C --> D[ClickClack upload API]
  D --> E[Channel message]
  E --> F[Attachment association]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the review found no concrete defect; this PR awaits ordinary maintainer merge handling.
Agent review details

Security

None.

PR surface

Source +1, Tests +82. Total +83 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 2 +1
Tests 1 83 1 +82
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 86 3 +83

Review metrics

Metric Value Why it matters
Production vs test delta production +3/-2; tests +83/-1 The net production line adds the visible MIME-derived fallback at the existing plugin upload owner; the larger test delta covers its filename cases.

Technical review

Best possible solution:

Land the plugin-owned fallback after the normal exact-head merge gate; keep filename policy local to ClickClack and reuse the public MIME mapping.

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

Yes: current main has a reachable extensionless fallback when loader metadata lacks a filename, while the source loader permits that state with a MIME type.

Is this the best way to solve the issue?

Yes: placing the fallback in ClickClack’s upload owner preserves the shared loader’s channel-neutral role and matches merged Slack and Mattermost patterns.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded attachment-filename usability 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 records an after-fix loopback ClickClack API run through the production sender and multipart client, with before/after filename and message-body results plus negative controls.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records an after-fix loopback ClickClack API run through the production sender and multipart client, with before/after filename and message-body results plus negative controls.

Evidence

What I checked:

  • Current-main defect: Current main falls back to the extensionless attachment when media has no filename; fetched media can legitimately have MIME metadata without a filename. (extensions/clickclack/src/outbound.ts:266, ce06e7924e88)
  • Owner-boundary repair: The PR computes the normalized content type and derives the fallback name before the existing upload and media-only message flow, leaving durable upload recovery intact. (extensions/clickclack/src/outbound.ts:267, 981da82a7770)
  • Shared SDK contract: The public plugin SDK MIME helper normalizes MIME values and returns extensions only for known types, so unknown and absent MIME values retain the generic fallback. (packages/media-core/src/mime.ts:268, 47ce26985d40)
  • Regression coverage: The added cases cover explicit filename precedence plus known, unknown, and missing MIME types through the ClickClack sender. (extensions/clickclack/src/outbound.test.ts:223, 981da82a7770)
  • Sibling precedent and provenance: The existing ClickClack outbound and multipart-client path dates to this commit; merged Slack and Mattermost implementations use the same public helper at their respective upload owners. (extensions/clickclack/src/http-client.ts:441, 47ce26985d40)
  • Merge and proof state: GitHub reports the PR mergeable; the submitted terminal proof runs the production sender and real multipart transport against a loopback ClickClack HTTP API, showing attachment.png only at the candidate head. (981da82a7770)

Likely related people:

  • fuller-stack-dev: Commit history attributes the outbound media path and multipart client to this contributor. (role: introduced current ClickClack upload behavior; confidence: medium; commits: 47ce26985d40; files: extensions/clickclack/src/outbound.ts, extensions/clickclack/src/http-client.ts)
  • sunlit-deng: Authored the merged Mattermost implementation using the same MIME-derived filename pattern. (role: adjacent precedent contributor; confidence: high; commits: a7ad4f756579; files: extensions/mattermost/src/mattermost/send.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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-05T14:30:16.381Z sha 981da82 :: needs maintainer review before merge. :: none

@Patrick-Erichsen
Patrick-Erichsen merged commit 66bfafa into openclaw:main Aug 5, 2026
95 checks passed
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main: (70 commits)
  fix(clickclack): preserve MIME extension for unnamed uploads (openclaw#119646)
  fix(memory): keep post-ready RPCs responsive (openclaw#119710)
  fix(browser): preserve locale, timezone, and device overrides (openclaw#119695)
  fix(agents): stop messaging dedupe from dropping final replies that quote a short tool send (openclaw#118178)
  test(agents): batch code mode budget proof (openclaw#119699)
  fix(memory): keep gateway RPCs responsive during startup (openclaw#119676)
  improve(ui): trail transient session status beside row actions (openclaw#119560)
  refactor(msteams): consolidate channel action target resolution (openclaw#119632)
  fix: tail context answers the current user message (openclaw#117364)
  fix(whatsapp): exercise descriptor-safe credential persistence (openclaw#119621)
  fix(diagnostics-otel): route OTLP endpoints by signal (openclaw#101655)
  refactor(skills): consolidate workshop transcript and record normalization (openclaw#119643)
  fix(video): harden DashScope task and media lifecycle (openclaw#117303)
  refactor(transcripts): consolidate persistence and export ownership (openclaw#119634)
  fix: preserve ClickClack discussion state contracts (openclaw#118851)
  fix(matrix): retire shared E2EE clients safely (openclaw#119570)
  refactor(cron): unify catch-up persistence and payload encoding (openclaw#119636)
  refactor(ui): centralize composer attachment and capability controls (openclaw#119650)
  refactor(daemon): consolidate managed service lifecycle ownership (openclaw#119647)
  fix(browser): honor explicit navigation timeouts across browser drivers (openclaw#119654)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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