Skip to content

fix(sandbox): resolve bare upload handles to staged inbound media - #129269

Merged
obviyus merged 1 commit into
openclaw:mainfrom
Finn763:fix/sandbox-image-bare-upload-handle-129084
Aug 30, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
Finn763:fix/sandbox-image-bare-upload-handle-129084

Conversation

@Finn763

@Finn763 Finn763 commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Sandboxed agents could not inspect an uploaded image when the model used its bare file_<id> handle. The image tool resolved that handle at the workspace root and returned ENOENT, even though inbound staging had copied the image into the private sandbox input directory.

PR #122031 established the contract: managed inbound media references remain available for later inspection.

Root cause

The staging producer knew the exact private path, but tool construction discarded that mapping. The stale patch scanned a former flat media/inbound layout and added directory-listing APIs. Current staging uses marker-owned media/inbound/openclaw-staged-<id>/input-<name> directories, so that scan could not own the mapping.

Fix

  • Mark producer-staged media facts explicitly.
  • Build one bounded alias-to-path map from those facts during attempt preparation.
  • Carry the map into sandbox media tools.
  • Resolve only exact file_ aliases, reject ambiguous aliases, and keep an existing workspace file authoritative.
  • Keep canonical media://inbound/... handling unchanged.

No directory scan, extension allowlist, filesystem bridge API, config change, or documented behavior change is added.

Evidence

  • Exact-main red at 0320297d7a1573c08cfaab781f93bd57dc4a694b: a real Docker sandbox staged a 519-byte JPEG, view_image("file_proof") returned ENOENT, and the exact staged path read with JPEG signature ffd8ff.
  • Exact-head green at aa4a2f88049a37af4814d68ab87f52b3f0ac2f7c: the same Docker and image-tool flow loaded the 519-byte JPEG from the producer path through the bare handle.
  • Focused suites: 494 tests passed across staging, tool assembly, sandbox path resolution, native image hydration, view_image, PDF, and media-generation references.
  • All permitted changed-scope checks passed. Hosted CI owns the required TypeScript checks for this host.

Scope

  • Production: +127/−76 lines, net +51. One shared sandbox-media configuration replaces five duplicate tool-specific builders and carries the producer-owned mapping.
  • Tests: +147/−1 lines, net +146. The image regression failed on pre-fix code for the expected workspace-root ENOENT; PDF and generation references cover the shared sibling path.

Closes #129084

@Finn763
Finn763 requested a review from a team as a code owner August 25, 2026 11:23
@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added docker Docker and sandbox tooling agents Agent runtime and tooling size: M labels Aug 25, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 8:05 AM ET / 12:05 UTC.

ClawSweeper review

What this changes

The PR carries staged upload-handle mappings into sandbox image, PDF, and generation tools so bare handles resolve to their staged files.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The PR remains necessary and is a correct producer-owned repair for the linked sandbox upload failure. No introduced correctness finding was found; wait for exact-head CI to finish before merge.

Priority: P1
Reviewed head: aa4a2f88049a37af4814d68ab87f52b3f0ac2f7c

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong Docker before/after evidence and cross-boundary sibling coverage support a clean repair.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied Docker terminal trace exercises the changed staging-to-image-tool path on the exact head and reports the bare JPEG handle changing from current-main ENOENT to a successful read; focused tests supplement producer, resolver, PDF, and generation-tool coverage.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied Docker terminal trace exercises the changed staging-to-image-tool path on the exact head and reports the bare JPEG handle changing from current-main ENOENT to a successful read; focused tests supplement producer, resolver, PDF, and generation-tool coverage.
Evidence reviewed 5 items Current main still has the failure path: Current main stages a private file path but does not mark it or pass an alias map into tool construction; its resolver leaves a bare handle as a direct workspace-relative path.
Producer-owned mapping: The branch accepts only successfully staged file_ paths under a valid staging directory, maps exact and extensionless aliases, and removes ambiguous aliases.
Complete tool propagation: The embedded attempt creates the per-turn map, then the shared tool factory supplies it to image, PDF, image-generation, video-generation, and music-generation tools.
Findings None None.
Security None None.

How this fits together

Inbound uploads are copied into a private sandbox workspace before agent tools read them. The embedded runner builds the tool set for that turn and now carries the staging producer’s exact handle-to-path facts into media resolution.

flowchart LR
  Upload[Inbound upload]
  Stage[Sandbox staging]
  Fact[Staged media fact]
  Map[Turn alias map]
  Runner[Embedded runner]
  Tool[Media tool]
  Read[Sandbox file read]
  Upload --> Stage --> Fact --> Map --> Runner --> Tool --> Read
Loading

Before merge

  • Resolve merge risk (P1) - Required exact-head CI is still incomplete and must finish successfully before merge.
Agent review details

Security

None.

PR surface

Source +51, Tests +146. Total +197 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 14 127 76 +51
Tests 4 147 1 +146
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 274 77 +197

Review metrics

Metric Value Why it matters
Production vs test delta production +127/−76; tests +147/−1 The production delta carries one producer fact across the shared tool boundary while replacing five local sandbox builders; tests cover producer, resolver, and sibling tools.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #129084
Summary: This PR is the explicit candidate fix for the reported bare sandbox-upload handle failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the producer-owned per-turn mapping after exact-head CI is green, retaining direct workspace-file precedence and ambiguous-alias rejection.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge the producer-owned per-turn mapping after exact-head CI is green, retaining direct workspace-file precedence and ambiguous-alias rejection.

Do we have a high-confidence way to reproduce the issue?

Yes, source-reproducible: current main treats the bare handle as a direct workspace path, while the supplied Docker trace reports ENOENT before this branch and a successful staged-file read after it.

Is this the best way to solve the issue?

Yes: preserving the staging producer’s exact per-turn fact is safer and more maintainable than rediscovering files by scanning the sandbox workspace.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a8c8c8270836.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P1: The PR addresses a current sandbox-upload failure that prevents agents from inspecting uploaded media.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied Docker terminal trace exercises the changed staging-to-image-tool path on the exact head and reports the bare JPEG handle changing from current-main ENOENT to a successful read; focused tests supplement producer, resolver, PDF, and generation-tool coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Docker terminal trace exercises the changed staging-to-image-tool path on the exact head and reports the bare JPEG handle changing from current-main ENOENT to a successful read; focused tests supplement producer, resolver, PDF, and generation-tool coverage.

Evidence

What I checked:

Likely related people:

  • Eden: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-08-25T11:30:49.810Z sha a9c6abeff2fc96a5568c73830ae98c2abb27000b :: needs real behavior proof before merge. :: [P2] Do not treat a failed direct stat as a missing workspace file
  • reviewed 2026-08-25T12:35:14.327Z sha fa6a63f0fdf80bc68cff727dd5b266ea7bc8484c :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T13:40:21.509Z sha c41b5b9fcea1e33effdf42245fbe137d9b83ce8a :: needs real behavior proof before merge. :: [P1] Resolve staged extensions from the producer contract
  • reviewed 2026-08-25T15:26:38.821Z sha 3331862f2351b08f37559c991377498a65dd0911 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-26T19:31:44.355Z sha 7a2f11e :: needs changes before merge. :: [P1] Restrict staged fallback to upload handles
  • reviewed 2026-08-26T21:08:09.730Z sha d751514 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-30T10:57:08.362Z sha 909c7369801926c977185b2a871bc18c3c7e561b :: needs changes before merge. :: [P1] Propagate staged aliases to every sandbox media tool
  • reviewed 2026-08-30T11:54:53.907Z sha ff25eb7b4f8798a8fe51b7d72a237c61dc2857a8 :: needs maintainer review before merge. :: none

@Finn763

Finn763 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 25, 2026
@Finn763

Finn763 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the controlled JPG/PNG test in #129084 — the split was real, and it exposed a gap in the first version of this fallback. The mechanism:

  • Inbound staging copies each upload into media/inbound/ inside the sandbox workspace preserving the uploaded basename, including its extension (allocateStagedFileName in src/auto-reply/reply/stage-sandbox-media.ts). A .jpg upload therefore lands as media/inbound/file_<id>.jpg.
  • The earlier fallback matched staged files verbatim against the handle the agent passed. A bare file_<id> reference has no .jpg, so the staged twin was never found and the read hit ENOENT at the workspace root — exactly the JPG failure you measured. The PNG flow worked because the reference it resolved already carried .png (or matched the staged name verbatim), so the lookup hit.

So it is not format-specific handling in the media store — it is a landed-filename vs handle-match gap: the fallback required the staged filename to equal the bare handle character-for-character.

The fix (c41b5b9fcea) closes that gap:

  1. The staged fallback first tries the verbatim staged name (unchanged behavior).
  2. For handles without an extension, it then probes same-handle handle.<ext> variants (common upload extensions, .jpg first among them), each stat-verified as a regular file under the sandbox media/inbound/ dir before being accepted.
  3. The workspace boundary guard still runs on the chosen staged path; direct workspace targets remain authoritative, and an existing-but-unreadable direct file still fails loud with its original error.

Regression coverage added for the JPG-with-extension case (file_upload-1 → media/inbound/file_upload-1.jpg), verbatim precedence, all-miss workspace-relative behavior, and skipping non-regular-file variants — src/agents/sandbox-media-paths.test.ts passes 29/29 locally. The check-lint failure was oxfmt --check flagging this same test file's formatting, fixed in the same commit.

@Finn763

Finn763 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

CI triage: checks-node-compact-large failures are a pre-existing main-branch red window

The failing test shards in this run are not caused by this PR. Evidence:

  • checks-node-compact-large-10 (job 97801961570) fails here with exactly two tests:

    1. src/agents/command/model-selection.turn-model-differential.test.ts → pins observed 'parent persisted override versus chan…' behavior — Error: Test timed out in 120000ms (test file line 225)
    2. src/agents/runtime-plan/prepare-auth.test.ts → keeps profile auth ahead of a literal provider apiKey fallback — Error: [vitest] No "resolveProviderDeprecatedAuthProfileIds" export is defined on the "../../plugins/provider-runtime.js" mock (src/agents/model-auth-provider.ts:124)
  • PR fix(config): bound JSON nesting before parsing to prevent native stack overflow #129324 (run 32848833389, job 97804925361, same base) fails the identical two tests in the same shard — two independent PRs, same failures.

  • This PR's diff touches neither test file nor src/agents/model-auth-provider.ts nor plugins/provider-runtime.

  • Main is currently red on these shards too: main run 32853196191 (latest main) has 13+ failed checks-node-compact-* shards.

Disposition: not caused by this PR; no fix included here. These shards should clear once main is green.

@Finn763

Finn763 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

CI triage — shard failures trace to main's red window (now recovered), not this diff

Completed CI runs don't auto-refresh, so a re-run of the failed jobs against current main should turn these checks green. No product failure is attributable to this PR's changes.

@Finn763

Finn763 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Hi @steipete @vincentkoc — follow-up on my CI triage comment above: main's red window is now closed.

push-to-main CI has been fully green since 12:38Z today:

This PR's head (3331862f2351) is unchanged since the failing run; every red check (check-lint-core-3, checks-node-compact-large-3/4/9/10/11/17/29, small-5/18/20/21/22/23/45, ci-gate) traces to that window, not this diff. "PR context and evidence" passes on this PR.

As an external contributor I have no write access to rerun failed jobs myself — could you please rerun the failed jobs on this PR? Thanks!

@Finn763
Finn763 force-pushed the fix/sandbox-image-bare-upload-handle-129084 branch from 3331862 to 7a2f11e Compare August 26, 2026 19:23
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Aug 26, 2026
@obviyus
obviyus force-pushed the fix/sandbox-image-bare-upload-handle-129084 branch from d751514 to 909c736 Compare August 30, 2026 10:46
@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed size: XL labels Aug 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@obviyus
obviyus force-pushed the fix/sandbox-image-bare-upload-handle-129084 branch from 909c736 to ff25eb7 Compare August 30, 2026 11:49
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@obviyus
obviyus force-pushed the fix/sandbox-image-bare-upload-handle-129084 branch from ff25eb7 to aa4a2f8 Compare August 30, 2026 11:58
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 30, 2026
@obviyus
obviyus requested a review from steipete August 30, 2026 12:15
@obviyus

obviyus commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

@steipete @vincentkoc @joshavant — security-owner review requested for the CODEOWNERS sandbox path. Exact head aa4a2f88049a37af4814d68ab87f52b3f0ac2f7c has green CI, clear ClawSweeper security review, and Docker red/green proof for the bare uploaded-image handle. Could one of you review this head? Thanks.

@obviyus
obviyus merged commit 0594a10 into openclaw:main Aug 30, 2026
264 of 266 checks passed
@obviyus

obviyus commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Finn763!

Proof: In a real Docker sandbox, a 519-byte uploaded JPEG referenced by its bare file_proof handle now loads through view_image with JPEG signature ffd8ff; the same flow on current main returned workspace-root ENOENT.

  • Bug: Bare uploaded-media handles resolved at the sandbox workspace root instead of the private staged input path.
  • Fix: The staging producer now carries an exact, bounded alias map into every sandbox media tool while direct workspace files remain authoritative.

Example

Before After
view_image("file_proof") returned ENOENT view_image("file_proof") loads the staged JPEG

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
Carry the staging producer's exact upload-handle mapping into every sandbox media tool. Bare handles now resolve to verified staged inputs without directory scans or extension guesses, while direct workspace files remain authoritative and ambiguous aliases fail closed.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docker Docker and sandbox tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: image tool resolves sandbox upload file_ reference as workspace-relative path → ENOENT

2 participants