Skip to content
Source
Sign inSign up
TanStack/db

fix(db): keep a live query running when a lazy demand fails during a truncate replay #2231

MergedKyleAMathews(GitHub profile, opens in a new tab)merged 47 commits intomain fromrefs/pull/2231/headmerged by KyleAMathews(GitHub profile, opens in a new tab)

Showing 22 changed files with 31 additions and 5 deletions (loading 19).

x
0 of 22 viewed, 22 left
11 additions and 0 deletions.changeset/keep-live-query-through-failed-replay.mdAdded
View file
@@ -0,0 +1,11 @@
+---
+'@tanstack/db': patch
+---
+​
+A query that joins and includes the same source has two subscriptions to it. Their truncate replays now share one barrier, so neither publishes while the other still loads. When a lazy demand of either fails while a failed replay of the source holds the query's results, the query keeps its last complete result until a later replay of that source succeeds. Before, retiring the other replay's failed demand could publish the window without that demand's rows.
+​
+Some sources refetch and then report that their pages shifted. An ordered window over such a source no longer skips a row tied with the refetched first page's new end. When the report shows that the page's end moved, the window repairs its first page. It no longer trusts a row that an older tie request installed.
+​
+A window move made while a truncate replay holds a live query's results now applies after that replay, even when a newer truncate discards it. Before, the move could reject, and an older move's window stayed. A reload of the query or of a source still ends the move.
+​
+An ordered, limited query over a source without an order index can read too few rows to fill its window. A join that drops rows can cause this. It no longer reads the whole source then. It reads a prefix twice as long instead. It grows again while that adds rows, so every request stays bounded.
2 additions and 2 deletionsdocs/contributing/glossary.mdModified
View file
@@ -131,7 +131,7 @@
| demand | The logical need for source data. Demand may outlive or replace physical work. | Request, transport, or row ownership. |
| logical subset owner | One subscription claim that keeps a subset demand active. | Physical acquisition. |
| request data | The immutable `LoadSubsetOptions` and attached signal passed to an adapter. | Demand or established coverage. |
-| acquisition attempt | One invocation that asks a sync adapter to start physical work. A synchronous throw ends the attempt before acceptance. If cleanup invalidates the captured sync run after the adapter returns but before activation, core cancels the tentative acquisition without retaining its lease; cleanup owns the adapter resources. | Physical acquisition or transport. |
+| acquisition attempt | One invocation that asks a sync adapter to start physical work. A synchronous throw is a rejection: the attempt fails, keeps its owner, and the owner's release unloads it. If cleanup invalidates the captured sync run after the adapter returns but before activation, core cancels the tentative acquisition without retaining its lease; cleanup owns the adapter resources. | Physical acquisition or transport. |
| physical acquisition | Request-scoped work accepted by a sync adapter for a demand. | Acquisition attempt, logical demand, or transport. |
| lease | An ownership token that requires a matching release. TanStack DB leases do not expire on a timer. Always qualify which resource the lease owns. | Demand, request, or data coverage. |
| acquisition lease | The release obligation created when an adapter accepts a physical acquisition. | The acquisition attempt itself. |
@@ -221,7 +221,7 @@