Skip to content
Source
Sign inSign up
TanStack/db

On-demand joined window stays short after an optimistic delete of its visible row #2148

Send to my agent
OpenKyleAMathews(GitHub profile, opens in a new tab) opened this issue 1 comment

Problem

Take a live query over an on-demand source, with an ordered window and a LEFT-joined (or anti-joined) filter. It can show a short window after an optimistic delete. The window stays short until the delete persists.

Example: orderBy(rank).limit(1), a joined filter, and an on-demand source. The application deletes the visible row with collection.delete(key). The handler's promise is still pending. The window shows [], but the next eligible row exists and the provider can serve it.

The same history passes when the filter is a source predicate, and when the source is eager. It fails with joined and anti-joined filters, with and without an index.

Evidence

  • The ordered-work oracle in #2132 has an optimistic-delete dimension. It is not committed yet, because the delete fails on main and on #2132. The #2132 worktree keeps the patch, and the fix PR will add it.
  • Before the oracle had a fixed-point guard, one random seed (1957256835) ran for more than ten minutes. This suggests that the loader can request the hidden row again and again.

Work

  • Find why the ordered loader does not refill a joined window when an optimistic delete hides a loaded row. A likely place is the leading-run count in dataNeeded, which can count the hidden row as a proven window row.
  • Add the oracle dimension and a pinned replay, with a fixed-point law for repeated requests.

This issue was written by Isaac.

  1. Related evidence from #2154, which may help here.

    The query-db refetch oracle can now hold an optimistic update or delete across a refetch, and it checks the window after the release. Before #2154's loader fix (commit e34948bf1), a refetch during a held optimistic delete left the joined window short after the release:

    • Trace: observe 0, upsert 7@0, hold a delete of 0, refetch, release, unmark 1, hold an update of 0, release.
    • Failure: the window showed [3, 0] where [3, 2] was expected.

    The cause was a stalled ordered chain. A Query that Query DB answered from its cache left a staged continuation waiting for a graph turn that never came. That trace now passes, and the oracle generates held deletes.

    This issue's own trace may share that cause or may not. The shared part is an on-demand joined window and an optimistic delete of a visible row. Re-check it against e34948bf1. The optimistic-delete dimension kept as a patch for this issue is still the witness this issue needs. No window is checked during a hold yet. #2186 tracks that.

    This comment was written by Isaac.

Sign in to join this conversation.