From d96415c814fe400b4bf8d2929eb2766240015742 Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Tue, 7 Jul 2026 19:21:19 -0700 Subject: [PATCH] fix: clear bot owner on handoff --- app/models/conversation.rb | 1 + spec/models/conversation_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/models/conversation.rb b/app/models/conversation.rb index c710a32b5..137df2b6a 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -165,6 +165,7 @@ class Conversation < ApplicationRecord def bot_handoff! update(waiting_since: Time.current) if waiting_since.blank? + self.assignee_agent_bot = nil open! dispatcher_dispatch(CONVERSATION_BOT_HANDOFF) end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 153649de2..129b08843 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -347,6 +347,14 @@ RSpec.describe Conversation do expect(conversation.reload.status).to eq('open') end + it 'clears agent bot ownership' do + conversation.update!(assignee_agent_bot: create(:agent_bot, account: conversation.account)) + + conversation.bot_handoff! + + expect(conversation.reload.assignee_agent_bot).to be_nil + end + it 'dispatches CONVERSATION_BOT_HANDOFF event' do expect(Rails.configuration.dispatcher).to receive(:dispatch) .with(described_class::CONVERSATION_BOT_HANDOFF, anything, hash_including(conversation: conversation))