chore(llc): tolerate duplicate-keyed inputs in SortedListX.merge#2660
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesSortedListX.merge duplicate-key tolerance
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
`ChannelClientState.updateChannelState` calls `messages.merge(..., compare: _sortByCreatedAt)`, which previously asserted both inputs had unique keys. Pull-to-refresh with offline storage on could surface a legacy in-memory state with a duplicated message id and trip that assertion in `queryChannelsOffline` → `updateChannelState`. Drop the unique-key and sortedness asserts (sortedness is now a documented contract — behavior is undefined if violated) and remove the non-overlapping append/prepend fast paths that could emit duplicates when keys collide despite non-overlapping compare ranges. Everything routes through the two-pointer merge, which already handles all these cases correctly: keys present in `other` take precedence over the receiver, and stray receiver duplicates are propagated rather than crashing. Co-authored-by: Cursor <cursoragent@cursor.com>
06aff57 to
dfe0a69
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/stream_chat/lib/src/core/util/list_extensions.dart (1)
4-6: ⚡ Quick winNarrow the migration-equivalence claim for duplicate-key inputs.
Line 6 currently says both implementations produce the same result for sorted inputs, but this file now explicitly tolerates/propgates some duplicate-key cases. That can diverge from keyed-map merge behavior and may mislead the later import swap.
Suggested doc tweak
-// keyed-map-merge-and-sort. Both produce the same result for sorted inputs. +// keyed-map-merge-and-sort. They produce the same result for sorted inputs +// when keys are unique within each input.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/stream_chat/lib/src/core/util/list_extensions.dart` around lines 4 - 6, Update the top-of-file comment that compares the two-pointer merge to the keyed-map-merge-and-sort to explicitly narrow the equivalence: state that both produce the same result for sorted inputs that do not contain conflicting duplicate keys (or when duplicate-key handling is equivalent), and note that this file's two-pointer merge may tolerate/propagate certain duplicate-key cases while the keyed-map approach deduplicates/overwrites; adjust the sentence referencing `merge` and "keyed-map-merge-and-sort" accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/stream_chat/lib/src/core/util/list_extensions.dart`:
- Around line 4-6: Update the top-of-file comment that compares the two-pointer
merge to the keyed-map-merge-and-sort to explicitly narrow the equivalence:
state that both produce the same result for sorted inputs that do not contain
conflicting duplicate keys (or when duplicate-key handling is equivalent), and
note that this file's two-pointer merge may tolerate/propagate certain
duplicate-key cases while the keyed-map approach deduplicates/overwrites; adjust
the sentence referencing `merge` and "keyed-map-merge-and-sort" accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f718eaa2-a867-44fa-88f7-667f0f47c167
📒 Files selected for processing (3)
packages/stream_chat/CHANGELOG.mdpackages/stream_chat/lib/src/core/util/list_extensions.dartpackages/stream_chat/test/src/core/util/list_extensions_test.dart
SortedListX.mergeSortedListX.merge
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2660 +/- ##
==========================================
- Coverage 65.29% 65.27% -0.02%
==========================================
Files 423 423
Lines 26635 26622 -13
==========================================
- Hits 17390 17377 -13
Misses 9245 9245 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
ChannelClientState.updateChannelStatecallsmessages.merge(..., compare: _sortByCreatedAt), which previously asserted both inputs had unique keys. Pull-to-refresh with offline storage enabled could surface a legacy in-memory channel state with a duplicated message id and trip that assertion inqueryChannelsOffline→updateChannelState(list_extensions.dart:123).othertake precedence over the receiver, and stray receiver duplicates are propagated rather than crashing.Repro that motivated the fix
Surfaces only when offline storage is enabled and a stale in-memory channel state contains a duplicate id.
Behaviour after the fix (no callers in
channel.dartneed to change)otherotherwinsotherotherhas dupTest plan
dart test packages/stream_chat/test/src/core/util/list_extensions_test.dart— 33/33 pass (added 3 new duplicate-tolerance cases, dropped 4 assert-trip cases)dart test packages/stream_chat/test/src/client/channel_test.dart— 276/276 passdart test(fullstream_chatsuite) — 1225/1225 pass (2 pre-existing skipped)dart analyzeclean on changed filesMade with Cursor
Summary by CodeRabbit
Improvements
Tests