{"record":{"id":"1d0ebfe5a4029d73","repo":"instructure/canvas-lms","slug":"not-for-this-conversation","errorCode":null,"errorMessage":"not for this conversation","messagePattern":"not for this conversation","errorType":"exception","errorClass":"ConversationsHelper::Error","httpStatus":400,"severity":"error","filePath":"app/helpers/conversations_helper.rb","lineNumber":142,"sourceCode":"        message = Conversation.build_message(*message_args)\n        message.id = 0\n        message.conversation_id = conversation.conversation_id\n        message.created_at = Time.now.utc\n        { message:, recipients_count: existing_participant_ids.size, status: :accepted }\n      end\n    elsif conversation.should_process_immediately?\n      message = conversation.process_new_message(message_args, recipients, message_ids, tags)\n      { message:, recipients_count: recipients ? recipients.count : 0, status: :ok }\n    else\n      conversation.delay(strand: \"add_message_#{conversation.global_conversation_id}\").process_new_message(message_args, recipients, message_ids, tags)\n      message = Conversation.build_message(*message_args)\n      message.id = 0\n      message.conversation_id = conversation.conversation_id\n      message.created_at = Time.now.utc\n      { message:, recipients_count: recipients ? recipients.count : 0, status: :accepted }\n    end\n  rescue ConversationsHelper::InvalidMessageForConversationError\n    raise ConversationsHelper::Error.new(message: I18n.t(\"not for this conversation\"), status: :bad_request, attribute: \"included_messages\")\n  rescue ConversationsHelper::InvalidMessageParticipantError\n    raise ConversationsHelper::Error.new(message: I18n.t(\"not a participant\"), status: :bad_request, attribute: \"included_messages\")\n  end\n\n  def contexts_for(audience, context_tags)\n    result = { courses: {}, groups: {} }\n    return result if audience.empty?\n\n    context_tags.each do |tag|\n      next unless tag =~ /\\A(course|group)_(\\d+)\\z/\n\n      result[:\"#{$1}s\"][$2.to_i] = []\n    end\n\n    if audience.size == 1 && include_private_conversation_enrollments\n      enrollments = Shard.partition_by_shard(result[:courses].keys) do |course_ids|\n        next unless audience.first.associated_shards.include?(Shard.current)\n","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/helpers/conversations_helper.rb#L124-L160","documentation":"Rescue translator: when building a conversation message, an included_message id that does not belong to the target conversation raises ConversationsHelper::InvalidMessageForConversationError, which is re-raised as a bad_request ConversationsHelper::Error with message 'not for this conversation'.","triggerScenarios":"Conversations API call passing included_messages[] referencing message ids whose conversation_id differs from the conversation being replied to (e.g. forwarding/multimedia attach with stale or mixed ids).","commonSituations":"Client merges messages from two threads; UI caches message ids after the conversation was deleted/merged; id typo from manual API testing.","solutions":["Only pass included_messages ids that appear under the same conversation_id.","Re-fetch the conversation's messages and rebuild the included_messages list before the call.","Catch ConversationsHelper::Error with attribute included_messages and prompt the user to reselect attachments.","Verify message ids via the conversation messages endpoint before attaching."],"exampleFix":"// before\nincluded_messages: [123, 456] // 456 belongs to another conversation\n// after\nincluded_messages: conversation.conversation_messages.where(id: [123,456]).pluck(:id)","handlingStrategy":"validation","validationCode":"msg_ids = conversation.conversation_messages.pluck(:id)\nbad = params[:included_messages] - msg_ids.map(&:to_i)\nraise ArgumentError, 'included_messages not in conversation' if bad.any?","typeGuard":null,"tryCatchPattern":"begin\n  add_message(...)\nrescue ConversationsHelper::Error => e\n  return render json: { error: e.message, attribute: 'included_messages' }, status: :bad_request\nend","preventionTips":["Build included_messages only from the same conversation's messages","Refresh message ids from the server before forwarding","Never mix ids across conversations in one request"],"tags":["conversations","bad-request","message-ownership"],"backgroundTag":"invalid-argument-value","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}