fix(db): scope truncate origin and test refused persisted inserts #2078
MergedKyleAMathewsmerged 16 commits into
main fromrefs/pull/2078/headmerged by KyleAMathews KyleAMathews changed the title
- docs/contributing/oracle-reviews/issue-2071-refused-insert.md line 52OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +32,21 @@32+Authority: the optimistic-state and accepted-sync-transaction contracts in `docs/contributing/glossary.md` and `optimistic-history-oracle.ts`. A local insert overlays the applied source rows while its handler runs. On rejection its optimistic state drops. Only an accepted source transaction can change the applied base or durable adapter. This is an outcome law; it does not choose the reporter's proposed repair mechanism. It covers R01–R03, R05, and R07.33+34+The old portfolio exercised core rollback but did not cross a rejecting `onInsert` through the sync-present persisted wrapper with source work on the same key, nor receive that controlled event with a fresh real SQLite adapter. The new independent single-row source reference state starts empty. Four legal histories cross first source `insert`/`delete` with acceptance before/after refusal, then apply the opposite turn. A source insert before refusal is an accepted independent source row, so it may survive; a refused local intent alone may not. The production path is `collection.insert` → wrapped `onInsert` → `SyncConfig` → real Collection and recording adapter. The driver compares the live row, exposed `collection.base`, durable adapter row, and origin while optimistic, after source acceptance, at `isPersisted` rejection, and after each source receipt. A held receipt must remain pending until the mutation settles.35+36+The real receiving path uses `createSQLiteCorePersistenceAdapter` with a SQLite CLI driver. It observes the absent durable row, accepted same-key source delete, live/base absence after rejection, later insert/delete/replacement, and reopening the same SQLite file with a new Collection, adapter, and driver. It does not restart an OS process. Its two histories cover reopen before later writes and reopen after the continuation. They receive the controlled delete-before-refusal premise, but do not receive every insert/timing cell.37+38+Encoding and enforcement are complete **for these bounded histories and checkpoints**: the independent source reference state predicts the row, and the production comparison reaches each named cut. They are not complete for the reporter's bridge, other mutation kinds, on-demand sync, other SQLite hosts, or a process restart. A reachable bridge-specific counterexample would keep the product class open; the current evidence does not establish its absence.39+40+### L2. Accepted source writes apply in order and receipts wait for visibility41+42+Authority: the accepted-sync-transaction glossary entry and the persisted wrapper contract. An accepted source transaction becomes durable and then visible in order. A same-key delete can remove an absent source key and still must reach core. If publication waits behind a persisting mutation, its commit receipt waits too. This covers R04 and the source portion of R02/R07.43+44+The refusal matrix checks source insert/delete in both orders and at settlement and each receipt. The real receiver confirms that a delete reaches the adapter and core and that subsequent source writes replace the row in live, base, storage, and reopened Collection. The original gap was the absence of a refused-insert wrapper history with a direct same-key source continuation. The model can represent absent keys, later replacement, and independent source writes; the recorder does not collapse them to a final snapshot. The exact private bridge sequencing remains uncovered.45+46+### L3. `$origin` is key-and-timing attribution, not causal authorship47+48+The old public API text said a `local` source row originated from this client. `SyncConfig.write` carries no source-client identity. Two temporary RED probes disproved that wording on the reviewed core: an independent peer write accepted on the same key during a successful local mutation was labeled `local`, and a second queued same-key source transaction was labeled `remote` even though it too was accepted before settlement. We chose the observed attribution contract, as directed in this review, and corrected API comments, guide, generated reference pages, production comments, glossary, and oracle prose. No production branch was changed.49+50+For one local mutation without truncate, a successful settlement grants local attribution to the first queued same-key source transaction. Every same-key write inside that atomic transaction keeps it; an absent-key delete consumes it without leaving a row. Later queued same-key transactions are remote without another local owner. A rejected mutation grants those queued writes none. A truncate is a distinct legal cut: it can publish a same-key source row while the mutation still persists, leaving that row labeled local after the mutation later fails. Local-only Collections always label rows local. These are attribution rules, not evidence of the writer's identity.51+52+The core `HistoryModel` independently tracks applied rows, local mutations, and accepted source batches. Its existing driver compares virtual properties, live rows, event replicas, downstream rows, request outcomes, and publication cuts after each step. New fixed witnesses reach one and two queued transactions, two different same-key writes inside the first atomic transaction, an absent-key delete followed by insert, and truncate before failed settlement. The persisted wrapper receives the one/two queued pair. The new truncate witness also prevents the revised public prose from overclaiming that every failed mutation leaves remote origin. This law is encoded and asserted for these histories. The current source-batch grammar writes rows before deletes, so it cannot express delete then reinsert within one batch. Overlapping same-key mutations and all truncate/source combinations are not claimed as exhausted; causal authorship would require a new source signal, model, and real-provider redocs/reference/interfaces/VirtualRowProps.md line 6OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3,4 +3,4 @@33 title: VirtualRowProps44 ---556-Defined in: [packages/db/src/virtual-props.ts:60](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L60)6+Defined in: [packages/db/src/virtual-props.ts:67](https://github.com/TanStack/db/blob/main/packages/db/src/virtual-props.ts#L67)
- docs/contributing/oracle-reviews/pr-2078-origin-attribution.md lines 199 to 201OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +181,21 @@181+added in this PR. The generated `VirtualRowProps` and `VirtualOrigin` reference182+pages linked to old source line numbers; all seven declaration links now match183+`virtual-props.ts`. These follow-ups do not change the eight-item accounting184+above. All reported CI checks passed on `e659d413e0f52fa0f9d800fb1d5a41ca784199c3`.185+186+CodeRabbit's next review, [5459093045](https://github.com/TanStack/db/pull/2078#pullrequestreview-5459093045),187+checked that head and found an oracle harness defect. Its three findings across188+both reviews are accounted for separately from the user's eight findings:189+190+| ID | Claim | Verdict and evidence | PR action and durable value |191+| --- | --- | --- | --- |192+| CR1 | The earlier #2071 review record still claimed that delete then reinsert was outside the source-batch grammar. | Correct on `00fcf0f`; the ordered grammar and coverage-map witness existed by that commit. | **fixed-now** in `e659d413e`; historical wording now identifies the earlier limit and later witness. |193+| CR2 | Six `VirtualRowProps` anchors and one `VirtualOrigin` anchor pointed into source comments. | Correct on `00fcf0f`; all seven current anchors match the declarations at lines 74, 85, 104, 133, 141, 149, and 36. | **fixed-now** in `e659d413e`; generated reference links were corrected. |194+| CR3 | A rejected pending manual transaction never starts its handler, so its `isPersisted` promise and oracle cleanup can remain pending. Commit the transaction after rejecting its handler promise. | Correct on `e659d413e`. Two source-row histories and one later-edit history failed at the settlement row assertion after the test first made cleanup safe. The proposed single-line fix alone leaves a later-edit history pending because the shared `starting` variable points to the later request. | **fixed-now** in this follow-up: commit the rejected manual request, bind each manual handler to its own deferred result, and release any still-active transaction during cleanup. The primary oracle and coverage map retain the law and limits. |195+196+The reviewer's three findings were accurate and focused. The proposed fix for197+CR3 identified the missing commit but did not account for a later edit replacing198+the shared deferred promise. The reviews distinguished documentation defects199+from a test-integrity defect and had little noise. **Hire recommendation:** yes200+for further review work, with adjacent interleavings checked before accepting201+the proposed patch verbatim.
- docs/contributing/oracle-reviews/pr-2078-origin-attribution.md line 387OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +367,21 @@367+hosts, or the unavailable private #2071 bridge sequence; their executable368+owners and needed witnesses remain in the coverage map.369+370+### CodeRabbit review of `ee21b1797`371+372+[Review 5460095613](https://github.com/TanStack/db/pull/2078#pullrequestreview-5460095613)373+contained one outside-diff behavior suggestion and one inline documentation374+suggestion. Both are accounted for here; its suggested agent prompts and local375+tool invocation are review metadata, not additional findings.376+377+| ID | Claim and proposed action | Evidence and technical verdict | Disposition and durable value |378+| --- | --- | --- | --- |379+| CR4 | The model keeps `activeKeys` after an empty truncate while production clears its active-key tracking; clear `activeKeys` after taking the batch snapshot. | Production did clear active tracking on the reviewed `ee21b1797`, so the observation was accurate there. Its proposed model change contradicts the `VirtualOrigin` active-key law and would make the model accept M01's product regression. After the production repair at `a109687c1`, that change was run as a temporary model mutant. Both new key 2 cases failed at their intended public cuts: the nonoptimistic case at complete source publication and the optimistic case at `isPersisted` settlement. The mutant was removed. | **stale** as a production/model mismatch after M01's repair; **refuted** as a model repair. Keep the empty-truncate/different-key challenge under the optimistic-history owner. |380+| CR5 | Remove a hiring recommendation from the engineering review record. | Correct maintainability point: the durable record needs code and test evidence; the user-facing review can carry the requested reviewer assessment. | **fixed-now.** Removed the personnel recommendation from this record while retaining the technical quality assessment and all law evidence. |381+382+CodeRabbit accounting for this review: **2 raw items = 1 stale with a refuted383+repair + 1 fixed-now**. CR4's historical observation and useful adversarial384+history remain recorded; no product law or test coverage was weakened to385+accept the proposed model change.386+387+### Merge-readiness self-review after green CI
KyleAMathews merged thisf6aba31
KyleAMathews closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: d4fad4e3c2f63863969905bee15f14e4f01a63c6
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 24 packages
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