Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f26f423c14
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| Log.d(TAG, "Queued PM for ${toPeerID} (no mesh, no Nostr mapping) msg_id=${messageID.take(8)}…") | ||
| val q = outbox.getOrPut(toPeerID) { mutableListOf() } | ||
| val q = outbox.getOrPut(toPeerID) { Collections.synchronizedList(mutableListOf()) } | ||
| q.add(Triple(content, recipientNickname, messageID)) |
There was a problem hiding this comment.
Avoid non-atomic getOrPut on ConcurrentHashMap
Because outbox is now a ConcurrentHashMap, getOrPut is no longer atomic. If two threads queue a message for the same peerID concurrently and the key is absent, both can create separate lists and one put will overwrite the other; the messages added to the losing list are no longer reachable and will never flush. This regression only appears under concurrent sends (e.g., UI and background threads) and defeats the “thread-safe” change. Use computeIfAbsent or synchronize around creation to guarantee a single list per peer.
Useful? React with 👍 / 👎.
38b91d5 to
f26f423
Compare
Summary
This PR improves the responsiveness and reliability of private messaging during the Noise session establishment phase.
Key Changes
MessageRouterto useConcurrentHashMapand synchronized lists, ensuring safe concurrent access between the UI and background services.onSessionEstablishedcallback to the mesh delegate to allow the UI to transition immediately from "handshaking" to "secure" state.Verification Results
MessageRouteroutbox.Reviewer Recommendations
MessageRouter.ktchanges for thread-safety.onSessionEstablisheddelegate method inChatViewModelandMeshDelegateHandler.