Repository navigation
fix(upload): retry Backblaze uploads on transient failures - #270
Merged
Merged
Conversation
Direct-to-B2 uploads made exactly one attempt per request. A 503, 408, 429 or dropped connection on any part failed the whole B2 upload, and the Supabase upload behind it was the only thing that caught it. - Retry each B2 request up to 4 times with jittered exponential backoff (1s, 2s, 4s; capped at 8s) on network errors and 408 / 429 / 5xx. - Large-file parts move on to the next upload URL on each retry, as B2 asks after a 503. The URLs are bound to the file, not the part number, so any of them can carry any part. A 401 is retried only there. - The simple (pre-signed S3) upload retries the same URL. - When every upload fails, the error now names the Backblaze failure as well as the Supabase one, instead of hiding it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
When the CLI uploads a binary, it uploads to Backblaze B2 and to Supabase. It fails only if both uploads fail. The B2 upload made one attempt per request, with no retry. So a single 503 or dropped connection on any large-file part failed the whole B2 upload, and the Supabase upload was the only thing left to save the run. When that also failed, the run failed.
The B2 error was also hidden. When both uploads failed, the CLI reported only the last error, which was the Supabase one. That made a B2 failure look like a Supabase problem.
B2 expects clients to retry. Its docs say uploads can get 503 / 500 / 408 or a dropped connection, and the client should back off and try again. After a 503 on a large-file part, it should use a different upload URL.
What changes
src/utils/b2-retry.ts. Each B2 request gets up to 4 attempts, with jittered exponential backoff (about 1 s, 2 s, 4 s, capped at 8 s). It retries on network errors (TypeError) and 408 / 429 / 5xx. Other 4xx responses fail straight away.partUploadUrlFor). The API mints one URL per part. Each URL is tied to the file, not to a part number (the part number is sent inX-Bz-Part-Number), so any URL can upload any part. Parts upload one at a time, so no URL is ever used twice at once. A 401 is retried only here, because the next attempt uses a URL with a different token.uploadToBackblazeanduploadLargeFileToBackblazethrow instead of returningfalse, sohandleBackblazeUploadpasses the error up. When every upload fails,validateUploadResultsputsBackblaze error: …before the existingLast error: {…}. That part of the message keeps its old format.There's no API change. The worst case adds about 7 s per failing part before giving up.
Testing
pnpm lintshows no new warnings (the same 24 asdev).pnpm typecheck,pnpm test:unit(489 passing) andpnpm buildall pass.test/unit/b2-retry.test.tscovers:🤖 Generated with Claude Code