fix(db): preserve exact D2 rows during sync reconciliation - #1794
fix(db): preserve exact D2 rows during sync reconciliation#1794obeattie wants to merge 4 commits into
Conversation
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
Co-authored-by: Codex <codex@openai.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughLive query and effect pipelines now track the exact rows contributed to D2. Updates and deletes retract those stored rows. Tests cover row reconciliation and updates to synchronously confirmed optimistic inserts. A patch changeset records the fix. ChangesLive query reconciliation
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: 🔵 Low · up to The PR correctly preserves exact rows during live-query reconciliation, preventing duplicate and update failures in normal operation. A bounded recovery risk remains if graph processing fails after bookkeeping is updated, which warrants owner awareness or follow-up but does not block merge under normal checks. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Collection
participant CollectionSubscriber
participant prepareChangesForD2
participant D2Pipeline
Collection->>CollectionSubscriber: update optimistically inserted row
CollectionSubscriber->>prepareChangesForD2: provide change and sent row map
prepareChangesForD2->>D2Pipeline: emit update with exact previousValue
D2Pipeline-->>CollectionSubscriber: process reconciled live query change
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Linked Issues checkExplanation The changes address issue Full details: Docstring CoverageExplanation Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🎯 Changes
Fixes #1783.
D2 applies an update by removing the old row and adding the new one. The row being removed must exactly match the row previously added. The state diverged like this:
Query contributors with the same row key are not congruent.Any differing property can cause this; it is not specific to
$syncedor$origin. A focused test demonstrates the same mismatch with a normalstatusproperty. Changing the hashing would only hide the mismatch by making different rows appear equal. The correct fix is to remove the exact row that was previously added.I bisected the regression to #1740. That PR added the congruence check which exposed the incorrect removal. This check is correct; the source bookkeeping was not.
The fix remembers the exact row sent to D2 for each key and uses it for later updates and deletes. The same bookkeeping also prevents duplicate inserts.
The regression test covers the original optimistic insert and synchronous sync confirmation, then verifies that the collection and live query each contain exactly one updated row.
✅ Checklist
pnpm test.🚀 Release Impact
Summary by CodeRabbit
Bug Fixes
Tests