Repository navigation
fix(gateway): pass managed inbound PDFs through chat.send - #90115
vincentkoc merged 2 commits into
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed June 14, 2026, 5:56 PM ET / 21:56 UTC. Summary PR surface: Source +49, Tests +220. Total +269 across 2 files. Reproducibility: yes. at source level: current main rejects sandboxed offloads over the 5 MB staging cap and deletes/fails on throwing or incomplete staging before managed inbound PDFs can proceed. I did not execute the runtime path because this review is read-only. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Choose one canonical fix path: land this focused gateway fallback after full redacted Do we have a high-confidence way to reproduce the issue? Yes at source level: current main rejects sandboxed offloads over the 5 MB staging cap and deletes/fails on throwing or incomplete staging before managed inbound PDFs can proceed. I did not execute the runtime path because this review is read-only. Is this the best way to solve the issue? Yes for the narrow AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f1b8827d20c8. Label changesLabel justifications:
Evidence reviewedPR surface: Source +49, Tests +220. Total +269 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
…fails chat.send force-stages offloaded non-image media into the sandbox workspace when one exists. If that optional staging was unavailable or incomplete, prestageMediaPathOffloads deleted the media buffers and failed the whole send with a 5xx — even for already-managed inbound PDFs that are safe to read host-side. A Control-UI-uploaded PDF could fail to send. When staging throws or is incomplete, fall back to the absolute managed paths iff every non-image offloaded ref is a managed-inbound application/pdf (reusing the existing resolveInboundMediaReference allow-check + the PDF mime type). This mirrors the existing no-sandbox passthrough: with MediaWorkspaceDir unset the managed media dir is a default media-understanding local root, so the absolute path resolves host-side. Gated all-or-nothing so a single non-managed or non-PDF ref keeps the previous delete + 5xx behavior. Success path and oversized 4xx are unchanged; managed buffers are not deleted on the fallback. Fixes openclaw#90097 Co-Authored-By: Claude Opus 4.8 <[email protected]>
b72b99e to
de87445
Compare
|
@clawsweeper re-review please. This has been green on all checks since June 4 with no review pass yet — could you run a review so it can be queued for a maintainer? Scope is small: routes managed inbound PDFs through |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…0115) * fix(gateway): pass managed inbound PDFs through when sandbox staging fails chat.send force-stages offloaded non-image media into the sandbox workspace when one exists. If that optional staging was unavailable or incomplete, prestageMediaPathOffloads deleted the media buffers and failed the whole send with a 5xx — even for already-managed inbound PDFs that are safe to read host-side. A Control-UI-uploaded PDF could fail to send. When staging throws or is incomplete, fall back to the absolute managed paths iff every non-image offloaded ref is a managed-inbound application/pdf (reusing the existing resolveInboundMediaReference allow-check + the PDF mime type). This mirrors the existing no-sandbox passthrough: with MediaWorkspaceDir unset the managed media dir is a default media-understanding local root, so the absolute path resolves host-side. Gated all-or-nothing so a single non-managed or non-PDF ref keeps the previous delete + 5xx behavior. Success path and oversized 4xx are unchanged; managed buffers are not deleted on the fallback. Fixes openclaw#90097 Co-Authored-By: Claude Opus 4.8 <[email protected]> * fix(gateway): exempt managed PDFs from staging cap --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
Summary
Fixes #90097.
chat.sendoffloads large attachments to the managed inbound media store, then for a sandboxed session may copy non-image refs into the sandbox throughstageSandboxMedia. That sandbox copy is optional for already-managed inbound PDFs: the managed media directory is host-readable by media understanding, so the gateway can pass the managed path through asMediaPath/MediaPathswithout granting locked-down agents broader filesystem access.This PR keeps the fix scoped to the #90097 gateway path:
application/pdf, or the previous fail-closed path remains.Collision check
Direct competing PR checked:
chat.sendmanaged-inbound PDF pass-through/fallback for Pass through already-managed inbound PDFs in chat.send #90097, with focused gateway regression coverage for staging throw, incomplete staging, mixed-batch rejection, and the 5-20 MB sandbox-cap case.Safety model
Rolling a managed PDF through this path requires both checks:
resolveInboundMediaReference(ref.path)accepts the saved path as managed inbound media.ref.mimeType === "application/pdf"for every offloaded non-image ref in the batch.A single non-managed path, non-PDF mime type, or unresolved media ref keeps the previous delete + failure behavior. The sandboxed agent still receives
MediaStaged: true; for the pass-through path,MediaWorkspaceDiris unset so host-side media understanding resolves the absolute managed path instead of treating it as a sandbox-relative file.Real behavior proof
Behavior addressed: an already-managed inbound PDF send can fail or be rejected before the agent sees it when optional sandbox staging is unavailable, incomplete, or over the 5 MB staging cap (#90097). The fix reaches a managed-PDF fallback inside
prestageMediaPathOffloadsthat passes refs through only when every ref isapplication/pdfand every path is accepted by theresolveInboundMediaReferencemanaged-inbound trust predicate; anything else stays fail-closed. The two merge-risk flags on this PR (message-delivery and security-boundary) hinge on that path, so the proof drives it two ways at real-filesystem runtime: Leg 1 runs the realprestageMediaPathOffloadsend-to-end so the oversize branch actually fires; Leg 2 exercises the trust gate across the boundary cases.Real environment tested: a real Node v22.19.0 process ran the code committed by this PR against a real on-disk managed media store (
OPENCLAW_STATE_DIRpointed at a scratch directory holding a realmedia/inbound/tree). Leg 1 drove the realprestageMediaPathOffloads(src/gateway/server-methods/chat.ts) with a host-only sandbox (sandbox.mode: "all",workspaceAccess: "rw"—ensureSandboxWorkspaceForSessionresolves a host workspace with no Docker daemon, so the real oversize branch is genuinely reached rather than skipped). Leg 2 drove the managed-PDF gate and the real, already-exportedresolveInboundMediaReferencepredicate against on-disk files: a 6.29 MB managed inbound PDF, a non-PDF, a nested-path PDF, an absolute PDF outside the store, and a symlink insideinbound/pointing outside it. Nothing was stubbed — the predicate's real path-containment andfs.realpath/symlink checks ran against the real filesystem. Both legs are driven by functions that are module-internal in the committed source; to import them, a throwawayexportkeyword was added in the worktree and reverted afterward, so the executed function bodies are byte-for-byte the committed code at de87445 and the branch diff stays the shipped 2 files.Exact steps or command run after this patch: wrote the real media store to disk (
<media>/inbound/report.pdf6.29 MB, a 6.29 MB non-PDFbig.bin,archive.zip,sub/nested.pdf, an outside-storeevil.pdf, and alink.pdfsymlink to it), then ran two harnesses in real Node processes —OPENCLAW_STATE_DIR=<root>/state node --import tsx integration-harness.mjs(Leg 1, drivesprestageMediaPathOffloads) andOPENCLAW_STATE_DIR=<root>/state node --import tsx harness.mjs(Leg 2, drives the gate + predicate). Reproducing this requires temporarily re-addingexporttoprestageMediaPathOffloadsandresolveManagedInboundPdfFallbackinchat.ts(both are module-internal); the executed bodies are otherwise unchanged from de87445, and every per-ref ACCEPTED/REJECTED decision in Leg 2 can also be reproduced with zero source edits via the already-exportedresolveInboundMediaReference.Evidence after fix (copied live console output from the real Node runs):
Leg 1 — real
prestageMediaPathOffloads, host sandbox active, oversize branch fires:Leg 2 — managed-PDF gate + real trust predicate across the boundary cases:
Observed result after fix: Leg 1 confirms the real call site — with a host sandbox resolved (so the oversize branch is reached, not skipped by the no-sandbox early return), the 6.29 MB managed inbound PDF returns the fallback
{ paths: [managed path], types: ["application/pdf"] }withworkspaceDir: undefined. Thatundefineduniquely identifies the managed-PDF fallback firing rather than the staging path (the post-staging return always sets a workspace dir), so the send proceeds with the PDF delivered. The 6.29 MB non-PDF over the same cap throws the realUnsupportedAttachmentError("attachments exceed sandbox staging limit") as a client-side 4xx — fail-closed. Leg 2 confirms the trust gate across the boundary: the managed PDF (Case A) is delivered, and a non-PDF in inbound (B), a mixed batch (C), a nested-path PDF (D), an absolute PDF outside the store (E), and a symlink inside inbound pointing outside it (F) all resolve tonull, keeping the prior delete-and-reject path. Case F is the key security-boundary check — a managed-looking path that resolves outsideinbound/via a symlink is rejected, so the pass-through cannot be used to read host files outside the managed store.What was not tested: the live oversize branch was driven above; the staging-throw and incomplete-staging branches that also route into the fallback were not driven against a live
stageSandboxMediahere (no containerized Docker sandbox runtime is available) and remain covered by the existing gateway regression suite listed under Regression coverage. The final announce transport hop over a real external channel was likewise not exercised.Supplemental checks
node scripts/run-vitest.mjs src/gateway/server-methods/chat.directive-tags.test.ts→ 2 files, 214 cases green (gateway suite, supplemental).node scripts/run-tsgo.mjs -p tsconfig.core.jsonand-p test/tsconfig/tsconfig.test.src.json→ clean.node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/gateway/server-methods/chat.ts src/gateway/server-methods/chat.directive-tags.test.ts→ clean.node_modules/.bin/oxfmt --check --threads=1 src/gateway/server-methods/chat.ts src/gateway/server-methods/chat.directive-tags.test.ts→ clean.git diff --check→ clean.Regression coverage
src/gateway/server-methods/chat.directive-tags.test.ts: fallback on incomplete sandbox staging.src/gateway/server-methods/chat.directive-tags.test.ts: fallback on sandbox staging throw.src/gateway/server-methods/chat.directive-tags.test.ts: 6 MB managed inbound PDF passes through instead of hitting the staging cap rejection.src/gateway/server-methods/chat.directive-tags.test.ts: mixed PDF + non-PDF managed batch still fails closed and deletes media buffers.src/gateway/server-methods/chat.directive-tags.test.ts: 6 MB non-PDF still returns a 4xx sandbox staging limit error.Files
src/gateway/server-methods/chat.ts— managed-inbound-PDF fallback inprestageMediaPathOffloads, now reached before sandbox-size rejection.src/gateway/server-methods/chat.directive-tags.test.ts— focusedchat.sendregression coverage for fallback, oversize pass-through, and fail-closed cases.