Skip to content

fix(device): time out stalled artifact downloads - #240

Merged
riglar merged 1 commit into
feature/agent-devicesfrom
fix/device-artifacts-timeout
Oct 20, 2026
Merged

riglar merged 1 commit into
feature/agent-devicesfrom
fix/device-artifacts-timeout

Conversation

@riglar

@riglar riglar commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Bug

dcd device artifacts <id> could hang forever. One download (a 4.5 MB device.log from the CDN) stalled at about 4 KB/s for more than 5 minutes. The downloads had no timeout, so the command never finished. The same URL worked in about 1.5 s when tried again.

Fix

In src/utils/device-artifacts.ts, each download now has two limits, enforced with an AbortController:

  • Idle timeout, 30 s. If no data arrives for 30 s, the download is aborted. This also covers waiting for the response headers.
  • Total cap, 10 minutes per file.

A failed or timed-out file is tried once more, because the CDN usually serves it fine on a second request. If it still fails, it goes in the existing failed list with a clear reason, such as timed out: no data for 30s (after 2 tries). Any half-written file is deleted. The command still exits 2, as it does for other failed files. Concurrency stays at 4.

The timeouts and the number of tries can be passed in through a new optional options argument to downloadArtifactFiles, so tests can use short values.

Tests

New cases in test/unit/device-artifacts.test.ts, all using a fake fetch (no network):

  • A body that never sends data is reported as timed out quickly, after 2 tries, and leaves no file behind.
  • A body that trickles data forever hits the total cap.
  • A body that stalls once and then succeeds is downloaded on the retry.

I also checked it by hand against a local HTTP server that stalls mid-body, using real fetch. It aborted at the idle limit and the retry succeeded.

pnpm lint, pnpm typecheck, pnpm test:unit (404 passing, exits 0) and pnpm build all pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_018tQfgpTsA9UhcopKoDezUA

Each artifact download now aborts after 30s with no data, or after 10
minutes in total, and is retried once. A file that still fails goes in
the failed list with the reason, so the command exits 2 instead of
hanging forever on a stalled CDN stream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018tQfgpTsA9UhcopKoDezUA
@claude

claude Bot commented Oct 20, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@riglar
riglar merged commit ff5b7c0 into feature/agent-devices Oct 20, 2026
3 checks passed
@riglar
riglar deleted the fix/device-artifacts-timeout branch October 20, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant