fix for schedular bug with lazy left-join sources#898
Merged
Conversation
🦋 Changeset detectedLatest commit: 0861ff9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
2123063 to
d06f565
Compare
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: +150 B (+0.17%) Total Size: 86.5 kB
ℹ️ View Unchanged
|
Contributor
|
Size Change: 0 B Total Size: 3.34 kB ℹ️ View Unchanged
|
kevin-dp
approved these changes
Nov 24, 2025
| return ( | ||
| typeof dep === `object` && | ||
| dep !== null && | ||
| typeof (dep as { hasPendingGraphRun?: unknown }).hasPendingGraphRun === |
Contributor
There was a problem hiding this comment.
It makes more sense to type this function's dep argument as any such that you don't need this typecast here.
Contributor
|
🎉 This PR has been released! Thank you for your contribution! |
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.
Fixes #813
Failed test run showing reproduction: https://github.com/TanStack/db/actions/runs/19632437525/job/56215175357?pr=898
Summary
Fix scheduler deadlocks from lazy left-join sources (e.g., the nested left join in the “should handle optimistic mutations with nested left joins without scheduler errors” test) by only blocking on dependencies that are actually enqueued or have pending work in the same transaction. Non-enqueued lazy deps are treated as satisfied, preventing unresolved dependency errors.
Background: How the scheduler and live queries interact
Scheduler detected unresolved dependencies for context ....Original issue
What changed (code)
packages/db/src/scheduler.tsPendingAwareJobtype andisPendingAwareJobguard to removeanycasting when checking for pending work.hasPendingGraphRun.packages/db/src/query/live/collection-config-builder.tshasPendingGraphRunso dependents can detect when a builder has work pending in a transaction (used by the scheduler dependency logic).autoCommit: falseto keep the transaction open during the race, ensuring the scheduler ordering is exercised without dropping optimistic state prematurely.Why this fixes the problem
Testing
pnpm vitest packages/db/tests/query/scheduler.test.ts -t "live query scheduler"(all 10 tests now pass, covering the deadlock scenario and the stale-read race).Notes
.changeset/soft-lazy-deps.md(patch for@tanstack/db).