fix(offline-transactions): infinite retries by default and online-status gating#1301
Open
KyleAMathews wants to merge 4 commits intomainfrom
Open
fix(offline-transactions): infinite retries by default and online-status gating#1301KyleAMathews wants to merge 4 commits intomainfrom
KyleAMathews wants to merge 4 commits intomainfrom
Conversation
…tus gating The hardcoded 10-retry limit caused transactions to be permanently dropped. Retries were also burned while offline. This changes the default to infinite retries with exponential backoff and gates execution on online status so retries are only attempted when connected. - DefaultRetryPolicy defaults to Infinity instead of 10 - Execution loop and retry timer skip while offline via isOnline() - OnlineDetector.isOnline() now required on the interface - ReactNativeOnlineDetector adds isOnline() and initial NetInfo.fetch - Extract TransactionSignaler interface to replace any type - Simplify test harness config with spread Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 533ba70 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Contributor
|
Size Change: 0 B Total Size: 92.6 kB ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
…iber gate notifyOnline() on OfflineExecutor was broken after online-gating changes (execution loop bails when detector reports offline). Rather than adding a force-bypass mechanism, remove the method — the OnlineDetector handles connectivity changes automatically. Users who need imperative control can build a custom OnlineDetector. Also removes the redundant isOnline() guard in the subscriber callback since the execution loop already gates on online status. Co-Authored-By: Claude Opus 4.6 <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.
Fix offline transaction retry behavior and add online-status gating
Transactions were being permanently dropped after 10 failed retries, and retry attempts were wasted while the device was offline. Both issues are now fixed — retries are infinite by default and gated on connectivity.
Root Cause
Two separate issues in
@tanstack/offline-transactions:DefaultRetryPolicyhardcodedmaxRetries = 10— After 10 transient failures (e.g., a brief server outage), transactions were treated as permanent failures, removed from the outbox, and lost.No online-status awareness in the execution loop — The executor would attempt transactions regardless of connectivity, burning through retries against an unreachable server.
Approach
Infinite retries by default: Changed
DefaultRetryPolicyfrommaxRetries = 10tomaxRetries = Infinity. Retriable errors (anything that isn'tNonRetriableError,AbortError, or a 4xx status) will keep retrying with exponential backoff until the server responds.Online-status gating: Added
isOnline()checks at two points:TransactionExecutor.runExecution()— breaks out of the batch loop when offlineTransactionExecutor.scheduleNextRetry()— skips scheduling retry timers when offlineWhen the device comes back online, the
OnlineDetectorsubscription handler resets retry delays and triggers execution immediately.OnlineDetector.isOnline()is now required on the interface. Both existing implementations (WebOnlineDetector,ReactNativeOnlineDetector) already provided it. Making it required eliminatestypeofguards with dangerousreturn truefallbacks.OfflineExecutor.notifyOnline()removed — this method was redundant with theOnlineDetectorsubscription. The detector is the single source of truth for connectivity. Users who need imperative control over online status should implement a customOnlineDetector.Key Invariants
NonRetriableErrorand specific status codes are permanent)isOnline()returns falseOnlineDetectoris the single source of truth for connectivity — no force flags or override mechanismsNon-goals
maxRetries/retryDelay/retryPolicy— stripped from the PR to avoid unnecessary API surface. Can be added when there's demand.Trade-offs
Breaking interface changes shipped as patch:
OnlineDetector.isOnline()is now required andOfflineExecutor.notifyOnline()is removed. This is technically a breaking change, but this package is pre-1.0 with very few users, making a patch appropriate.Verification
pnpm --filter @tanstack/offline-transactions testFiles changed
maxRetrieschanged from 10 toInfinityTransactionSignalerinterface replacesanytypenotifyOnline(); addedisOnline()method; subscription handler triggers execution on connectivity changeisOnline(), initialNetInfo.fetch(), extractedtoConnectivityState()OnlineDetector.isOnline()now required; addedTransactionSignalerinterface🤖 Generated with Claude Code