diff --git a/.changeset/replace-fragmented-join-demand.md b/.changeset/replace-fragmented-join-demand.md new file mode 100644 index 0000000000..123544c2a7 --- /dev/null +++ b/.changeset/replace-fragmented-join-demand.md @@ -0,0 +1,5 @@ +--- +'@tanstack/db': patch +--- + +Consolidate fragmented join demand after churn while retaining established coverage until the union replacement applies. Monotonic growth continues to load only new keys. diff --git a/docs/contributing/oracle-coverage.md b/docs/contributing/oracle-coverage.md index 9685576f1b..b9c904af04 100644 --- a/docs/contributing/oracle-coverage.md +++ b/docs/contributing/oracle-coverage.md @@ -101,7 +101,7 @@ comment and the current API/architecture contract before extending its model. | Surface | Primary executable owners | Independent judgment and important limit | | --- | --- | --- | | Ordered relations and BTree | [top-K relation oracle](https://github.com/TanStack/db/blob/main/packages/db-ivm/tests/operators/topk-relation-oracle.test.ts), [BTree/Map](https://github.com/TanStack/db/blob/main/packages/db/tests/btree-map-oracle.test.ts), [incrementalization laws](https://github.com/TanStack/db/blob/main/packages/db-ivm/tests/incrementalization-law.property.test.ts) | Independent ordered relations and cumulative signed output. Top-K consolidation compares same-key values without hashing, including cyclic replacements and fresh transient cancellation. Other hash-based operators retain hashing's declared domain. Algebra does not specify client readiness. | -| Includes and publication | [cross-formulation](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-cross-formulation-oracle.property.test.ts), [temporal](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-temporal-oracle.test.ts), [Collection includes](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-collection-oracle.property.test.ts), [architecture and complete suite map](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/ARCHITECTURE.md#executable-contracts) | Per-parent/flat-join/partition relations, callback-time rows, nested values, and route histories. Observe raw promised order; fresh queries do not establish continuous publication safety. | +| Includes and publication | [cross-formulation](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-cross-formulation-oracle.property.test.ts), [temporal](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-temporal-oracle.test.ts), [Collection includes](https://github.com/TanStack/db/blob/main/packages/db/tests/query/includes-collection-oracle.property.test.ts), [architecture and complete suite map](https://github.com/TanStack/db/blob/main/packages/db/src/query/live/ARCHITECTURE.md#executable-contracts) | Per-parent/flat-join/partition relations, callback-time rows, nested values, and route histories. Fragmented lazy-demand consolidation covers delta growth and successful, rejected/retried, and obsolete replacements at the Collection request boundary; it observes exact key unions and abort checkpoints. A compiled-includes fixture makes adapter unload evict owned child rows and proves a rejected union cannot remove established public child rows. Retry after that terminal live-query failure remains covered at the acquisition boundary; no automatic in-place recovery is claimed. Observe raw promised order; fresh queries do not establish continuous publication safety. | | Collection lifecycle | [mutation startup](https://github.com/TanStack/db/blob/main/packages/db/tests/collection-mutation-startup-oracle.test.ts), [history](https://github.com/TanStack/db/blob/main/packages/db/tests/collection-subscription-lifecycle-history.property.test.ts), [publication](https://github.com/TanStack/db/blob/main/packages/db/tests/collection-subscription-lifecycle-publication.property.test.ts), [replay](https://github.com/TanStack/db/blob/main/packages/db/tests/collection-subscription-replay-oracle.property.test.ts), [effect disposal](https://github.com/TanStack/db/blob/main/packages/db/tests/effect-disposal-oracle.test.ts) | Core Collection `insert`/`update`/`delete` admission while `startSync:false` is idle; ownership and phase histories; exact caller/error/publication evidence; late completion and restart. Query write utilities and effect self-dependent disposal remain separate contracts. | | Optimistic state | [history model](https://github.com/TanStack/db/blob/main/packages/db/tests/optimistic-history-oracle.ts), [generated histories](https://github.com/TanStack/db/blob/main/packages/db/tests/optimistic-transaction-oracle.property.test.ts), [truncate capture ownership](https://github.com/TanStack/db/blob/main/packages/db/tests/collection-truncate-ownership-oracle.property.test.ts), [outcomes](https://github.com/TanStack/db/blob/main/packages/db/tests/optimistic-history-outcomes.test.ts), [publication](https://github.com/TanStack/db/blob/main/packages/db/tests/optimistic-history-publication.test.ts) | Independent whole-row snapshots, rollback dependencies, captured truncate ownership, metadata and prior-value events. Never rebase a pending snapshot merely to simplify the model. | | Drafts and native values | [proxy](https://github.com/TanStack/db/blob/main/packages/db/tests/proxy.test.ts), [detachment](https://github.com/TanStack/db/blob/main/packages/db/tests/proxy-detachment-contract.test.ts), [iteration](https://github.com/TanStack/db/blob/main/packages/db/tests/proxy-iteration-contract.test.ts) | Native-operation controls, exact patches and actual stored rows; alias/cycle/adversarial-key histories. General native-mutator and symbol-write support is not established by a plain-object oracle. | diff --git a/packages/db/src/query/live/ARCHITECTURE.md b/packages/db/src/query/live/ARCHITECTURE.md index 8f6401af9e..727b37681e 100644 --- a/packages/db/src/query/live/ARCHITECTURE.md +++ b/packages/db/src/query/live/ARCHITECTURE.md @@ -734,6 +734,16 @@ of that contract. Buffering, snapshot tokens, shape offsets, Collection transactions, and local indexes are source-specific ways to satisfy it; they are not materializer state. +Lazy-demand growth requests only uncovered keys. When contraction or churn +would leave fragmented coverage, the controller requests one complete current +key union while retaining every established acquisition that still intersects +current demand. It releases those acquisitions only after the replacement's +applied settlement. A failed or obsolete replacement cannot retire established +coverage, and a retry requests the same union again. A partial shrink may keep +one intersecting acquisition without replacement. This avoids repeatedly +loading the growing prefix while allowing a changing bounded window to return +to one acquisition. + Every sync `commit()` returns an applied receipt: `true` when that transaction's writes and events are already visible, or a promise when the transaction is parked in the causal queue. The promise resolves only after the @@ -1191,6 +1201,8 @@ create recursive Collection machinery. graph work. 10. **Initial demand:** preload completes when every initially reachable demand is covered; obsolete demand does not block it. + Lazy-demand growth loads only uncovered keys. A fragmented churn replacement + retires prior coverage only after its union applies; failure preserves it. 11. **Ownership:** a query-db row exists exactly while an explicit owner remains. 12. **Work:** irrelevant rows do not cause unrelated scans or activate unrelated diff --git a/packages/db/src/query/live/subset-demand-controller.ts b/packages/db/src/query/live/subset-demand-controller.ts index af194a92ce..e252f1113a 100644 --- a/packages/db/src/query/live/subset-demand-controller.ts +++ b/packages/db/src/query/live/subset-demand-controller.ts @@ -12,7 +12,8 @@ type DemandSegment = { where: BasicExpression abortController: AbortController ready: LoadSubsetRequestResult - state: `pending` | `settled` | `failed` + state: `starting` | `pending` | `settled` | `failed` + replaces?: Array } type DemandState = { @@ -28,8 +29,8 @@ export type DemandUpdate = { /** * Keeps lazy subset requests aligned with the current relation of demanded - * keys. Additions load only new coverage. Removals release and rebuild only - * request segments that covered a removed key. + * keys. Growth loads only new keys. Churn replaces fragmented coverage after + * the replacement applies, so prior coverage remains live in the meantime. */ export class SubsetDemandController { private readonly states = new Map() @@ -55,22 +56,32 @@ export class SubsetDemandController { return { changed: false, empty: nextKeys.size === 0, ready: true } } - const segments: Array = [] + const segments = (previous?.segments ?? []).filter( + (segment) => + segment.state !== `failed` && + intersects(segment.keys, nextKeys) && + (!segment.replaces || equalKeySets(segment.keys, nextKeys)), + ) + const retired = (previous?.segments ?? []).filter( + (segment) => !segments.includes(segment), + ) + const retryReplacement = previous?.segments.some( + (segment) => + segment.replaces && + segment.state === `failed` && + equalKeySets(segment.keys, nextKeys), + ) + const state: DemandState = { keys: nextKeys, segments } + this.states.set(plan.id, state) - for (const segment of previous?.segments ?? []) { - if (segment.state !== `failed` && intersects(segment.keys, nextKeys)) { - segments.push(segment) - continue - } + for (const segment of retired) releaseSegment(subscription, segment) + if (this.states.get(plan.id) !== state) { + return { changed: false, empty: false, ready: true } + } - segment.abortController.abort() - try { - subscription.releaseSnapshot(segment.where) - } catch { - // The subscription reports adapter cleanup failures after its one - // release attempt. Demand changes must still reach the graph instead - // of escaping the source commit; adapters own any remote retry. - } + if (nextKeys.size === 0) { + this.states.delete(plan.id) + return { changed: true, empty: true, ready: true } } const coveredKeys = new Set( @@ -79,29 +90,45 @@ export class SubsetDemandController { const added = new Map( [...nextKeys].filter(([key]) => !coveredKeys.has(key)), ) - if (added.size > 0) { - segments.push( - requestSegment(subscription, plan, added, () => - this.warnUnoptimized(plan), - ), + const removed = previous + ? [...previous.keys.keys()].some((key) => !nextKeys.has(key)) + : false + const replace = + retryReplacement || (removed && (added.size > 0 || segments.length > 1)) + const requestedKeys = replace ? nextKeys : added + if (requestedKeys.size > 0) { + const segment = createSegment(plan, requestedKeys) + if (replace) segment.replaces = [...segments] + segments.push(segment) + const started = startSegment(subscription, segment, () => + this.warnUnoptimized(plan), ) + if (this.states.get(plan.id) !== state) { + return { changed: false, empty: false, ready: true } + } + if (!started) throw new Error(`Subset demand snapshot did not start`) + if (replace) { + if (segment.ready instanceof Promise) { + void segment.ready.then( + () => this.finishReplacement(subscription, plan.id, segment), + () => {}, + ) + } else { + this.finishReplacement(subscription, plan.id, segment) + } + } } - if (nextKeys.size === 0) { - this.states.delete(plan.id) - } else { - this.states.set(plan.id, { keys: nextKeys, segments }) - } - - const activeSegments = segments.filter((segment) => - intersects(segment.keys, nextKeys), - ) - const pending = activeSegments + const pending = state.segments + .filter( + (segment) => + segment.state === `pending` && intersects(segment.keys, nextKeys), + ) .map((segment) => segment.ready) .filter((ready): ready is Promise => ready instanceof Promise) return { changed: true, - empty: nextKeys.size === 0, + empty: false, ready: pending.length > 0 ? Promise.all(pending) : true, } } @@ -115,6 +142,25 @@ export class SubsetDemandController { this.valueIdentity = createValueIdentity() } + private finishReplacement( + subscription: CollectionSubscription, + planId: string, + replacement: DemandSegment, + ): void { + const state = this.states.get(planId) + if ( + !state?.segments.includes(replacement) || + !equalKeySets(replacement.keys, state.keys) + ) { + releaseSegment(subscription, replacement) + return + } + const replaced = replacement.replaces ?? [] + replacement.replaces = undefined + state.segments = [replacement] + for (const segment of replaced) releaseSegment(subscription, segment) + } + private warnUnoptimized(plan: LazyDemandPlan): void { if (this.warnedPlans.has(plan.id)) return this.warnedPlans.add(plan.id) @@ -153,34 +199,39 @@ function intersects( return [...left.keys()].some((key) => right.has(key)) } -function requestSegment( - subscription: CollectionSubscription, +function createSegment( plan: LazyDemandPlan, keys: Map, - onUnoptimized: () => void, ): DemandSegment { const where = inArray(new PropRef(plan.path), [...keys.values()]) - const abortController = new AbortController() - const load = { ready: true as LoadSubsetRequestResult } - subscription.requestSnapshot({ + return { + keys, where, - signal: abortController.signal, + abortController: new AbortController(), + ready: true, + state: `starting`, + } +} + +function startSegment( + subscription: CollectionSubscription, + segment: DemandSegment, + onUnoptimized: () => void, +): boolean { + let observed = false + const requested = subscription.requestSnapshot({ + where: segment.where, + signal: segment.abortController.signal, trackLoadSubsetPromise: false, onUnoptimized, onLoadSubsetResult: (result) => { - load.ready = result + observed = true + segment.ready = result + segment.state = result instanceof Promise ? `pending` : `settled` }, }) - const ready = load.ready - const segment: DemandSegment = { - keys, - where, - abortController, - ready, - state: ready instanceof Promise ? `pending` : `settled`, - } - if (ready instanceof Promise) { - void ready.then( + if (segment.ready instanceof Promise) { + void segment.ready.then( () => { segment.state = `settled` }, @@ -189,5 +240,17 @@ function requestSegment( }, ) } - return segment + return requested && observed +} + +function releaseSegment( + subscription: CollectionSubscription, + segment: DemandSegment, +): void { + segment.abortController.abort() + try { + subscription.releaseSnapshot(segment.where) + } catch { + // CollectionSubscription has already reported the one cleanup failure. + } } diff --git a/packages/db/tests/query/includes-temporal-oracle.test.ts b/packages/db/tests/query/includes-temporal-oracle.test.ts index 74f7745b21..48a7429040 100644 --- a/packages/db/tests/query/includes-temporal-oracle.test.ts +++ b/packages/db/tests/query/includes-temporal-oracle.test.ts @@ -17,6 +17,7 @@ import { runTrace } from '../trace-runner.js' import { oraclePropertyOptions } from '../oracle-config.js' import { flushPromises } from '../utils.js' import type { Collection } from '../../src/collection/index.js' +import type { CollectionSubscription } from '../../src/collection/subscription.js' import type { Deferred } from '../../src/deferred.js' import type { LoadSubsetOptions, SyncAppliedReceipt } from '../../src/types.js' import type { LazyDemandPlan } from '../../src/query/compiler/joins.js' @@ -37,6 +38,8 @@ import type { Scheduler } from 'fast-check' * 4. A successful load settles only after its source writes are public. * 5. Failure belongs to the demand that failed. Retired failure cannot poison * a later demand or keep unrelated graph work private. + * 6. Growth loads only uncovered keys. Churn replaces fragmented coverage only + * after the complete current union applies; failure preserves prior coverage. * * No one state machine mirrors the production controller. The file uses small * models for readiness, cancellation, scheduled completion, and progressive @@ -46,8 +49,16 @@ import type { Scheduler } from 'fast-check' * * The production drivers use real Collections, compiled includes, applied * receipts, release callbacks, replay barriers, and source writes. They observe - * readiness, preload settlement, visible rows, request keys, and errors at each - * named boundary. The live-query architecture remains the contract source. + * readiness, preload settlement, visible rows, request keys, release signals, + * and errors at each named boundary. The live-query architecture remains the + * contract source. + * + * The fragmented-demand lanes observe requested key unions and adapter abort + * signals before settlement and after success, rejection, retry, or + * obsolescence. The direct controller lane proves the acquisition-retirement + * boundary. A compiled includes lane also makes adapter unload remove owned + * rows, so rejection proves that established child rows remain publicly + * visible rather than only that old signals remain live. */ type Post = { @@ -56,6 +67,11 @@ type Post = { title: string } +type PostChange = { + type: `insert` | `delete` + value: Post +} + type Comment = { id: number postId: number @@ -1262,10 +1278,11 @@ function createMutablePosts( options: { markReadyInitially?: boolean } = {}, ): { collection: Collection - write: (type: `insert` | `delete`, post: Post) => void + write: (type: PostChange[`type`], post: Post) => void + writeBatch: (changes: ReadonlyArray) => void markReady: () => void } { - let writePost: (type: `insert` | `delete`, post: Post) => void = () => { + let writePosts: (changes: ReadonlyArray) => void = () => { throw new Error(`Post collection has not started`) } let markPostsReady: () => void = () => { @@ -1280,9 +1297,9 @@ function createMutablePosts( for (const post of initial) write({ type: `insert`, value: post }) commit() if (options.markReadyInitially !== false) markReady() - writePost = (type, post) => { + writePosts = (changes) => { begin() - write({ type, value: post }) + for (const change of changes) write(change) commit() } markPostsReady = markReady @@ -1291,7 +1308,8 @@ function createMutablePosts( }) return { collection, - write: (type, post) => writePost(type, post), + write: (type, post) => writePosts([{ type, value: post }]), + writeBatch: (changes) => writePosts(changes), markReady: () => markPostsReady(), } } @@ -1387,6 +1405,238 @@ async function expectRetainedDemandBlocksReadiness(): Promise { } } +async function expectDemandChurnPreservesCoverage( + replacementOutcome: `success` | `failure` | `obsolete`, +): Promise { + const { collection, requests } = createPendingComments() + const subscription = collection.subscribeChanges(() => {}, { + includeInitialState: false, + }) + const controller = new SubsetDemandController() + const plan: LazyDemandPlan = { + id: `churn-consolidation`, + path: [`postId`], + collectionId: collection.id, + initialKeys: new Set(), + } + const settle = async (index: number, ready: Promise | true) => { + requests[index]!.deferred.resolve() + await requests[index]!.outcome + if (ready instanceof Promise) await ready + } + + try { + for (let key = 1; key <= 3; key++) { + const update = controller.setDemand( + subscription, + plan, + new Set(Array.from({ length: key }, (_, index) => index + 1)), + ) + expect(requests[key - 1]!.keys).toEqual([key]) + await settle(key - 1, update.ready) + } + expect(requests.flatMap(({ keys }) => keys)).toHaveLength(3) + + const replacement = controller.setDemand( + subscription, + plan, + new Set([2, 3, 4]), + ) + expect(requests[3]!.keys).toEqual([2, 3, 4]) + expect(requests[1]!.signal?.aborted).toBe(false) + expect(requests[2]!.signal?.aborted).toBe(false) + + if (replacementOutcome === `failure`) { + if (!(replacement.ready instanceof Promise)) { + throw new Error(`Expected replacement demand to be asynchronous`) + } + const failure = new Error(`replacement failed`) + const failed = Promise.all([requests[3]!.outcome, replacement.ready]) + requests[3]!.deferred.reject(failure) + await expect(failed).rejects.toBe(failure) + expect(requests[1]!.signal?.aborted).toBe(false) + expect(requests[2]!.signal?.aborted).toBe(false) + + const retry = controller.setDemand(subscription, plan, new Set([2, 3, 4])) + expect(requests[3]!.signal?.aborted).toBe(true) + expect(requests[4]!.keys).toEqual([2, 3, 4]) + expect(requests[1]!.signal?.aborted).toBe(false) + expect(requests[2]!.signal?.aborted).toBe(false) + await settle(4, retry.ready) + } else if (replacementOutcome === `obsolete`) { + const current = controller.setDemand(subscription, plan, new Set([2, 3])) + expect(requests[3]!.signal?.aborted).toBe(true) + expect(requests[4]!.keys).toEqual([2, 3]) + expect(requests[1]!.signal?.aborted).toBe(false) + expect(requests[2]!.signal?.aborted).toBe(false) + await settle(3, replacement.ready) + expect(requests[1]!.signal?.aborted).toBe(false) + expect(requests[2]!.signal?.aborted).toBe(false) + await settle(4, current.ready) + } else { + await settle(3, replacement.ready) + } + + expect(requests[1]!.signal?.aborted).toBe(true) + expect(requests[2]!.signal?.aborted).toBe(true) + } finally { + for (const request of requests) request.deferred.resolve() + await Promise.allSettled(requests.map(({ outcome }) => outcome)) + controller.clear() + subscription.unsubscribe() + await collection.cleanup() + } +} + +async function expectFailedConsolidationKeepsVisibleRows(): Promise { + const posts = createMutablePosts([ + { id: 1, authorId: `selected`, title: `one` }, + ]) + const requests: Array<{ + deferred: Deferred + outcome: Promise + keys: Array + signal: AbortSignal | undefined + }> = [] + const installed = new Map() + const acquisitionKeys = new Map>() + const comments = createCollection({ + id: nextCollectionId(`temporal-visible-coverage-comments`), + getKey: (comment) => comment.id, + syncMode: `on-demand`, + autoIndex: `eager`, + defaultIndexType: BasicIndex, + sync: { + sync: ({ begin, write, commit, markReady }) => ({ + loadSubset: (options) => { + const deferred = createDeferred() + const keys = correlationKeys([options], `postId`) + const outcome = deferred.promise.then(async () => { + if (options.signal?.aborted) return + begin() + for (const postId of keys) { + const comment = { + id: postId * 100, + postId, + body: `comment ${postId}`, + } + installed.set(postId, comment) + write({ type: `insert`, value: comment }) + } + const applied = commit(options.signal) + if (applied instanceof Promise) await applied + acquisitionKeys.set(options, keys) + markReady() + }) + requests.push({ deferred, outcome, keys, signal: options.signal }) + return outcome + }, + unloadSubset: (options) => { + const keys = acquisitionKeys.get(options) + if (!keys) return + acquisitionKeys.delete(options) + begin() + for (const postId of keys) { + const comment = installed.get(postId) + if (comment) write({ type: `delete`, value: comment }) + installed.delete(postId) + } + commit() + }, + }), + }, + }) + const live = createPostsWithCommentsLive(posts.collection, comments) + const consoleError = vi.spyOn(console, `error`).mockImplementation(() => {}) + const settle = async (index: number) => { + requests[index]!.deferred.resolve() + await requests[index]!.outcome + await flushPromises() + } + const visibleCommentIds = () => + live.toArray + .flatMap(({ comments: rows }) => rows.map(({ id }) => id)) + .sort((left, right) => left - right) + + try { + const preload = live.preload() + await flushPromises() + expect(requests.map(({ keys }) => keys)).toEqual([[1]]) + await settle(0) + await preload + + for (let postId = 2; postId <= 3; postId++) { + posts.write(`insert`, { + id: postId, + authorId: `selected`, + title: String(postId), + }) + await flushPromises() + expect(requests.at(-1)?.keys).toEqual([postId]) + await settle(postId - 1) + } + expect(visibleCommentIds()).toEqual([100, 200, 300]) + + posts.writeBatch([ + { + type: `delete`, + value: { id: 1, authorId: `selected`, title: `one` }, + }, + { + type: `insert`, + value: { id: 4, authorId: `selected`, title: `four` }, + }, + ]) + await flushPromises() + expect(requests[3]?.keys).toEqual([2, 3, 4]) + expect(requests[1]?.signal?.aborted).toBe(false) + expect(requests[2]?.signal?.aborted).toBe(false) + + const failure = new Error(`replacement failed`) + requests[3]!.deferred.reject(failure) + await expect(requests[3]!.outcome).rejects.toBe(failure) + await flushPromises() + + expect(live.status).toBe(`error`) + expect(live.utils.lastSubsetError).toBe(failure) + expect(visibleCommentIds()).toEqual([200, 300]) + } finally { + for (const request of requests) request.deferred.resolve() + await Promise.allSettled(requests.map(({ outcome }) => outcome)) + await live.cleanup() + await Promise.all([posts.collection.cleanup(), comments.cleanup()]) + consoleError.mockRestore() + } +} + +function expectContradictoryReplacementStartCrashes(): void { + const releaseSnapshot = vi.fn() + let requestCount = 0 + const subscription = { + requestSnapshot: ( + options?: Parameters[0], + ) => { + requestCount += 1 + options?.onLoadSubsetResult?.(true, { where: options.where }, () => {}) + return requestCount === 1 + }, + releaseSnapshot, + } as unknown as CollectionSubscription + const controller = new SubsetDemandController() + const plan: LazyDemandPlan = { + id: `contradictory-replacement-start`, + path: [`postId`], + collectionId: `contradictory-replacement-start`, + initialKeys: new Set(), + } + + controller.setDemand(subscription, plan, new Set([1, 2])) + expect(() => + controller.setDemand(subscription, plan, new Set([2, 3])), + ).toThrow(`Subset demand snapshot did not start`) + expect(releaseSnapshot).not.toHaveBeenCalled() +} + async function expectObsoleteDemandCannotSettleReactivatedDemand(): Promise { const post = { id: 1, authorId: `selected`, title: `one` } const posts = createMutablePosts([post], { markReadyInitially: false }) @@ -2120,6 +2370,25 @@ describe(`includes temporal oracle`, () => { expectRetainedDemandBlocksReadiness, ) + it(`consolidates churn after apply without reloading monotonic growth`, () => + expectDemandChurnPreservesCoverage(`success`)) + + it(`failed churn replacement retains coverage and retries its union`, () => + expectDemandChurnPreservesCoverage(`failure`)) + + it( + `failed churn replacement keeps established child rows visible`, + expectFailedConsolidationKeepsVisibleRows, + ) + + it(`obsolete churn replacement cannot retire established coverage`, () => + expectDemandChurnPreservesCoverage(`obsolete`)) + + it( + `crashes before replacing coverage when snapshot admission contradicts its result`, + expectContradictoryReplacementStartCrashes, + ) + it( `obsolete demand cannot settle a reactivated demand incarnation`, expectObsoleteDemandCannotSettleReactivatedDemand,