Skip to content

fix: unread count racecondition#3784

Merged
jamesarich merged 3 commits into
meshtastic:mainfrom
mdecourcy:fix/unread-count-racecondition
Nov 22, 2025
Merged

fix: unread count racecondition#3784
jamesarich merged 3 commits into
meshtastic:mainfrom
mdecourcy:fix/unread-count-racecondition

Conversation

@mdecourcy

Copy link
Copy Markdown
Contributor

Root Cause:

The unread count clearing mechanism had a race condition when users sent messages during the debounce period. The LaunchedEffect was keyed on the entire messages list, which meant:

  1. User receives message, unread divider appears, 3-second debounce timer starts
  2. User sends message during this window, messages list changes
  3. LaunchedEffect(messages) restarts, cancels the in-flight debounce timer
  4. snapshotFlow starts fresh, but since the user isn't scrolling anymore, it doesn't emit a new value
  5. No new debounce timer starts, unread count never clears until another message arrives

Changes Made:

  1. Fixed race condition in UpdateUnreadCount

  2. Simplified and corrected unread marking logic

  3. Reduced debounce time

Improves responsiveness while still preventing database thrashing during scrolling

- Log when LaunchedEffect starts/restarts in UpdateUnreadCount
- Log when debounce triggers and clearing conditions
- Log message state changes and clearing attempts
- Log clearUnreadCount function calls and results

This will help identify why the unread divider never clears.
@github-actions github-actions Bot added the bugfix PR tag label Nov 22, 2025
@mdecourcy mdecourcy force-pushed the fix/unread-count-racecondition branch from 98b6d76 to 2f6e8e5 Compare November 22, 2025 02:26
@mdecourcy mdecourcy force-pushed the fix/unread-count-racecondition branch from 2f6e8e5 to 17a786d Compare November 22, 2025 02:27
@mdecourcy mdecourcy changed the title Fix: unread count racecondition fix: unread count racecondition Nov 22, 2025
@mdecourcy mdecourcy marked this pull request as ready for review November 22, 2025 02:30
@jamesarich jamesarich added this pull request to the merge queue Nov 22, 2025
Merged via the queue into meshtastic:main with commit 15481dd Nov 22, 2025
5 checks passed
@codecov

codecov Bot commented Nov 22, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.56%. Comparing base (f9575a2) to head (fb805f3).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...in/org/meshtastic/feature/messaging/MessageList.kt 0.00% 10 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #3784      +/-   ##
========================================
- Coverage   0.56%   0.56%   -0.01%     
========================================
  Files        381     381              
  Lines      21733   21738       +5     
  Branches    2684    2683       -1     
========================================
  Hits         122     122              
- Misses     21591   21596       +5     
  Partials      20      20              

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

@jamesarich jamesarich added this to the 2.7.8 milestone Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants