chatwoot/spec/services/auto_assignment
Vishnu Narayanan 6fbff026eb
fix: skip AutoAssignment bulk loop when no agents are online (#14500)
## Description

When an inbox has `enable_auto_assignment` and `assignment_v2` enabled
but no agents are currently online,
`AutoAssignment::AssignmentService#perform_bulk_assignment` still loaded
up to 100 unassigned conversations and iterated each one, calling
`inbox.available_agents` per conversation. Each call hits Redis presence
lookups that return empty, no conversations get assigned, and the loop
finishes having done only wasted work.

For a busy inbox with a long unassigned backlog and offline agents, this
is hundreds of Redis ops per job, multiplied by every
`AutoAssignment::AssignmentJob` enqueue from the per-save handler. The
pressure is significant when inbound volume is high.

This adds a single early-return guard: if
`inbox.available_agents.empty?`, return `0` immediately. Existing
semantics are preserved (jobs are still enqueued on conversation events;
they just exit cheaply when there is no one to assign to).

## Type of change

- [x] Performance improvement (non-breaking change)

## Test coverage

- [x] Added specs
2026-05-25 15:17:05 +05:30
..
agent_assignment_service_spec.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
assignment_service_spec.rb fix: skip AutoAssignment bulk loop when no agents are online (#14500) 2026-05-25 15:17:05 +05:30
inbox_round_robin_service_spec.rb chore: Update translations (#6941) 2023-04-21 15:28:56 +05:30
rate_limiter_spec.rb perf: add default configs for assignment V2 (#13577) 2026-02-23 15:08:11 +05:30
round_robin_selector_spec.rb feat: Assignment service (v2) (#12320) 2025-11-17 10:08:25 +05:30