diff --git a/enterprise/app/jobs/captain/conversation/response_builder_job.rb b/enterprise/app/jobs/captain/conversation/response_builder_job.rb index 36d80fa2d..136b2c14f 100644 --- a/enterprise/app/jobs/captain/conversation/response_builder_job.rb +++ b/enterprise/app/jobs/captain/conversation/response_builder_job.rb @@ -37,7 +37,7 @@ class Captain::Conversation::ResponseBuilderJob < ApplicationJob @response = Captain::Llm::AssistantChatService.new(assistant: @assistant, conversation: @conversation).generate_response( message_history: message_history ) - classify_v1_response_action(message_history) + classify_v1_response_action(message_history) if conversation_pending? process_response end diff --git a/spec/enterprise/jobs/captain/conversation/response_builder_job_spec.rb b/spec/enterprise/jobs/captain/conversation/response_builder_job_spec.rb index ca3d7b61f..23dcaccdf 100644 --- a/spec/enterprise/jobs/captain/conversation/response_builder_job_spec.rb +++ b/spec/enterprise/jobs/captain/conversation/response_builder_job_spec.rb @@ -138,6 +138,20 @@ RSpec.describe Captain::Conversation::ResponseBuilderJob, type: :job do expect(conversation.messages.outgoing.last.content).to eq('Hey, welcome to Captain Specs') expect(account.reload.usage_limits[:captain][:responses][:consumed]).to eq(1) end + + it 'skips the classifier when the conversation is no longer pending after response generation' do + allow(mock_llm_chat_service).to receive(:generate_response) do + conversation.open! + { 'response' => 'Hey, welcome to Captain Specs' } + end + + expect(Captain::Llm::AssistantActionClassifierService).not_to receive(:new) + + described_class.perform_now(conversation, assistant) + + expect(conversation.messages.outgoing.count).to eq(0) + expect(account.reload.usage_limits[:captain][:responses][:consumed]).to eq(0) + end end it 'does not send a response when the conversation is no longer pending' do