Skip to content

fix: transferToAgent doesn't stop on transfer failure#38061

Merged
kodiakhq[bot] merged 8 commits intodevelopfrom
fix/transfer-to-agent
Jan 8, 2026
Merged

fix: transferToAgent doesn't stop on transfer failure#38061
kodiakhq[bot] merged 8 commits intodevelopfrom
fix/transfer-to-agent

Conversation

@KevLehman
Copy link
Copy Markdown
Member

@KevLehman KevLehman commented Jan 5, 2026

Proposed changes (including videos or screenshots)

Issue(s)

https://rocketchat.atlassian.net/browse/SUP-930

Steps to test or reproduce

Further comments

For context: the process should have stopped by the callback returning undefined... however, the callbacks do item() ?? firstParam which causes that callbacks returning undefined (probably for the cases when the callback doesn't exist yet) are forced to return the first param.

The forwardToAgent function expected the takeInquiry to return undefined to stop the process and avoid sending the system message but since it returned something, it just continued "as if it has succeeded" even when it did not.

:confused_cat:

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of chat queue management when routing inquiries, including explicit handling of edge cases where agents are unavailable or at capacity limits.
    • Enhanced error handling in agent assignment process to prevent undefined behavior in queue operations.
  • Tests

    • Added validation for chat forwarding behavior when agents reach their simultaneous chat limits.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Jan 5, 2026

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

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Jan 5, 2026

⚠️ No Changeset found

Latest commit: 0c23b72

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 5, 2026

Walkthrough

The PR updates livechat inquiry routing and callback methods to use false as an explicit sentinel value instead of void/undefined for failure states. This includes type signature updates in RoutingManager and callbacks, implementation changes in agent assignment failure handling and queue processing, and a new end-to-end test for chat limit enforcement during agent forwarding.

Changes

Cohort / File(s) Summary
Type Signature Updates
apps/meteor/app/livechat/server/lib/RoutingManager.ts, apps/meteor/server/lib/callbacks.ts
Updated return types of delegateInquiry and takeInquiry to return false instead of void on failure; updated livechat.onAgentAssignmentFailed callback signature to reflect Promise<...false> instead of Promise<...undefined>
Implementation Updates
apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts, apps/meteor/server/services/omnichannel/queue.ts
Modified all early-return paths in onAgentAssignmentFailed to return explicit false instead of undefined; added null guard in processWaitingQueue to check for null delegateInquiry result before proceeding
Test Additions
apps/meteor/tests/end-to-end/api/livechat/07-queue.ts
Added export of startANewLivechatRoomAndTakeIt helper; introduced new test scenario verifying agent chat limit enforcement during guest forwarding with disabled waiting queue behavior

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ggazzo
  • MartinSchoeler
  • sampaiodiego

Poem

🐰 A quest for clarity, false not void!
Constants now reign where shadows toiled,
Guard the null, test the limit,
Queues and callbacks—truth within it,
Sentinel values, precise and bright! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The linked issue SUP-930 lacks detailed requirements, making it impossible to validate whether the PR implementation fully addresses chat limit and transfer failure handling requirements. Review the full SUP-930 issue details to confirm all requirements are met; verify the PR handles all edge cases for transfer limits and failure scenarios.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: fixing transferToAgent to properly stop on transfer failure, which aligns with modifications to return types and error handling across routing and queue management.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing transfer failure handling: updated return types to use false instead of void/undefined, added null checks, modified routing logic, and added E2E tests for the transfer failure scenario.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/transfer-to-agent

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 and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.69%. Comparing base (4211011) to head (0c23b72).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38061      +/-   ##
===========================================
+ Coverage    70.64%   70.69%   +0.05%     
===========================================
  Files         3146     3146              
  Lines       108826   108829       +3     
  Branches     19579    19569      -10     
===========================================
+ Hits         76876    76940      +64     
+ Misses       29937    29890      -47     
+ Partials      2013     1999      -14     
Flag Coverage Δ
e2e 60.19% <ø> (+0.05%) ⬆️
e2e-api 48.45% <25.00%> (+1.06%) ⬆️
unit 71.80% <25.00%> (+0.03%) ⬆️

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 5, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/08 19:11 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38061
  • Baseline: develop
  • Timestamp: 2026-01-08 19:11:08 UTC
  • Historical data points: 30

Updated: Thu, 08 Jan 2026 19:11:09 GMT

@KevLehman KevLehman changed the title fix: transfertoagent fix: transferToAgent doesn't stop on transfer failure Jan 6, 2026
@KevLehman KevLehman marked this pull request as ready for review January 6, 2026 19:34
@KevLehman KevLehman requested review from a team as code owners January 6, 2026 19:34
Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 5 files

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI Agents
In @apps/meteor/tests/end-to-end/api/livechat/07-queue.ts:
- Around line 897-953: Two duplicate Mocha before hooks should be consolidated
into one: merge the second before (which forces agent B to take a room) into the
first before so setup runs once in order. Locate the first before block that
creates userA/userB, agents, logins, makes them available, creates
forwardingDept, updates Livechat settings, and starts room1 (symbols:
createUser, createAgent, login, makeAgentAvailable, createDepartment,
updateLivechatSettingsForUser, startANewLivechatRoomAndTakeIt,
getLivechatRoomInfo); append the logic from the second before (starting room2
for forwardUserB, assigning visitor2 and forwardingRoom and asserting servedBy)
into that same before, preserving the sequence and assertions, or if the second
setup must run before each test change its hook to beforeEach instead of before.
- Line 648: The before hook grants the 'transfer-livechat-guest' permission via
updatePermission('transfer-livechat-guest', ['livechat-agent']) but the after
hook never restores it; in the test file add a call in the after hook to
updatePermission('transfer-livechat-guest', []) to remove the granted role and
restore state, locating the after hook near the existing before hook and
ensuring the call runs even if tests fail (e.g., add it into the existing
teardown/after block).
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d3511ea and ba4bb9e.

📒 Files selected for processing (5)
  • apps/meteor/app/livechat/server/lib/RoutingManager.ts
  • apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts
  • apps/meteor/server/lib/callbacks.ts
  • apps/meteor/server/services/omnichannel/queue.ts
  • apps/meteor/tests/end-to-end/api/livechat/07-queue.ts
🧰 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/services/omnichannel/queue.ts
  • apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts
  • apps/meteor/server/lib/callbacks.ts
  • apps/meteor/app/livechat/server/lib/RoutingManager.ts
  • apps/meteor/tests/end-to-end/api/livechat/07-queue.ts
🧠 Learnings (3)
📚 Learning: 2025-09-25T09:59:26.461Z
Learnt from: Dnouv
Repo: RocketChat/Rocket.Chat PR: 37057
File: packages/apps-engine/src/definition/accessors/IUserRead.ts:23-27
Timestamp: 2025-09-25T09:59:26.461Z
Learning: UserBridge.doGetUserRoomIds in packages/apps-engine/src/server/bridges/UserBridge.ts has a bug where it implicitly returns undefined when the app lacks read permission (missing return statement in the else case of the permission check).

Applied to files:

  • apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts
📚 Learning: 2025-11-27T17:56:26.050Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37557
File: apps/meteor/client/views/admin/ABAC/AdminABACRooms.tsx:115-116
Timestamp: 2025-11-27T17:56:26.050Z
Learning: In Rocket.Chat, the GET /v1/abac/rooms endpoint (implemented in ee/packages/abac/src/index.ts) only returns rooms where abacAttributes exists and is not an empty array (query: { abacAttributes: { $exists: true, $ne: [] } }). Therefore, in components consuming this endpoint (like AdminABACRooms.tsx), room.abacAttributes is guaranteed to be defined for all returned rooms, and optional chaining before calling array methods like .join() is sufficient without additional null coalescing.

Applied to files:

  • apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • apps/meteor/tests/end-to-end/api/livechat/07-queue.ts
🧬 Code graph analysis (2)
apps/meteor/server/lib/callbacks.ts (1)
packages/core-typings/src/IRoom.ts (1)
  • IOmnichannelRoom (269-320)
apps/meteor/app/livechat/server/lib/RoutingManager.ts (1)
packages/core-typings/src/IRoom.ts (1)
  • IOmnichannelRoom (269-320)
🪛 Biome (2.1.2)
apps/meteor/tests/end-to-end/api/livechat/07-queue.ts

[error] 940-953: Disallow duplicate setup and teardown hooks.

Disallow before duplicacy inside the describe function.

(lint/suspicious/noDuplicateTestHooks)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (5)
apps/meteor/server/services/omnichannel/queue.ts (1)

257-260: LGTM! Proper guard for routing failure.

The guard correctly handles the new false sentinel value from RoutingManager.delegateInquiry. The !room check catches null, undefined, and false, preventing potential null-pointer access at line 262 while providing clear failure signaling.

apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts (1)

19-36: LGTM! Explicit failure signaling with false sentinel.

The changes consistently replace implicit undefined returns with explicit false returns across all early-exit paths. This aligns with the updated callback signature in apps/meteor/server/lib/callbacks.ts (line 191) and makes failure states explicit and type-safe.

apps/meteor/server/lib/callbacks.ts (1)

191-191: LGTM! Type signature updated for explicit failure handling.

The return type change from undefined to false makes failure states explicit in the type system. This aligns with the implementation changes in apps/meteor/ee/app/livechat-enterprise/server/hooks/onAgentAssignmentFailed.ts and provides type-safe failure signaling throughout the callback chain.

apps/meteor/app/livechat/server/lib/RoutingManager.ts (1)

50-50: LGTM! Return types updated for explicit failure signaling.

The return type updates from void to false for both delegateInquiry and takeInquiry align with the PR's objective to make transfer failures explicit. This enables callers (like the queue processor) to distinguish between success and failure states, particularly at line 269 where cbRoom could now be false from the callback chain.

Also applies to: 65-65

apps/meteor/tests/end-to-end/api/livechat/07-queue.ts (1)

965-1003: Excellent test coverage for the transfer failure fix.

The test suite properly validates the PR's fix by:

  1. Verifying that forwarding to an agent at their limit returns 400 and produces no transfer history messages when the waiting queue is enabled (lines 965-982)
  2. Confirming that forwarding succeeds when the waiting queue is disabled (lines 984-1003)

This comprehensive coverage ensures the new false sentinel behavior works correctly in real-world scenarios.

@KevLehman KevLehman added the stat: QA assured Means it has been tested and approved by a company insider label Jan 8, 2026
@KevLehman KevLehman added this to the 8.1.0 milestone Jan 8, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 8, 2026
@kodiakhq kodiakhq bot merged commit 8b2a50d into develop Jan 8, 2026
45 checks passed
@kodiakhq kodiakhq bot deleted the fix/transfer-to-agent branch January 8, 2026 20:24
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants