Skip to content

fix: business-hour availability not recomputed when agents are removed from a department - #41158

Merged
dionisio-bot[bot] merged 4 commits into
developfrom
fix/business-hour-agents-availability
Jul 4, 2026
Merged

fix: business-hour availability not recomputed when agents are removed from a department#41158
dionisio-bot[bot] merged 4 commits into
developfrom
fix/business-hour-agents-availability

Conversation

@KevLehman

@KevLehman KevLehman commented Jul 3, 2026

Copy link
Copy Markdown
Member

Proposed changes (including videos or screenshots)

Related to the aggregation audit in #41157 (independent — can merge in any order; rebased onto develop).

LivechatDepartment.findAgentsByBusinessHourId (EE) passes its pipeline double-wrapped — aggregate([[...stages]]) — and MongoDB rejects non-object pipeline elements (TypeMismatch: Each element of the 'pipeline' array must be an object, reproduced against a live server). The method has thrown on every invocation since it was introduced in #31468 (2024-01-19).

Its only call path is fire-and-forget: updateDepartmentAgentscallbacks.runAsync('livechat.removeAgentDepartment')MultipleBusinessHoursBehavior.onRemoveAgentFromDepartmenthandleRemoveAgentsFromDepartments. runAsync schedules callbacks via setTimeout with a discarded promise, so the rejection surfaces as an unhandled promise rejection. Per RocketChat.ErrorHandler.ts, the impact depends on the environment:

  • development / TEST_MODE / EXIT_UNHANDLEDPROMISEREJECTION set: process.exit(1)removing an agent from a business-hour-linked department crashes the server (reproduced locally).
  • production default: logged and swallowed — agent removal succeeds but the removed agents' openBusinessHours is never recomputed, leaving their livechat availability stale until an unrelated event refreshes it.

This PR unwraps the pipeline so the recomputation actually executes, and adds two EE e2e tests:

  1. Removing an agent from its only department falls back to the default business hour — fails against the unfixed code (verified by temporarily reverting the fix: the callback rejected and the dev server exited).
  2. Removing an agent from one of two departments sharing the same business hour keeps that business hour open — exercises the agentIds set the fixed aggregation returns. A control agent (only in the first department, removed in the same request) must observably fall back to the default business hour first, proving the recomputation ran — the kept-state assertion equals the pre-removal state, so it isn't meaningful on its own.

Both tests poll for the result since the recomputation is asynchronous.

Issue(s)

Steps to test or reproduce

  1. EE license, enable business hours in Multiple mode.
  2. Create a custom business hour linked to a department; add an agent to that department.
  3. Remove the agent from the department (department edit → save).
  4. Before: unhandled TypeMismatch rejection (dev/test: server exits; prod: silently skipped bookkeeping, agent keeps stale openBusinessHours). After: the agent's business hour closes or falls back to the default business hour.

Or: IS_EE=true yarn testapi:livechat --grep 'On agent removed from department'

Further comments

Requires EE + multiple business hours + a department linked to a business hour — narrow enough that the failure survived 2.5 years.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Livechat business-hours availability so agent status updates correctly after an agent is removed from a department linked to business hours (including when multiple business hours are enabled).
    • Prevented agents from being marked open/closed based on business hours that no longer apply, improving recomputation reliability and overall stability.
  • Tests

    • Added end-to-end coverage for agent-removal scenarios, including overlapping-department behavior, to ensure cached business-hours availability updates correctly.

Task: CORE-2378

@dionisio-bot

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

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fbd687d

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 3, 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

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: caba63d0-705a-4a71-bd7a-12e7900cae3c

📥 Commits

Reviewing files that changed from the base of the PR and between 6308d81 and fbd687d.

📒 Files selected for processing (1)
  • .changeset/fix-business-hour-agents-availability.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-business-hour-agents-availability.md
📜 Recent review details
⏰ Context from checks skipped due to timeout. (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build

Walkthrough

Adds a Changesets patch note for a business-hours agent availability recomputation fix, reformats the aggregation pipeline in findAgentsByBusinessHourId, and adds end-to-end tests verifying cached openBusinessHours recomputes after agents are removed from departments, including overlapping-department scenarios.

Changes

Business Hour Agent Availability Fix

Layer / File(s) Summary
Changeset and pipeline formatting
.changeset/fix-business-hour-agents-availability.md, apps/meteor/ee/server/models/raw/LivechatDepartment.ts
Adds a patch changeset describing the recomputation fix and its unhandled-rejection crash risk; reformats aggregation pipeline punctuation and whitespace without altering stages or logic.
EE suite setup and recompute helper
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
Imports createAnOnlineAgent, enables multiple business-hour mode, resets custom business hours, creates department/agent fixtures, and adds a polling helper to await async recomputation of openBusinessHours.
Single-department removal case
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
Adds a test verifying an agent removed from its only linked department falls back to the default business hour.
Overlapping department case and cleanup
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
Adds a test verifying overlapping department membership preserves the shared custom business hour while a control agent falls back to default; adds per-test and suite-level cleanup.

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

Suggested labels: type: bug

Suggested reviewers: gabriellsh

🚥 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 matches the main fix: recomputing business-hour availability when agents are removed from a department.
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-2378: 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.

@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

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.30%. Comparing base (115dfe8) to head (fbd687d).
⚠️ Report is 34 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop   #41158    +/-   ##
=========================================
  Coverage    69.29%   69.30%            
=========================================
  Files         3539     3545     +6     
  Lines       138832   139290   +458     
  Branches     24767    24908   +141     
=========================================
+ Hits         96210    96537   +327     
- Misses       38607    38725   +118     
- Partials      4015     4028    +13     
Flag Coverage Δ
e2e 59.53% <ø> (+0.13%) ⬆️
e2e-api 49.76% <ø> (-0.10%) ⬇️
unit 70.14% <ø> (-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.

@KevLehman
KevLehman requested a review from a team as a code owner July 3, 2026 01:56

@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

🧹 Nitpick comments (1)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts (1)

738-738: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Implementation comments added.

As per coding guidelines, **/*.{ts,tsx,js} should "Avoid code comments in the implementation." These explanatory comments about the fire-and-forget timing could be dropped or moved into more descriptive test/variable names.

Also applies to: 753-753, 791-791, 815-815

🤖 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/tests/end-to-end/api/livechat/19-business-hours.ts` at line 738,
The livechat business-hours test contains implementation comments that should be
removed from the code; the note about the fire-and-forget recomputation timing
should be expressed through clearer test/variable names instead of inline
comments. Update the affected sections in the 19-business-hours test to drop
these explanatory comments while keeping the polling/assertion flow in the same
test helpers and steps.

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 `@apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts`:
- Around line 790-824: The test in the business-hours scenario still relies on a
fixed sleep, which can hide failures in the async recomputation path. Replace
the sleep in the test around addOrRemoveAgentFromDepartment/getMe with an
explicit wait helper or polling assertion that watches
ILivechatAgent.openBusinessHours until the expected settled state is observed.
Use the existing test helpers and the latestAgent assertion block to wait for
the transition instead of assuming a 2-second delay is enough.

---

Nitpick comments:
In `@apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts`:
- Line 738: The livechat business-hours test contains implementation comments
that should be removed from the code; the note about the fire-and-forget
recomputation timing should be expressed through clearer test/variable names
instead of inline comments. Update the affected sections in the
19-business-hours test to drop these explanatory comments while keeping the
polling/assertion flow in the same test helpers and steps.
🪄 Autofix (Beta)

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

Run ID: e005dcd5-1d9b-4f6d-b586-af607665d188

📥 Commits

Reviewing files that changed from the base of the PR and between e77c75f and 3cfbb96.

📒 Files selected for processing (2)
  • .changeset/fix-business-hour-agents-availability.md
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/fix-business-hour-agents-availability.md
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: Hacktron Security Check
  • 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/livechat/19-business-hours.ts
🧠 Learnings (3)
📚 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/livechat/19-business-hours.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/livechat/19-business-hours.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/livechat/19-business-hours.ts
🔇 Additional comments (3)
apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts (3)

732-769: LGTM!


771-788: LGTM!


826-834: LGTM!

Comment thread apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts

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

1 issue found across 2 files (changes from recent commits).

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

Re-trigger cubic

Comment thread apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts Outdated
KevLehman added 2 commits July 3, 2026 08:06
…partment

LivechatDepartment.findAgentsByBusinessHourId passed its pipeline double-wrapped
(aggregate([[...stages]])); MongoDB rejects non-object pipeline elements with
TypeMismatch, so the method threw on every invocation since its introduction.

The only caller runs via callbacks.runAsync('livechat.removeAgentDepartment')
(fire-and-forget), so the failure was silent: removing agents from a department
linked to a business hour (multiple business hours mode) succeeded, but the
removed agents' openBusinessHours were never recomputed, leaving their livechat
availability stale until an unrelated event refreshed it.
…a department

Two EE e2e tests for the multiple-business-hours flow:
- removing an agent from its only department falls back to the default
  business hour (fails against the unfixed code: the recomputation callback
  rejects and, in dev/test mode, crashes the server)
- removing an agent from one of two departments sharing the same business
  hour keeps that business hour open for the agent (exercises the agentIds
  set returned by the fixed aggregation)

Both poll for the result since the recomputation runs on a fire-and-forget
callback (callbacks.runAsync).
@KevLehman
KevLehman force-pushed the fix/business-hour-agents-availability branch from 3cfbb96 to 673657a Compare July 3, 2026 14:06
@KevLehman
KevLehman requested review from a team as code owners July 3, 2026 14:06
@KevLehman
KevLehman changed the base branch from chore/model-aggregations-perf to develop July 3, 2026 14:07
The kept-business-hour assertion equals the pre-removal state, so on its own
it cannot distinguish 'correctly kept' from 'callback never ran'. Add a
control agent that belongs only to the first department and is removed in the
same request: both agents are processed by the same callback invocation, so
observing the control agent fall back to the default business hour proves the
recomputation ran before asserting the overlapping agent's unchanged state.
Also replaces the fixed 2s sleep with the existing polling helper.

@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

Caution

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

⚠️ Outside diff range comments (1)
apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (1)

92-117: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset invalid when reverting edits. cancel() restores value and changed, but leaves invalid behind, so a code setting can keep showing an error state after reverting to a valid value.

🤖 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/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx`
around lines 92 - 117, The cancel handler in SettingsGroupPage is restoring
value and changed, but it is not clearing invalid, so reverted settings can
remain stuck in an error state. Update the cancel useStableCallback block to
also reset invalid when building the settingsToDispatch entries, and make sure
both the isColorSetting branch and the non-color branch in the SettingsGroupPage
component preserve or clear all relevant fields consistently before calling
dispatchToEditing.
🤖 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/client/hooks/useDeviceLogout.tsx`:
- Around line 27-43: The logout flow in useDeviceLogout should not run
success-only side effects inside onSettled, since it fires for both success and
failure. Move the current success behavior from useMutation’s onSettled into
onSuccess in logoutDevice, and add an onError handler to avoid showing
Device_Logged_Out, invalidating deviceManagementQueryKeys, closing the
contextual bar, or calling logout() when the request fails. Keep
isCurrentSession and the current
queryClient/handleCloseContextualBar/disptachToastMessage behavior scoped to the
success path only.

---

Outside diff comments:
In
`@apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx`:
- Around line 92-117: The cancel handler in SettingsGroupPage is restoring value
and changed, but it is not clearing invalid, so reverted settings can remain
stuck in an error state. Update the cancel useStableCallback block to also reset
invalid when building the settingsToDispatch entries, and make sure both the
isColorSetting branch and the non-color branch in the SettingsGroupPage
component preserve or clear all relevant fields consistently before calling
dispatchToEditing.
🪄 Autofix (Beta)

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

Run ID: 3af9e0a3-b04d-4bba-a454-842ef4b468ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfbb96 and 673657a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (43)
  • .changeset/all-baths-cry.md
  • .changeset/fix-business-hour-agents-availability.md
  • .changeset/forty-stars-bathe.md
  • .changeset/json-setting-validation-feedback.md
  • .changeset/spotlight-perf.md
  • apps/meteor/client/hooks/useDeviceLogout.tsx
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.ts
  • apps/meteor/client/providers/SettingsProvider.tsx
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/client/views/admin/settings/Setting/Setting.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx
  • apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx
  • apps/meteor/ee/server/api/sessions.ts
  • apps/meteor/ee/server/models/raw/LivechatDepartment.ts
  • apps/meteor/ee/server/settings/ldap.ts
  • apps/meteor/lib/utils/isJSON.spec.ts
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/package.json
  • apps/meteor/server/lib/spotlight.js
  • apps/meteor/server/publications/spotlight.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/uikit-playground/package.json
  • packages/core-typings/src/ISession.ts
  • packages/fuselage-ui-kit/package.json
  • packages/gazzodown/package.json
  • packages/i18n/src/locales/en.i18n.json
  • packages/model-typings/src/models/ISessionsModel.ts
  • packages/models/src/models/Sessions.ts
  • packages/models/src/models/Subscriptions.ts
  • packages/storybook-config/package.json
  • packages/ui-avatar/package.json
  • packages/ui-client/package.json
  • packages/ui-composer/package.json
  • packages/ui-contexts/package.json
  • packages/ui-video-conf/package.json
  • packages/ui-voip/package.json
  • packages/web-ui-registration/package.json
✅ Files skipped from review due to trivial changes (12)
  • apps/uikit-playground/package.json
  • packages/ui-composer/package.json
  • packages/ui-avatar/package.json
  • .changeset/forty-stars-bathe.md
  • packages/ui-voip/package.json
  • apps/meteor/lib/utils/isJSON.spec.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.ts
  • packages/ui-contexts/package.json
  • .changeset/json-setting-validation-feedback.md
  • .changeset/spotlight-perf.md
  • .changeset/all-baths-cry.md
  • apps/meteor/ee/server/models/raw/LivechatDepartment.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Hacktron Security Check
🧰 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/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx
  • packages/model-typings/src/models/ISessionsModel.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx
  • apps/meteor/server/publications/spotlight.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx
  • apps/meteor/ee/server/api/sessions.ts
  • packages/models/src/models/Sessions.ts
  • apps/meteor/client/providers/SettingsProvider.tsx
  • packages/core-typings/src/ISession.ts
  • apps/meteor/ee/server/settings/ldap.ts
  • apps/meteor/server/lib/spotlight.js
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx
  • apps/meteor/client/views/admin/settings/Setting/Setting.tsx
  • apps/meteor/client/hooks/useDeviceLogout.tsx
**/*.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/client/lib/utils/getCodeSettingError.spec.ts
🧠 Learnings (12)
📚 Learning: 2026-06-16T14:13:34.463Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40974
File: packages/web-ui-registration/package.json:31-31
Timestamp: 2026-06-16T14:13:34.463Z
Learning: In Rocket.Chat’s monorepo, when reviewing a dependency entry and flagging that a specific version “does not exist” (e.g., in package.json), first verify the exact package/version directly against the npm registry (use URLs like https://registry.npmjs.org/<package>/<version> or https://www.npmjs.com/package/<package>/v/<version>). Do not rely on web search results for this check, since they may be stale or cached and may not reflect the latest published versions.

Applied to files:

  • packages/web-ui-registration/package.json
  • packages/fuselage-ui-kit/package.json
  • packages/ui-client/package.json
  • packages/gazzodown/package.json
  • packages/ui-video-conf/package.json
  • packages/storybook-config/package.json
📚 Learning: 2026-06-16T14:13:49.795Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40974
File: packages/web-ui-registration/package.json:26-26
Timestamp: 2026-06-16T14:13:49.795Z
Learning: During code reviews that check whether a dependency version exists in package.json (especially for Rocket.Chat’s rocket.chat/fuselage and related rocket.chat/fuselage-* packages), don’t rely on web search results. Instead, verify the version directly against the npm registry (e.g., via the npm registry API or the canonical package URL https://www.npmjs.com/package/<package>/v/<version>) before deciding that a version bump is invalid. If the version is present in the npm registry, do not flag it as invalid.

Applied to files:

  • packages/web-ui-registration/package.json
  • packages/fuselage-ui-kit/package.json
  • packages/ui-client/package.json
  • packages/gazzodown/package.json
  • packages/ui-video-conf/package.json
  • packages/storybook-config/package.json
📚 Learning: 2026-06-16T14:13:59.986Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 40974
File: packages/ui-video-conf/package.json:25-25
Timestamp: 2026-06-16T14:13:59.986Z
Learning: In the Rocket.Chat monorepo, when reviewing a dependency version bump for rocket.chat/fuselage in a package.json, do not flag the new version constraint as “non-existent” or invalid unless you verify the published versions directly from the npm registry (https://www.npmjs.com/package/rocket.chat/fuselage). Don’t rely on search/web results for available versions since they can be stale.

Applied to files:

  • packages/web-ui-registration/package.json
  • packages/fuselage-ui-kit/package.json
  • packages/ui-client/package.json
  • packages/gazzodown/package.json
  • packages/ui-video-conf/package.json
  • packages/storybook-config/package.json
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx
  • apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx
  • apps/meteor/client/providers/SettingsProvider.tsx
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx
  • apps/meteor/client/views/admin/settings/Setting/Setting.tsx
  • apps/meteor/client/hooks/useDeviceLogout.tsx
📚 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/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx
  • packages/model-typings/src/models/ISessionsModel.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx
  • apps/meteor/server/publications/spotlight.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx
  • apps/meteor/ee/server/api/sessions.ts
  • packages/models/src/models/Sessions.ts
  • apps/meteor/client/providers/SettingsProvider.tsx
  • packages/core-typings/src/ISession.ts
  • apps/meteor/ee/server/settings/ldap.ts
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx
  • apps/meteor/client/views/admin/settings/Setting/Setting.tsx
  • apps/meteor/client/hooks/useDeviceLogout.tsx
📚 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/ISessionsModel.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/server/publications/spotlight.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/ee/server/api/sessions.ts
  • packages/models/src/models/Sessions.ts
  • packages/core-typings/src/ISession.ts
  • apps/meteor/ee/server/settings/ldap.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/ISessionsModel.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/server/publications/spotlight.ts
  • packages/models/src/models/Subscriptions.ts
  • apps/meteor/ee/server/api/sessions.ts
  • packages/models/src/models/Sessions.ts
  • packages/core-typings/src/ISession.ts
  • apps/meteor/ee/server/settings/ldap.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/client/views/admin/EditableSettingsContext.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/client/lib/utils/getCodeSettingError.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/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
📚 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/fix-business-hour-agents-availability.md
🔇 Additional comments (32)
.changeset/fix-business-hour-agents-availability.md (1)

5-5: LGTM!

apps/meteor/server/lib/spotlight.js (1)

42-42: LGTM!

Also applies to: 59-70

apps/meteor/server/publications/spotlight.ts (1)

64-70: LGTM!

packages/models/src/models/Subscriptions.ts (1)

460-465: LGTM!

Projected fields align exactly with what's consumed downstream in the corresponding $group stages.

Also applies to: 502-503

packages/ui-video-conf/package.json (1)

25-25: LGTM!

packages/web-ui-registration/package.json (1)

26-26: LGTM!

apps/meteor/package.json (1)

110-110: LGTM!

packages/fuselage-ui-kit/package.json (1)

46-49: LGTM!

packages/gazzodown/package.json (1)

34-34: LGTM!

packages/storybook-config/package.json (1)

36-36: LGTM!

packages/ui-client/package.json (1)

29-29: LGTM!

apps/meteor/ee/server/api/sessions.ts (1)

98-105: 🎯 Functional Correctness

See related concern in packages/models/src/models/Sessions.ts.

This is the source of the currentLoginToken value used in the $eq comparison flagged in Sessions.ts (aggregateSessionsByUserId). Please confirm this.token here matches the format of Sessions.loginToken before relying on this for the "current" session flag.

packages/core-typings/src/ISession.ts (1)

78-80: LGTM!

packages/model-typings/src/models/ISessionsModel.ts (1)

40-54: LGTM!

apps/meteor/client/hooks/useDeviceLogout.tsx (2)

9-21: LGTM!

Also applies to: 45-49


22-22: 🎯 Functional Correctness

No issue: both logout endpoints share the same SessionsProps payload, so the union path doesn’t affect logoutDevice({ sessionId }).

apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx (1)

16-36: LGTM!

apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx (1)

69-69: LGTM!

packages/i18n/src/locales/en.i18n.json (1)

7285-7286: LGTM!

packages/models/src/models/Sessions.ts (1)

745-758: 🎯 Functional Correctness

No raw-vs-hashed mismatch here this.token is the hashed auth token, and the session/logout flow uses the same token format, so the current flag won’t be stuck false for that reason.

			> Likely an incorrect or invalid review comment.
apps/meteor/lib/utils/isJSON.ts (1)

1-8: LGTM!

apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx (1)

2-4: LGTM!

Also applies to: 32-34, 48-48

apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx (1)

1-13: LGTM! Manual id/aria-describedby/role="alert" wiring is appropriate here since FieldError is imported from plain @rocket.chat/fuselage, not fuselage-forms wrappers, which don't auto-wire these attributes.

Based on learnings, "This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs."

Also applies to: 32-48, 63-79

Source: Learnings

apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx (2)

1-41: LGTM! Good coverage for the invalid/valid JSON and accessibility association cases.


12-22: 🎯 Functional Correctness

No change needed for baseProps autocomplete, required, and onResetButtonClick are optional in SettingInputProps, so omitting them here does not affect type-checking.

			> Likely an incorrect or invalid review comment.
apps/meteor/ee/server/settings/ldap.ts (1)

138-146: LGTM! code: 'application/json' additions are consistent with the existing pattern used by LDAP_Sync_User_Data_RolesMap and LDAP_Sync_User_Data_ChannelsMap.

Also applies to: 259-266, 303-312

apps/meteor/server/settings/ldap.ts (1)

229-235: LGTM!

apps/meteor/client/lib/utils/getCodeSettingError.spec.ts (1)

1-30: LGTM!

apps/meteor/client/providers/SettingsProvider.tsx (1)

2-2: LGTM!

Also applies to: 15-15, 119-130

apps/meteor/client/views/admin/EditableSettingsContext.ts (1)

7-12: LGTM!

apps/meteor/client/views/admin/settings/Setting/Setting.tsx (1)

2-2: LGTM!

Also applies to: 12-12, 40-41, 56-61, 81-86

apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (1)

49-51: LGTM!

Also applies to: 79-81, 168-168

@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

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

Caution

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

⚠️ Outside diff range comments (1)
apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (1)

92-117: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset invalid when reverting edits. cancel() restores value and changed, but leaves invalid behind, so a code setting can keep showing an error state after reverting to a valid value.

🤖 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/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx`
around lines 92 - 117, The cancel handler in SettingsGroupPage is restoring
value and changed, but it is not clearing invalid, so reverted settings can
remain stuck in an error state. Update the cancel useStableCallback block to
also reset invalid when building the settingsToDispatch entries, and make sure
both the isColorSetting branch and the non-color branch in the SettingsGroupPage
component preserve or clear all relevant fields consistently before calling
dispatchToEditing.
🤖 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/client/hooks/useDeviceLogout.tsx`:
- Around line 27-43: The logout flow in useDeviceLogout should not run
success-only side effects inside onSettled, since it fires for both success and
failure. Move the current success behavior from useMutation’s onSettled into
onSuccess in logoutDevice, and add an onError handler to avoid showing
Device_Logged_Out, invalidating deviceManagementQueryKeys, closing the
contextual bar, or calling logout() when the request fails. Keep
isCurrentSession and the current
queryClient/handleCloseContextualBar/disptachToastMessage behavior scoped to the
success path only.

---

Outside diff comments:
In
`@apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx`:
- Around line 92-117: The cancel handler in SettingsGroupPage is restoring value
and changed, but it is not clearing invalid, so reverted settings can remain
stuck in an error state. Update the cancel useStableCallback block to also reset
invalid when building the settingsToDispatch entries, and make sure both the
isColorSetting branch and the non-color branch in the SettingsGroupPage
component preserve or clear all relevant fields consistently before calling
dispatchToEditing.
🪄 Autofix (Beta)

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

Run ID: 3af9e0a3-b04d-4bba-a454-842ef4b468ca

📥 Commits

Reviewing files that changed from the base of the PR and between 3cfbb96 and 673657a.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (43)
  • .changeset/all-baths-cry.md
  • .changeset/fix-business-hour-agents-availability.md
  • .changeset/forty-stars-bathe.md
  • .changeset/json-setting-validation-feedback.md
  • .changeset/spotlight-perf.md
  • apps/meteor/client/hooks/useDeviceLogout.tsx
  • apps/meteor/client/lib/utils/getCodeSettingError.spec.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.ts
  • apps/meteor/client/providers/SettingsProvider.tsx
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx
  • apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx
  • apps/meteor/client/views/admin/EditableSettingsContext.ts
  • apps/meteor/client/views/admin/settings/Setting/Setting.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx
  • apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx
  • apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx
  • apps/meteor/ee/server/api/sessions.ts
  • apps/meteor/ee/server/models/raw/LivechatDepartment.ts
  • apps/meteor/ee/server/settings/ldap.ts
  • apps/meteor/lib/utils/isJSON.spec.ts
  • apps/meteor/lib/utils/isJSON.ts
  • apps/meteor/package.json
  • apps/meteor/server/lib/spotlight.js
  • apps/meteor/server/publications/spotlight.ts
  • apps/meteor/server/settings/ldap.ts
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
  • apps/uikit-playground/package.json
  • packages/core-typings/src/ISession.ts
  • packages/fuselage-ui-kit/package.json
  • packages/gazzodown/package.json
  • packages/i18n/src/locales/en.i18n.json
  • packages/model-typings/src/models/ISessionsModel.ts
  • packages/models/src/models/Sessions.ts
  • packages/models/src/models/Subscriptions.ts
  • packages/storybook-config/package.json
  • packages/ui-avatar/package.json
  • packages/ui-client/package.json
  • packages/ui-composer/package.json
  • packages/ui-contexts/package.json
  • packages/ui-video-conf/package.json
  • packages/ui-voip/package.json
  • packages/web-ui-registration/package.json
✅ Files skipped from review due to trivial changes (12)
  • apps/uikit-playground/package.json
  • packages/ui-composer/package.json
  • packages/ui-avatar/package.json
  • .changeset/forty-stars-bathe.md
  • packages/ui-voip/package.json
  • apps/meteor/lib/utils/isJSON.spec.ts
  • apps/meteor/client/lib/utils/getCodeSettingError.ts
  • packages/ui-contexts/package.json
  • .changeset/json-setting-validation-feedback.md
  • .changeset/spotlight-perf.md
  • .changeset/all-baths-cry.md
  • apps/meteor/ee/server/models/raw/LivechatDepartment.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/tests/end-to-end/api/livechat/19-business-hours.ts
📜 Review details
🔇 Additional comments (32)
.changeset/fix-business-hour-agents-availability.md (1)

5-5: LGTM!

apps/meteor/server/lib/spotlight.js (1)

42-42: LGTM!

Also applies to: 59-70

apps/meteor/server/publications/spotlight.ts (1)

64-70: LGTM!

packages/models/src/models/Subscriptions.ts (1)

460-465: LGTM!

Projected fields align exactly with what's consumed downstream in the corresponding $group stages.

Also applies to: 502-503

packages/ui-video-conf/package.json (1)

25-25: LGTM!

packages/web-ui-registration/package.json (1)

26-26: LGTM!

apps/meteor/package.json (1)

110-110: LGTM!

packages/fuselage-ui-kit/package.json (1)

46-49: LGTM!

packages/gazzodown/package.json (1)

34-34: LGTM!

packages/storybook-config/package.json (1)

36-36: LGTM!

packages/ui-client/package.json (1)

29-29: LGTM!

apps/meteor/ee/server/api/sessions.ts (1)

98-105: 🎯 Functional Correctness

See related concern in packages/models/src/models/Sessions.ts.

This is the source of the currentLoginToken value used in the $eq comparison flagged in Sessions.ts (aggregateSessionsByUserId). Please confirm this.token here matches the format of Sessions.loginToken before relying on this for the "current" session flag.

packages/core-typings/src/ISession.ts (1)

78-80: LGTM!

packages/model-typings/src/models/ISessionsModel.ts (1)

40-54: LGTM!

apps/meteor/client/hooks/useDeviceLogout.tsx (2)

9-21: LGTM!

Also applies to: 45-49


22-22: 🎯 Functional Correctness

No issue: both logout endpoints share the same SessionsProps payload, so the union path doesn’t affect logoutDevice({ sessionId }).

apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountRow.tsx (1)

16-36: LGTM!

apps/meteor/client/views/account/deviceManagement/DeviceManagementAccountTable/DeviceManagementAccountTable.tsx (1)

69-69: LGTM!

packages/i18n/src/locales/en.i18n.json (1)

7285-7286: LGTM!

packages/models/src/models/Sessions.ts (1)

745-758: 🎯 Functional Correctness

No raw-vs-hashed mismatch here this.token is the hashed auth token, and the session/logout flow uses the same token format, so the current flag won’t be stuck false for that reason.

			> Likely an incorrect or invalid review comment.
apps/meteor/lib/utils/isJSON.ts (1)

1-8: LGTM!

apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.tsx (1)

2-4: LGTM!

Also applies to: 32-34, 48-48

apps/meteor/client/views/admin/settings/Setting/inputs/CodeMirror/CodeMirrorBox.tsx (1)

1-13: LGTM! Manual id/aria-describedby/role="alert" wiring is appropriate here since FieldError is imported from plain @rocket.chat/fuselage, not fuselage-forms wrappers, which don't auto-wire these attributes.

Based on learnings, "This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs."

Also applies to: 32-48, 63-79

Source: Learnings

apps/meteor/client/views/admin/settings/Setting/inputs/CodeSettingInput.spec.tsx (2)

1-41: LGTM! Good coverage for the invalid/valid JSON and accessibility association cases.


12-22: 🎯 Functional Correctness

No change needed for baseProps autocomplete, required, and onResetButtonClick are optional in SettingInputProps, so omitting them here does not affect type-checking.

			> Likely an incorrect or invalid review comment.
apps/meteor/ee/server/settings/ldap.ts (1)

138-146: LGTM! code: 'application/json' additions are consistent with the existing pattern used by LDAP_Sync_User_Data_RolesMap and LDAP_Sync_User_Data_ChannelsMap.

Also applies to: 259-266, 303-312

apps/meteor/server/settings/ldap.ts (1)

229-235: LGTM!

apps/meteor/client/lib/utils/getCodeSettingError.spec.ts (1)

1-30: LGTM!

apps/meteor/client/providers/SettingsProvider.tsx (1)

2-2: LGTM!

Also applies to: 15-15, 119-130

apps/meteor/client/views/admin/EditableSettingsContext.ts (1)

7-12: LGTM!

apps/meteor/client/views/admin/settings/Setting/Setting.tsx (1)

2-2: LGTM!

Also applies to: 12-12, 40-41, 56-61, 81-86

apps/meteor/client/views/admin/settings/SettingsGroupPage/SettingsGroupPage.tsx (1)

49-51: LGTM!

Also applies to: 79-81, 168-168

🛑 Comments failed to post (1)
apps/meteor/client/hooks/useDeviceLogout.tsx (1)

27-43: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Success-path side effects run even when the logout request fails.

onSettled executes on both success and failure, but this block contains only "success" behavior (toast, cache invalidation, or forcing a client-side logout()) with no onError handler and throwOnError: false. A failed API call will still show "Device Logged Out", invalidate queries, and even log the current user out client-side, while giving no error feedback at all.

🛠️ Proposed fix: split success/error handling
 	const { mutate: logoutDevice } = useMutation({
 		mutationFn: logoutEndpoint,
-		onSettled: () => {
-			if (isCurrentSession) {
-				setModal(null);
-				logout();
-			} else {
-				queryClient.invalidateQueries({ queryKey: deviceManagementQueryKeys.all });
-				if (isContextualBarOpen) {
-					handleCloseContextualBar();
-				}
-				dispatchToastMessage({ type: 'success', message: t('Device_Logged_Out') });
-				setModal(null);
-			}
-		},
+		onSuccess: () => {
+			if (isCurrentSession) {
+				logout();
+				return;
+			}
+			queryClient.invalidateQueries({ queryKey: deviceManagementQueryKeys.all });
+			if (isContextualBarOpen) {
+				handleCloseContextualBar();
+			}
+			dispatchToastMessage({ type: 'success', message: t('Device_Logged_Out') });
+		},
+		onError: (error) => {
+			dispatchToastMessage({ type: 'error', message: error });
+		},
+		onSettled: () => {
+			setModal(null);
+		},
 		throwOnError: false,
 	});
🤖 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/client/hooks/useDeviceLogout.tsx` around lines 27 - 43, The
logout flow in useDeviceLogout should not run success-only side effects inside
onSettled, since it fires for both success and failure. Move the current success
behavior from useMutation’s onSettled into onSuccess in logoutDevice, and add an
onError handler to avoid showing Device_Logged_Out, invalidating
deviceManagementQueryKeys, closing the contextual bar, or calling logout() when
the request fails. Keep isCurrentSession and the current
queryClient/handleCloseContextualBar/disptachToastMessage behavior scoped to the
success path only.

@KevLehman KevLehman added this to the 8.7.0 milestone Jul 3, 2026
@KevLehman

Copy link
Copy Markdown
Member Author

/jira CORE

@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jul 3, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 3, 2026
Comment thread .changeset/fix-business-hour-agents-availability.md Outdated
Comment thread .changeset/fix-business-hour-agents-availability.md Outdated
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 3, 2026
@KevLehman KevLehman removed this from the 8.7.0 milestone Jul 4, 2026
@dionisio-bot dionisio-bot Bot removed the stat: ready to merge PR tested and approved waiting for merge label Jul 4, 2026
@KevLehman KevLehman added this to the 8.7.0 milestone Jul 4, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Jul 4, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 4, 2026
@dionisio-bot
dionisio-bot Bot added this pull request to the merge queue Jul 4, 2026
Merged via the queue into develop with commit 3296b4d Jul 4, 2026
48 checks passed
@dionisio-bot
dionisio-bot Bot deleted the fix/business-hour-agents-availability branch July 4, 2026 18:25
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.

2 participants