fix: run captain v2 outside the transaction (#12756)

This commit is contained in:
Shivam Mishra
2025-10-30 13:35:20 +05:30
committed by GitHub
parent c31d693add
commit d20de25da1

View File

@@ -10,8 +10,12 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
Current.executed_by = @assistant Current.executed_by = @assistant
ActiveRecord::Base.transaction do if captain_v2_enabled?
generate_and_process_response generate_response_with_v2
else
ActiveRecord::Base.transaction do
generate_and_process_response
end
end end
rescue StandardError => e rescue StandardError => e
raise e if e.is_a?(ActiveStorage::FileNotFoundError) || e.is_a?(Faraday::BadRequestError) raise e if e.is_a?(ActiveStorage::FileNotFoundError) || e.is_a?(Faraday::BadRequestError)
@@ -26,16 +30,20 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
delegate :account, :inbox, to: :@conversation delegate :account, :inbox, to: :@conversation
def generate_and_process_response def generate_and_process_response
@response = if captain_v2_enabled? @response = Captain::Llm::AssistantChatService.new(assistant: @assistant).generate_response(
Captain::Assistant::AgentRunnerService.new(assistant: @assistant, conversation: @conversation).generate_response( message_history: collect_previous_messages
message_history: collect_previous_messages )
) process_response
else end
Captain::Llm::AssistantChatService.new(assistant: @assistant).generate_response(
message_history: collect_previous_messages
)
end
def generate_response_with_v2
@response = Captain::Assistant::AgentRunnerService.new(assistant: @assistant, conversation: @conversation).generate_response(
message_history: collect_previous_messages
)
process_response
end
def process_response
return process_action('handoff') if handoff_requested? return process_action('handoff') if handoff_requested?
create_messages create_messages
@@ -123,6 +131,6 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob
end end
def captain_v2_enabled? def captain_v2_enabled?
return account.feature_enabled?('captain_integration_v2') account.feature_enabled?('captain_integration_v2')
end end
end end