Skip to content

fix(llc): Don't upsert out-of-window messages on message.updated/message.deleted events#2815

Open
VelikovPetar wants to merge 1 commit into
v9from
port/master-to-v9/FLU-560_message-updated-out-of-window
Open

fix(llc): Don't upsert out-of-window messages on message.updated/message.deleted events#2815
VelikovPetar wants to merge 1 commit into
v9from
port/master-to-v9/FLU-560_message-updated-out-of-window

Conversation

@VelikovPetar

Copy link
Copy Markdown
Contributor

Submit a pull request

Linear: FLU-560

Github Issue: #

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Backport of #2794 (FLU-560) from master to v9.

message.updated and soft message.deleted events were being unconditionally upserted into ChannelState.messages (and thread reply lists). When the target message wasn't in the currently loaded window — e.g. it lived on an older page the client hadn't paged in yet — this created a phantom entry in the sorted list, leaving a visible gap between the loaded slice and history.

Manual port (not a clean cherry-pick)

The original master change lives on bug/FLU-560_fix_message_updated_event_inserting_messages (earliest commit 9f39525). It could not be cherry-picked: master's updateMessage/deleteMessage were refactored into an _updateMessages / _updateThreadMessages / _mergeMessagesIntoExisting family that doesn't exist on v9, where these methods are still monolithic. The same intent was re-implemented against the v9 architecture.

What changed on v9

  • _listenMessageUpdated (which on v9 also handles reaction.updated) now passes upsert: false.
  • ChannelClientState.updateMessage gains a {bool upsert = true} flag. With upsert: false, an out-of-window message (id not already in messages) is not inserted into the sorted list, but pinned-message maintenance still runs.
  • deleteMessage's soft-delete path now uses upsert: false (hard deletes are unchanged). Since the public deleteMessage also backs the optimistic delete flow, two existing optimistic-delete tests were updated to seed the message first.
  • ChannelClientState.updateThreadInfo gains a {bool upsert = true} flag that guards against creating a phantom threads[parentId] entry for a thread that was never paged in, and against inserting unknown replies into a loaded thread.

The guard is id-based and independent of isUpToDate — even at the latest page we may have paginated past older history and receive an event for a message no longer in memory.

Tests

Ported the applicable coverage from #2794:

  • New ChannelClientState.updateMessage group (upsert true/false, in-window update).
  • messageUpdated → "outside loaded window": no phantom insert, out-of-window pin still lands, unknown reply not inserted into a thread, no phantom thread entry.
  • New messageDeleted group: soft delete doesn't insert a phantom record, in-window soft delete marks as deleted, hard delete is a no-op out of window.

Three tests from the master PR were skipped because the underlying features don't exist on v9: the two activeLiveLocations tests (no live-location feature on v9) and the _pinIsValid unpin test (no _pinIsValid on v9).

Full stream_chat suite passes locally.

Screenshots / Videos

No UI changes.

…essage.deleted` events

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e2199071-a12c-4802-a092-1f839883041c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch port/master-to-v9/FLU-560_message-updated-out-of-window

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@VelikovPetar VelikovPetar marked this pull request as ready for review July 14, 2026 13:41
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.28571% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v9@4a7ca7a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/stream_chat/lib/src/client/channel.dart 94.28% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##             v9    #2815   +/-   ##
=====================================
  Coverage      ?   66.91%           
=====================================
  Files         ?      430           
  Lines         ?    27143           
  Branches      ?        0           
=====================================
  Hits          ?    18162           
  Misses        ?     8981           
  Partials      ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant