Skip to content

fix: geohash online count accuracy and channel switch latency#672

Open
moehamade wants to merge 1 commit intopermissionlesstech:mainfrom
moehamade:fix/geohash-online-count
Open

fix: geohash online count accuracy and channel switch latency#672
moehamade wants to merge 1 commit intopermissionlesstech:mainfrom
moehamade:fix/geohash-online-count

Conversation

@moehamade
Copy link
Contributor

Summary

  • Stale timestamp overwrite: relays deliver events newest-first (NIP-01), so a user's older heartbeats were overwriting their fresher lastSeen, pushing them past the 5-minute cutoff and dropping them from the count. Fix: only update lastSeen when the incoming timestamp is strictly newer.
  • Silent ConcurrentModificationException: event processing ran on Dispatchers.Default (thread pool), causing concurrent coroutines to hit the same HashMap with iterator() + put() simultaneously. The resulting ConcurrentModificationException was swallowed by the catch block, so heartbeat updates were silently dropped — only less-frequent chat messages updated the count reliably. Fix: process events on viewModelScope's default dispatcher (Main), which is single-threaded.
  • Channel switch latency: switching to a new geohash channel set currentGeohash but never called refreshGeohashPeople(), so the header count waited for a relay round-trip even though sampling subscriptions had already populated participant data for that channel. Fix: call refreshGeohashPeople() immediately after setCurrentGeohash().

Test plan

  • Open a geohash channel — online count matches iOS (~50) and stays stable
  • Leave app open for 5+ minutes — count does not drop to 0 between heartbeat cycles
  • Switch between geohash channels — count updates immediately without waiting for relay response
  • Send a chat message — count does not increment by exactly 1 (presence drives the count, not messages)

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 18f54d33f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Keep max lastSeen per user so relay's newest-first delivery doesn't
  overwrite a fresh timestamp with a stale one
- Serialize event processing on Main dispatcher to eliminate
  ConcurrentModificationException on geohashParticipants maps
- Immediately refresh people list on channel switch so sampling data
  is reflected before the first relay response arrives
@moehamade moehamade force-pushed the fix/geohash-online-count branch from 18f54d3 to 9528f50 Compare February 19, 2026 15:10
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