fix(query-db): preserve source ownership and refetch outcomes #2143
main fromcodex/query-source-reuse-followup·opened Summary#
After #2135, a narrow on-demand query could settle from a full Query result before the Collection applied it. A retained subset could also lose its persisted owner before replacement applied. This PR makes acquisition settlement depend on an eligible, applied source result. It keeps each row owned until another accepted result replaces that owner.
Each Collection caller owns an acquisition. Query Core owns the physical fetch. Releasing one caller aborts that caller's signal. A surviving caller or outside observer can keep the fetch alive. A canceled caller cannot publish rows from work that outlives its acquisition.
Behavior#
- A complete, applied full-source result can serve a later filtered demand while its Query remains owned. A pending, failed, incomplete, or unapplied result cannot establish that coverage.
- After a full refresh fails, an existing filtered dependent keeps its observer lease and rows. A new equal filtered demand starts an exact request.
- A retained persisted subset keeps its rows and marker until a new result revalidates its scope. Revalidation can use a complete full result or an exact subset request.
- Exact snapshot refetches and utility refetches follow the fetch that served each call. A reverted cancellation cannot return old cached data as a new result. A silent replacement waits for its successor.
- If Query behavior fails before fetch installation, initial loads, live-query preloads, and explicit refetches settle with that setup error. A source value invoked before failure enters neither Collection rows nor Query cache.
The lifecycle and ownership oracles exercise held fetches, shared observers, direct writes, retained storage, cancellation, replacement, and failure. The oracle review record records the bounded laws, hostile controls, and open histories.
Verification and release dependency#
All 951 Query DB tests pass in 19 files against frozen Query Core #12023 at 273eb2526. The package TypeScript check with a Core source alias, Prettier, and changed-file lint pass. Lint reports 12 existing warnings outside edited lines. A disposable control without the new utility sequence guard fails both overlapping setup-error histories at their terminal assertions.
Published Query Core 5.90.20 lacks the required fetch attribution and setup-error behavior. The Query DB peer range still admits ^5.90.15. Publish a compatible Query Core release and raise the Query DB minimum peer version before releasing this PR. A later Core draft at 371b1f49e failed two reset receiving histories, so final integration remains open.
- 1
Important
Draft PR not reviewed#
Draft PRs are not automatically reviewed by default.
- Trigger a manual review
To automatically review draft PRs, update your CodeRabbit configuration:
reviews: auto_review: drafts: true- 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.
Comment `@coderabbitai help` to get the list of available commands.Size Change: 0 B
Total Size: 215 kB
compressed-size-action::db-and-react-package-sizeℹ️ View Unchanged
Filename Size packages/db/dist/esm/client.js4.22 kB packages/db/dist/esm/collection-options-brand.js219 B packages/db/dist/esm/collection-options.js258 B packages/db/dist/esm/collection/change-events.js1.76 kB packages/db/dist/esm/collection/changes.js2.96 kB packages/db/dist/esm/collection/cleanup-queue.js901 B packages/db/dist/esm/collection/config-errors.js547 B packages/db/dist/esm/collection/events.js481 B packages/db/dist/esm/collection/index.js5.23 kB packages/db/dist/esm/collection/indexes.js2.3 kB packages/db/dist/esm/collection/lifecycle.js2.94 kB packages/db/dist/esm/collection/mutations.js2.99 kB packages/db/dist/esm/collection/state.js7.13 kB packages/db/dist/esm/collection/subscription.js8.84 kB packages/db/dist/esm/collection/sync.js5.32 kB packages/db/dist/esm/collection/validate-config.js1.17 kB packages/db/dist/esm/deferred.js207 B packages/db/dist/esm/error-message.js642 B packages/db/dist/esm/errors.js6.49 kB packages/db/dist/esm/event-emitter.js1.06 kB packages/db/dist/esm/index.js4.49 kB packages/db/dist/esm/indexed-db-wrapper.js1.91 kB packages/db/dist/esm/indexed-db.js3.7 kB packages/db/dist/esm/indexes/auto-index.js926 B packages/db/dist/esm/indexes/base-index.js1.92 kB packages/db/dist/esm/indexes/basic-index.js1.93 kB packages/db/dist/esm/indexes/btree-index.js1.62 kB packages/db/dist/esm/indexes/index-registry.js916 B packages/db/dist/esm/indexes/reverse-index.js1.01 kB packages/db/dist/esm/live-query-adapter.js338 B packages/db/dist/esm/live-query-observer.js4.8 kB packages/db/dist/esm/live-query-options.js1.4 kB packages/db/dist/esm/live-query-window-controller.js4.27 kB packages/db/dist/esm/local-only.js1.08 kB packages/db/dist/esm/local-storage.js3.93 kB packages/db/dist/esm/optimistic-action.js359 B packages/db/dist/esm/paced-mutations.js1.11 kB packages/db/dist/esm/persisted-readiness.js195 B packages/db/dist/esm/proxy.js3.51 kB packages/db/dist/esm/query/builder/clone-query.js849 B packages/db/dist/esm/query/builder/functions.js1.56 kB packages/db/dist/esm/query/builder/index.js7.48 kB packages/db/dist/esm/query/builder/query-ir.js312 B packages/db/dist/esm/query/builder/ref-proxy-identity.js292 B packages/db/dist/esm/query/builder/ref-proxy.js1.67 kB packages/db/dist/esm/query/builder/wrapper-identity.js221 B packages/db/dist/esm/query/compiler/evaluators.js2.51 kB packages/db/dist/esm/query/compiler/expressions.js603 B packages/db/dist/esm/query/compiler/group-by.js4.48 kB packages/db/dist/esm/query/compiler/index.js10.1 kB packages/db/dist/esm/query/compiler/joins.js3.42 kB packages/db/dist/esm/query/compiler/lazy-targets.js1.11 kB packages/db/dist/esm/query/compiler/order-by.js2.23 kB packages/db/dist/esm/query/compiler/parent-routes.js319 B packages/db/dist/esm/query/compiler/query-equivalence.js568 B packages/db/dist/esm/query/compiler/route-metadata.js1.24 kB packages/db/dist/esm/query/compiler/select.js1.5 kB packages/db/dist/esm/query/effect.js5.26 kB packages/db/dist/esm/query/equality-conjunct.js486 B packages/db/dist/esm/query/equality-value-identity.js735 B packages/db/dist/esm/query/expression-helpers.js1.61 kB packages/db/dist/esm/query/ir-stable-identity.js4.2 kB packages/db/dist/esm/query/ir.js2.2 kB packages/db/dist/esm/query/join-conditions.js257 B packages/db/dist/esm/query/live-query-collection.js391 B packages/db/dist/esm/query/live/bucket-facade-adapter.js3.17 kB packages/db/dist/esm/query/live/collection-config-builder.js6.75 kB packages/db/dist/esm/query/live/collection-registry.js264 B packages/db/dist/esm/query/live/collection-subscriber.js2.2 kB packages/db/dist/esm/query/live/graph-scheduler.js305 B packages/db/dist/esm/query/live/internal.js145 B packages/db/dist/esm/query/live/materialized-pipeline.js2.39 kB packages/db/dist/esm/query/live/ordered-source-loader.js4.49 kB packages/db/dist/esm/query/live/subset-demand-controller.js1.73 kB packages/db/dist/esm/query/live/utils.js1.35 kB packages/db/dist/esm/query/optimizer.js2.95 kB packages/db/dist/esm/query/pooled-live-query.js4.13 kB packages/db/dist/esm/query/query-once.js359 B packages/db/dist/esm/query/runtime-reference-identity.js630 B packages/db/dist/esm/query/subset-dedupe.js493 B packages/db/dist/esm/scheduler.js1.23 kB packages/db/dist/esm/SortedMap.js1.6 kB packages/db/dist/esm/strategies/commit-completion.js156 B packages/db/dist/esm/strategies/debounceStrategy.js658 B packages/db/dist/esm/strategies/queueStrategy.js523 B packages/db/dist/esm/strategies/serial-pacer.js486 B packages/db/dist/esm/strategies/throttleStrategy.js738 B packages/db/dist/esm/sync-persistence.js626 B packages/db/dist/esm/sync-receipt.js211 B packages/db/dist/esm/transaction-commit-work.js351 B packages/db/dist/esm/transactions.js4.61 kB packages/db/dist/esm/utils.js1.67 kB packages/db/dist/esm/utils/array-utils.js270 B packages/db/dist/esm/utils/browser-polyfills.js304 B packages/db/dist/esm/utils/btree.js3.02 kB packages/db/dist/esm/utils/callbacks.js174 B packages/db/dist/esm/utils/comparison.js1.94 kB packages/db/dist/esm/utils/cursor.js753 B packages/db/dist/esm/utils/error.js262 B packages/db/dist/esm/utils/get-or-create.js155 B packages/db/dist/esm/utils/index-optimization.js2.43 kB packages/db/dist/esm/utils/source-record.js140 B packages/db/dist/esm/utils/type-guards.js230 B packages/db/dist/esm/utils/uuid.js530 B packages/db/dist/esm/virtual-props.js413 B packages/react-db/dist/esm/DbProvider.js317 B packages/react-db/dist/esm/development.js190 B packages/react-db/dist/esm/HydrationBoundary.js263 B packages/react-db/dist/esm/index.js330 B packages/react-db/dist/esm/live-query-internals.js282 B packages/react-db/dist/esm/source-id-bindings.js746 B packages/react-db/dist/esm/useLiveInfiniteQuery.js2.15 kB packages/react-db/dist/esm/useLiveQuery.js3.34 kB packages/react-db/dist/esm/useLiveQueryEffect.js504 B packages/react-db/dist/esm/useLiveSuspenseQuery.js1.33 kB packages/react-db/dist/esm/usePacedMutations.js401 B More templates
- todos
- offline-first-electron
- @tanstack/db-example-react-action-enforcement
- @tanstack/db-example-react-next-ssr-e2e
- tanstack-start-example-basic
- @tanstack/db-example-paced-mutations-demo
- tanstack-start-db-projects-example
- @tanstack/db-example-react-start-ssr-e2e
- @tanstack/db-example-react-todo
- offline-transactions-react-native
- shopping-list-react-native
- @tanstack/db-example-solid-todo
@tanstack/angular-db
npm i https://pkg.pr.new/@tanstack/angular-db@2143@tanstack/browser-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/browser-db-sqlite-persistence@2143@tanstack/capacitor-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/capacitor-db-sqlite-persistence@2143@tanstack/cloudflare-durable-objects-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/cloudflare-durable-objects-db-sqlite-persistence@2143@tanstack/db
npm i https://pkg.pr.new/@tanstack/db@2143@tanstack/db-ivm
npm i https://pkg.pr.new/@tanstack/db-ivm@2143@tanstack/db-sqlite-persistence-core
npm i https://pkg.pr.new/@tanstack/db-sqlite-persistence-core@2143@tanstack/electric-db-collection
npm i https://pkg.pr.new/@tanstack/electric-db-collection@2143@tanstack/electron-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/electron-db-sqlite-persistence@2143@tanstack/expo-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/expo-db-sqlite-persistence@2143@tanstack/node-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/node-db-sqlite-persistence@2143@tanstack/offline-transactions
npm i https://pkg.pr.new/@tanstack/offline-transactions@2143@tanstack/powersync-db-collection
npm i https://pkg.pr.new/@tanstack/powersync-db-collection@2143@tanstack/query-db-collection
npm i https://pkg.pr.new/@tanstack/query-db-collection@2143@tanstack/react-db
npm i https://pkg.pr.new/@tanstack/react-db@2143@tanstack/react-native-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/react-native-db-sqlite-persistence@2143@tanstack/react-router-with-db
npm i https://pkg.pr.new/@tanstack/react-router-with-db@2143@tanstack/rxdb-db-collection
npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@2143@tanstack/solid-db
npm i https://pkg.pr.new/@tanstack/solid-db@2143@tanstack/svelte-db
npm i https://pkg.pr.new/@tanstack/svelte-db@2143@tanstack/tauri-db-sqlite-persistence
npm i https://pkg.pr.new/@tanstack/tauri-db-sqlite-persistence@2143@tanstack/trailbase-db-collection
npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@2143@tanstack/vue-db
npm i https://pkg.pr.new/@tanstack/vue-db@2143commit:
f301084KyleAMathews(GitHub profile, opens in a new tab) changed the title
KyleAMathews(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 128b9c4a5cfa98a29944aedca5440d07b1bca938
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