Repository navigation
fix(query-db): compose accepted ownership before publication - #2198
Conversation
🦋 Changeset detectedLatest commit: de1ea0d 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Size Change: 0 B Total Size: 218 kB ℹ️ View Unchanged
|
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
🎉 This PR has been released! Thank you for your contribution! |
Why this matters
An ordered refetch could retain a backend-absent row after another Query observed that row. The failure required an optimistic mutation to delay publication.
PR #2030 introduced the accepted-before-publication interval. PR #2154 exposed the regression through its ordered-prefix oracle.
The failing CI replay showed the concrete result. The ordered window disagreed with the backend after publication resumed.
Cause
The Query ownership indexes accepted newer results before the Collection published their metadata. Cleanup could then rebuild ownership from older published metadata.
That stale metadata could restore an owner that an accepted result retired. An older cleanup could also invalidate ownership from a later reacquisition.
The same authority problem made cold restore depend on row order. Processing one row could make a partially rebuilt Query appear fully resolved.
Repair
Resolved Query ownership now takes precedence over persisted ownership. Persisted metadata seeds only Queries that do not yet have a resolved ownership result.
Each accepted result installs a new ownership generation. Cleanup removes its accepted edges immediately and keeps an empty tombstone until publication completes.
The tombstone retires only when it still belongs to that cleanup. Therefore, an older cleanup cannot invalidate a later acquisition.
Cold persisted and hydrated rows project their owners before they update the ownership indexes. This makes reconstruction independent of row order.
This repair reuses the existing ownership indexes. Production source changes by 54 additions and 60 deletions.
Excluding comments and blank lines, production code changes by 49 additions and 53 deletions.
Oracle model
The ownership oracle does not copy the production maps or cleanup algorithm. Its model stores each active Query's latest complete result.
The expected public Collection is the union of those results. The histories compare that model with public rows and durable effects at defined checkpoints.
New histories cover these cases:
The oracle documentation records the covered histories and the remaining limits.
Verification
pnpm vitest run packages/query-db-collection/tests/ownership-lifecycle.oracle.test.ts packages/query-db-collection/tests/refetch-ordered-prefix-oracle.test.ts --pool-options.threads.maxThreads=2passed 379 tests.query-db.refetch-ordered-prefixCI replay passed with seed-1338032236and its recorded path.pnpm --filter @tanstack/query-db-collection buildpassed.git diff --checkpassed.Summary by CodeRabbit