fix(offline-transactions): enforce strict FIFO when retries are pending#1300
Open
KyleAMathews wants to merge 4 commits intomainfrom
Open
fix(offline-transactions): enforce strict FIFO when retries are pending#1300KyleAMathews wants to merge 4 commits intomainfrom
KyleAMathews wants to merge 4 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: 9dce679 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: -2 B (0%) Total Size: 92.6 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.7 kB ℹ️ View Unchanged
|
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Enforce strict FIFO ordering in
KeyScheduler.getNextBatchso that a transaction waiting for retry delay blocks all later transactions from executing. Previously, later transactions could jump the queue, causing dependent UPDATE-before-INSERT failures.Root Cause
getNextBatchused.find()to locate any pending transaction that was ready to run. If the oldest transaction had failed and was in a retry backoff window (nextAttemptAtin the future),.find()would skip past it and return a later transaction that was ready. This violated the FIFO contract — a newer transaction could execute before an older one that it depended on.Approach
Replace the
.find()scan with a check on onlythis.pendingTransactions[0](the oldest transaction). If it's not ready, return an empty batch. If it is ready, return it.The
scheduleNextRetrymechanism inTransactionExecutorensures that when the first transaction's retry delay elapses, execution resumes automatically.Key Invariants
createdAtorder — no transaction can execute before an older onescheduleNextRetryprovides the eventual recovery path after a breakNon-goals
TransactionExecutoror the execution loopmarkStarted/markFailednot validating transaction identity) are out of scopeVerification
pnpm --filter @tanstack/offline-transactions test -- KeyScheduler.test.ts8 tests cover: FIFO blocking during retry, delay elapse, queue advancement after completion,
isRunningguard, full retry-then-success lifecycle, out-of-order scheduling,updateTransactionsort preservation, and empty queue boundary.Files Changed
packages/offline-transactions/src/executor/KeyScheduler.ts— Replace.find()scan with strict first-element check; use non-null assertion after length guardpackages/offline-transactions/tests/KeyScheduler.test.ts— New test file with 8 tests covering the FIFO ordering contract🤖 Generated with Claude Code