Skip to content

fix(media): let media tools read agent-rendered files outside default roots - #289

Merged
convyusboy merged 2 commits into
boonfrom
ridho/eng-21228-media-tmp-media-access
Oct 14, 2026
Merged

convyusboy merged 2 commits into
boonfrom
ridho/eng-21228-media-tmp-media-access

Conversation

@convyusboy

@convyusboy convyusboy commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes ENG-21228: Sentry
OPENCLAW-FLEET-XM (51 events, 7 customer sessions across tc-browne,
power-solutions, affinity, guido, builders-inc, boon-test-automation). Agent
scripts that render crops/pages into /tmp (pdf2image, matplotlib, etc.) and
then hand that path to the image tool are blocked with Error: Local media path is not under an allowed directory: /tmp/..., so customers never get the
takeoff/plan diagrams they were promised.

Why This Change Was Made

The allowed media-read roots are /tmp/openclaw + state/config media dirs +
the agent workspace (src/media/local-roots.ts). The outbound MEDIA:
send path already widens that allowlist to a referenced file's own directory
when the agent is permitted host reads outside its workspace
(getAgentScopedMediaLocalRootsForSources, gated on
resolveEffectiveToolFsWorkspaceOnly / resolveEffectiveToolFsRootExpansionAllowed).
The media tools (image, pdf, image_generate, video_generate,
music_generate) never got the same treatment — resolveMediaToolLocalRoots
silently discarded the media source it was handed (the parameter was literally
named _mediaSources). That asymmetry is why MEDIA:/tmp/x.png sends fine
but image(/tmp/x.png) throws — exactly what the Sentry telemetry shows
(tool: image on every event).

This carries the already-resolved fs-policy decision forward as a prepared
rootExpansionAllowed fact on ToolFsPolicy (computed once in
createOpenClawCodingTools, the only place both cfg and agentId — and the
memory-flush trigger — are known), and reuses the existing
appendLocalMediaParentRoots helper in the five media tools. No new config
key, no /tmp added to the default allowlist, no change for agents that are
workspaceOnly or whose policy denies read — they stay exactly as locked
down as before. Traversal/symlink containment in assertLocalMediaAllowed
(realpath-based) is unaffected and covered by a new test.

Also fixed: a blocked path was thrown as a raw error and classified
"upstream" by classifyToolCallErrorKind, paging Sentry as a host defect
even though it's a policy outcome. image and pdf now catch the
path-not-allowed case and return a denied tool result the model can act
on (same pattern as the existing image-too-large handling), so genuinely
denied paths (e.g. workspaceOnly agents) stop paging while still failing
the turn for the model to see and self-correct.

User Impact

  • Agents permitted host reads outside their workspace (the shipped fleet
    default — no tools.fs.workspaceOnly, no restrictive tools.profile) can
    now hand the image/pdf/*_generate tools a file they just rendered
    anywhere on the host, including /tmp, matching what already worked for
    MEDIA: sends.
  • workspaceOnly agents and restrictive tool-policy agents: unchanged.
  • A blocked media path now returns a graceful, self-correcting tool result
    instead of an unhandled exception; stops paging OPENCLAW-FLEET-XM.

Out of scope (follow-up, different repo): updating boon-skills agent
skills to prefer writing media under the workspace directory in the first
place.

Evidence

  • node scripts/run-vitest.mjs src/agents/tools/{media-tool-shared,image-tool,pdf-tool,image-generate-tool,video-generate-tool,music-generate-tool}.test.ts src/media/{local-media-access,local-roots,read-capability,load-options}.test.ts — all green (new tests included: root-expansion widening, workspaceOnly still wins, symlink-escape still rejected, graceful denial result).
  • node --import tsx scripts/check-import-cycles.ts — 0 cycles.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental ... — clean.
  • node_modules/.bin/oxlint <touched files> — exit 0, no issues.
  • $autoreview --mode local (Claude engine; Codex unavailable — not logged in in this environment) — scoped-clean, 0 accepted/actionable findings, "patch is correct (0.72)".
  • Sentry issue: https://boon-technologies-inc.sentry.io/issues/7693739833/

Remaining gap: live Crabbox proof of an actual /tmp-rendered image upload to
Slack/Web, and post-release Sentry zero-event confirmation, are not done in
this session — flagging for follow-up before/after merge.


Summary by cubic

Fixes ENG-21228: the image, pdf, image_generate, video_generate, and music_generate tools rejected files an agent just rendered under /tmp (via pdf2image, matplotlib, etc.), even though the same path already works through MEDIA: sends. Those tools now widen their read allowlist to the referenced file's own directory when the agent is permitted host reads outside its workspace, matching the outbound send path. The widening's permission check runs against the full layered tool policy set, so any layer (group, sender, sandbox, subagent, inherited) that denies read keeps the narrow default roots.

  • workspaceOnly agents and restrictive tool policies are unchanged and keep the narrow default roots.
  • A blocked media path now returns a denied tool result (status: "denied", which classifyToolCallErrorKind reads directly) the model can act on — write the file under the workspace and retry — instead of throwing, so genuine denials stop paging Sentry as host defects.
  • Path traversal and symlink-escape containment stays enforced via the existing realpath-based checks.

Written for commit 9afb9de. Summary will update on new commits.

View guided diff Turn on auto-fix

@convyusboy
convyusboy requested a review from a team October 14, 2026 09:55

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

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

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

Comment thread src/agents/agent-tools.ts Resolved
Comment thread src/agents/tools/image-tool.ts Resolved
Comment thread src/agents/tools/pdf-tool.ts Resolved
Comment thread src/agents/tools/video-generate-tool.ts Resolved
Comment thread docs/tools/media-overview.md 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.

✅ Approved

Resolves ENG-21228 and Sentry OPENCLAW-FLEET-XM by aligning media tools (image, pdf, image_generate, video_generate, music_generate) with the outbound MEDIA: send path, allowing them to read agent-rendered files (e.g., under /tmp) when host-level read is permitted.

Strengths

  • Parity with outbound media access: Fixes the asymmetry where MEDIA:/tmp/x.png succeeded but image(/tmp/x.png) failed, directly mitigating recurring Sentry errors on agent plan/diagram generation.
  • Strict policy containment: rootExpansionAllowed is gated on !fsWorkspaceOnly && isToolAllowedByPolicies("read", layeredToolPolicies), checking all 11 policy layers (group, sender, sandbox, subagent, inherited). workspaceOnly remains authoritative and strictly fails closed.
  • Symlink & traversal safety: Traversal protection remains anchored in realpath checks via assertLocalMediaAllowed, backed by explicit test coverage.
  • Graceful error classification: Converts raw uncaught exceptions into structured { status: "denied", details: { error: "media_path_not_allowed", status: "denied" } } responses, preventing Sentry host defect alerts while giving the agent clear guidance to copy to the workspace and retry.

Technical Verification

  • ✅ Test execution: Verified locally with node scripts/run-vitest.mjs across media-tool-shared.test.ts, image-tool.test.ts, pdf-tool.test.ts, and local-media-access.test.ts (150/150 tests passing).
  • ✅ Static analysis: Zero import cycles (check-import-cycles.ts) and zero oxlint violations.
  • ✅ CI checks: All GitHub Actions check runs are passing green.
  • ✅ Prior feedback addressed: Thoroughly handled bot review feedback in commit 6266124542607633b5c70f44e6162191c0ef26e3.

LGTM!

convyusboy and others added 2 commits October 14, 2026 18:09
… roots

Agent scripts that render crops/pages into /tmp (pdf2image, matplotlib, etc.)
and then hand that path to a media tool were blocked with "Local media path
is not under an allowed directory", even though the same path already sends
fine through MEDIA:. The outbound send path widens its allowlist to a
referenced file's own directory when the agent is permitted host reads
outside its workspace (getAgentScopedMediaLocalRootsForSources); the media
tools (image, pdf, image_generate, video_generate, music_generate) never did
the same, silently discarding the media source they were given
(resolveMediaToolLocalRoots's third parameter was literally `_mediaSources`).

Carry the already-resolved fs policy decision forward as a prepared
`rootExpansionAllowed` fact on ToolFsPolicy, computed once in
createOpenClawCodingTools (agent-tools.ts) where workspaceOnly and the memory-
flush trigger are both known, and thread it through the five media tools'
local-roots resolution. Reuses the existing appendLocalMediaParentRoots
helper, so traversal/symlink containment checks in assertLocalMediaAllowed
are unaffected. Agents that are workspaceOnly, or whose policy denies read,
are unchanged.

Also: a blocked media path was thrown as a raw error and classified
"upstream" by classifyToolCallErrorKind, paging Sentry as a host defect
(OPENCLAW-FLEET-XM). image and pdf now catch the path-not-allowed case and
return a `denied` tool result the model can act on instead, same pattern as
the existing image-too-large handling.

Fixes ENG-21228.

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

Address cubic review feedback on PR #289:

- rootExpansionAllowed was computed from
  resolveEffectiveToolFsRootExpansionAllowed, which only checks
  profile/global/agent policy. It missed group/sender/sandbox/subagent/
  inherited policies that applyToolPolicyPipeline also applies, so a policy
  layer denying `read` could still leave media tools able to widen past the
  workspace. Now checks isToolAllowedByPolicies("read", ...) against the same
  full layered policy list already used for allowBackground, extracted as a
  shared `layeredToolPolicies` array.
- The graceful media-path denial result used details.denied, which is
  reserved in this codebase for inline gateway exec approval denials (where
  `status` is already overloaded by exit-code semantics). Switched to
  `status: "denied"`, which classifyToolCallErrorKind already reads directly.
- Doc fix: list the state canvas/workspace/sandboxes directories explicitly
  in the local-roots description.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@convyusboy
convyusboy force-pushed the ridho/eng-21228-media-tmp-media-access branch from 6266124 to 9afb9de Compare October 14, 2026 11:10
@convyusboy
convyusboy merged commit cdf80b6 into boon Oct 14, 2026
250 of 252 checks passed
@convyusboy
convyusboy deleted the ridho/eng-21228-media-tmp-media-access branch October 14, 2026 11:44
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.

2 participants