fix: handle empty round robin queues (#15399)

Round-robin queue resets now leave the Redis queue empty when an inbox
has no members, avoiding an invalid sorted-set write while keeping
normal queue population unchanged.

## Closes

-
[CW-7922](https://linear.app/chatwoot/issue/CW-7922/harden-backend-paths-causing-production-sentry-errors)
- [Sentry 7663380084](https://chatwoot-p3.sentry.io/issues/7663380084/)

## How to reproduce

Run round-robin assignment for an inbox with no inbox members. Resetting
the queue previously attempted a Redis sorted-set write without any
member/score pairs.

## What changed

- Clear the existing queue as before.
- Skip queue population when there are no eligible user IDs.
- Add service coverage for an inbox with no members.
This commit is contained in:
Sony Mathew
2026-08-13 17:03:36 +05:30
committed by GitHub
parent ba1973ea40
commit 8a778f4f5b
2 changed files with 11 additions and 1 deletions

View File

@@ -17,8 +17,9 @@ class AutoAssignment::InboxRoundRobinService
end
def reset_queue
user_ids = inbox.inbox_members.map(&:user_id)
clear_queue
add_agent_to_queue(inbox.inbox_members.map(&:user_id))
add_agent_to_queue(user_ids) if user_ids.any?
end
# end of queue management functions

View File

@@ -27,6 +27,15 @@ describe AutoAssignment::InboxRoundRobinService do
expect(inbox_round_robin_service.send(:queue).map(&:to_i)).to match_array(inbox_members.map(&:user_id))
end
it 'keeps the queue empty when the inbox has no members' do
empty_inbox = create(:inbox, account: account)
service = described_class.new(inbox: empty_inbox)
service.add_agent_to_queue(-1)
expect(service.available_agent).to be_nil
expect(service.send(:queue)).to be_empty
end
it 'validates the queue and correct it before performing round robin' do
# adding some invalid ids to queue
inbox_round_robin_service.add_agent_to_queue([2, 3, 5, 9])