Skip to content

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

Merged
convyusboy merged 2 commits into
boonfrom
worktree-tender-noodling-dove
Nov 30, 2026
Merged

convyusboy merged 2 commits into
boonfrom
worktree-tender-noodling-dove

Conversation

@convyusboy

@convyusboy convyusboy commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes ENG-21758

What Problem This Solves

Fixes an issue where a Discord slash-command reply containing a relative local attachment path (e.g. one the message tool produced) would fail with "Local media path is not under an allowed directory" even though the agent's workspace is an allowed root. This affected /status direct replies, direct plugin-command replies, and agent-reply dispatch — the three reply branches reachable from Discord's native slash-command handler.

Why This Change Was Made

loadWebMedia only resolves a relative local media path against the agent workspace when workspaceDir reaches it alongside the allowed roots. Discord's native slash-command reply family built its media access using the roots-only getAgentScopedMediaLocalRoots helper instead of the complete resolveAgentScopedOutboundMediaAccess, so workspaceDir never reached the terminal loadWebMedia call; a relative path resolved against the gateway process cwd instead.

This mirrors ENG-21421 / #299 (83847399af6), which fixed the identical bug class across telegram, msteams, imessage, whatsapp, mattermost, the gateway, and Discord's other reply paths, but explicitly deferred this one surface. While implementing, an independent review pass also found that Discord's direct plugin-command reply branch (e.g. /pair) had never threaded any media access at all, even before this change — the same bug class, in the same function, so it's fixed here too rather than filed as a separate follow-up.

The fix threads OutboundMediaAccess (roots + workspaceDir + policy-gated host reader) end to end instead of the roots-only shape, matching the already-established pattern in extensions/discord/src/send.shared.ts and the other channels ENG-21421 fixed. No new code path or compat shim was added.

User Impact

Discord slash-command replies (status, plugin commands, and agent replies) that attach a relative local file path now resolve it against the agent's workspace, instead of failing with a false "not under an allowed directory" error. Absolute paths were already unaffected. The allowed-directory check itself is unchanged — paths outside the workspace are still rejected.

Evidence

  • Added tests exercising all three reply branches:
    • native-command-reply.test.ts: a mock-based assertion that the full mediaAccess (roots, workspaceDir, readFile) reaches the terminal loadWebMedia call, plus a real-filesystem test (mkdtemp + realpath) proving a relative in-workspace path loads and an outside-workspace path is still rejected.
    • native-command.status-direct.test.ts: asserts workspaceDir reaches loadWebMedia through the direct /status branch.
    • native-command.plugin-dispatch.test.ts: asserts workspaceDir reaches loadWebMedia through both the direct plugin-command branch and the agent-reply dispatcher branch.
  • Scoped Vitest (vitest.extension-discord.config.ts) on the three touched test files: 37/37 passing.
  • Full discord extension suite: same 78 pre-existing failures before and after this change (all traced to a local Node 24.13.1 vs. required Node 24.15+ SQLite WAL-safety guard — an environment issue, not this diff); one additional test now passes (1873 vs. 1872).
  • tsgo:extensions and tsgo:extensions:test: both clean.
  • oxfmt --check / run-oxlint.mjs: clean on all touched files.
  • Blacksmith Testbox warmup failed in the implementing environment (blacksmith binary not on $PATH), so remote CI proof did not run there; this PR's own CI run is the first remote proof.

Summary by cubic

Fixes Discord slash-command replies so relative local attachment paths (like ones the message tool produces) resolve against the agent workspace instead of failing with a false "Local media path is not under an allowed directory" error.

The reply family (direct /status replies, direct plugin-command replies, and agent-reply dispatch) built media access with a roots-only helper, so workspaceDir never reached the terminal loadWebMedia call. The fix threads the full OutboundMediaAccess end to end, matching the pattern used by other channels (ENG-21421). It also fixes the direct plugin-command reply branch, which had no media access threading at all.

  • Relative paths in slash-command replies now resolve against the agent's workspace; absolute paths and the allowed-directory check are unchanged.
  • Adds tests covering all three reply branches, including a real-filesystem test proving an in-workspace relative path loads and an outside-workspace path is still rejected.

Written for commit ef866f7. Summary will update on new commits.

View guided diff Turn on auto-fix

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]>

@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 7 files

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

Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

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

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]>

@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.

Summary

Threads OutboundMediaAccess (via resolveAgentScopedOutboundMediaAccess) into Discord native slash-command handling instead of using getAgentScopedMediaLocalRoots. This supplies mediaAccess across all three reply branches: direct plugin-command execution, direct /status replies, and agent-reply dispatch. deliverDiscordInteractionReply now uses buildOutboundMediaLoadOptions to pass workspaceDir, localRoots, and readFile into loadWebMedia.

Relative local media paths attached in slash-command replies resolve against workspaceDir instead of falling back to gateway cwd. The allowed-root boundaries remain enforced.

Key Findings

  • Correctness: Covers all three native slash-command reply branches, including the direct plugin-command branch which previously lacked media access threading.
  • Boundary Safety: Relative path resolution occurs against workspaceDir, while assertLocalMediaAllowed continues to reject paths outside the allowed roots.
  • Test Coverage: Verified with targeted tests across all three dispatch branches plus a real-filesystem test covering in-workspace and outside-workspace path resolution.

Local and CI Verification

  • Targeted Vitest: 3 files, 37/37 tests passed (native-command-reply.test.ts, native-command.plugin-dispatch.test.ts, native-command.status-direct.test.ts).
  • Lint & Format: oxlint and oxfmt --check passed cleanly across all 7 touched files.
  • Typecheck: pnpm tsgo:extensions and pnpm tsgo:extensions:test passed cleanly.
  • CI: ci-gate and all 30 check runs completed with success on commit ef866f7af906c66dcbdd35efb0984e3f32d84161.
  • Commits: Both commits are GPG-signed and cryptographically verified.

Verdict: APPROVE (ready-to-release)

@convyusboy
convyusboy merged commit 476eddd into boon Nov 30, 2026
148 of 151 checks passed
@convyusboy
convyusboy deleted the worktree-tender-noodling-dove branch November 30, 2026 04:26
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.

1 participant