Skip to content

fix(discord): upload-file with a base64 buffer fails without pointing at send - #123748

Merged
steipete merged 4 commits into
openclaw:mainfrom
feniix:fix/discord-upload-file-buffer-contract
Aug 23, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
feniix:fix/discord-upload-file-buffer-contract

Conversation

@feniix

@feniix feniix commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #123747

What Problem This Solves

Fixes an issue where callers sending in-memory bytes to Discord via message with action: "upload-file" and a base64 buffer would hit upload-file requires filePath, path, or media. with no hint that action: "send" is the supported path. The flat tool schema advertises buffer for every action, so the failing shape is exactly what the schema invites.

Why This Change Was Made

Owner-local fix only: Discord's upload-file branch now rejects a buffer-only call with guidance to use send. Per review, the shared buffer schema description is left channel-neutral — iMessage's upload-file deliberately consumes a buffer (extensions/imessage/src/actions.ts), so send-only wording there would teach models away from a supported path. Supporting upload-file + buffer on Discord was deliberately not done — it would duplicate the existing send + buffer capability (#90768) without a distinct use case. Calls with a valid file source are untouched.

User Impact

Agents and operators get an actionable redirect instead of a dead end: Use action: "send" for base64 buffer attachments; upload-file requires filePath, path, or media.

Evidence

Real behavior (real Discord setup, live server)

Traces from a real Discord bot + server, driven through the same path openclaw message <action> rides (runtime config → channel plugin preload → messageCommand → runMessageAction → Discord plugin dispatch). Driver source is at the bottom; channel/message ids redacted.

Before (unpatched main, ffd42dd8a39) — upload-file + valid base64 buffer, filename, contentType, real channel target:

$ node --import tsx proof-driver.mts upload-file '{"channel":"discord","target":"channel:<redacted>","filename":"proof.txt","contentType":"text/plain","buffer":"cHJvb2Y6IGdlbmVyYXRlZCBpbi1tZW1vcnkgYnl0ZXM="}'
Error: upload-file requires filePath, path, or media.

After (this branch) — same call:

$ node --import tsx proof-driver.mts upload-file '{"channel":"discord","target":"channel:<redacted>","filename":"proof.txt","contentType":"text/plain","buffer":"cHJvb2Y6IGdlbmVyYXRlZCBpbi1tZW1vcnkgYnl0ZXM="}'
Error: Use action: "send" for base64 buffer attachments; upload-file requires filePath, path, or media.

Redirect target works (this branch) — the guidance's send + buffer shape delivers a real attachment to the same live channel:

$ node --import tsx proof-driver.mts send '{"channel":"discord","target":"channel:<redacted>","message":"PR 123748 proof: send + buffer delivers in-memory bytes","filename":"proof.txt","contentType":"text/plain","buffer":"cHJvb2Y6IGdlbmVyYXRlZCBpbi1tZW1vcnkgYnl0ZXM="}'
...
      "deliveredTo": [
        {
          "channel": "discord",
          "messageId": "<redacted>",
          "channelId": "<redacted>"
        }
      ],
  "deliveryStatus": "sent",

The rejection fires in the Discord handler before any Discord API call, so the error-path traces involve no outbound request; the send trace is a real delivery observed in the Discord client.

Tests and static checks

  • New regression test: Discord upload-file + buffer rejects with the actionable error and never reaches the channel runtime (extensions/discord/src/actions/handle-action.test.ts), alongside the existing buffer-less rejection test.
  • extensions/discord/src/actions/handle-action.test.ts 37/37 and src/agents/tools/message-tool.test.ts 232/232 on this branch (rebased on current main); tsgo core+extensions test projects, oxlint, and oxfmt --check clean on touched files.
  • Existing coverage already pins the adjacent contract: buffer-only send success and invalid-base64 rejection (src/infra/outbound/message-action-params.test.ts), upload-file file-source hydration (src/infra/outbound/message-action-params.attachments.test.ts), and iMessage's buffer-consuming upload-file (extensions/imessage/src/actions.test.ts).
Proof driver source (local one-off, not part of the PR)

Run from the repo root with OPENCLAW_HOME pointing at an isolated state dir whose openclaw.json contains only channels.discord.{enabled,token}, and OPENCLAW_BUNDLED_PLUGINS_DIR=$PWD/extensions so the loader uses the source tree under test instead of a stale dist/.

// proof-driver.mts — mirrors src/cli/program/message/helpers.ts runMessageAction flow
import { messageCommand } from "./src/commands/message.js";
import { getRuntimeConfig } from "./src/config/config.js";
import { withActivatedPluginIds } from "./src/plugins/activation-context.js";
import { resolveConfiguredChannelPluginIds } from "./src/plugins/channel-plugin-ids.js";
import { loadPluginRegistryHandle } from "./src/plugins/loader.js";
import { withPluginRuntimeRegistryScope } from "./src/plugins/runtime/gateway-request-scope.js";
import { defaultRuntime } from "./src/runtime.js";
import { createDefaultDeps } from "./src/cli/deps.js";

const action = process.argv[2];
const params = JSON.parse(process.argv[3] ?? "{}") as Record<string, unknown>;

const config = getRuntimeConfig();
const pluginIds = resolveConfiguredChannelPluginIds({
  config,
  activationSourceConfig: config,
  env: process.env,
});
const activatedConfig = withActivatedPluginIds({ config, pluginIds }) ?? config;
const pluginRegistry = loadPluginRegistryHandle({
  config: activatedConfig,
  activationSourceConfig: activatedConfig,
  onlyPluginIds: pluginIds,
  throwOnLoadError: true,
});

try {
  await withPluginRuntimeRegistryScope(pluginRegistry, () =>
    messageCommand({ ...params, action, json: true }, createDefaultDeps(), defaultRuntime),
  );
  process.exit(0);
} catch (err) {
  console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
  process.exit(1);
}

The flat message tool schema advertises buffer for every action, so
callers reasonably infer upload-file + buffer is valid on Discord. The
Discord handler only reads filePath/path/media for upload-file and
failed with an error that never mentioned the supported path.

Scope the buffer schema description to action="send" and make Discord
upload-file reject a buffer-only call with guidance to use send instead
of duplicating the send buffer pipeline under a second action.
@clawsweeper

clawsweeper Bot commented Aug 14, 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 channel: discord Channel integration: discord agents Agent runtime and tooling size: XS labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 7:04 AM ET / 11:04 UTC.

ClawSweeper review

What this changes

The PR changes Discord’s buffer-only upload-file error to direct callers to the existing send attachment path and adds a regression test.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking findings. This is a focused Discord-plugin repair with convincing live before/after proof; GitHub reports it cleanly mergeable, though it is behind main and should receive current-base merge validation before landing.

Priority: P2
Reviewed head: c6cf0e7830962a8ccc190e9e97d91d50daac2756

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The narrowly scoped owner-local repair has direct live evidence, focused regression coverage, and no correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body shows redacted before/after output from a real Discord setup and a live successful send-plus-buffer delivery receipt.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body shows redacted before/after output from a real Discord setup and a live successful send-plus-buffer delivery receipt.
Evidence reviewed 7 items Current-main behavior: Current main accepts only filePath, path, or media in Discord upload-file and emits the non-actionable generic error when none is supplied.
Owner-local repair: The proposed branch distinguishes a supplied base64 buffer from a missing file source before any Discord runtime call, directing it to send while preserving the existing file-source path.
Caller and normalization boundary: The core runner hydrates upload-file parameters, then dispatches non-send actions to their plugin; buffer-only upload-file remains a plugin-owned decision, whereas send stages its buffer as outbound media.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw message --help

Result: PASS (completed)

pnpm openclaw message --help
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-123748-162j7v/target$ pnpm openclaw message --help
$ node scripts/run-node.mjs message --help
pnpm openclaw message --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 400.66 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 91.01 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.5s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

[tsdown-build] invocation 2/2 finished in 10.8s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 3493ms (slowest: built plugin control-plane loads 2833ms)
│
◇

OpenClaw 2026.8.1 (c6cf0e7) — All your chats, one OpenClaw.

Usage: openclaw message [options] [command]

Send, read, and manage messages and channel actions

Options:
  -h, --help   Display help for command

Commands:
  ban          Ban a member
  broadcast    Broadcast a message to multiple targets
  channel      Channel actions
  delete       Delete a message
  edit         Edit a message
  emoji        Emoji actions
  event        Event actions
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

The message tool routes an action and attachment parameters through the core message-action runner to a selected channel plugin. Discord’s upload-file branch accepts file sources, while base64 attachments already use the send path and return a delivery result.

flowchart LR
  A[Agent or CLI message action] --> B[Message action runner]
  B --> C[Attachment normalization]
  C --> D[Discord action handler]
  D --> E{File source supplied?}
  E -->|Yes| F[Discord upload delivery]
  E -->|Buffer only| G[Actionable send guidance]
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by 6 lines for a bug fix; the explicit buffer branch is justified by the distinct actionable error, and no clearer net-neutral owner refactor is apparent.
  • Resolve merge risk (P1) - GitHub reports the PR cleanly mergeable but behind main; refresh current-base merge validation before landing.
  • Complete next step (P2) - No repair lane is needed: there is no actionable patch defect; obtain current-base merge validation for the existing contributor branch.
Agent review details

Security

None.

PR surface

Source +6, Tests +19. Total +25 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 0 +6
Tests 1 19 0 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 25 0 +25

Review metrics

Metric Value Why it matters
Production versus test LOC production +6, tests +19 The small production increase is limited to an actionable owner-local diagnostic; the added test locks the no-runtime-call behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #123747
Summary: This PR directly implements the canonical issue’s Discord buffer-only upload-file guidance defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the Discord-local redirect, preserve the channel-neutral shared schema for iMessage compatibility, and land after current-base validation confirms the exact merged result.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the Discord-local redirect, preserve the channel-neutral shared schema for iMessage compatibility, and land after current-base validation confirms the exact merged result.

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

Yes. Current main’s Discord handler deterministically emits the generic error for buffer-only upload-file, and the PR body includes a real-channel before/after invocation path.

Is this the best way to solve the issue?

Yes. The mismatch is Discord-local; changing the shared flat schema would conflict with iMessage upload-file, which legitimately accepts a buffer.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded Discord message-action usability bug with an existing working send path.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body shows redacted before/after output from a real Discord setup and a live successful send-plus-buffer delivery receipt.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body shows redacted before/after output from a real Discord setup and a live successful send-plus-buffer delivery receipt.

Evidence

What I checked:

Likely related people:

  • steipete: A local shortlog sample reports 22 contributions to the Discord action handler, the primary owner boundary for this change. (role: frequent current-file contributor; confidence: medium; files: extensions/discord/src/actions/handle-action.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 (5 earlier review cycles)
  • reviewed 2026-08-14T16:47:40.773Z sha 6d61ef6 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-14T16:54:11.609Z sha 6d61ef6 :: needs real behavior proof before merge. :: [P2] Keep the shared buffer description channel-neutral
  • reviewed 2026-08-14T17:31:20.722Z sha 5aa33b0 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T17:36:36.168Z sha 5aa33b0 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-14T19:07:21.417Z sha 5aa33b0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Aug 14, 2026
iMessage's upload-file deliberately consumes a buffer, so scoping the
shared schema text to send would teach models away from a supported
path. Keep the guidance owner-local: Discord's rejection carries it.
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Aug 14, 2026
@feniix

feniix commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 19, 2026
@steipete
steipete merged commit b9b6ca4 into openclaw:main Aug 23, 2026
161 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 24, 2026
… at send (openclaw#123748)

* fix(discord): reject upload-file buffer attachments with send guidance

The flat message tool schema advertises buffer for every action, so
callers reasonably infer upload-file + buffer is valid on Discord. The
Discord handler only reads filePath/path/media for upload-file and
failed with an error that never mentioned the supported path.

Scope the buffer schema description to action="send" and make Discord
upload-file reject a buffer-only call with guidance to use send instead
of duplicating the send buffer pipeline under a second action.

* review: keep the shared buffer description channel-neutral

iMessage's upload-file deliberately consumes a buffer, so scoping the
shared schema text to send would teach models away from a supported
path. Keep the guidance owner-local: Discord's rejection carries it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: message schema advertises buffer for Discord upload-file, which rejects it without pointing at send

2 participants