feat: trigger assignment on resolve (#13780)

## Description

When an agent resolves or snoozes a conversation, their capacity frees
up — but under Assignment V2, no new conversation was assigned until the
next event triggered the assignment job. This meant agents could sit
idle despite having queued conversations waiting. This change triggers
the AssignmentJob immediately on resolve/snooze so freed capacity is
utilized right away.

## Type of change

- [ ] New feature (non-breaking change which adds functionality)

## How Has This Been Tested?

- Enable auto assignment v2 on an inbox
- Create a conversation (gets auto-assigned to an available agent)
- Resolve the conversation
- Verify that another unassigned conversation in the inbox gets assigned
to the freed-up agent

## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules

---------

Co-authored-by: tds-1 <tds-1@users.noreply.github.com>
This commit is contained in:
Tanmay Deep Sharma
2026-03-16 13:13:37 +05:30
committed by GitHub
parent a452ce9e84
commit a5c50354fc

View File

@@ -9,9 +9,9 @@ module AutoAssignmentHandler
private
def run_auto_assignment
# Round robin kicks in on conversation create & update
# run it only when conversation status changes to open
return unless conversation_status_changed_to_open?
# Assignment V2: Also trigger assignment when conversation is resolved or snoozed,
# bypassing the open-only condition so the AssignmentJob can redistribute capacity.
return unless conversation_status_changed_to_open? || conversation_status_changed_to_resolved_or_snoozed?
return unless should_run_auto_assignment?
if inbox.auto_assignment_v2_enabled?
@@ -25,6 +25,10 @@ module AutoAssignmentHandler
end
end
def conversation_status_changed_to_resolved_or_snoozed?
inbox.auto_assignment_v2_enabled? && saved_change_to_status? && (resolved? || snoozed?)
end
def team_member_ids_with_capacity
return [] if team.blank? || team.allow_auto_assign.blank?
@@ -33,6 +37,9 @@ module AutoAssignmentHandler
def should_run_auto_assignment?
return false unless inbox.enable_auto_assignment?
# Assignment V2: Resolved/snoozed conversations still have an assignee, so bypass the
# assignee-blank check below. The AssignmentJob needs to run to rebalance assignments.
return true if conversation_status_changed_to_resolved_or_snoozed?
# run only if assignee is blank or doesn't have access to inbox
assignee.blank? || inbox.members.exclude?(assignee)