Skip to content

refactor(media): reuse guarded remote media downloads - #117771

Merged
steipete merged 1 commit into
mainfrom
codex/goal100k-provider-prod-wave8-2d45
Aug 2, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/goal100k-provider-prod-wave8-2d45

Conversation

@steipete

@steipete steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Remote media saved through the media store used a second handwritten HTTP downloader instead of the canonical guarded media-fetch owner. This duplicated redirect, DNS, timeout, size-limit, streaming, and temporary-file policy and made those safety rules easier to drift.

Why This Change Was Made

Route saveMediaSource URL inputs through the existing SSRF-guarded saveRemoteMedia owner, retain a narrow lazy module boundary to avoid the store/fetch import cycle, and delete the obsolete downloader. A small fetch adapter immediately cancels ignored error bodies, preserving the existing prompt rejection even when response-body cancellation itself never resolves.

User Impact

Remote media downloads retain strict DNS and redirect protection, cross-origin credential stripping, configured size and timeout limits, atomic private-file publication, MIME/extension behavior, and immediate rejection of hostile HTTP error responses. This removes 201 handwritten production lines and 592 lines overall without changing the shipped media-store result contract.

Evidence

  • Blacksmith focused matrix: 258 tests passed across canonical fetch (77), store timeout delegation (1), public redirect/error boundaries (7), SSRF guard (99), and managed-image gateway integration (74).
  • A deterministic public-boundary test proves a 500 response with a never-resolving ReadableStream.cancel() still rejects immediately.
  • Both independent xhigh reviews explicitly reconciled all seven removed duplicate-owner registrations against retained canonical and public-boundary assertions; no security or timeout coverage was lost.
  • Full remote pnpm check:changed: passed (17m31s).
  • Full remote pnpm build: passed (2m52s), including plugin assets, runtime postbuild, plugin SDK exports, and the UI build.
  • src/media/fetch.ts and src/media/fetch.test.ts remain untouched, avoiding unrelated active PR ownership.

@openclaw-barnacle openclaw-barnacle Bot added size: XL maintainer Maintainer-authored PR labels Aug 2, 2026
@steipete steipete self-assigned this Aug 2, 2026
@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Aug 2, 2026
@clawsweeper

clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 1, 2026, 11:30 PM ET / August 2, 2026, 03:30 UTC.

ClawSweeper review

What this changes

The branch routes remote URL inputs to the media store through the canonical SSRF-guarded remote-media saver, removes the older handwritten downloader, and updates focused delegation and boundary tests.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

The PR appears to be the right owner-boundary refactor: current main has a separate media-store HTTP downloader while src/media/fetch.ts already owns guarded remote-media ingestion. The patch removes that duplicate path and retains redirect, header, timeout, size, and atomic-publication coverage; no discrete correctness defect was found. Keep it open for the assigned maintainer/security-boundary review and completion of the currently running checks.

Priority: P2
Reviewed head: 1ede39da32f50dea42abf08726ef933546f38b11

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A well-scoped owner-boundary refactor with focused safety coverage and strong reported validation; merge readiness depends on the remaining exact-head checks and security-path review.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-labeled refactor is exempt from the external-contributor proof gate; the PR body supplies focused Blacksmith and exact-head validation evidence, including a deterministic hostile-response boundary check.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-labeled refactor is exempt from the external-contributor proof gate; the PR body supplies focused Blacksmith and exact-head validation evidence, including a deterministic hostile-response boundary check.
Evidence reviewed 6 items Duplicate owner on current main: Current main sends URL inputs from saveMediaSource to downloadMediaToFile, while the separate src/media/fetch.ts path already performs guarded remote fetches and stores the response. Consolidating these two paths removes duplicate network-policy ownership.
Adapter preserves the canonical boundary: The proposed adapter calls saveRemoteMedia with the existing source URL, headers, file-path hint, byte limit, redirect cap, deadlines, subdirectory, and test-only pinned lookup. It cancels ignored non-success response bodies without awaiting cancellation, so canonical status handling remains prompt.
Focused public-boundary coverage: The branch tests delegation parameters, unsafe subdirectories before fetch, URL-suffix preservation, non-resolving error-body cancellation, and cross-origin redirect header stripping through the canonical guarded path.
Findings None None.
Security None None.

How this fits together

The media store accepts local paths and remote URLs and persists validated private media for plugin and runtime consumers. Remote URLs pass through network protections before the resulting file is atomically saved and exposed through the store result contract.

flowchart LR
  A[Remote media URL] --> B[Media store]
  B --> C[Lazy remote-media adapter]
  C --> D[Guarded fetch and redirect policy]
  D --> E[Validated private media file]
  E --> F[Plugin and runtime consumers]
Loading

Before merge

  • Add real behavior proof - Not applicable: This maintainer-labeled refactor is exempt from the external-contributor proof gate; the PR body supplies focused Blacksmith and exact-head validation evidence, including a deterministic hostile-response boundary check.
  • Resolve merge risk (P1) - This is a security-boundary refactor: a difference in the adapter’s dispatcher, proxy, DNS, redirect, or header behavior could affect existing remote-media integrations even though the focused tests cover the principal paths.
  • Resolve merge risk (P1) - The PR is cleanly mergeable but behind current main, and its larger validation matrix was still running at review time; refresh the exact-head review after those checks finish.
  • Complete next step (P2) - No mechanical repair is indicated; the remaining action is assigned maintainer review of a remote-media security boundary after the exact-head checks complete.
Agent review details

Security

None.

PR surface

Source -204, Tests -388. Total -592 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 4 87 291 -204
Tests 2 168 556 -388
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 255 847 -592

Review metrics

Metric Value Why it matters
Remote downloader ownership 1 handwritten owner removed; 1 canonical guarded owner reused Remote URL handling is security-sensitive, so reducing two policy implementations to one lowers future redirect, DNS, timeout, and header-policy drift.

Merge-risk options

Maintainer options:

  1. Confirm guarded-fetch parity before merge (recommended)
    Finish the exact-head checks and confirm that the adapter preserves configured dispatcher, redirect, DNS, proxy, header-stripping, and timeout behavior for existing remote-media callers.
  2. Retain the legacy downloader
    Pause this refactor if maintainers need the media store to preserve a behavior the canonical guarded fetch owner cannot express without a new shared contract.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require a refreshed exact-head security-path review after the remaining checks complete; add a focused dispatcher or proxy regression test only if that review exposes a coverage gap.

Technical review

Best possible solution:

Keep one canonical guarded remote-media ingestion flow, retain the small lazy boundary that prevents the store/fetch cycle, and land only after the exact head’s remaining checks and security-path review confirm no dispatcher or upgrade regression.

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

Not applicable as a defect reproduction: this PR refactors an existing remote-media path. The branch supplies focused source-level boundary coverage for the changed behavior, but this review did not execute the untrusted PR branch.

Is this the best way to solve the issue?

Yes. Current main has two owners for the same guarded remote-download responsibility; routing the store through saveRemoteMedia is more maintainable than retaining a second downloader, while the lazy adapter avoids a direct import cycle.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a substantial internal remote-media safety refactor with bounded user impact rather than an active user-facing outage.
  • add merge-risk: 🚨 compatibility: Existing callers of the public media-store URL entry point move from a dedicated downloader to the shared guarded-fetch implementation and need exact-head upgrade-path confirmation.
  • add merge-risk: 🚨 security-boundary: The diff changes the implementation path that enforces SSRF, redirect, and cross-origin credential behavior for untrusted remote URLs.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-labeled refactor is exempt from the external-contributor proof gate; the PR body supplies focused Blacksmith and exact-head validation evidence, including a deterministic hostile-response boundary check.

Label justifications:

  • P2: This is a substantial internal remote-media safety refactor with bounded user impact rather than an active user-facing outage.
  • merge-risk: 🚨 security-boundary: The diff changes the implementation path that enforces SSRF, redirect, and cross-origin credential behavior for untrusted remote URLs.
  • merge-risk: 🚨 compatibility: Existing callers of the public media-store URL entry point move from a dedicated downloader to the shared guarded-fetch implementation and need exact-head upgrade-path confirmation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-labeled refactor is exempt from the external-contributor proof gate; the PR body supplies focused Blacksmith and exact-head validation evidence, including a deterministic hostile-response boundary check.

Evidence

What I checked:

  • Duplicate owner on current main: Current main sends URL inputs from saveMediaSource to downloadMediaToFile, while the separate src/media/fetch.ts path already performs guarded remote fetches and stores the response. Consolidating these two paths removes duplicate network-policy ownership. (src/media/store.ts:537, 14322647cd6c)
  • Adapter preserves the canonical boundary: The proposed adapter calls saveRemoteMedia with the existing source URL, headers, file-path hint, byte limit, redirect cap, deadlines, subdirectory, and test-only pinned lookup. It cancels ignored non-success response bodies without awaiting cancellation, so canonical status handling remains prompt. (src/media/store.remote.runtime.ts:13, 1ede39da32f5)
  • Focused public-boundary coverage: The branch tests delegation parameters, unsafe subdirectories before fetch, URL-suffix preservation, non-resolving error-body cancellation, and cross-origin redirect header stripping through the canonical guarded path. (src/media/store.redirect.test.ts:1, 1ede39da32f5)
  • Dependency/runtime-fetch contract: The adapter uses the repository runtime-fetch helper, whose documented implementation preserves test-injected global fetches and otherwise uses the runtime dispatcher; this keeps the guarded fetch path compatible with the existing dispatcher-aware request init. (src/infra/net/runtime-fetch.ts:112, 14322647cd6c)
  • Current-media provenance: Blame attributes the current saveMediaSource remote branch and canonical saveRemoteMedia section to the recent media consolidation commit, which added both surfaces together; that makes the duplicate-owner comparison a current-main behavior assessment rather than an inferred historical contract. (src/media/fetch.ts:676, 65d64818bb6b)
  • Submitted validation evidence: The PR body reports a focused Blacksmith matrix, a passing remote pnpm check:changed, and a passing remote build. GitHub check context also shows the real-behavior-proof check passed, while the remaining full matrix is still in progress. (1ede39da32f5)

Likely related people:

  • Yiğit ERDOĞAN: Current-main blame ties both the canonical remote saver and the store URL branch to the same recent media consolidation commit. (role: recent media-path contributor; confidence: medium; commits: 65d64818bb6b; files: src/media/fetch.ts, src/media/store.ts, src/media/store.download.ts)

Rank-up moves

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

  • Let the in-progress exact-head validation finish, then refresh the guarded-fetch parity review before merging.

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.

@steipete
steipete merged commit 2bbc2f5 into main Aug 2, 2026
131 of 139 checks passed
@steipete
steipete deleted the codex/goal100k-provider-prod-wave8-2d45 branch August 2, 2026 03:34
@steipete

steipete commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

1 participant