chatwoot/app/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.rb feat: Enable Capacity Config UI (#5164) 2022-08-16 16:58:23 +05:30
assignment_service.rb fix: skip AutoAssignment bulk loop when no agents are online (#14500) 2026-05-25 15:17:05 +05:30
inbox_round_robin_service.rb chore: Update typo in inbox_round_robin_service (#9590) 2024-06-06 18:49:53 -07:00
rate_limiter.rb perf: add default configs for assignment V2 (#13577) 2026-02-23 15:08:11 +05:30
round_robin_selector.rb feat: Assignment service (v2) (#12320) 2025-11-17 10:08:25 +05:30