Skip to content

fix: missing "user left" system message after omnichannel room forward - #41480

Merged
ggazzo merged 2 commits into
developfrom
fix/livechat-forward-ul-message-race
Jul 20, 2026
Merged

fix: missing "user left" system message after omnichannel room forward#41480
ggazzo merged 2 commits into
developfrom
fix/livechat-forward-ul-message-race

Conversation

@KevLehman

@KevLehman KevLehman commented Jul 20, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

When an omnichannel room is forwarded (agent, department, or department fallback), RoutingManager.removeAllRoomSubscriptions removed each agent subscription with a fire-and-forget void removeAgentFromSubscription(...) inside a forEach. The ul (user left) system message written inside that call was never awaited by any caller, so it raced the rest of the transfer flow: the message could be persisted only after the transfer had already completed and the endpoint had responded. Anything reading the room history right after the transfer — like the LIVECHAT - rooms livechat/room.forward system messages sent on transfer should be properly generated API test — could intermittently see 0 ul messages, making that test flaky. It also allowed the message to land out of order relative to the transfer system messages.

Changes:

  • Await each removeAgentFromSubscription call (iterating the cursor directly) so the ul message is persisted before the transfer flow returns, and failures surface instead of being swallowed by the floating promise
  • Project only u from the subscriptions query, which is all the removal needs

Issue(s)

Steps to test or reproduce

  1. Create two departments with online agents, forward a livechat room from one to the other (livechat/room.forward)
  2. Fetch the room message history immediately — the previous agent's ul system message is now always already present

Further comments

The fire-and-forget dates back to the Fibers-era JS, where the call was effectively synchronous; the TS conversion added void to silence lint, making the race explicit but unhandled.

Task: CORE-2449

Summary by CodeRabbit

  • Bug Fixes
    • Fixed conversation forwarding so the “user left” system message appears in the correct order within conversation history.
    • Improved subscription removal handling to ensure agent removals complete reliably during room cleanup.

@dionisio-bot

dionisio-bot Bot commented Jul 20, 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 Jul 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 56dcabe

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 Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 02302924-f1ac-41a1-af16-2b55c8fa28c7

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8cd01 and 56dcabe.

📒 Files selected for processing (2)
  • .changeset/livechat-forward-ul-message.md
  • apps/meteor/server/lib/omnichannel/RoutingManager.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Hacktron Security Check
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (5/5)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (4/4)
  • GitHub Check: 🔨 Test UI (CE) / MongoDB 8.0 (1/4)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (3/5)
  • GitHub Check: 🔨 Test UI (EE) / MongoDB 8.0 coverage (4/5)
🧰 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/server/lib/omnichannel/RoutingManager.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/livechat-forward-ul-message.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/server/lib/omnichannel/RoutingManager.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/lib/omnichannel/RoutingManager.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/lib/omnichannel/RoutingManager.ts
🔇 Additional comments (2)
apps/meteor/server/lib/omnichannel/RoutingManager.ts (1)

374-379: LGTM!

.changeset/livechat-forward-ul-message.md (1)

1-5: LGTM!


Walkthrough

Changes

Omnichannel forwarding

Layer / File(s) Summary
Await room subscription removal
apps/meteor/server/lib/omnichannel/RoutingManager.ts, .changeset/livechat-forward-ul-message.md
removeAllRoomSubscriptions now processes subscriptions asynchronously and awaits each removal while preserving ignored-user filtering. The changeset records the patch and the message-order fix.

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

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 describes the main fix: the missing or delayed "user left" message after omnichannel room forwarding.
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.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • CORE-2449: 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 Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.59%. Comparing base (b0ecca0) to head (56dcabe).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #41480      +/-   ##
===========================================
- Coverage    68.62%   68.59%   -0.03%     
===========================================
  Files         4134     4134              
  Lines       160801   160802       +1     
  Branches     29247    29267      +20     
===========================================
- Hits        110342   110299      -43     
- Misses       45353    45398      +45     
+ Partials      5106     5105       -1     
Flag Coverage Δ
e2e 58.86% <ø> (-0.01%) ⬇️
e2e-api 45.34% <100.00%> (-0.02%) ⬇️
unit 70.54% <ø> (-0.05%) ⬇️

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.

@KevLehman

Copy link
Copy Markdown
Member Author

/jira CORE

@KevLehman KevLehman added this to the 8.7.0 milestone Jul 20, 2026
@KevLehman
KevLehman marked this pull request as ready for review July 20, 2026 18:10
@KevLehman
KevLehman requested a review from a team as a code owner July 20, 2026 18:10
@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jul 20, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 20, 2026

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

No issues found across 2 files

Re-trigger cubic

@ggazzo
ggazzo merged commit 8d4507d into develop Jul 20, 2026
99 of 101 checks passed
@ggazzo
ggazzo deleted the fix/livechat-forward-ul-message-race branch July 20, 2026 18:29
This was referenced Jul 20, 2026
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