Skip to content

fix: read receipts of thread messages stuck as "sent" - #41707

Merged
dionisio-bot[bot] merged 2 commits into
developfrom
fix/thread-read-receipts
Aug 13, 2026
Merged

fix: read receipts of thread messages stuck as "sent"#41707
dionisio-bot[bot] merged 2 commits into
developfrom
fix/thread-read-receipts

Conversation

@ricardogarim

@ricardogarim ricardogarim commented Aug 5, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

The problem. A thread reply only turns into a double check once the server has a read record from every member of the room, and it then clears messages up to the oldest of those records. Nothing ever wrote that record for the author of the reply, so the author stayed missing from the count and the gate never closed. Rooms don't have this problem: sending already counts as reading there, since notifyUsersOnMessage sets the sender's own ls right after saving. #27074 (e9667ed, 6.0.0) gave threads the gate, in MessageReadsService.readThread, without the equivalent write.

Why it usually looked fine. The record was written by a client side effect: the author's browser receives its own message back over the WebSocket and, while its local copy is still the unconfirmed (temp) one, treats it as new and calls chat.readThread on itself. Not a designed path — the receipt was riding on a dedup heuristic.

Why it broke. Whenever that heuristic doesn't run:

  1. No web client at all — replies posted through the API, a bot or a webhook. Nothing compensates, so it fails every time.
  2. The server's two replies arrive out of order. The browser gets its own message back twice: the POST response, which marks the local copy confirmed, and the WebSocket copy, which triggers readThread — but only while that copy is still unconfirmed, a check that keeps the client from treating its own message as one that just arrived from someone else. Response first, and the WebSocket copy is dismissed as already known, so readThread never runs. That is the normal order in a scaled deployment, where a separate process terminates the socket and the message travels farther back than the response does; bursts produce it too.
  3. The author leaves before the echo — closes the pane, switches room, reloads.

The call is skipped, not delayed: no retry, no catch-up. The only recovery was reopening the thread, which calls readThread regardless of any echo (useThreadMessagesQuery) — that writes the record late, the gate closes, and the stuck replies jump to double check at once.

The fix. processThreads now writes the record when the reply is saved, through afterReadMessages, the same hook the canonical read path uses. It runs after the metadata update, since readThread bails out while the parent's tlm is unset, and skips edits. The write happens before any broadcast, so arrival order stops mattering and the echo goes back to being just rendering.

Issue(s)

Steps to test or reproduce

Requires an EE license with Message_Read_Receipt_Enabled and Message_Read_Receipt_Store_Users on, and a channel with two members, A and B.

On a single-process dev instance the echo always wins, so the compensation always hides the bug. Emulating the extra hop of a scaled deployment makes it deterministic — in notifyOnMessageChange, apps/meteor/server/lib/notifyListener.ts:

// local only, revert afterwards
setTimeout(() => void api.broadcast('watch.messages', { message }), 300);

Restart, then:

  1. As A, post a message and open it as a thread.
  2. As B, reply once, from the UI.
  3. As A, open the thread and react to the reply, without replying.
  4. On develop the reply stays on a single check, every time. With this branch it turns into a double check.

Without touching code: have B reply through chat.sendMessage passing tmid — no browser to compensate, so it fails on a plain instance too. In the failing state, "Read receipts" lists only A. Use a fresh channel per round, and don't reopen the thread as B — that calls readThread and heals it.

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Thread replies now correctly update to “viewed” after the thread is read, instead of remaining marked as “sent.”
    • Edited replies and non-thread messages retain their existing read-status behavior.

@ricardogarim ricardogarim added this to the 8.8.0 milestone Aug 5, 2026
@dionisio-bot

dionisio-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7d3657a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

processThreads now triggers afterReadMessages for non-edited thread replies after metadata updates. Unit tests cover callback behavior and exclusions. A patch changeset documents the thread read-status fix.

Changes

Thread read callback

Layer / File(s) Summary
Thread read callback and validation
apps/meteor/server/hooks/messages/processThreads.ts, apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts, .changeset/kind-peas-greet.md
processThreads invokes afterReadMessages for non-edited thread replies. Tests verify callback arguments, ordering, and negative cases. The changeset documents the read-status fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the fix for thread message read receipts remaining in the "sent" state.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2508: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.63%. Comparing base (a9296f1) to head (7d3657a).
⚠️ Report is 38 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41707      +/-   ##
===========================================
- Coverage    68.64%   68.63%   -0.01%     
===========================================
  Files         4162     4164       +2     
  Lines       158824   158974     +150     
  Branches     28107    28209     +102     
===========================================
+ Hits        109023   109116      +93     
- Misses       44628    44681      +53     
- Partials      5173     5177       +4     
Flag Coverage Δ
e2e 58.89% <ø> (+0.04%) ⬆️
e2e-api 45.73% <50.00%> (-0.26%) ⬇️
unit 70.53% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/meteor/server/hooks/messages/processThreads.ts`:
- Around line 66-68: Update processThreads so the afterReadMessages callback is
awaited and its promise is returned when processing an unedited message,
ensuring asynchronous thread read-receipt writes complete and failures
propagate. Add coverage for both successful read-receipt completion and callback
failure.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c834f75-ab28-4487-b174-e8dbbbcd0bdf

📥 Commits

Reviewing files that changed from the base of the PR and between 692be5e and c6986f4.

📒 Files selected for processing (2)
  • apps/meteor/server/hooks/messages/processThreads.ts
  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: 🚢 Build Docker (amd64, account-service, presence-service, omnichannel-transcript-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: 🚢 Build Docker (arm64, account-service, presence-service, omnichannel-transcript-service, cove...
  • GitHub Check: 🚢 Build Docker (amd64, rocketchat, fips)
  • GitHub Check: 🚢 Build Docker (amd64, account-service, presence-service, omnichannel-transcript-service, fips)
  • GitHub Check: 🚢 Build Docker (amd64, authorization-service, queue-worker-service, ddp-streamer-service, cove...
  • GitHub Check: 🚢 Build Docker (amd64, rocketchat, coverage)
  • GitHub Check: 🚢 Build Docker (amd64, authorization-service, queue-worker-service, ddp-streamer-service, fips)
  • GitHub Check: 🚢 Build Docker (arm64, rocketchat, coverage)
  • GitHub Check: 🔎 Code Check / Code Lint
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/server/hooks/messages/processThreads.ts
  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
🧠 Learnings (5)
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/server/hooks/messages/processThreads.ts
  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/server/hooks/messages/processThreads.ts
  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/server/hooks/messages/processThreads.ts
  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
🔇 Additional comments (1)
apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts (1)

1-66: LGTM!

Comment thread apps/meteor/server/hooks/messages/processThreads.ts
@ricardogarim
ricardogarim marked this pull request as ready for review August 5, 2026 22:13
@ricardogarim
ricardogarim requested a review from a team as a code owner August 5, 2026 22:13

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread apps/meteor/server/hooks/messages/processThreads.ts
Comment thread apps/meteor/tests/unit/server/hooks/messages/processThreads.spec.ts
Comment thread apps/meteor/server/hooks/messages/processThreads.ts
Comment thread apps/meteor/server/hooks/messages/processThreads.ts
@nazabucciarelli nazabucciarelli added the stat: QA assured Means it has been tested and approved by a company insider label Aug 12, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 12, 2026
@ricardogarim ricardogarim removed this from the 8.8.0 milestone Aug 12, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 12, 2026
@ricardogarim ricardogarim added this to the 8.8.0 milestone Aug 12, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 12, 2026
@alfredodelfabro alfredodelfabro removed this from the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@alfredodelfabro alfredodelfabro added this to the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@ricardogarim ricardogarim removed this from the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@ricardogarim ricardogarim added this to the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@ricardogarim ricardogarim removed this from the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@ricardogarim ricardogarim added this to the 8.8.0 milestone Aug 13, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 13, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Aug 13, 2026
Merged via the queue into develop with commit 02e633c Aug 13, 2026
350 of 371 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/thread-read-receipts branch August 13, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants