Repository navigation
fix(media): thread workspaceDir through outbound channel adapters - #299
Merged
convyusboy merged 4 commits intoOct 20, 2026
Merged
convyusboy merged 4 commits into
convyusboy merged 4 commits into
Conversation
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]>
There was a problem hiding this comment.
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
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]>
There was a problem hiding this comment.
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
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]>
There was a problem hiding this comment.
LGTM / Approved
Nice work on the end-to-end fix for OPENCLAW-FLEET-XZ (ENG-21421).
What was reviewed & verified:
-
Core SDK & Types:
resolveAgentScopedOutboundMediaAccessexported canonically fromopenclaw/plugin-sdk/agent-media-payload.OutboundMediaAccesstype re-exported fromopenclaw/plugin-sdk/outbound-mediaand adopted across adapters (GoogleChat, Matrix, Signal, Slack, WhatsApp, Teams) preventing silent narrowing.loadOutboundMediaFromUrlnow forwardsoptimizeImagestobuildOutboundMediaLoadOptions.- Plugin SDK surface report budget and guardrail test snapshots updated and passing (
10418exports /5222callable).
-
Channel Adapters:
- MSTeams:
mediaAccessthreaded throughsendMessageMSTeams,buildActivity, andcreateMSTeamsReplyDispatcher. - iMessage:
mediaAccessthreaded throughsendIMessageOutboundandsendMessageIMessage. - WhatsApp: Hand-rolled
loadOutboundMediaFromUrlduplicate deleted in favor of the canonical SDK helper;deliverWebReplyproperly forwardsworkspaceDir,localRoots, andreadFile. - Telegram, Discord, Mattermost: Auto-reply / dispatchers upgraded from
getAgentScopedMediaLocalRootstoresolveAgentScopedOutboundMediaAccesspreservingworkspaceDirand host read capability.
- MSTeams:
-
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
3471d4dafddare green.
- Workspace boundary containment verified: relative media paths resolve against
orswn
approved these changes
Oct 20, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Sentry
OPENCLAW-FLEET-XZ(3 events): sending a local attachment through themessagetool can fail withLocal media path is not under an allowed directory: ...even though the path is under the agent's own workspace. This only affects relative paths —loadWebMediaonly resolves a relative media path againstworkspaceDirbefore the allowed-roots check runs; ifworkspaceDirdoesn'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
OutboundMediaAccessdown to{localRoots, readFile}before handing it to the loader, silently droppingworkspaceDirthe 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:
loadWebMedia(url, maxBytes)with no roots/access at all) now threadmediaAccessend-to-end.mediaAccessreferences anywhere; now matches the existing Signal pattern.loadOutboundMediaFromUrlthat droppedworkspaceDirand silently widened host reads tolocalRoots: "any"; repointed to the canonical SDK helper.getAgentScopedMediaLocalRootsinstead of the completeresolveAgentScopedOutboundMediaAccess— now exported from the plugin SDK for the first time, since no plugin previously had access to it.mediaAccessredeclarations with the sharedOutboundMediaAccesstype 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.loadOutboundMediaFromUrl's public option type never forwardedoptimizeImages, even though the underlying loader supports it — this surfaced viatsgoafter deleting WhatsApp's local duplicate (which did support it) and is fixed at the root rather than patched locally.resolveAgentScopedOutboundMediaAccesscall sites omittingsessionKey, 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.sendRPC hydration call — was investigated and found to be dead code for this purpose (hydrateAttachmentParamsForAction'saction === "send"branch never reads themediaPolicyit'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
messagetool (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:
src/plugin-sdkfiles — all green except 3 pre-existing failures confirmed unrelated (zero diff overlap with this change, verified individually): one Telegram HTML-rendering test, two WhatsAppmedia.test.tserror-message-wording tests, one msteams tool-schema test.pnpm build— clean, no errors, noINEFFECTIVE_DYNAMIC_IMPORTwarnings.pnpm tsgo:prod,tsgo:core:test,tsgo:extensions:test— all clean.blacksmithCLI installed). Should run before merge/release.🤖 Generated with Claude Code
Summary by cubic
Fixes the
messagetool droppingworkspaceDiracross 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
mediaAccessthreading end-to-end; msteams's agent-reply path had no media access at all.loadOutboundMediaFromUrl(which droppedworkspaceDirand widened reads tolocalRoots: "any") is deleted in favor of the canonical SDK helper.mediaAccessviaresolveAgentScopedOutboundMediaAccessinstead of the roots-onlygetAgentScopedMediaLocalRoots.OutboundMediaAccesstype instead of narrowed local redeclarations.SDK
resolveAgentScopedOutboundMediaAccessis now exported from the plugin SDK for the first time; the public surface budget was raised accordingly (10418 exports / 5222 callable).openclaw/plugin-sdk/agent-media-payloadrather than re-exporting it through the hot-path runtime barrel.loadOutboundMediaFromUrlnow forwardsoptimizeImages, which its public option type previously dropped.mediaAccess.readFilealongside roots and workspace.OutboundMediaAccessre-export.Written for commit 3471d4d. Summary will update on new commits.