Skip to content

fix(media): resolve relative media/PDF paths against the agent workspace - #292

Merged
convyusboy merged 2 commits into
boonfrom
ridho/eng-21407-relative-media-pdf-paths
Oct 14, 2026
Merged

convyusboy merged 2 commits into
boonfrom
ridho/eng-21407-relative-media-pdf-paths

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Agents that write a file into a workspace subfolder (e.g. ststephens/doc.pdf)
and then reference it by that relative path from the pdf, image_generate,
video_generate, or music_generate tool get rejected with Error: Local media path is not under an allowed directory, even though the same file is
already reachable with read/ls and the workspace is an allowed root.

Reported live via Sentry fleet telemetry at Peterson Sheet Metal, Guido, and
C&S Technical Resources (OPENCLAW-FLEET-16P).

Why This Change Was Made

assertLocalMediaAllowed (src/media/local-media-access.ts) has no workspace
context: a non-absolute path falls through to path.resolve(mediaPath),
resolving against the gateway process cwd instead of the agent workspace,
then fails containment against workspace-anchored roots.

The loader already solves this correctly: loadWebMediaInternal resolves a
relative mediaUrl against an optional workspaceDir before that guard runs
(covered by src/media/web-media.test.ts), and the outbound send path already
passes it via OutboundMediaAccess.workspaceDir. No media tool passed it. The
image tool separately carried a hand-rolled, inline copy of the same
resolution logic.

This change threads workspaceDir into the loadWebMedia/loadWebMediaRaw
call from pdf, image_generate, video_generate, and music_generate
(matching how the image tool already resolved relative refs), then deletes the
image tool's inline duplicate so the loader is the single canonical place this
resolution happens. Net production LOC is +22/-16, mostly comments; the image
tool's own prod code shrinks by 10 lines.

User Impact

  • A model may reference a workspace-relative path (e.g. ststephens/doc.pdf)
    from any of the five media tools and have it resolve correctly.
  • Directory-traversal escapes outside the workspace remain blocked — verified
    with a dedicated regression test using a relative ../ escape under
    fsPolicy.workspaceOnly.
  • No config or API surface changes.

Scope note: OPENCLAW-FLEET-XZ

The ticket's second Sentry issue, OPENCLAW-FLEET-XZ (tool: message), is a
different, multi-plugin gap: the outbound message tool already threads
workspaceDir correctly through its core plumbing
(resolveAgentScopedOutboundMediaAccess → OutboundMediaAccess.workspaceDir),
but several bundled channel adapters (Telegram, MS Teams, iMessage, WhatsApp —
and the gateway send RPC re-entry path for Telegram specifically) flatten
mediaAccess down to { mediaLocalRoots, mediaReadFile } and drop
.workspaceDir before their own terminal loadWebMedia call. That is a
separate, channel-plugin-owned fix spanning several files per plugin; filed as
ENG-21421 rather than bundled
into this PR.

Evidence

  • node scripts/run-vitest.mjs src/agents/tools/pdf-tool.test.ts src/agents/tools/image-tool.test.ts src/agents/tools/image-generate-tool.test.ts src/agents/tools/video-generate-tool.test.ts src/agents/tools/music-generate-tool.test.ts src/agents/tools/media-tool-shared.test.ts src/media/web-media.test.ts src/media/local-media-access.test.ts — 337/337 passed.
  • node scripts/run-vitest.mjs src/agents/openclaw-tools.pdf-registration.test.ts src/agents/openclaw-tools.tts-config.test.ts src/agents/tools/video-generate-tool.status.test.ts src/agents/tools/music-generate-tool.status.test.ts src/agents/tools/image-tool.custom-provider-auth.regression.test.ts —
    22/22 passed (sibling wiring tests).
  • pnpm tsgo:core — clean, no errors.
  • pnpm format:check / node scripts/run-oxlint.mjs on all touched files —
    clean.
  • Fresh $autoreview (Claude engine; Codex unavailable in this environment —
    authentication failure) on the final diff: one P2 raised
    ("image-tool relative-path resolution removed without a regression test"),
    resolved by existing, unmodified, real-loader coverage at
    image-tool.test.ts ("resolves relative image paths against workspaceDir"),
    re-verified green (97/97) after the change.
  • New tests added: pdf-tool.test.ts (relative path resolves; relative
    traversal escape still denied), image-generate-tool.test.ts,
    video-generate-tool.test.ts, music-generate-tool.test.ts (each proves
    workspaceDir reaches the loader for a relative reference).
  • git diff --numstat — non-test prod LOC +22/-16 (net +6, comments); test
    LOC +223 across 4 files.

Known gap: no Crabbox/live-channel proof was run for this PR (narrow,
single-module fix); CI will cover broader lanes.

🤖 Generated with Claude Code


Summary by cubic

Fixes media tools rejecting relative media and PDF paths that point inside the agent workspace. Previously the pdf, image_generate, video_generate, and music_generate tools resolved a non-absolute path against the gateway process cwd, which failed the workspace containment check even when the file was valid. They now thread workspaceDir through to the media loader, and the image tool's inline copy of the same resolution logic is removed since the loader handles it canonically.

  • Directory-traversal escapes outside the workspace are still blocked; regression tests were added for each affected tool.
  • A related Sentry issue for the message tool is out of scope: channel adapters drop workspaceDir before their own media load, filed separately as ENG-21421.

Written for commit 123ad02. Summary will update on new commits.

View guided diff Turn on auto-fix

@convyusboy
convyusboy requested a review from a team October 14, 2026 13:36

@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

All reported issues were addressed across 10 files

Linked issue analysis

Linked issue: ENG-21407: [Sentry][Fleet] OPENCLAW-FLEET-16P: Relative media and PDF paths rejected by directory containment guard

Status Acceptance criteria Notes
✅ Resolve relative media and PDF paths against the workspace The PDF tool and media-generation tools pass workspaceDir to the loader, which resolves relative references there.
✅ Allow valid files in workspace subdirectories The PDF regression test processes ststephens/doc.pdf from the workspace, and the other tools pass workspaceDir for relative references.
✅ Keep paths that escape the workspace blocked A regression test verifies a relative path outside the workspace is denied under workspaceOnly policy.

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

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

Comment thread docs/tools/media-overview.md Resolved
Comment thread src/agents/tools/pdf-tool.test.ts Resolved
Comment thread src/agents/tools/music-generate-tool.ts Resolved
Comment thread src/agents/tools/image-tool.ts Resolved
Comment thread src/agents/tools/video-generate-tool.ts Resolved
Comment thread src/agents/tools/pdf-tool.ts Resolved

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

Code Review: APPROVE

Verdict: APPROVE (siap-rilis)

Summary & Technical Verification

  • Workspace-Relative Path Resolution (OPENCLAW-FLEET-16P): Media tools (pdf, image, image_generate, video_generate, and music_generate) now pass workspaceDir through to loadWebMedia/loadWebMediaRaw. Fixes Sentry errors where files written to workspace subfolders were rejected by containment checks against the gateway process cwd.
  • Centralized Resolution: Removes redundant inline path resolution logic from src/agents/tools/image-tool.ts, establishing loadWebMediaInternal as the single canonical resolution point.
  • Containment & Security: Directory-traversal escapes outside the workspace remain denied, verified by explicit regression tests under fsPolicy.workspaceOnly.
  • Scope Precision: Separates the plugin-adapter channel flattening issue into follow-up ENG-21421.
  • Test Coverage: Added regression tests across pdf-tool.test.ts, image-generate-tool.test.ts, music-generate-tool.test.ts, and video-generate-tool.test.ts. All 151 CI check runs completed cleanly.

convyusboy and others added 2 commits October 14, 2026 23:19
Agents writing a file into a workspace subfolder (e.g. "ststephens/doc.pdf")
and then handing that relative path to a media tool were rejected with
"Local media path is not under an allowed directory", even though the same
file is reachable with read/ls and the workspace is an allowed root.

assertLocalMediaAllowed has no workspace context: a non-absolute path falls
through to path.resolve(mediaPath), resolving against the gateway process
cwd instead of the agent workspace, then fails containment against
workspace-anchored roots. loadWebMediaInternal already resolves a relative
mediaUrl against an optional workspaceDir before that guard runs
(already covered by web-media.test.ts), and the outbound send path already
passes it via OutboundMediaAccess.workspaceDir. No media tool did.

Thread workspaceDir into the loadWebMedia/loadWebMediaRaw call in pdf,
image_generate, video_generate, and music_generate, matching how the image
tool already resolved it -- then delete the image tool's inline duplicate
of that same resolution, since the loader now owns it canonically.

Fixes ENG-21407 (OPENCLAW-FLEET-16P). OPENCLAW-FLEET-XZ (tool: message) is a
separate, multi-plugin gap in several channel adapters dropping
workspaceDir before their own loadWebMedia calls; filed as ENG-21421.

Co-Authored-By: Claude Opus 5 <[email protected]>
Drop PR-specific ticket references from inline/test comments (repo policy:
no Linear ticket IDs in code/comments/commits), and replace a customer-
derived example path with a generic one in docs and the regression test
that mirrored it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy force-pushed the ridho/eng-21407-relative-media-pdf-paths branch from 141ac0d to 123ad02 Compare October 14, 2026 16:20
@convyusboy
convyusboy merged commit db2ff81 into boon Oct 14, 2026
144 checks passed
@convyusboy
convyusboy deleted the ridho/eng-21407-relative-media-pdf-paths branch October 14, 2026 16:52
convyusboy added a commit that referenced this pull request Oct 15, 2026
Cut the fork release that ships the six commits on boon since
v2026.6.34-boon.7:

- #292 (ENG-21407): resolve relative media/PDF paths against the agent
  workspace in pdf, image_generate, video_generate, and music_generate,
  instead of the gateway process cwd; delete the image tool's duplicate
  inline resolution now that the loader owns it canonically.
- #289 (ENG-21228): let image, pdf, image_generate, video_generate, and
  music_generate read agent-rendered files outside the default roots
  (e.g. /tmp crops) when the agent is permitted host reads outside its
  workspace, matching the outbound MEDIA: path; a blocked path now
  returns a denied tool result instead of a raw error that paged Sentry.
- #293 (ENG-21406): raise the image tool's default vision timeout 60s ->
  150s (above boon-llm-gateway's 120s fallback-chain budget), share one
  deadline across setup and the provider request, and return a graceful
  timeout status instead of letting the raw error end the turn; mirrored
  in the Codex dynamic-tool watchdog; sentry-monitor downgrades image
  timeouts to a warning.
- #291: sentry-monitor no longer pages on ordinary non-zero exec exit
  codes; only shell lookup failures (126/127) stay exceptions, now
  fingerprinted per missing binary. Runtime Docker image adds unzip.
- #288 (ENG-21227): memory_search no longer pauses/pages Sentry while
  the index is still building ("missing" identity); only a real
  "mismatched" embedding provider pauses it.
- #294 (ENG-21405, test-only): regression coverage confirming the cron
  delivery-target guard already rejects a directory-less channel's
  unknown target end to end; root cause for the live Sentry errors was
  a stale anychat-boon-web plugin install, not a core gap.

Bump root package.json and npm-shrinkwrap.json, all 136 plugin
manifests, and the version field in every extension's
npm-shrinkwrap.json via pnpm plugins:sync, hand-patched the same way as
boon.7 (the npm-shrinkwrap generator still can't regenerate cleanly on
this fork: pre-existing, unrelated @sentry/node nested
@opentelemetry/resources / sdk-trace-base registry-resolution drift,
reproduced again on this base). Verified via
test/package-manager-config.test.ts (12/12) and the full
release-preflight check suite (plugin versions, inventory, base config
schema, bundled channel config metadata, config docs baseline, plugin
SDK exports/API baseline/surface budget, root dependency ownership) --
all green except the known shrinkwrap generator drift. Add the
2026.6.34-boon.8 CHANGELOG.md section and the generated
extensions/matrix/CHANGELOG.md entry.

No config schema, plugin-SDK surface, or plugin source/dependency
change in slack/msteams/diagnostics-prometheus; this is a gateway-only
roll (bundled-plugin source changes in codex, memory-core, and
sentry-monitor ship inside the gateway tarball). Targeted tests for all
three touched extensions plus the codex dynamic-tool-execution suite:
1075/1075 passing.

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.

3 participants