Skip to content

fix: discussion parent message count and last message time out of sync with the discussion - #41702

Merged
dionisio-bot[bot] merged 9 commits into
developfrom
fix/discussions-msg-count
Aug 7, 2026
Merged

dionisio-bot[bot] merged 9 commits into
developfrom
fix/discussions-msg-count

Conversation

@nazabucciarelli

@nazabucciarelli nazabucciarelli commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Proposed changes (including videos or screenshots)

Root cause 1: the refresh reads outdated values (lag of one message). In #33034 we moved the flush of the roomUpdater out of the notifyUsersOnMessage callback and into afterSaveMessage, where it now runs after the whole callback chain. Previously the room record was already updated by the MEDIUM priority notifyUsersOnMessage callback and then freshly consumed by PropagateDiscussionMetadata (LOW priority); nowadays that callback reads the room before the flush, so it propagates the pre-increment msgs and the previous lm.

Root cause 2: the refresh never runs for system messages. Message.saveSystemMessage does not run the afterSaveMessage callbacks at all: it inserts the message, increments the room counter and notifies the message and room changes. Since PropagateDiscussionMetadata is one of those callbacks, system messages added to a discussion leave the parent message outdated until the next user message triggers the refresh. This one is not a regression from #33034, it has been like that since discussions were introduced.

Solution 1: use the roomUpdater received by the callback to read the update filter operations staged in memory (getRawUpdateFilter()) and apply them on top of the room fetched from the database, so the discussion metadata is computed against the state the room is about to have.

Solution 2: refresh the discussion metadata from saveSystemMessage itself. The Rooms.incMsgCountById call it already performs is replaced with a new findOneAndIncMsgCountById, which returns the updated room from the increment already in flight, so the refresh costs no extra round trip.

Issue(s)

CORE-2517 Discussion parent message count (dcount) and last message time (dlm) are out of sync with the discussion

Steps to test or reproduce

Lag of one message

  1. Go to any channel and create a new discussion.
  2. Send the first message inside the newly created discussion.
  3. Look at the parent message in the original channel: it says "Reply / No messages yet" (dcount is 0, dlm is not set).
  4. Send a second message inside the discussion: it says "1 message", with the timestamp of the first one.
    Expected after the fix: the parent message reads "1 message" right after step 2, with the timestamp
    of that message.

System messages

  1. Create a discussion and send a message inside it.
  2. Add a user to the discussion, or change its topic, so a system message is added to it.
  3. Look at the parent message: the count and the timestamp do not change until a regular message is sent inside the discussion.

Expected after the fix: the parent message reflects the new message as soon as the system message is
added.

Further comments

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Fixed discussion parent message counts so they stay synchronized when regular or system messages are added.
    • Ensured the latest discussion activity timestamp is accurately reflected on the parent message.
    • Improved consistency of discussion metadata after activity.
  • Tests

    • Added end-to-end coverage for message counts and activity timestamps, including discussion rename system messages.

@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: 5c79bd8

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

This PR includes changesets to release 5 packages
Name Type
@rocket.chat/models Patch
@rocket.chat/model-typings Patch
@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

@nazabucciarelli nazabucciarelli added this to the 8.8.0 milestone Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Message-save flows now include pending room updates and returned room counts when propagating discussion metadata. End-to-end tests verify parent message counts and timestamps for regular and rename system messages.

Changes

Discussion metadata synchronization

Layer / File(s) Summary
Return updated room counts
packages/model-typings/src/models/IRoomsModel.ts, packages/models/src/models/Rooms.ts
The room model adds findOneAndIncMsgCountById, which increments msgs and returns the updated room.
Propagate discussion metadata
apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts, apps/meteor/server/services/messages/service.ts, apps/meteor/server/lib/messaging/discussions/updateAndNotifyParentRoomWithParentMessage.ts
Message-save flows apply pending msgs and lm updates before refreshing and notifying the discussion parent message.
Verify discussion metadata synchronization
apps/meteor/tests/end-to-end/api/rooms.ts, .changeset/tangy-cobras-beg.md
End-to-end tests verify dcount and dlm for regular discussion and rename system messages. The changeset records patch releases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MessageSave
  participant Rooms
  participant ParentRoomUpdater
  participant MessageNotifier
  MessageSave->>Rooms: Increment msgs and return updated room
  MessageSave->>ParentRoomUpdater: Refresh parent discussion metadata
  ParentRoomUpdater->>MessageNotifier: Notify refreshed parent message
Loading

Possibly related PRs

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary fix for discussion parent message count and last-message time synchronization.
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.
✨ 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-2517: 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

❌ Patch coverage is 58.82353% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.67%. Comparing base (a9296f1) to head (5c79bd8).
⚠️ Report is 11 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41702      +/-   ##
===========================================
+ Coverage    68.64%   68.67%   +0.02%     
===========================================
  Files         4162     4165       +3     
  Lines       158824   159274     +450     
  Branches     28107    28274     +167     
===========================================
+ Hits        109023   109375     +352     
- Misses       44628    44743     +115     
+ Partials      5173     5156      -17     
Flag Coverage Δ
e2e 58.89% <ø> (+0.04%) ⬆️
e2e-api 45.72% <58.82%> (-0.27%) ⬇️
unit 70.55% <ø> (+<0.01%) ⬆️

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.

@nazabucciarelli
nazabucciarelli marked this pull request as ready for review August 5, 2026 20:00
@nazabucciarelli
nazabucciarelli requested a review from a team as a code owner August 5, 2026 20:00

@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: 2

🧹 Nitpick comments (1)
apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts (1)

9-14: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove the implementation comment block.

Lines 9-14 add an implementation comment. Remove it. The helper name already describes the operation.

As per coding guidelines, **/*.{ts,tsx,js} must avoid code comments in implementation.

🤖 Prompt for 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.

In `@apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts` around
lines 9 - 14, Remove the implementation comment block immediately preceding the
helper in propagateDiscussionMetadata.ts, leaving the helper implementation
unchanged.

Source: Coding guidelines

🤖 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 @.changeset/tangy-cobras-beg.md:
- Line 5: Update the changeset entry describing the discussion parent metadata
fix to explicitly mention both corrected fields: the parent message count and
the parent dlm (last-message timestamp) value.

In `@apps/meteor/tests/end-to-end/api/rooms.ts`:
- Line 2094: Update the assertion for discussionMessage.dlm to validate its
timestamp value rather than only its existence. Capture the sent message
timestamp, normalize both dates consistently, and assert that
discussionMessage.dlm matches it.

---

Nitpick comments:
In `@apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts`:
- Around line 9-14: Remove the implementation comment block immediately
preceding the helper in propagateDiscussionMetadata.ts, leaving the helper
implementation unchanged.
🪄 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: 7cd3b57d-9457-421f-bf70-9cb7e8ef9fbf

📥 Commits

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

📒 Files selected for processing (3)
  • .changeset/tangy-cobras-beg.md
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 📦 Meteor Build (coverage)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/tangy-cobras-beg.md
📚 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/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.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/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.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/tests/end-to-end/api/rooms.ts
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts
🔇 Additional comments (2)
apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts (1)

3-8: LGTM!

Also applies to: 15-25, 44-44, 60-60

apps/meteor/tests/end-to-end/api/rooms.ts (1)

2063-2093: LGTM!

Also applies to: 2095-2096

Comment thread .changeset/tangy-cobras-beg.md Outdated
Comment thread apps/meteor/tests/end-to-end/api/rooms.ts Outdated

@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/tests/end-to-end/api/rooms.ts Outdated
@nazabucciarelli nazabucciarelli changed the title fix: discussion parent message count lagged by one fix: discussion parent message count and last message time lagged by one message Aug 5, 2026
cardoso
cardoso previously approved these changes Aug 6, 2026
@nazabucciarelli nazabucciarelli changed the title fix: discussion parent message count and last message time lagged by one message fix: discussion parent message count and last message time out of sync with the discussion Aug 6, 2026

@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: 2

🤖 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/services/messages/service.ts`:
- Around line 217-220: Update saveSystemMessage so failures from
updateAndNotifyParentRoomWithParentMessage do not propagate after the system
message and room count are persisted. Run this parent-room refresh as a
non-failing, repairable post-commit metadata sync while preserving the existing
conditional room?.prid behavior and successful save result.

In `@packages/models/src/models/Rooms.ts`:
- Around line 798-808: The findOneAndIncMsgCountById contract must always return
the post-increment IRoom without permitting caller-controlled upsert or
result-shape options. In Rooms.ts, restrict the method options type, filter out
returnDocument, includeResultMetadata, and upsert, and apply protected
returnDocument: 'after', includeResultMetadata: false, and upsert: false
settings after caller options are merged. Update
IRoomsModel.findOneAndIncMsgCountById in
packages/model-typings/src/models/IRoomsModel.ts:171 to use the same restricted
options type.
🪄 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: cba19e13-8dba-45a0-a28d-a2ed55a79613

📥 Commits

Reviewing files that changed from the base of the PR and between 2cd9cdc and e828a2f.

📒 Files selected for processing (6)
  • .changeset/tangy-cobras-beg.md
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • packages/model-typings/src/models/IRoomsModel.ts
  • packages/models/src/models/Rooms.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/meteor/server/hooks/messages/propagateDiscussionMetadata.ts
  • .changeset/tangy-cobras-beg.md
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
⚠️ CI failures not shown inline (3)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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:

  • packages/model-typings/src/models/IRoomsModel.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • packages/models/src/models/Rooms.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:

  • packages/model-typings/src/models/IRoomsModel.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • packages/models/src/models/Rooms.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:

  • packages/model-typings/src/models/IRoomsModel.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • packages/models/src/models/Rooms.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:

  • packages/model-typings/src/models/IRoomsModel.ts
  • apps/meteor/server/services/messages/service.ts
  • apps/meteor/tests/end-to-end/api/rooms.ts
  • packages/models/src/models/Rooms.ts
📚 Learning: 2026-07-15T01:31:50.632Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 41382
File: packages/model-typings/src/models/IPushTokenModel.ts:10-10
Timestamp: 2026-07-15T01:31:50.632Z
Learning: In Rocket.Chat’s push-token model, APNs/GCM standard tokens and PushKit VoIP tokens use distinct, globally-unique token string values. As a result, when deduplicating/looking up tokens, key identity solely on `{ tokenValue, appName }` (e.g., for `findOneByTokenAndAppName`, `removeDuplicateTokens`) and do **not** include `tokenType` in the uniqueness criteria to avoid collisions between standard and VoIP tokens.

Applied to files:

  • packages/model-typings/src/models/IRoomsModel.ts
  • packages/models/src/models/Rooms.ts
📚 Learning: 2026-08-05T22:02:59.828Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 41707
File: apps/meteor/server/hooks/messages/processThreads.ts:66-68
Timestamp: 2026-08-05T22:02:59.828Z
Learning: In Rocket.Chat Meteor server code, `callbacks.runAsync` returns its input item rather than the asynchronous callback promise. Callers of `afterReadMessages` must invoke `callbacks.runAsync` without awaiting it, keeping read-receipt I/O off the message-send path; this includes `apps/meteor/server/hooks/messages/processThreads.ts`.

Applied to files:

  • apps/meteor/server/services/messages/service.ts
🔇 Additional comments (3)
packages/models/src/models/Rooms.ts (1)

833-835: LGTM!

Also applies to: 1811-1817

apps/meteor/server/services/messages/service.ts (1)

21-21: LGTM!

Also applies to: 189-199

apps/meteor/tests/end-to-end/api/rooms.ts (1)

2073-2087: LGTM!

Also applies to: 2088-2094, 2096-2110

Comment thread apps/meteor/server/services/messages/service.ts
Comment thread packages/models/src/models/Rooms.ts Outdated

@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 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread apps/meteor/server/services/messages/service.ts Outdated
Comment thread apps/meteor/server/services/messages/service.ts Outdated
Comment thread packages/model-typings/src/models/IRoomsModel.ts Outdated
Comment thread apps/meteor/server/services/messages/service.ts Outdated

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/models/src/models/Rooms.ts (2)

801-811: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Enforce the protected MongoDB options at runtime.

Line 801 narrows the TypeScript type, but it does not remove properties from runtime objects. A value typed as the broader FindOneAndUpdateOptions can still contain upsert: true or includeResultMetadata: true. Line 811 forwards both options.

upsert: true can create an incomplete room when _id does not exist. includeResultMetadata: true changes the result shape and violates Promise<IRoom | null>. Set both values after spreading options.

Proposed fix
 		return this.findOneAndUpdate(query, update, {
 			...options,
 			returnDocument: 'after',
+			includeResultMetadata: false,
+			upsert: false,
 		});

This is the same unresolved contract risk identified in the previous review.

🤖 Prompt for 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.

In `@packages/models/src/models/Rooms.ts` around lines 801 - 811, Update the
findOneAndUpdate call in the room update method to override protected runtime
options after spreading options: set upsert and includeResultMetadata to false
while retaining returnDocument: 'after'. Preserve the existing query, update,
and Promise<IRoom | null> behavior.

1823-1824: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not cast the projected document to IRoom.

This query returns only abacAttributes and _id, but insertAbacAttributeIfNotExistsById is typed as Promise<IRoom | null>. Callers can read required IRoom fields such as msgs, t, or u from data that is absent at runtime. If callers need a full room, remove the projection. Otherwise, return an accurate projected type such as Pick<IRoom, '_id' | 'abacAttributes'> | null.

🤖 Prompt for 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.

In `@packages/models/src/models/Rooms.ts` around lines 1823 - 1824, Update
insertAbacAttributeIfNotExistsById to remove the unsafe cast to Promise<IRoom |
null> and accurately type the projected result as Pick<IRoom, '_id' |
'abacAttributes'> | null; keep the projection limited to the fields actually
returned.
🤖 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.

Outside diff comments:
In `@packages/models/src/models/Rooms.ts`:
- Around line 801-811: Update the findOneAndUpdate call in the room update
method to override protected runtime options after spreading options: set upsert
and includeResultMetadata to false while retaining returnDocument: 'after'.
Preserve the existing query, update, and Promise<IRoom | null> behavior.
- Around line 1823-1824: Update insertAbacAttributeIfNotExistsById to remove the
unsafe cast to Promise<IRoom | null> and accurately type the projected result as
Pick<IRoom, '_id' | 'abacAttributes'> | null; keep the projection limited to the
fields actually returned.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ba220ec5-da73-4189-9fa1-523bbc89a7b8

📥 Commits

Reviewing files that changed from the base of the PR and between e828a2f and be78193.

📒 Files selected for processing (3)
  • apps/meteor/server/services/messages/service.ts
  • packages/model-typings/src/models/IRoomsModel.ts
  • packages/models/src/models/Rooms.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/model-typings/src/models/IRoomsModel.ts
  • apps/meteor/server/services/messages/service.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
⚠️ CI failures not shown inline (5)

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**

GitHub Check: Dionisio QA: Some checks did not pass

Conclusion: failure

View job details

**Conclusion:** failure
### Steps
- ✅ **No merge conflicts**
- ❌ **QA assured** — This PR is missing the 'stat: QA assured' label
- ✅ **Mergeable**
- ✅ **Has milestone or project**
- ✅ **Valid PR title**
- ✅ **Correct target version**
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{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:

  • packages/models/src/models/Rooms.ts
🧠 Learnings (4)
📚 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:

  • packages/models/src/models/Rooms.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:

  • packages/models/src/models/Rooms.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:

  • packages/models/src/models/Rooms.ts
📚 Learning: 2026-07-15T01:31:50.632Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 41382
File: packages/model-typings/src/models/IPushTokenModel.ts:10-10
Timestamp: 2026-07-15T01:31:50.632Z
Learning: In Rocket.Chat’s push-token model, APNs/GCM standard tokens and PushKit VoIP tokens use distinct, globally-unique token string values. As a result, when deduplicating/looking up tokens, key identity solely on `{ tokenValue, appName }` (e.g., for `findOneByTokenAndAppName`, `removeDuplicateTokens`) and do **not** include `tokenType` in the uniqueness criteria to avoid collisions between standard and VoIP tokens.

Applied to files:

  • packages/models/src/models/Rooms.ts
🔇 Additional comments (1)
packages/models/src/models/Rooms.ts (1)

837-843: LGTM!

@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 (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread apps/meteor/server/services/messages/service.ts
cardoso
cardoso previously approved these changes Aug 7, 2026
tassoevan
tassoevan previously approved these changes Aug 7, 2026
@nazabucciarelli
nazabucciarelli dismissed stale reviews from tassoevan and cardoso via 5c79bd8 August 7, 2026 14:16
@jessicaschelly jessicaschelly added the stat: QA assured Means it has been tested and approved by a company insider label Aug 7, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Aug 7, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
@nazabucciarelli nazabucciarelli added stat: ready to merge PR tested and approved waiting for merge and removed stat: ready to merge PR tested and approved waiting for merge labels Aug 7, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Aug 7, 2026
Merged via the queue into develop with commit a9f3e6c Aug 7, 2026
99 of 101 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/discussions-msg-count branch August 7, 2026 20:49
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.

4 participants