Skip to content

fix(media): thread workspaceDir through outbound channel adapters - #299

Merged
convyusboy merged 4 commits into
boonfrom
ridho/eng-21421-sentryfleet-openclaw-fleet-xz-message-tool-drops
Oct 20, 2026
Merged

convyusboy merged 4 commits into
boonfrom
ridho/eng-21421-sentryfleet-openclaw-fleet-xz-message-tool-drops

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Sentry OPENCLAW-FLEET-XZ (3 events): sending a local attachment through the message tool can fail with Local media path is not under an allowed directory: ... even though the path is under the agent's own workspace. This only affects relative paths — loadWebMedia only resolves a relative media path against workspaceDir before the allowed-roots check runs; if workspaceDir doesn't reach the loader, the path resolves against the gateway process cwd instead and fails containment.

Several channel-plugin outbound and reply-delivery paths narrowed OutboundMediaAccess down to {localRoots, readFile} before handing it to the loader, silently dropping workspaceDir the moment anything rebuilt the object — this is the same bug class as the sibling fix in #292, but in the channel-adapter layer rather than the media tools.

Why This Change Was Made

The linked ticket's cited line numbers turned out to be partially stale (Telegram's outbound/gateway path was already fixed by the upstream v2026.6.35 sync) and partially incomplete (it missed Discord's and Mattermost's reply-delivery paths, and undersold how broken msteams actually was — its auto-reply path had no media-access carrier at all, not just a dropped field). This PR fixes the actual current gap rather than the ticket's original line numbers:

  • msteams: both the message-tool send path and the agent-reply path (which previously called loadWebMedia(url, maxBytes) with no roots/access at all) now thread mediaAccess end-to-end.
  • iMessage: had zero mediaAccess references anywhere; now matches the existing Signal pattern.
  • WhatsApp: deleted a 42-line local duplicate of the SDK's loadOutboundMediaFromUrl that dropped workspaceDir and silently widened host reads to localRoots: "any"; repointed to the canonical SDK helper.
  • Telegram, Discord, Mattermost, WhatsApp auto-reply: the same invariant was missing from agent-reply delivery (sibling surfaces to the message-tool send path), which read roots via the lossy getAgentScopedMediaLocalRoots instead of the complete resolveAgentScopedOutboundMediaAccess — now exported from the plugin SDK for the first time, since no plugin previously had access to it.
  • Signal, Slack, Matrix, GoogleChat: replaced narrowed local mediaAccess redeclarations with the shared OutboundMediaAccess type so this exact class of silent field-drop becomes a type error instead of a runtime bug the next time someone touches these call sites.
  • Core SDK: loadOutboundMediaFromUrl's public option type never forwarded optimizeImages, even though the underlying loader supports it — this surfaced via tsgo after deleting WhatsApp's local duplicate (which did support it) and is fixed at the root rather than patched locally.
  • A code-review pass (second agent) additionally caught 3 of 7 new resolveAgentScopedOutboundMediaAccess call sites omitting sessionKey, which would have skipped group/sender-scoped tool-policy gating on the host-read capability in those contexts; all three are fixed.

One site the original ticket named — the gateway's message.send RPC hydration call — was investigated and found to be dead code for this purpose (hydrateAttachmentParamsForAction's action === "send" branch never reads the mediaPolicy it's given), so it was left alone rather than patched for appearance.

Explicitly out of scope: Discord's slash-command native-reply family (native-command.ts, native-command-status.ts, native-command-reply.ts) has the same bug pattern but is a separate call tree; flagging as a follow-up rather than expanding this PR further.

User Impact

Sending a workspace-relative local attachment through the message tool (or through an agent's own reply) on msteams, iMessage, WhatsApp, Telegram, Discord, or Mattermost now succeeds instead of failing with a spurious "not under an allowed directory" error. Absolute paths and Slack/Signal/Matrix/GoogleChat (which worked correctly by reference before, just without type safety) are unaffected. An out-of-workspace path is still correctly rejected — verified with a dedicated negative test.

Evidence

Validation:

  • Full local Vitest suites for every touched plugin (msteams, imessage, whatsapp, telegram, discord/monitor, mattermost, signal, slack, matrix, googlechat) plus the two touched core src/plugin-sdk files — all green except 3 pre-existing failures confirmed unrelated (zero diff overlap with this change, verified individually): one Telegram HTML-rendering test, two WhatsApp media.test.ts error-message-wording tests, one msteams tool-schema test.
  • pnpm build — clean, no errors, no INEFFECTIVE_DYNAMIC_IMPORT warnings.
  • pnpm tsgo:prod, tsgo:core:test, tsgo:extensions:test — all clean.
  • Two independent code-review passes (correctness + test-quality) run and all findings addressed before this PR.
  • Not yet run: Crabbox/Testbox broad remote proof — blocked in the authoring environment (no Azure CLI/credentials, no blacksmith CLI installed). Should run before merge/release.

🤖 Generated with Claude Code


Summary by cubic

Fixes the message tool dropping workspaceDir across several channel adapters, which caused relative attachment paths to fail with "Local media path is not under an allowed directory" even when inside the agent workspace. Relative paths now resolve against the agent workspace instead of the gateway process cwd; absolute paths are unaffected and out-of-workspace paths are still rejected.

Channel fixes

  • msteams and iMessage get mediaAccess threading end-to-end; msteams's agent-reply path had no media access at all.
  • WhatsApp's local duplicate of loadOutboundMediaFromUrl (which dropped workspaceDir and widened reads to localRoots: "any") is deleted in favor of the canonical SDK helper.
  • Telegram, Discord, Mattermost, and WhatsApp auto-reply now resolve mediaAccess via resolveAgentScopedOutboundMediaAccess instead of the roots-only getAgentScopedMediaLocalRoots.
  • Signal, Slack, Matrix, and GoogleChat now use the shared OutboundMediaAccess type instead of narrowed local redeclarations.
  • Discord's slash-command native-reply family has the same bug pattern but is left as a follow-up.

SDK

  • resolveAgentScopedOutboundMediaAccess is now exported from the plugin SDK for the first time; the public surface budget was raised accordingly (10418 exports / 5222 callable).
  • msteams imports it directly from openclaw/plugin-sdk/agent-media-payload rather than re-exporting it through the hot-path runtime barrel.
  • loadOutboundMediaFromUrl now forwards optimizeImages, which its public option type previously dropped.
  • WhatsApp and Mattermost auto-reply now forward mediaAccess.readFile alongside roots and workspace.
  • The msteams runtime-api guardrail test was updated to pin the OutboundMediaAccess re-export.

Written for commit 3471d4d. Summary will update on new commits.

View guided diff Turn on auto-fix

A relative local media path handed to the message tool (e.g.
"projects/foo/report.pdf") resolved against the gateway process cwd
instead of the agent workspace, and was rejected by the allowed-
directory check even though the workspace is an allowed root.
Absolute paths were unaffected, which is why this was rare.

loadWebMedia only resolves a relative path against workspaceDir when
that field actually reaches it. Several channel-plugin outbound and
reply-delivery paths narrowed OutboundMediaAccess down to
{localRoots, readFile} before handing it to the loader, silently
dropping workspaceDir the moment anything rebuilt the object.

- msteams, iMessage: no mediaAccess threading at all on the
  message-tool send path; msteams's agent-reply path had no media
  roots/access whatsoever. Both now resolve relative attachments.
- WhatsApp: deleted a 42-line local duplicate of the SDK's
  loadOutboundMediaFromUrl that dropped workspaceDir and widened to
  localRoots: "any"; repointed to the canonical helper.
- Telegram, Discord, Mattermost, WhatsApp auto-reply: the same gap in
  agent-reply delivery, which read roots via the lossy
  getAgentScopedMediaLocalRoots instead of the complete
  resolveAgentScopedOutboundMediaAccess (now exported from the plugin
  SDK for the first time; no plugin had access to it before).
- Signal, Slack, Matrix, GoogleChat: replaced narrowed local
  mediaAccess redeclarations with the shared OutboundMediaAccess type
  so this class of silent field-drop becomes a type error instead of
  a runtime bug.
- Core SDK: loadOutboundMediaFromUrl's public option type never
  forwarded optimizeImages even though the underlying loader supports
  it; surfaced by tsgo after the WhatsApp dedup and fixed at the root.

Verified: full local Vitest suites for every touched plugin, pnpm
build, and pnpm tsgo:prod/core:test/extensions:test all pass clean.
Crabbox/Testbox broad proof did not run in this environment (missing
provider credentials/CLI) and should run before release.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy requested a review from a team October 19, 2026 09:23

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

2 issues found across 52 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/plugin-sdk/agent-media-payload.ts">

<violation number="1" location="src/plugin-sdk/agent-media-payload.ts:8">
P2: `resolveAgentScopedOutboundMediaAccess` is an outbound-send helper, but it is exported from the legacy `agent-media-payload` subpath. That subpath is imported by lightweight channel entrypoints, so they now load the agent-policy and fs-safe graph at module load. Place the export on the outbound media subpath (`plugin-sdk/outbound-media`) instead, and keep the import paths consistent across extensions.</violation>

<violation number="2" location="src/plugin-sdk/agent-media-payload.ts:8">
P2: This adds a public SDK export without updating the checked-in SDK API baseline, so `plugin-sdk:api:check` will report API drift. Regenerate and commit the SDK baseline artifacts with the new export.</violation>
</file>

Linked issue analysis

Linked issue: ENG-21421: [Sentry][Fleet] OPENCLAW-FLEET-XZ: message tool drops workspaceDir to loadWebMedia across several channel adapters

Status Acceptance criteria Notes
✅ Forward workspaceDir through Teams attachment loading sendMessageMSTeams passes mediaAccess to the shared loader, and tests cover relative paths and workspace escapes.
✅ Forward workspaceDir through iMessage attachment resolution The channel action passes mediaAccess through to sendMessageIMessage, whose attachment resolver receives it.
✅ Forward workspaceDir through WhatsApp attachment loading sendMessageWhatsApp uses the shared loader, and its test verifies workspaceDir reaches the media-loading options.
✅ Keep rejecting attachments outside the workspace The Teams regression test confirms a relative path escaping the workspace still fails the allowed-directory check.

Heads up: you’re close to your included review allowance. Set a flex budget so reviews don’t pause.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread extensions/whatsapp/src/runtime-api.ts Resolved
Comment thread src/plugin-sdk/agent-media-payload.ts Resolved
Comment thread src/plugin-sdk/agent-media-payload.ts Resolved
Comment thread src/plugin-sdk/outbound-media.ts Resolved
Comment thread src/plugin-sdk/agent-media-payload.ts Resolved
convyusboy and others added 2 commits October 19, 2026 20:15
cubic-dev-ai review on this PR surfaced 8 findings; 6 were real and are
fixed here, 2 were disproven with direct evidence:

- extensions/msteams/runtime-api.ts: resolveAgentScopedOutboundMediaAccess
  was re-exported from msteams's shared top-level runtime-api.ts, which
  channel.ts imports eagerly at hot-path module load. That pulled the full
  agent-policy/fs-safe dependency graph into every msteams channel startup
  even though only reply-dispatcher.ts (a lazily-loaded module) needs it.
  Removed the re-export; reply-dispatcher.ts now imports it directly from
  openclaw/plugin-sdk/agent-media-payload, bypassing the hot barrel.
- extensions/whatsapp/src/auto-reply/deliver-reply.ts and
  extensions/mattermost/src/mattermost/reply-delivery.ts: both dropped
  mediaAccess.readFile (the policy-gated host reader) before loading
  attachments, forwarding only localRoots/workspaceDir. Both now forward
  readFile too, matching the complete OutboundMediaAccess contract.
- src/plugins/contracts/plugin-sdk-runtime-api-guardrails.test.ts: this
  PR's msteams runtime-api.ts change (adding `type OutboundMediaAccess` to
  an existing re-export) wasn't reflected in this file's pinned export
  snapshot, so the guardrail test failed. Updated the pinned line. (cubic
  attributed this failure to whatsapp/src/runtime-api.ts, a different,
  unguarded nested file — verified by running the test directly; the real
  failure was only in msteams.)
- Two doc-comment nits (ambiguous `optimizeImages` wording, an overlong
  comment) applied as suggested.

Disproven claims, verified directly rather than taken on faith:
- "Adds a public SDK export without updating the SDK API baseline" —
  `pnpm plugin-sdk:api:check` passes clean; `agent-media-payload` isn't a
  subpath tracked by that baseline mechanism.
- The msteams test-coverage gap cubic flagged (mock returns `{}`, nothing
  asserts the dispatcher forwards mediaAccess) was real; added a dedicated
  test asserting resolveAgentScopedOutboundMediaAccess is called with
  agentId/sessionKey and its result is forwarded to sendMSTeamsMessages.

Verified: full Vitest suites for msteams, whatsapp, mattermost, the
touched plugin-sdk/contracts files; plugin-sdk:api:check; pnpm build;
tsgo:prod + tsgo:core:test + tsgo:extensions:test. All clean except the
same 3 pre-existing failures already confirmed unrelated in the prior
commit (zero diff overlap).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
OutboundMediaAccess (type) and resolveAgentScopedOutboundMediaAccess
are each counted once per reachable entrypoint subpath (their own
plus media-runtime's wildcard re-export), moving the measured public
surface to 10418 exports / 5222 callable. Match the committed budget
to the new authoritative count.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread scripts/plugin-sdk-surface-report.mjs Resolved
Keep the rationale for the surface-budget bump but remove the ticket
ID per the repo's ticket-free source comment policy.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@boon-hermes-bot boon-hermes-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM / Approved

Nice work on the end-to-end fix for OPENCLAW-FLEET-XZ (ENG-21421).

What was reviewed & verified:

  1. Core SDK & Types:

    • resolveAgentScopedOutboundMediaAccess exported canonically from openclaw/plugin-sdk/agent-media-payload.
    • OutboundMediaAccess type re-exported from openclaw/plugin-sdk/outbound-media and adopted across adapters (GoogleChat, Matrix, Signal, Slack, WhatsApp, Teams) preventing silent narrowing.
    • loadOutboundMediaFromUrl now forwards optimizeImages to buildOutboundMediaLoadOptions.
    • Plugin SDK surface report budget and guardrail test snapshots updated and passing (10418 exports / 5222 callable).
  2. Channel Adapters:

    • MSTeams: mediaAccess threaded through sendMessageMSTeams, buildActivity, and createMSTeamsReplyDispatcher.
    • iMessage: mediaAccess threaded through sendIMessageOutbound and sendMessageIMessage.
    • WhatsApp: Hand-rolled loadOutboundMediaFromUrl duplicate deleted in favor of the canonical SDK helper; deliverWebReply properly forwards workspaceDir, localRoots, and readFile.
    • Telegram, Discord, Mattermost: Auto-reply / dispatchers upgraded from getAgentScopedMediaLocalRoots to resolveAgentScopedOutboundMediaAccess preserving workspaceDir and host read capability.
  3. Security & Tests:

    • Workspace boundary containment verified: relative media paths resolve against workspaceDir, while paths traversing outside workspace root remain strictly rejected.
    • Dedicated Vitest test coverage across touched extensions passes cleanly.
    • All CI checks on 3471d4dafdd are green.

@convyusboy
convyusboy merged commit 8384739 into boon Oct 20, 2026
147 of 149 checks passed
@convyusboy
convyusboy deleted the ridho/eng-21421-sentryfleet-openclaw-fleet-xz-message-tool-drops branch October 20, 2026 02:10
convyusboy added a commit that referenced this pull request Oct 26, 2026
* chore(release): bump version 2026.6.35-boon.1 -> 2026.6.35-boon.2

Cuts the fork release covering the 9 PRs merged to boon since v2026.6.35-boon.1:
#298 (ENG-21265) stuck-generation cut-off retry + sub-agent spawn backstop,
#299 workspaceDir threading through outbound channel media adapters,
#304 (ENG-19208) real inbound media path in the system prompt,
#301 (ENG-21585) forced sessions_yield on narrated sub-agent turns,
#305 message-tool source reply observed outside message_tool_only,
#306 (ENG-19103) reasoning-stream callbacks honor message_tool_only,
#303 sub-agent/completion-turn usage attribution,
#302 clears 7 high-severity pnpm-audit-prod advisories,
#300 (ENG-21588) boon-estimation trajectory label detail.

Bump root package.json/npm-shrinkwrap.json, all bundled plugin manifests, and
the version + openclaw peer floor in every extension npm-shrinkwrap.json. Add
the 2026.6.35-boon.2 CHANGELOG.md section. No additional dependency or source
changes beyond what already shipped in #299 and #302.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* docs(changelog): fold PR #309's advisory fixes into the 2026.6.35-boon.2 entry

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
convyusboy added a commit that referenced this pull request Nov 30, 2026
…ia (#348)

* fix(discord): thread workspaceDir into native slash-command reply media

Discord's native slash-command reply family (direct /status replies,
direct plugin-command replies, and agent-reply dispatch) built outbound
media access with the roots-only getAgentScopedMediaLocalRoots helper
instead of the complete resolveAgentScopedOutboundMediaAccess, so
workspaceDir never reached the terminal loadWebMedia call. A relative
attachment path from the message tool resolved against the gateway
process cwd instead of the agent workspace and was rejected by the
allowed-directory check even though the workspace is an allowed root.

Mirrors ENG-21421 / PR #299 (8384739), which fixed
the same bug class everywhere except this one surface, which it
explicitly deferred.

- native-command.ts: swap getAgentScopedMediaLocalRoots for
  resolveAgentScopedOutboundMediaAccess; thread the result into the
  direct-status, direct-plugin-command, and agent-reply dispatch
  branches (the plugin-command branch had no media access threading at
  all before this change, same as the other fixed channels originally
  lacked).
- native-command-status.ts, native-command-agent-reply.ts: param swap
  from mediaLocalRoots: readonly string[] to mediaAccess:
  OutboundMediaAccess.
- native-command-reply.ts: deliverDiscordInteractionReply's terminal
  loadWebMedia call now builds options via buildOutboundMediaLoadOptions
  with the full mediaAccess, instead of forwarding only localRoots.

Tests: mock-based mediaAccess-forwarding assertions for all three
branches, plus a real-filesystem test proving a relative in-workspace
path resolves and an outside-workspace path is still rejected.

Verified: scoped Vitest (extension-discord project) on the four touched
source files' test files, 37/37 passing; full discord extension suite,
same 78 pre-existing failures as before this change (local Node 24.13.1
vs required 24.15+ SQLite WAL-safety guard, unrelated to this diff);
tsgo:extensions and tsgo:extensions:test both clean; oxfmt/oxlint clean
on touched files. Blacksmith Testbox warmup failed in this environment
(blacksmith binary not on $PATH) so remote CI proof did not run here.

Fixes ENG-21758.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(discord): drop ticket reference from test comments per cubic review

cubic-dev-ai flagged two test comments citing the ENG-21758 ticket ID
and PR-specific history, which don't belong in source per repo policy
(no Linear ticket references in code/comments/commit messages). Both
replaced with the technical rationale alone.

Addresses PR review feedback on #348.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants