Skip to content

Send typing indicators off the main thread - #2242

Draft
mpretty-cyro wants to merge 1 commit into
devfrom
fix/typing-indicator-off-main
Draft

mpretty-cyro wants to merge 1 commit into
devfrom
fix/typing-indicator-off-main

Conversation

@mpretty-cyro

@mpretty-cyro mpretty-cyro commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Contributor checklist

  • I have tested my contribution on these devices:
  • Virtual device: Pixel 6 profile, API 37 (arm64), play flavour, debug
  • My contribution is fully baked and ready to be merged as is
  • I ensure that all the open issues my contribution fixes are mentioned in the commit message of my first commit using the Fixes #1234 syntax

Description

The #1 ANR cluster on 1.33.7 ("Input dispatching timed out", top frame Unsafe.park) includes samples where the main thread is in
ConversationActivityV2.setUpTypingObserver → TypingStatusSender.sendTyping → MessageSender.send → JobQueue.add →
SessionJobDatabase.persistJob, waiting for a database connection.

TypingStatusSender now does the send (thread address and recipient lookup, MessageSender.send) on a dedicated single background
thread. The start/stop timers are unchanged and still run on the main thread; the single thread keeps sends in order.

No change inside MessageSender or JobQueue.

While the pool is busy, a queued "started" can now go out after a message sent in the meantime, so the recipient may see "typing" until it times out. Sending a message doesn't send "stopped", on dev or here.

Testing: reproduced on an emulator with a debug-only hook (not in this PR) that holds the database write lock: with typing indicators on, typing ANR'd on dev with the main thread in MessageSender.send → JobQueue.add → persistJob. With this change the same steps gave no ANR and no main-thread database access.

Every typing indicator was sent from the input field's text watcher on
the main thread: sendTyping read the thread's address and recipient and
MessageSender.send persisted a job. When the connection pool was busy,
typing froze the conversation until the app was killed for not
responding. Sends now run in order on a dedicated background thread.

@mpretty-cyro mpretty-cyro left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

lgtm

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