Skip to content

fix: wait for the read marker of an opened room with unread messages - #218

Open
meenzen wants to merge 1 commit into
mainfrom
fix/tui-unread-marker-race
Open

meenzen wants to merge 1 commit into
mainfrom
fix/tui-unread-marker-race

Conversation

@meenzen

@meenzen meenzen commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Fixes the flaky UnreadMessages_ShouldBeCountedInTheRoomList (TUI client tests), which failed 4 of ~8 CI runs of the recent Renovate PRs with Timed out after 00:00:30 waiting for "Rooms (1 unread)".

Cause

Reproduced locally (4 cores under load) with temporary logging of ShowTimeline:

46.553 ShowTimeline selectUnread=True  count=3  loadedHistory=False kinds=In,Da,Me   ← U opened the room: only the newest message
46.580 ShowTimeline selectUnread=True  count=2  loadedHistory=True  kinds=Da,Me      ← PaginateBackwards returned…
46.580 MarkAsRead   selected=2 count=3                                               ← …no marker yet: treated as read, receipt sent
46.610 ShowTimeline count=13 …,Me,Me                                                 ← the page's items arrive ~30 ms later
46.611 ShowTimeline count=14 In,MARKER,Da,…                                          ← and the read marker with them

ChatWindow.ShowTimeline stopped waiting for the read marker once OpenedRoom.LoadedHistory was set, but the SDK delivers the paginated items (and the marker) asynchronously after PaginateBackwards returns.

Fix

  • While the opened room's summary reports unread messages, the TUI keeps waiting for the marker after the history loaded. Without unread messages nothing changes.
  • Moving in the timeline (j/k/G/gg/Ctrl-d/…) ends the wait and checks whether the user reached the end, so a room whose marker never comes is still marked as read once the user reads to the end.

Tests

  • TUI client tests: 141/141 passed
  • RoomTests 60× pinned to 4 loaded cores (the setup that reproduced the flake at run 39 before): no unread failure. One run failed all 8 tests at once, a homeserver/container setup failure that also happened before the fix.

🤖 Generated with Claude Code

An opened room stopped waiting for its first unread message once the first
page of history was loaded. The SDK delivers the items of that page, and with
them the read marker, after PaginateBackwards returned: in between the TUI saw
no marker, showed the end of the timeline and sent a read receipt.

While the room has unread messages it now keeps waiting for the marker, moving
in the timeline ends the wait, so the room is still marked as read when the
marker never comes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.80%. Comparing base (4f730f3) to head (d9bb8fc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
+ Coverage   79.72%   79.80%   +0.08%     
==========================================
  Files          76       76              
  Lines        7240     7250      +10     
  Branches      928      933       +5     
==========================================
+ Hits         5772     5786      +14     
+ Misses       1160     1156       -4     
  Partials      308      308              

☔ 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.

This branch has not been deployed

No deployments
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