Skip to content

fix(cli): bound node camera URL downloads - #103266

Merged
steipete merged 5 commits into
openclaw:mainfrom
mikasa0818:fix/nodes-camera-download-timeout
Jul 10, 2026
Merged

steipete merged 5 commits into
openclaw:mainfrom
mikasa0818:fix/nodes-camera-download-timeout

Conversation

@mikasa0818

Copy link
Copy Markdown
Contributor

What Problem This Solves

  • Fixes an issue where users running openclaw nodes camera snap or clip with a URL-backed payload could have the CLI remain occupied indefinitely when the node server sent valid response headers but then streamed too slowly or never completed the body.
  • Affected surface / workflow: node camera URL artifact download in writeUrlToFile().
  • Root cause, in product terms: the downloader enforced HTTPS, host/redirect policy, Content-Length, and streamed byte caps, but omitted timeoutMs from fetchWithSsrFGuard(). The guard therefore had no request-lifetime abort to interrupt a stalled body read.
  • Why it matters / User impact: a node-controlled media response could hold the camera command and its network/file resources indefinitely.

Why This Change Was Made

  • Fix classification: Root cause fix.
  • Complete shipped solution: pass a bounded total request deadline into the existing guarded-fetch owner, retain that deadline through response-body consumption, and keep the existing partial-file cleanup path authoritative when the abort reaches reader.read().
  • Why this is root-cause fix: it closes the missing bound at the network owner already responsible for SSRF, redirects, dispatcher lifetime, and abort cleanup; it does not add a second downloader timer or catch-and-mask the hang.
  • Key design boundary / source of truth: fetchWithSsrFGuard() and buildTimeoutAbortSignal() own the request lifetime. The default is the existing bounded-media ceiling of 15 minutes rather than a short control-request deadline, while tests and direct callers can provide a smaller deadline.
  • Non-goals / what did not change: no changes to URL validation, allowed node host policy, redirect handling, the 250 MiB cap, base64 payloads, CLI flags, config, or gateway protocol.
  • Compatibility, merge-risk, or maintainer-decision notes: downloads that continue beyond 15 minutes now fail instead of remaining unbounded. A total deadline is intentional so a peer that emits tiny chunks forever still terminates. Fresh related-PR search found overlapping PR fix(nodes-camera): add timeout to URL media downloads #103019; latest origin/main at 6b90610cdb985e7413d43efd9ea64c7c4fd5ad89 still omitted the timeout. This patch differs by using the bounded-media ceiling and proving a post-header, continuously slow body plus file/socket cleanup.

User Impact

  • Users/operators/developers can now: rely on URL-backed node camera downloads eventually terminating even after a response body has started.
  • Existing behavior preserved: normal downloads, SSRF/HTTPS checks, node-host pinning, redirect validation, byte limits, and successful file output are unchanged.
  • What was not tested or remains unavailable: no physical paired camera node was available; the live proof exercised the real production downloader and guarded-fetch implementation against a controlled local HTTPS peer.

Evidence

  • Environment: Windows Git Bash; supported Node 24.4.1 for the focused repository test; local HTTPS server with an ephemeral self-signed certificate trusted only for the proof process.
  • Commands run after this patch:
    • npx -y [email protected] scripts/run-vitest.mjs src/cli/nodes-camera.test.ts
    • pnpm tsgo:core && pnpm tsgo:test:src
    • pnpm exec oxfmt --check --threads=1 src/cli/nodes-camera.ts src/cli/nodes-camera.test.ts
    • pnpm exec oxlint src/cli/nodes-camera.ts src/cli/nodes-camera.test.ts
    • git diff --check
    • production writeUrlToFile -> fetchWithSsrFGuard -> response body reader call against a local HTTPS server that flushed 200 headers, wrote a valid prefix, then emitted one byte every 25 ms without ending.
  • Key results / observations: focused test passed 29/29; core and source-test tsgo lanes passed; formatting, lint, and whitespace checks passed. In the live run, the server sent 74 slow chunks after valid headers; a configured 3000 ms deadline raised TimeoutError: request timed out after 3296 ms; the partial output did not exist afterward; the server observed response closure; open sockets after guarded-fetch release were 0.
  • Review findings addressed, if any: none on this branch. The proof specifically covers the real-behavior gap and short-total-timeout compatibility concern visible on related PR fix(nodes-camera): add timeout to URL media downloads #103019.
  • Regression guardrail: the new test asserts the default media deadline is passed to guarded fetch and that an abort during body consumption removes the partially written file.
  • Patch quality notes: two files only; no dependency, lockfile, config, protocol, or changelog changes.
  • Maintainer-ready confidence: high for the root cause, bounded lifetime, and cleanup behavior; physical node hardware remains the only proof gap.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S labels Jul 10, 2026
@steipete steipete self-assigned this Jul 10, 2026
@steipete
steipete requested a review from a team as a code owner July 10, 2026 04:25
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord channel: matrix Channel integration: matrix channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: voice-call Channel integration: voice-call app: android App: android app: ios App: ios app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core scripts Repository scripts commands Command implementations docker Docker and sandbox tooling agents Agent runtime and tooling channel: feishu Channel integration: feishu extensions: openai extensions: deepseek extensions: memory-wiki extensions: codex plugin: google-meet extensions: google extensions: xai labels Jul 10, 2026
@steipete

Copy link
Copy Markdown
Contributor

Land-ready maintainer pass complete.

  • The shared node-media URL writer now owns a fixed 15-minute deadline and requireHttps: true, so insecure redirects are rejected before dispatch and the guard remains active through body consumption.
  • Removed the test-only timeout override and duplicate hanging-stream harness; retained focused success-policy and partial-file cleanup proof after reading the fetch guard, Undici abort, dispatcher teardown, and all camera/photos callers.
  • Exact prepared head ee30439a361f341f8440f75df60b938ccb748eda passed full hosted CI: https://github.com/openclaw/openclaw/actions/runs/29070305200
  • Fresh autoreview, review artifacts, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 103266 passed. Current mobile nodes emit base64, so no physical-node URL payload was available; deterministic transport proof covers the shipped compatibility path.

Merging with contributor credit preserved. Thanks @mikasa0818.

@steipete
steipete merged commit 541c9f0 into openclaw:main Jul 10, 2026
113 of 118 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 10, 2026
* fix(cli): bound node camera URL downloads

* refactor(cli): enforce camera download policy at guard

* refactor(cli): enforce camera download policy at guard

* refactor(cli): enforce camera download policy at guard

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Jul 11, 2026
Add WebMediaOptions.timeoutMs passthrough and apply the shared bounded-media
ceiling (15 min, matching the canonical precedent in PR openclaw#103266) to the Tlon
download/upload fetch paths. Bounds endpoints that never respond, while
readIdleTimeoutMs continues to protect slow-but-progressing transfers.

- src/media/web-media.ts: forward timeoutMs through loadWebMediaInternal to
  readRemoteMediaBuffer / fetchWithSsrFGuard's abort signal.
- extensions/tlon: set a 15-min total deadline on downloadMedia and
  uploadImageFromUrl; their existing null / original-URL fallbacks now bound
  indefinite stalls.
- tests: switch the two exact-match Tlon option assertions to
  objectContaining and assert the new timeoutMs value; add a controlled
  stalled-endpoint test proving loadWebMediaRaw aborts a never-responding
  fetch at the timeoutMs deadline.

Co-Authored-By: Claude <[email protected]>
steipete pushed a commit to wangmiao0668000666/openclaw that referenced this pull request Jul 21, 2026
Apply the shared bounded-media ceiling (15 min, matching the canonical precedent
in PR openclaw#103266) to the three agent-tool remote-media callers (image, image-generate,
pdf) via the new REMOTE_MEDIA_TIMEOUT_MS constant, forwarded through loadWebMedia /
loadWebMediaRaw's timeoutMs seam. Bounds endpoints that never respond while
REMOTE_MEDIA_READ_IDLE_TIMEOUT_MS keeps protecting slow-but-progressing transfers.

This branch includes the WebMediaOptions.timeoutMs seam so it typechecks and stays
green as a standalone fork PR; it reduces to agent-tool-only once the canonical
seam+Tlon PR openclaw#103206 lands. The Tlon caller changes live in openclaw#103206 (the earlier
openclaw#103199 is closed as a subset).

- src/agents/tools/media-tool-shared.ts: export REMOTE_MEDIA_TIMEOUT_MS = 15*60_000.
- image-tool / image-generate-tool / pdf-tool: pass timeoutMs on remote (http) loads.
- src/media/web-media.ts: forward timeoutMs (shared seam; see openclaw#103206).
- tests: assert timeoutMs forwarding for all three agent tools.

Co-Authored-By: Claude <[email protected]>
steipete added a commit that referenced this pull request Jul 21, 2026
* fix(agent-tools): bound remote media fetches with a 15-min total timeout

Apply the shared bounded-media ceiling (15 min, matching the canonical precedent
in PR #103266) to the three agent-tool remote-media callers (image, image-generate,
pdf) via the new REMOTE_MEDIA_TIMEOUT_MS constant, forwarded through loadWebMedia /
loadWebMediaRaw's timeoutMs seam. Bounds endpoints that never respond while
REMOTE_MEDIA_READ_IDLE_TIMEOUT_MS keeps protecting slow-but-progressing transfers.

This branch includes the WebMediaOptions.timeoutMs seam so it typechecks and stays
green as a standalone fork PR; it reduces to agent-tool-only once the canonical
seam+Tlon PR #103206 lands. The Tlon caller changes live in #103206 (the earlier
#103199 is closed as a subset).

- src/agents/tools/media-tool-shared.ts: export REMOTE_MEDIA_TIMEOUT_MS = 15*60_000.
- image-tool / image-generate-tool / pdf-tool: pass timeoutMs on remote (http) loads.
- src/media/web-media.ts: forward timeoutMs (shared seam; see #103206).
- tests: assert timeoutMs forwarding for all three agent tools.

Co-Authored-By: Claude <[email protected]>

* fix(agent-tools): adopt canonical responseHeaderTimeoutMs seam from main

* test(agent-tools): cover media header deadlines

Lock the existing image, image-generation, and PDF remote-media call sites to the proposed header-only deadline and remove the PR-only proof script.\n\nCo-authored-by: wangmiao0668000666 <[email protected]>

* style: oxfmt

* fix(media): default stalled header deadline

Co-authored-by: wangmiao0668000666 <[email protected]>

---------

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

Labels

cli CLI command changes size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants