Skip to content

fix(unread counts): a gappy sync shouldn't decrease the unread counts#6284

Open
bnjbvr wants to merge 2 commits intomainfrom
bnjbvr/event-cache-shrink-unread-counts
Open

fix(unread counts): a gappy sync shouldn't decrease the unread counts#6284
bnjbvr wants to merge 2 commits intomainfrom
bnjbvr/event-cache-shrink-unread-counts

Conversation

@bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Mar 12, 2026

See code comments and commits descriptions :) This fixes a situation where a gappy sync could cause unread counts to decrease (because unread counts computation rely on the linked-chunk to be completely loaded up to the latest active read receipt).

  • I've documented the public API Changes in the appropriate CHANGELOG.md files.
  • This PR was made with the help of AI.

Part of #4113

bnjbvr added 2 commits March 12, 2026 16:17
This test exhibits an edge case: when a room event cache is shrunk
(because of a gappy/limited sync), then the unread count might decrease,
without the latest active read receipt changing.
A gappy sync may cause a linked chunk to shrink, waiting for callers to
lazy-reload it again in the future. But, because the unread counts
computation rely on the in-memory linked chunk, this means that the
values computed for the unread count may be incorrect (and decrease).

Fortunately, this situation is rather easy to detect, because the latest
active read receipt doesn't change in this case, so we can first check
that, and then manually readjust the unread counts, if they've
decreased.

Future work should trigger back-pagination in those cases, so the unread
counts keeps on being precise, despite the gappy sync.
@bnjbvr bnjbvr requested a review from a team as a code owner March 12, 2026 15:31
@bnjbvr bnjbvr requested review from Hywan and removed request for a team March 12, 2026 15:31
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.90%. Comparing base (b6c4bca) to head (030af23).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...es/matrix-sdk/src/event_cache/caches/room/state.rs 45.45% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6284   +/-   ##
=======================================
  Coverage   89.90%   89.90%           
=======================================
  Files         374      374           
  Lines      102613   102624   +11     
  Branches   102613   102624   +11     
=======================================
+ Hits        92250    92266   +16     
+ Misses       6798     6789    -9     
- Partials     3565     3569    +4     

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

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 12, 2026

Merging this PR will degrade performance by 60.29%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 49 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Restore session [memory store] 111.9 ms 281.8 ms -60.29%

Comparing bnjbvr/event-cache-shrink-unread-counts (030af23) with main (b6c4bca)

Open in CodSpeed

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