chatwoot/app/services
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
..
account fix: account email validation during signup (#11307) 2025-05-20 20:45:39 -07:00
auto_assignment fix: atomically claim conversation to prevent duplicate assignment (#14495) 2026-05-21 16:14:28 +05:30
automation_rules feat: add automation condition to filter private notes (#12102) 2026-04-13 10:40:46 +05:30
base feat(voice): add WhatsApp inbound call webhook pipeline [3] (#14315) 2026-05-12 11:23:57 +05:30
contacts feat: outbound voice call essentials (#12782) 2025-11-24 17:47:00 -08:00
conversations feat: Unread Count: Frontend changes for showing unread count badges (3/3)[CW-6851] (#14372) 2026-05-20 19:21:25 +05:30
crm chore: verbosely log errors for leadsquare activity failure (#14407) 2026-05-11 10:58:23 +05:30
data_import fix: standardize contact company field on company_name (#14099) 2026-04-27 18:43:26 +05:30
email chore: Migrate mailers from the worker to jobs (#12331) 2025-10-21 16:36:37 -07:00
email_templates chore: Fix emails being sent with the wrong translations (#2236) 2021-06-08 22:45:01 +05:30
facebook feat(facebook): use HUMAN_AGENT tag for Messenger replies when human-agent config is enabled (#13690) 2026-03-02 15:32:59 +04:00
filters refactor: extract custom attribute methods from FilterService (#13743) 2026-03-10 14:15:52 +05:30
geocoder fix: ip-lookup database lazy loading for all environments (#8052) 2024-10-22 23:18:30 -07:00
google feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
imap feat: Ability to specify the authentication type for imap server (#12306) 2026-05-08 16:40:15 +05:30
instagram fix: Handle Instagram API error codes properly in message processing (#13002) 2025-12-04 18:53:50 +05:30
internal fix: use last_activity_at for orphan conversation cleanup timeframe (#13859) 2026-03-20 16:28:05 +05:30
labels feat(labels): remove label associations asynchronously on delete (#13531) 2026-05-08 13:40:36 +05:30
line fix(line): Use non-expiring URLs for image and video messages (#13949) 2026-04-01 17:29:12 +05:30
linear feat: Add activity messages for linear actions (#11654) 2025-06-13 11:57:11 +05:30
liquid feat: Add liquid processing for SMS campaigns (#10981) 2025-06-11 13:16:44 -04:00
llm_formatter feat: new Captain Editor (#13235) 2026-01-21 13:39:07 +05:30
macros feat: Add webhook event support for macros (#11235) 2025-04-02 20:26:55 -07:00
mailbox refactor: strategy pattern for mailbox conversation finding (#12766) 2025-11-10 20:47:18 +05:30
message_templates fix: Captain not responding to campaign conversations (#13489) 2026-02-12 10:07:56 +05:30
messages fix(notifications): Respect conversation access when notifying agents (#14412) 2026-05-12 10:57:29 +04:00
mfa feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
microsoft feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
notification feat(super-admin): Add push diagnostics tool (#14105) 2026-04-21 15:55:12 +04:00
onboarding feat: don't let onboarding write domain (#14442) 2026-05-13 20:09:48 +05:30
reporting_events feat(rollup): add models and write path [1/3] (#13796) 2026-03-19 13:12:36 +05:30
reports fix: prevent bot metrics double-counting when handoff and resolution coexist [CW-6210] (#14032) 2026-05-13 18:43:23 +05:30
sms fix: Error shouldn't halt the campaign for entire audience (#11980) 2025-08-11 12:03:48 +05:30
telegram fix: Use Faraday for Telegram document uploads to fix large file failures (#13397) 2026-02-10 14:25:25 -08:00
tiktok fix(tiktok): Resolve media upload failures and gate attachments by conversation capability (#13643) 2026-05-06 11:21:15 +04:00
twilio feat: Store WhatsApp BSUID identifiers from inbound webhooks (#14436) 2026-05-20 13:36:43 +04:00
twitter feat: hide CSAT survey URLs from agents in dashboard (#11622) 2025-06-11 23:39:47 +05:30
whatsapp feat: Store WhatsApp BSUID identifiers from inbound webhooks (#14436) 2026-05-20 13:36:43 +04:00
widget feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
account_deletion_service.rb fix(account-deletion): normalize deleted email suffix and handle collisions safely (#13472) 2026-02-07 17:29:27 -08:00
action_service.rb feat: Introduce last responding agent option to automation assign agent (#12326) 2026-04-16 18:54:35 +05:30
base_refresh_oauth_token_service.rb feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
base_token_service.rb feat: MFA (#12290) 2025-09-18 20:19:24 +05:30
contact_inbox_source_id_resolver.rb feat: Store WhatsApp BSUID identifiers from inbound webhooks (#14436) 2026-05-20 13:36:43 +04:00
csat_survey_service.rb fix: Respect survey label rules for WhatsApp CSAT template (#13285) 2026-01-15 22:16:00 -08:00
csat_template_management_service.rb feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
csat_template_name_service.rb feat: Add support for sending CSAT surveys via templates (Whatsapp Twilio) (#13143) 2026-01-13 16:32:02 +04:00
csat_template_utility_analysis_service.rb feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
csat_template_utility_rubric.rb feat(csat): Add WhatsApp utility template analyzer with rewrite guidance (#13575) 2026-02-24 15:11:04 +04:00
filter_service.rb refactor: extract custom attribute methods from FilterService (#13743) 2026-03-10 14:15:52 +05:30
ip_lookup_service.rb feat(poc): Disable widget based on country (#6658) 2023-03-14 09:09:57 -07:00
search_service.rb feat: Advanced Search Backend (#12917) 2026-01-07 15:30:49 +05:30
social_link_parser.rb feat: account enrichment using context.dev [UPM-27] (#13978) 2026-04-08 11:16:52 +05:30
website_branding_service.rb feat: account enrichment using context.dev [UPM-27] (#13978) 2026-04-08 11:16:52 +05:30