Skip to content

Prefetch files when downloading archive - #2855

Merged
dwwoelfel merged 7 commits into
mainfrom
prefetch-downloads
Aug 11, 2026
Merged

Prefetch files when downloading archive#2855
dwwoelfel merged 7 commits into
mainfrom
prefetch-downloads

Conversation

@dwwoelfel

@dwwoelfel dwwoelfel commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

A few fixes and improvements for downloading backups:

  1. Prefetches 4 urls. It just starts the connection, but this helps the download speed of $files a ton.
  2. Add a button to copy the command to download from the cli (includes the self-hosted url if necessary)
Screenshot 2026-08-10 at 5 21 01 PM 3. Adds a user-agent from the client--this was causing downloads from cloudfront to fail.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a7645789-afdf-47e1-b504-359ecceff278

📥 Commits

Reviewing files that changed from the base of the PR and between 1486a41 and b384c99.

📒 Files selected for processing (1)
  • client/packages/version/src/version.ts

📝 Walkthrough

Walkthrough

Backup downloads now support bounded concurrent prefetching, retryable entry opening, progress updates, and improved CLI HTTP errors. The dashboard exposes a copyable CLI download command and conditionally retains backup deletion.

Changes

Backup download flow

Layer / File(s) Summary
Download options and retry handling
client/packages/platform/src/backupDownload.ts
Adds prefetch and retry options. Entry opening uses abort-aware exponential backoff.
Bounded archive prefetch
client/packages/platform/src/backupDownload.ts, client/packages/platform/__tests__/src/backupDownload.test.ts
Fetches entries concurrently before ordered archive writing. Entity and storage entries use shared retries. Tests cover concurrent fetching, first-read retries, mid-stream failures, and exhausted retries.
CLI HTTP request diagnostics
client/packages/cli/src/lib/backupDownload.ts, client/packages/version/src/version.ts
Adds a versioned User-Agent and includes bounded response bodies in HTTP errors. Updates the shared version to v1.0.65.
Dashboard backup actions
client/www/components/dash/Backups.tsx
Adds CLI command construction and clipboard copying. The actions menu is available to all users, while deletion remains permission-controlled.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant downloadBackupArchive
  participant prefetchEntries
  participant openWithRetry
  participant ArchiveWriter
  downloadBackupArchive->>prefetchEntries: provide deferred entry specifications
  prefetchEntries->>openWithRetry: open entry bodies with retry
  openWithRetry-->>prefetchEntries: return prepared entry bodies
  prefetchEntries-->>downloadBackupArchive: yield entries in order
  downloadBackupArchive->>ArchiveWriter: write archive entry
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: prefetching files during archive downloads.
Description check ✅ Passed The description accurately summarizes the download performance, CLI command, and user-agent changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

View Vercel preview at instant-www-js-prefetch-downloads-jsv.vercel.app.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@client/packages/cli/src/lib/backupDownload.ts`:
- Around line 63-69: Update the chunk accumulation loop in the backup download
flow to enforce the 2 KiB limit before appending data. In the loop over res,
calculate the remaining budget, slice the current chunk to that size, append
only the sliced portion, update total accordingly, and stop once the limit is
reached.
- Around line 61-79: Update readErrorBody to accept and use the request’s
AbortSignal or an internally enforced finite timeout while reading the response,
ensuring partial error bodies cannot block indefinitely. Preserve abort errors
instead of swallowing them in the catch block, while retaining the existing
empty-string fallback for other read failures and cleanup via res.destroy().

In `@client/packages/platform/src/backupDownload.ts`:
- Around line 321-326: Normalize the retry and prefetch options before use: in
the retry setup around retryAttempts and retryDelayMs, accept attempts only when
it is a finite positive integer, otherwise use DEFAULT_FETCH_ATTEMPTS; normalize
delayMs to a finite non-negative number, otherwise use DEFAULT_RETRY_DELAY_MS.
Apply the same finite positive-integer validation to prefetch, falling back to
its existing default when invalid, so NaN and Infinity cannot alter retry or
pipeline bounds.
- Around line 94-105: Extend openWithRetry and the body-consumption flow so
failures encountered before the first yielded chunk trigger a fresh fetch/retry,
including streams returned by fetchBody that fail on their first read. Track
whether writer.add has received any chunk; propagate errors after the first
chunk as unrecoverable mid-stream failures. Add coverage for a fetchBody result
whose first read errors.

In `@client/www/components/dash/Backups.tsx`:
- Around line 262-268: Update copyCliDownloadCommand to support non-secure HTTP
origins by either requiring HTTPS before using navigator.clipboard.writeText or,
preferably, providing a manual-copy fallback when the Clipboard API is
unavailable or fails. Preserve the success toast when copying succeeds and show
the failure toast only when both automatic and fallback copying cannot be
completed.
- Around line 250-260: Update the cliDownloadCommand construction to POSIX-shell
quote the dynamic config.apiURI, backup.id, and app.id values before
interpolation, including the INSTANT_CLI_API_URI assignment, while preserving
the existing production-backend omission behavior. Do not add alternate shell
formats unless this command explicitly supports PowerShell or cmd.exe.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e9ee21d8-2e1e-4369-b86d-3623ff8b4987

📥 Commits

Reviewing files that changed from the base of the PR and between a679d8b and 93d7348.

📒 Files selected for processing (4)
  • client/packages/cli/src/lib/backupDownload.ts
  • client/packages/platform/__tests__/src/backupDownload.test.ts
  • client/packages/platform/src/backupDownload.ts
  • client/www/components/dash/Backups.tsx

Comment thread client/packages/cli/src/lib/backupDownload.ts Outdated
Comment thread client/packages/cli/src/lib/backupDownload.ts
Comment thread client/packages/platform/src/backupDownload.ts
Comment thread client/packages/platform/src/backupDownload.ts Outdated
Comment thread client/www/components/dash/Backups.tsx
Comment thread client/www/components/dash/Backups.tsx
@dwwoelfel dwwoelfel changed the title [WIP] prefetch files when downloading archive Prefetch files when downloading archive Aug 11, 2026
@dwwoelfel
dwwoelfel marked this pull request as ready for review August 11, 2026 00:22

@stopachka stopachka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suuper cool!

@dwwoelfel
dwwoelfel merged commit 61f1918 into main Aug 11, 2026
29 of 30 checks passed
@dwwoelfel
dwwoelfel deleted the prefetch-downloads branch August 11, 2026 18:06
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.

2 participants