chatwoot/app/models/concerns
Tanmay Deep Sharma 3cd8cf43ce
fix: atomically claim conversation to prevent duplicate assignment (#14495)
## Description

Fixes a bug under Assignment V2 where a single conversation could be
reassigned dozens of times in a row by the system, producing long stacks
of "Assigned to X by Automation System via <policy>" activity messages
alternating between agents. After this change each unassigned
conversation is assigned exactly once, even on busy inboxes.

## Fixes # (issue)


## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

## How to reproduce
1. Enable `assignment_v2` on an account with at least 2 online agents in
an inbox.
2. Generate sustained resolve/snooze activity in the inbox (each one
enqueues `AutoAssignment::AssignmentJob` for the whole inbox).
3. Watch any one unassigned conversation while the jobs drain — pre-fix
it picks up multiple back-to-back "Assigned to …" activity rows
alternating between agents.


## 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
2026-05-21 16:14:28 +05:30
..
.keep Initial Commit 2019-08-14 15:18:44 +05:30
access_tokenable.rb Chore: Replaced dependent destroy with dependent destroy_async in all models (#3249) 2021-11-18 10:32:29 +05:30
account_cache_revalidator.rb feat: expiry for cache keys [CW-3038] (#8793) 2024-01-29 15:27:26 +05:30
account_captain_auto_resolve.rb feat: Add force legacy auto-resolve flag (#13804) 2026-03-13 15:04:58 -07:00
account_email_rate_limitable.rb fix: Skip email rate limiting for self-hosted instances (#13915) 2026-03-26 18:06:10 +05:30
account_settings_schema.rb fix: validate support_email format and handle parse errors in mailer (#13958) 2026-04-13 19:06:06 +07:00
activity_message_handler.rb feat: show assignment policy name in auto-assignment activity messages (#13598) 2026-02-24 13:32:54 +05:30
assignee_activity_message_handler.rb feat: show assignment policy name in auto-assignment activity messages (#13598) 2026-02-24 13:32:54 +05:30
assignment_handler.rb feat: Add support for multi-language support for Captain (#11068) 2025-03-19 18:25:33 -07:00
auto_assignment_handler.rb fix: atomically claim conversation to prevent duplicate assignment (#14495) 2026-05-21 16:14:28 +05:30
availability_statusable.rb chore: Move agent availability to Account level (#3074) 2021-10-07 13:21:46 +05:30
avatarable.rb fix: [CW-6931] Harden external downloads against SSRF [avatar from url job] (#14153) 2026-04-24 18:59:45 +05:30
cache_keys.rb feat: Unread Count: added api, store refresher, invalidation and events (2/3)[CW-6851] (#14369) 2026-05-20 17:36:09 +05:30
captain_featurable.rb feat: add global config for captain settings (#13141) 2026-01-12 19:54:19 +05:30
channelable.rb chore: Centralize outgoing message reply restrictions for all the channels (#11279) 2025-04-12 08:52:12 +05:30
content_attribute_validator.rb chore: Upgrade rails and ruby versions (#2400) 2021-08-03 20:11:52 +05:30
conversation_mute_helpers.rb fix: prevent NoMethodError in mute helpers when contact is nil (#13277) 2026-01-15 22:00:09 -08:00
email_address_parseable.rb fix: validate support_email format and handle parse errors in mailer (#13958) 2026-04-13 19:06:06 +07:00
featurable.rb chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
inbox_agent_availability.rb feat: Assignment service (v2) (#12320) 2025-11-17 10:08:25 +05:30
json_schema_validator.rb feat: Add support for minutes in auto resolve feature (#11269) 2025-05-07 00:36:15 -07:00
label_activity_message_handler.rb feat: add activity message for SLA (#9100) 2024-03-13 20:05:34 +05:30
labelable.rb feat: Add support for labels in automations (#11658) 2025-09-18 14:17:54 +05:30
liquidable.rb fix: render agent variables in automation messages (#14338) 2026-05-04 13:25:40 +05:30
llm_formattable.rb chore: Update LLM formatter classes to include additional details (#11491) 2025-05-15 17:47:37 -07:00
message_filter_helpers.rb fix: Skip notifications for private notes (#13617) 2026-02-23 15:40:54 +04:00
out_of_offisable.rb perf: eliminate N+1 queries on inboxes#index (#14451) 2026-05-14 14:20:52 +05:30
priority_activity_message_handler.rb chore(i18n): Improvements in automation and macros (#11231) 2025-04-02 15:48:42 -07:00
pubsubable.rb chore: Rotate pubsub token on password change (#7194) 2023-05-27 13:24:31 +05:30
push_data_helper.rb fix: strip markdown hard-break backslashes from webhook payloads (#13950) 2026-04-16 13:19:35 +05:30
reauthorizable.rb fix: call authorization_error! on IMAP auth failures (#13560) (revert) (#13671) 2026-02-26 18:45:18 -08:00
reportable.rb Chore: clean up Reporting Events (#4044) 2022-02-28 18:16:12 +05:30
sla_activity_message_handler.rb feat: add activity message for SLA (#9100) 2024-03-13 20:05:34 +05:30
sort_handler.rb fix(perf): force better index for pending_reponses longest first sort (#14291) 2026-04-28 18:50:29 +07:00
sso_authenticatable.rb feat: Prevent saving preferences and status when impersonating (#11164) 2025-05-20 17:34:30 -07:00
team_activity_message_handler.rb feat: add activity message for SLA (#9100) 2024-03-13 20:05:34 +05:30
user_attribute_helpers.rb chore: Account switching issue in newly added accounts (#12403) 2025-09-10 14:12:22 +05:30
webhook_secretable.rb feat: sign webhooks for API channel and agentbots (#13892) 2026-04-06 15:28:25 +05:30