Skip to content

fix(storage): keep a minimum wait between resumable upload retries - #1866

Merged
grdsdev merged 8 commits into
mainfrom
claude/storage-resumable-retry-floor
Nov 18, 2026
Merged

grdsdev merged 8 commits into
mainfrom
claude/storage-resumable-retry-floor

Conversation

@grdsdev

@grdsdev grdsdev commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Stacked on #1860.

#1860 changes the shared HTTP backoff to full jitter (0...cap). The resumable upload loop in Sources/Storage/ResumableUpload.swift has no attempt limit. Only retryTimeout stops it, and it counts only the sleep time. With full jitter, waits can be near zero, so the loop can send many quick retries to a server that already fails. The docs also say the waits grow.

Fix

The loop now waits a random duration in cap/2...cap (equal jitter), with cap from RetryPolicy.default. This keeps the old minimum wait for this loop only. The time budget then bounds the attempt count again. The auto_retry spec draft (supabase/sdk#190) covers per-request retries with an attempt limit. It does not cover the resumable loop, so this keeps the loop's time-budget model. Sources/Helpers does not change.

Test

everyRetryWaitsAtLeastHalfTheBackoffCap records each sleep through a clock and checks that every wait is in cap/2...cap. It failed before the fix (2 waits under the floor) and passes after it. ResumableUploadTests: 27 tests pass.

The draft auto_retry specs (supabase/sdk PR 190) draw the wait before the
n-th retry from 0...min(maxDelay, baseDelay * 2^(n-1)). RetryPolicy drew it
from cap/2...cap (equal jitter). Full jitter spreads clients that failed
together over the whole window, and matches the Realtime reconnect backoff.

backoffDelay(retry:random:) takes the jitter source so tests can pin it.
… and Realtime

RetryPolicy.backoffDelay repeated the full-jitter math of Realtime's
BackoffPolicy. Move BackoffPolicy into Helpers, which Realtime already
depends on, and have RetryPolicy delegate to it. Move its tests to
HelpersTests and drop the randomized RetryPolicy backoff test that the
pinned-jitter test now covers.
- The interceptor test now runs ten retries and checks that the wait window grows,
  so a wrong retry number fails it.
- The default random test draws 200 delays and checks they spread over the window.
- RetryPolicyTests keeps one delegation check instead of repeating BackoffPolicy's tests.
- The RetryPolicy doc no longer says it drives Realtime's reconnect delays.
The resumable upload loop has a time budget (retryTimeout) but no attempt
limit. With full jitter (0...cap) in the shared backoff, waits can be near
zero, so the loop could send a burst of retries to a failing server. Each
retry now waits a random duration in cap/2...cap, so the waits grow as the
docs say and the budget bounds the attempt count.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes

    • HTTP retry delays now use full jitter, allowing waits to vary from zero up to the exponential backoff limit. This also applies when a server-provided retry delay is unavailable or invalid.
    • Resumable upload retries now use a delay between half the capped backoff and the full cap.
  • Documentation

    • Clarified which retry policy applies to HTTP requests and Realtime connections.

RetryPolicy.backoffDelay now delegates to BackoffPolicy.fullJitter and accepts an injectable random function. Resumable upload transport retries use a custom delay based on the capped and default backoff values. Tests cover full-jitter bounds and resumable upload retry sleep durations.

Possibly related PRs

Change: Bug fix

Merge Risk: Minimal · up to 2d141

Resumable upload retries now keep a minimum wait between attempts, which prevents many near-instant retries. No merge-blocking risk was found.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1366ab2a-adb1-4491-84a4-a6cb3095f658
Commits

Reviewing files that changed from the base of the PR and between 8592676 and 2d14145.

Files selected for processing: 2

  • Sources/Storage/ResumableUpload.swift
  • Tests/StorageTests/ResumableUploadTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@coveralls

coveralls commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 44367387824

Coverage increased (+0.001%) to 96.194%

Details

  • Coverage increased (+0.001%) from the base build.
  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 17209
Covered Lines: 16554
Line Coverage: 96.19%
Coverage Strength: 446613.73 hits per line

💛 - Coveralls

Base automatically changed from claude/retry-status-set-f87cab to main November 18, 2026 13:13
@grdsdev
grdsdev merged commit 908d3a5 into main Nov 18, 2026
50 checks passed
@grdsdev
grdsdev deleted the claude/storage-resumable-retry-floor branch November 18, 2026 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants