Skip to content

fix(media): decode file URLs at the native reply boundary - #133146

Merged
steipete merged 3 commits into
mainfrom
codex/qa-20260830-media-file-url
Aug 30, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/qa-20260830-media-file-url

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #133144

What Problem This Solves

Legacy final-reply attachments fail when a valid local file URL contains an encoded filename or a localhost authority. A file named café 100% image.png loads through the direct media loader, but prefix stripping turns its URL into a nonexistent percent-encoded filename or a relative localhost/... path.

Why This Change Was Made

The shared parser now preserves file URL references. The existing native reply-directive producer converts valid local URLs with the canonical file URL helper before reply policy and attachment deduplication. That preserves the legacy directive-to-path contract without importing Node filesystem code into the browser or copying a decoder. Raw structured host file URLs retain their existing reply policy, and malformed URLs, remote hosts, and encoded separators still reach native rejection.

Production LOC is -1 (+15/-16): URL conversion moves to its native owner, and that owner's silent-text handling returns the conditional value directly with its explanatory comment retained. Test LOC is +95 (+116/-21). No new dependency, configuration, public API, persistent state, or security policy is introduced.

User Impact

Legacy MEDIA: replies can load local files with spaces, Unicode, literal percent signs, and localhost file URLs. Captions, filenames, MIME types, and file bytes are preserved. Equivalent explicit local paths and directive URLs still produce one attachment. Existing structured-file-URL restrictions and sandbox mapping remain intact.

Evidence

  • Before: two real-file tests failed on main 3f1c84c706bf1e4c8bc7b2ab106ab96ff1fe6ddb: encoded filenames produced not-found; localhost produced path-not-allowed. Direct URL loading succeeded.
  • After: the nine-file owner/sibling suite passed 467 tests, with one Windows-only test skipped on macOS. It covers parsing, real media loading, reference comparison, reply policy, outbound deduplication, Docker/OpenShell/custom sandbox mapping, Windows drive mapping, and browser message normalization/local-media handling.
  • An owned temporary PNG passed the actual reply producer → reply media normalizer → attachment staging flow for plain, encoded, localhost, and uppercase single-slash URLs. Each preserved caption, filename, image/png, and exact bytes; the same raw structured host URL remained blocked, and mixed explicit/directive references deduplicated to one attachment. No provider or channel credentials were used.
  • The Control UI production build passed, including sidecar and performance gates. Its existing local-media renderer accepts opaque file URLs; no Node shim or browser decoder was added.
  • All local changed-file checks passed across the initial run and its focused continuation: structural guards, core production/test type checking, formatting, exact-file lint, storage/media/import-cycle/auth guards. The initial run stopped at two lint issues; corrected lint and the eight remaining guards passed without repeating already-green type checks. The final cleanup also passed 198 parser/UI tests, the four-case real reply-staging probe, and fresh full-candidate autoreview. Exact-head hosted CI remains required before landing.
  • Fresh structured autoreview is scoped-clean at its default P0 threshold. A separate read-only Codex review found no actionable P0–P2 issues. The lead independently inspected the owner boundary and reran the four-case real reply-staging proof successfully.
  • Exact submitted head: c2f67f402e9a41e3b5e2aa11443a9894bf174f0f, a byte-for-byte patch-identical rebase onto repaired main be5e79ca4713c33a11ccd56b2d728c19f0779f3d. The refreshed head passed 213 focused parser/reply-policy/outbound tests, the four-case real attachment-staging proof, and fresh autoreview. An obsolete CI run was canceled after its preflight proved it still checked out the earlier broken-main merge tree; new-head hosted CI remains required.

Dependency behavior was checked directly in installed @openclaw/fs-safe 0.5.6. Stable v2026.6.9 already distinguished legacy directive-to-path conversion from raw structured file URL policy; #121676 retained that distinction when broadening URL spelling. The original prefix-stripping introduction is unknown. Windows-native execution and an authenticated channel send were not run locally; the real proof covers the shared filesystem loading and reply staging boundary.

The latest ClawSweeper localhost-preview finding was checked through the actual exported UI policy and proxy helpers: local authorities normalize to an empty hostname before the existing guard. Lowercase/uppercase localhost inside allowed roots pass; remote hosts, outside paths, and encoded separators remain rejected. Proxy URLs retain the exact source and media ticket. The proposed production policy change is skipped as a false positive; the unchanged policy already satisfies that rank-up request.

@clawsweeper

clawsweeper Bot commented Aug 30, 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 app: web-ui App: web-ui size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 07:14
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 30, 2026, 3:44 AM ET / 07:44 UTC.

ClawSweeper review

What this changes

The PR preserves file: media references through shared parsing and converts safe local URLs to native paths before reply attachment staging.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the native reply conversion fixes the reported staging path, but the prior P2 Control UI localhost-preview blocker remains on the exact head.

Priority: P2
Reviewed head: 7d9084fa160079282460a2e8dbbd22231fb58d31

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The native repair and focused regressions are useful, but an existing P2 preview-path regression remains unresolved.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports an after-fix native reply-staging run, which does not cover the remaining Control UI preview admission branch.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports an after-fix native reply-staging run, which does not cover the remaining Control UI preview admission branch.
Evidence reviewed 5 items Introduced parser behavior: The PR now retains the original file://localhost/... source in parsed media output, which exposes that form to downstream consumers instead of the former stripped path.
Current Control UI rejection: Current main rejects every file URL with a hostname before allowed-root comparison, so canonical localhost references become unavailable even though the Gateway accepts them.
Gateway supports the intended form: The Control UI Gateway route sends file URLs through the canonical safe converter before allowed-root checks, so the missing behavior is the browser-side preview admission policy.
Findings 1 actionable finding [P2] Support localhost URLs in the Control UI preview path
Security None None.

How this fits together

Assistant reply text is parsed into media references, then native reply handling applies local-file policy and stages attachments for channel delivery. The Control UI separately proxies local assistant-media references for chat previews.

flowchart LR
  A[Assistant reply text] --> B[Shared media parser]
  B --> C[Native reply handling]
  C --> D[Local-file policy]
  D --> E[Attachment staging]
  B --> F[Control UI preview policy]
  F --> G[Gateway media proxy]
Loading

Before merge

  • Support localhost URLs in the Control UI preview path (P2) - The changed parser now emits file://localhost/... as an attachment, but the Control UI rejects every file URL with a hostname before it can request Gateway metadata. The Gateway itself safely converts this canonical local form, so a chat preview is marked unavailable. Permit only localhost beside the hostless form and cover allowed-root and proxy behavior; this is the still-unfixed prior review finding.
  • Resolve merge risk (P1) - The PR broadens parser output to canonical localhost file URLs while the Control UI still classifies that form as outside allowed folders, leaving delivery and chat-preview behavior inconsistent.
  • Complete next step (P2) - A narrow, mechanical UI policy repair and focused boundary test can address the remaining blocker without changing product direction.

Findings

  • [P2] Support localhost URLs in the Control UI preview path — src/media/parse.ts:652
Agent review details

Security

None.

PR surface

Source -1, Tests +95. Total +94 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 2 15 16 -1
Tests 5 116 21 +95
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 131 37 +94

Review metrics

Metric Value Why it matters
Production vs test delta production -1 (+15/-16); tests +95 (+116/-21) The repair stays net-negative in production; the remaining change should add focused UI boundary coverage rather than more parser-only cases.

Merge-risk options

Maintainer options:

  1. Complete localhost preview support (recommended)
    Permit only localhost in the Control UI local-file preview policy and add allowed-root plus proxy-path coverage before merge.

Technical review

Best possible solution:

Allow only the canonical localhost file authority alongside hostless local file URLs in the Control UI preview policy, retain remote-host and encoded-separator rejection, and cover the complete proxy path.

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

Yes—source inspection gives a high-confidence path: the PR emits file://localhost/..., while the Control UI rejects any hostname before proxying it. The supplied staging proof does not exercise that preview-policy branch.

Is this the best way to solve the issue?

No. Moving decoding to the native owner is the right delivery boundary, but the change is incomplete until the Control UI recognizes the same safe localhost form and continues rejecting remote authorities.

Full review comments:

  • [P2] Support localhost URLs in the Control UI preview path — src/media/parse.ts:652
    The changed parser now emits file://localhost/... as an attachment, but the Control UI rejects every file URL with a hostname before it can request Gateway metadata. The Gateway itself safely converts this canonical local form, so a chat preview is marked unavailable. Permit only localhost beside the hostless form and cover allowed-root and proxy behavior; this is the still-unfixed prior review finding.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. This shared final-reply attachment change can be user-visible when a Telegram reply contains the newly supported local media reference.

Label justifications:

  • P2: The patch repairs a bounded attachment compatibility defect but currently leaves the affected Control UI preview path unavailable.
  • merge-risk: 🚨 compatibility: Accepted local-file URL spelling changes require the delivery and preview consumers to agree for existing chat behavior to remain coherent.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This MEMBER-authored PR is exempt from the external-contributor proof gate; its body nevertheless reports an after-fix native reply-staging run, which does not cover the remaining Control UI preview admission branch.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. This shared final-reply attachment change can be user-visible when a Telegram reply contains the newly supported local media reference.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/components/chat-message-local-media.test.ts.
  • [P1] node scripts/run-vitest.mjs src/media/parse.test.ts src/media/web-media.test.ts src/auto-reply/reply/reply-media-paths.test.ts.
  • [P1] git diff --check.

What I checked:

  • Introduced parser behavior: The PR now retains the original file://localhost/... source in parsed media output, which exposes that form to downstream consumers instead of the former stripped path. (src/media/parse.ts:652, 94e156b43bee)
  • Current Control UI rejection: Current main rejects every file URL with a hostname before allowed-root comparison, so canonical localhost references become unavailable even though the Gateway accepts them. (ui/src/pages/chat/components/chat-message-local-media.ts:41, f1d2c5b91f80)
  • Gateway supports the intended form: The Control UI Gateway route sends file URLs through the canonical safe converter before allowed-root checks, so the missing behavior is the browser-side preview admission policy. (src/gateway/control-ui.ts:233, 7d9084fa1600)
  • Coverage gap: The added UI test only verifies message normalization retains localhost as an attachment; it does not exercise allowed-root admission, metadata fetch, or proxy rendering. (ui/src/lib/chat/message-normalizer.test.ts:640, 7d9084fa1600)
  • Dependency signal: The changed native owner imports the local re-export of the fs-safe file-URL conversion contract; the dependency package itself is unavailable in this read-only checkout, so this review does not make an independent dependency-contract claim. (src/infra/local-file-access.ts:10, 7d9084fa1600)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Allow only localhost in Control UI local-file preview admission while preserving remote-host and encoded-separator rejection.
  • Add a focused allowed-root and Gateway-proxy test for a localhost file URL.

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 (1 earlier review cycle)
  • reviewed 2026-08-30T07:35:37.976Z sha 7d9084fa160079282460a2e8dbbd22231fb58d31 :: needs changes before merge. :: [P2] Support localhost URLs in the Control UI preview path

@steipete
steipete marked this pull request as draft August 30, 2026 07:38
@steipete
steipete marked this pull request as ready for review August 30, 2026 07:38
@clawsweeper clawsweeper Bot added the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

The localhost preview finding does not reproduce through the actual UI owner. new URL("file://localhost/tmp/media-preview-owned/image.png").hostname is the empty string; the URL parser canonicalizes the local authority before the hostname guard. The same holds for uppercase LOCALHOST.

I ran the exported isLocalAttachmentPreviewAllowed and buildAssistantAttachmentUrl functions on the reviewed repair: lowercase/uppercase localhost and single-slash file URLs inside an allowed root pass; remote hosts, paths outside that root, and encoded / or \ separators remain rejected. Proxy construction preserves the exact source and media ticket. The existing parser/UI regressions also pass.

Rank-up disposition: skip the proposed production policy change because the existing policy already admits localhost; adding an exception would duplicate the URL parser's contract. The focused actual-owner proof covers the requested allowed-root/proxy boundary and negative controls, so no additional test-only head change is needed for this false positive. The repair remains production net -1.

The branch is being refreshed onto the separately repaired main commit without changing the patch. Final hosted CI and native landing gates still apply.

@steipete
steipete force-pushed the codex/qa-20260830-media-file-url branch from 7d9084f to c2f67f4 Compare August 30, 2026 07:48
@steipete
steipete merged commit 8f71fb2 into main Aug 30, 2026
251 of 253 checks passed
@steipete
steipete deleted the codex/qa-20260830-media-file-url branch August 30, 2026 08:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
…33146)

* fix(media): decode file URLs at the native reply boundary

* test(media): consolidate file URL cases and satisfy lint

* test(media): simplify the shared attachment table assertion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Legacy media directives corrupt encoded local file URLs

1 participant