Skip to content

fix(nodes-camera): add timeout to URL media downloads - #103019

Closed
Alix-007 wants to merge 2 commits into
openclaw:mainfrom
Alix-007:alix/nodes-camera-url-media-fetch-timeout
Closed

Alix-007 wants to merge 2 commits into
openclaw:mainfrom
Alix-007:alix/nodes-camera-url-media-fetch-timeout

Conversation

@Alix-007

@Alix-007 Alix-007 commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Node camera URL-backed media downloads used the guarded fetch path but did not provide a request deadline. If the node host accepted the connection and never sent headers or completed the response, writeUrlToFile could wait indefinitely while saving camera artifacts.

Why This Change Was Made

This PR adds a 120s deadline to writeUrlToFile's guarded fetch call, while leaving the existing HTTPS requirement, node-host match, redirect host validation, body cleanup, and max-byte enforcement intact. Tests can pass a smaller timeout override so the regression proof remains fast.

User Impact

A stalled node-hosted camera URL now fails through the existing error path instead of wedging the CLI media write.

Evidence

  • Focused test: pnpm vitest run src/cli/nodes-camera.test.ts -> 29 passed.
  • Format/lint: 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 -> passed.
  • Whitespace: git diff --check -> clean.
  • Collision check before opening: open PR changed-files query for src/cli/nodes-camera.ts returned no open PRs.

Proof

Regression contract: the branch test aborts hanging url payload downloads through the guarded fetch timeout starts a local node:http server that accepts the request and never sends response headers. It then calls writeUrlToFile with a production-shaped HTTPS node URL, routes the guarded fetch mock to that real hanging server, asserts timeoutMs: 50, and verifies the expected output path is missing after the failure.

Controlled stall transcript from the same guarded fetch runtime path, using a 500ms timeout so the proof does not wait two minutes:

$ pnpm exec tsx --input-type=module - <<'SCRIPT'
# starts a local node:http server, calls fetchWithSsrFGuard with timeoutMs=500,
# and lets the server accept the request while withholding headers
SCRIPT
stall-server: accepted node media request; intentionally withholding headers
[fetch-timeout] fetch timeout after 500ms (elapsed 501ms) operation=fetchWithSsrFGuard url=http://127.0.0.1:<port>/camera.bin
guarded-fetch: aborted stalled request after 585ms
guarded-fetch: error=TimeoutError: request timed out

Why this covers the bug: before this PR, writeUrlToFile did not pass a request timeout into fetchWithSsrFGuard, so a node-hosted URL that accepted the connection but withheld headers could remain pending. After this PR, the same guarded fetch path has a deadline; the committed regression also asserts no partial output file is left behind.

Compatibility note: the production deadline is intentionally 120s total for URL-backed camera media downloads. A node-hosted transfer that is still progressing but takes longer than 120s can now fail instead of hanging indefinitely.

What was not tested: live node hardware. The proof uses a controlled local hanging server plus the committed writeUrlToFile regression.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S labels Jul 9, 2026
@clawsweeper

clawsweeper Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 1:23 PM ET / 17:23 UTC.

Summary
Adds a 120s default timeout to node camera URL-backed media downloads and adds a hanging-server regression test with a shorter timeout override.

PR surface: Source +2, Tests +115. Total +117 across 2 files.

Reproducibility: yes. source inspection shows current main does not pass a timeout into writeUrlToFile's guarded fetch call, and the PR includes a clear hanging-server regression path. I did not execute the test in this read-only review.

Review metrics: 1 noteworthy metric.

  • Download default: 1 added: 120s URL media download deadline. This is a user-visible runtime default for existing node camera URL payload downloads, so maintainers should notice the slow-transfer behavior change before merge.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted terminal output, logs, or a linked artifact from a real CLI or harness run showing a stalled URL-backed camera media download times out and leaves no partial file.
  • Keep the proof free of private IPs, API keys, phone numbers, and non-public endpoints; updating the PR body should trigger a fresh ClawSweeper review, or a maintainer can request @clawsweeper re-review.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body only provides a mocked/unit regression proof; before merge, add redacted terminal/live output or logs from a real CLI or harness run showing the stalled URL path timing out and cleaning up. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The new 120s deadline is an unconditional total deadline for URL-backed camera downloads, so an extremely slow but still-progressing node-hosted media transfer would now fail once that timer expires.
  • [P1] The PR body provides mocked/unit regression proof rather than a real CLI or harness transcript from an after-fix run.

Maintainer options:

  1. Accept the 120s deadline (recommended)
    Land with 120s as the intentional total bound for node-hosted camera URL downloads once real behavior proof is added.
  2. Make the timeout progress-aware
    Change the implementation to refresh or separately track progress if maintainers want slow active transfers to continue beyond 120s.

Next step before merge

  • [P2] The remaining blocker is contributor real behavior proof and maintainer comfort with the new timeout default, not a narrow ClawSweeper code repair.

Security
Cleared: No concrete security or supply-chain regression was found; the diff preserves the SSRF guard and host policy while adding a timeout.

Review details

Best possible solution:

Land the existing guarded-fetch timeout approach after contributor proof shows a stalled URL media write times out cleanly and maintainers accept 120s as the intended total deadline for node camera URL downloads.

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

Yes, source inspection shows current main does not pass a timeout into writeUrlToFile's guarded fetch call, and the PR includes a clear hanging-server regression path. I did not execute the test in this read-only review.

Is this the best way to solve the issue?

Yes, this is the narrowest maintainable fix shape: the node camera writer uses the existing fetchWithSsrFGuard timeout contract at the media download boundary instead of adding a parallel network wrapper. The only open merge questions are proof quality and acceptance of the 120s total deadline.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This is a normal-priority CLI bug fix for a bounded node camera media hang with limited blast radius.
  • add merge-risk: 🚨 compatibility: Existing URL-backed camera downloads that are very slow but still progressing can now fail after the new 120s total timeout.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body only provides a mocked/unit regression proof; before merge, add redacted terminal/live output or logs from a real CLI or harness run showing the stalled URL path timing out and cleaning up. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a normal-priority CLI bug fix for a bounded node camera media hang with limited blast radius.
  • merge-risk: 🚨 compatibility: Existing URL-backed camera downloads that are very slow but still progressing can now fail after the new 120s total timeout.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body only provides a mocked/unit regression proof; before merge, add redacted terminal/live output or logs from a real CLI or harness run showing the stalled URL path timing out and cleaning up. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +2, Tests +115. Total +117 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 1 120 5 +115
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 123 6 +117

What I checked:

  • Current main behavior: Current main calls fetchWithSsrFGuard from writeUrlToFile without a timeout, so a connection that never yields headers or body completion can remain pending at this boundary. (src/cli/nodes-camera.ts:123, 8c78e1c035a6)
  • PR implementation: The PR widens writeUrlToFile's internal opts with timeoutMs and passes opts.timeoutMs ?? CAMERA_URL_DOWNLOAD_TIMEOUT_MS into the guarded fetch call. (src/cli/nodes-camera.ts:128, 85c570fc6c08)
  • Guarded fetch contract: fetchWithSsrFGuard already accepts timeoutMs and builds an abort signal for the fetch operation, making this a narrow use of the existing network boundary rather than a custom downloader timer. (src/infra/net/fetch-guard.ts:451, 8c78e1c035a6)
  • Timeout helper contract: buildTimeoutAbortSignal creates a cleanup-owned AbortController and aborts with a TimeoutError when the configured delay expires. (src/utils/fetch-timeout.ts:108, 8c78e1c035a6)
  • Regression test shape: The PR test uses a local HTTP server that intentionally never sends headers, a mocked guarded-fetch implementation, a 50ms timeout override, and an assertion that no partial file remains. (src/cli/nodes-camera.test.ts:348, 85c570fc6c08)
  • Feature history: The node camera URL download path traces through the original camera feature, Android URL payload support, and later fail-closed SSRF hardening before this timeout fix. (src/cli/nodes-camera.ts:94, 8c78e1c035a6)

Likely related people:

  • steipete: Git history shows Peter Steinberger introduced the original camera snap/clip helper, later fail-closed node camera URL downloads through the SSRF guard, and refactored the camera payload helpers. (role: feature owner and recent area maintainer; confidence: high; commits: a92eb1f33d09, 3bf19d6f40a0, bb60687b899f; files: src/cli/nodes-camera.ts, src/cli/nodes-camera.test.ts, src/cli/nodes-cli/register.camera.ts)
  • smartprogrammer93: GitHub PR history shows Android gateway URL camera payload support and CLI URL payload tests landed through the merged URL-payload feature work. (role: URL payload feature contributor; confidence: medium; commits: c179f71f42bc; files: src/cli/nodes-camera.ts, src/cli/nodes-camera.test.ts, src/cli/nodes-cli/register.camera.ts)
  • masatohoshino: Current-main blame attributes the present nodes-camera helper file to commit 34248e1, so this person is a recent history signal for the exact file even though the PR title was adjacent gateway work. (role: recent current-main contributor; confidence: medium; commits: 34248e101fd3; files: src/cli/nodes-camera.ts, src/cli/nodes-camera.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 9, 2026
@Alix-007

Alix-007 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 9, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@steipete

Copy link
Copy Markdown
Contributor

Superseded by #103266, merged as 541c9f0bf01712d81d5217eb2a5c15d05686259d.

The landed fix applies the fixed 15-minute deadline at the shared node-media URL writer, enforces HTTPS on every redirect hop before dispatch, retains the fetch guard through body consumption, and preserves partial-file cleanup. Its exact prepared head passed full hosted CI: https://github.com/openclaw/openclaw/actions/runs/29070305200

Closing this overlapping implementation so the transport invariant has one canonical owner. Thanks @Alix-007 for the report and patch.

@steipete steipete closed this Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants