WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: AbsolutePathBuf("/tmp/codex-home"))
Reading additional input from stdin...
{"type":"thread.started","thread_id":"01a13b98-2869-7001-a7a5-16660bb1d263"}
{"type":"turn.started"}
{"type":"item.completed","item":{"id":"item_0","type":"agent_message","text":"I’ll trace both worker handlers from queue payload parsing through every MongoDB read/write, then add tenant scoping and verify malformed or unauthorized jobs are contained without stopping the polling loops."}}
{"type":"item.started","item":{"id":"item_1","type":"command_execution","command":"/bin/bash -lc \"pwd && rg --files -g '\"'!node_modules'\"' -g '\"'!vendor'\"' | sed -n '1,240p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_1","type":"command_execution","command":"/bin/bash -lc \"pwd && rg --files -g '\"'!node_modules'\"' -g '\"'!vendor'\"' | sed -n '1,240p'\"","aggregated_output":"/workspace\nvoice-synthsizer-job-handler/salutation/salutation_service.js\nvoice-synthsizer-job-handler/salutation/salutation_model.js\nvoice-synthsizer-job-handler/salutation/index.js\nrequirements.dev.local.txt\nvoice-synthsizer-job-handler/pm2-development.yml\nvoice-synthsizer-job-handler/recording/recording_model.js\nvoice-synthsizer-job-handler/recording/index.js\nvoice-synthsizer-job-handler/index.js\nvoice-synthsizer-job-handler/package.json\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js\nvoice-synthsizer-job-handler/recording_salutation/index.js\nvoice-synthsizer-job-handler/pm2-production.yml\nvoice-synthsizer-job-handler/job/job_service.js\nvoice-synthsizer-job-handler/job/index.js\nvoice-synthsizer-job-handler/job/job_model.js\nvoice-synthsizer-job-handler/user_audio_profile/index.js\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\npackage.json\napp/services/s3/index.js\napp/services/s3/s3_service.js\nvoice-cloning/train_config.py\nvoice-cloning/score_models.py\nvoice-cloning/minimize_cloned_voice_model.py\nvoice-cloning/synthesize_speech.py\napp/services/utils/index.js\napp/services/utils/deleteFile.js\napp/services/utils/logService.js\napp/services/utils/bugsnag.js\nvoice-cloning/utils/transcription_utils.py\nvoice-cloning/utils/matching_utils.py\nvoice-cloning/utils/synthesize_utils.py\nvoice-cloning/utils/scoring_utils.py\nvoice-cloning/train_multispeaker_baseline_model.py\napp/services/voice_cloning/voice_cloning_model.js\napp/services/voice_cloning/index.js\napp/services/voice_cloning/voice_cloning_service.js\napp/services/sqs/index.js\napp/services/sqs/sqs_service.js\nrequirements.prod.cpu.txt\nrequirements.prod.gpu.txt\nvoice-cloning/docs/potion-voice-cloning_Installation_Guide.md\nvoice-cloning/score_cloned_voice.py\nvoice-cloning/clone_voice.py\nvoice-cloning/assets/speaker_encoder_model/model_se.pth.tar\nvoice-cloning/assets/speaker_encoder_model/config_se.json\nvoice-cloning/assets/wgnd_2_0_unique_names_only.csv.gz\nvoice-cloning/assets/wgnd_2_0_unique_names_only_limited_special_chars.csv\nvoice-cloning/assets/wgnd_2_0_sources.csv.gz\nvoice-cloning/prepare_datasets.py\nvoice-cloning/score_salutation.py\nrequirements.txt\nREADME.md\nrequirements.dev.txt\nvoice-cloning-job-handler/pm2-development.yml\nvoice-cloning-job-handler/index.js\nvoice-cloning-job-handler/package.json\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js\nvoice-cloning-job-handler/voice_cloning/index.js\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js\nvoice-cloning-job-handler/pm2-production.yml\nvoice-cloning-job-handler/user_audio_profile/index.js\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_2","type":"command_execution","command":"/bin/bash -lc \"find voice-cloning-job-handler voice-synthsizer-job-handler -type f \\\\( -name '*.js' -o -name 'package.json' \\\\) -maxdepth 4 -print\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_2","type":"command_execution","command":"/bin/bash -lc \"find voice-cloning-job-handler voice-synthsizer-job-handler -type f \\\\( -name '*.js' -o -name 'package.json' \\\\) -maxdepth 4 -print\"","aggregated_output":"voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js\nvoice-cloning-job-handler/user_audio_profile/index.js\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js\nvoice-cloning-job-handler/voice_cloning/index.js\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js\nvoice-cloning-job-handler/package.json\nvoice-cloning-job-handler/index.js\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js\nvoice-synthsizer-job-handler/user_audio_profile/index.js\nvoice-synthsizer-job-handler/job/job_model.js\nvoice-synthsizer-job-handler/job/index.js\nvoice-synthsizer-job-handler/job/job_service.js\nvoice-synthsizer-job-handler/recording_salutation/index.js\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js\nvoice-synthsizer-job-handler/package.json\nvoice-synthsizer-job-handler/index.js\nvoice-synthsizer-job-handler/recording/index.js\nvoice-synthsizer-job-handler/recording/recording_model.js\nvoice-synthsizer-job-handler/salutation/index.js\nvoice-synthsizer-job-handler/salutation/salutation_model.js\nvoice-synthsizer-job-handler/salutation/salutation_service.js\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_3","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,240p' package.json && sed -n '1,240p' voice-cloning-job-handler/package.json && sed -n '1,260p' voice-synthsizer-job-handler/package.json\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_3","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,240p' package.json && sed -n '1,240p' voice-cloning-job-handler/package.json && sed -n '1,260p' voice-synthsizer-job-handler/package.json\"","aggregated_output":"{\n  \"name\": \"potion-voice\",\n  \"version\": \"1.0.0\",\n  \"description\": \"This will handle the voice cloning jobs\",\n  \"main\": \"index.js\",\n  \"scripts\": {},\n  \"dependencies\": {\n    \"@bugsnag/js\": \"^7.3.5\",\n    \"aws-sdk\": \"^2.752.0\",\n    \"fs-extra\": \"^9.0.1\",\n    \"mongoose\": \"^6.8.0\",\n    \"pm2\": \"^5.2.0\",\n    \"rimraf\": \"^3.0.2\",\n    \"uuid\": \"^8.3.2\"\n  },\n  \"devDependencies\": {\n    \"aws-code-deploy\": \"^1.0.11\"\n  },\n  \"author\": \"potion Team\",\n  \"license\": \"ISC\"\n}\n{\n  \"name\": \"voice-cloning-job-handler\",\n  \"version\": \"1.0.0\",\n  \"description\": \"This will handle the voice cloning jobs\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"deploy-production\": \"npx dotenv-cli -e ./app-scripts/env-aws-code-deploy/.env.production.aws-code-deploy node ./app-scripts/deploy-scripts/deploy-production.js\",\n    \"deploy-staging\": \"npx dotenv-cli -e ./app-scripts/env-aws-code-deploy/.env.staging.aws-code-deploy node ./app-scripts/deploy-scripts/deploy-staging.js\"\n  },\n  \"dependencies\": {\n    \"@bugsnag/js\": \"^7.3.5\",\n    \"aws-sdk\": \"^2.752.0\",\n    \"fs-extra\": \"^9.0.1\",\n    \"mongoose\": \"^6.8.0\",\n    \"pm2\": \"^5.2.0\",\n    \"rimraf\": \"^3.0.2\",\n    \"uuid\": \"^8.3.2\"\n  },\n  \"devDependencies\": {\n    \"aws-code-deploy\": \"^1.0.11\"\n  },\n  \"author\": \"potion Team\",\n  \"license\": \"ISC\"\n}{\n  \"name\": \"voice-synthesizer-job-handler\",\n  \"version\": \"1.0.0\",\n  \"description\": \"This will handle the voice synthesizer jobs\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"deploy-production\": \"npx dotenv-cli -e ./app-scripts/env-aws-code-deploy/.env.production.aws-code-deploy node ./app-scripts/deploy-scripts/deploy-production.js\",\n    \"deploy-staging\": \"npx dotenv-cli -e ./app-scripts/env-aws-code-deploy/.env.staging.aws-code-deploy node ./app-scripts/deploy-scripts/deploy-staging.js\"\n  },\n  \"dependencies\": {\n    \"@bugsnag/js\": \"^7.3.5\",\n    \"aws-sdk\": \"^2.752.0\",\n    \"fs-extra\": \"^9.0.1\",\n    \"mongoose\": \"^6.8.0\",\n    \"rimraf\": \"^3.0.2\",\n    \"uuid\": \"^8.3.2\"\n  },\n  \"devDependencies\": {\n    \"aws-code-deploy\": \"^1.0.11\"\n  },\n  \"author\": \"potion Team\",\n  \"license\": \"ISC\"\n}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_4","type":"command_execution","command":"/bin/bash -lc 'git status --short && rg -n \"(find|findOne|findById|update|delete|remove|save|create|aggregate|mongoose|Mongo|userId|jobId|audioProfile|salutation|recording)\" voice-cloning-job-handler voice-synthsizer-job-handler'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_4","type":"command_execution","command":"/bin/bash -lc 'git status --short && rg -n \"(find|findOne|findById|update|delete|remove|save|create|aggregate|mongoose|Mongo|userId|jobId|audioProfile|salutation|recording)\" voice-cloning-job-handler voice-synthsizer-job-handler'","aggregated_output":"voice-cloning-job-handler/index.js:7:const mongoose = require('mongoose')\nvoice-cloning-job-handler/index.js:14:AWS.config.update({ region: 'us-west-2' })\nvoice-cloning-job-handler/index.js:26:const updateUrl = (str, cloudFrontUrl) => {\nvoice-cloning-job-handler/index.js:34:    mongoose.set('strictQuery', true)\nvoice-cloning-job-handler/index.js:35:    mongoose\nvoice-cloning-job-handler/index.js:38:        console.log('Connected to Mongo DB !')\nvoice-cloning-job-handler/index.js:72:      const writeStream = fs.createWriteStream(path)\nvoice-cloning-job-handler/index.js:130:          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\nvoice-cloning-job-handler/index.js:138:          // update the db model to processing\nvoice-cloning-job-handler/index.js:139:          await voiceCloningService.update({ _id, status: 'processing' })\nvoice-cloning-job-handler/index.js:140:          await userAudioProfileService.update({\nvoice-cloning-job-handler/index.js:145:          // create directory for userid-useraudioprofileid if not exist\nvoice-cloning-job-handler/index.js:164:            await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\nvoice-cloning-job-handler/index.js:178:          console.log('ZIP created ', zipFileName)\nvoice-cloning-job-handler/index.js:202:          //update pth file for cloning\nvoice-cloning-job-handler/index.js:242:          // Add the  code to update location of generated model and status into DB\nvoice-cloning-job-handler/index.js:243:          await voiceCloningService.update({ _id, status: 'completed' })\nvoice-cloning-job-handler/index.js:248:            voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\nvoice-cloning-job-handler/index.js:253:          await userAudioProfileService.update({\nvoice-cloning-job-handler/index.js:274:          await userAudioProfileService.update({\nvoice-cloning-job-handler/index.js:287:          // update the db to set status as error\nvoice-cloning-job-handler/index.js:288:          await voiceCloningService.update({ _id, status: 'error' })\nvoice-cloning-job-handler/index.js:289:          await userAudioProfileService.update({\nvoice-cloning-job-handler/index.js:305:      mongoose.connection.close()\nvoice-synthsizer-job-handler/salutation/salutation_service.js:1:const create = (Salutation) => async (salutationData, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:2:  const newSalutation = new Salutation({ ...salutationData, userId })\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:3:  const savedSalutation = await newSalutation.save()\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:4:  return savedSalutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:8:  const foundSalutation = await Salutation.findOne({\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:10:    deleted: false,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:15:const find = (Salutation) => async (filter) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:16:  const foundSalutations = await Salutation.find({\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:18:    deleted: false,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:23:const update = (Salutation) => async (salutation, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:24:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:25:    { _id: salutation._id, userId },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:26:    salutation,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:29:  return updatedSalutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:32:const modify = (Salutation) => async (salutation) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:33:  const findQuery = salutation._id\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:34:    ? { _id: salutation._id }\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:35:    : { transcriptId: salutation.transcriptId }\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:37:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:38:    findQuery,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:39:    salutation,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:42:  return updatedSalutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:45:const updateOrCreate =\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:47:  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:48:    const salutation = await read(Salutation)({\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:51:      userId,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:53:    if (salutation) {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:54:      salutation.salutationVideo = salutationVideo\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:55:      return await update(Salutation)(salutation, userId)\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:57:      return await create(Salutation)(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:58:        { firstName, salutationVideo, userAudioProfileId },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:59:        userId\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:64:const remove = (Salutation) => async (filter, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:65:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:66:    { ...filter, userId },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:69:        deleted: true,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:74:  return updatedSalutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:79:    create: create(Salutation),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:81:    remove: remove(Salutation),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:82:    update: update(Salutation),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:83:    updateOrCreate: updateOrCreate(Salutation),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:84:    find: find(Salutation),\r\nvoice-cloning-job-handler/package.json:14:    \"mongoose\": \"^6.8.0\",\nvoice-synthsizer-job-handler/salutation/salutation_model.js:1:const mongoose = require('mongoose')\r\nvoice-synthsizer-job-handler/salutation/salutation_model.js:2:const Schema = mongoose.Schema\r\nvoice-synthsizer-job-handler/salutation/salutation_model.js:5:    userId: {\r\nvoice-synthsizer-job-handler/salutation/salutation_model.js:15:    salutationVideo: {\r\nvoice-synthsizer-job-handler/salutation/salutation_model.js:34:    deleted: {\r\nvoice-synthsizer-job-handler/salutation/salutation_model.js:44:module.exports = mongoose.model('Salutations', SalutationSchema)\r\nvoice-synthsizer-job-handler/salutation/index.js:1:const SalutationModel = require('./salutation_model')\r\nvoice-synthsizer-job-handler/salutation/index.js:2:const SalutationService = require('./salutation_service')\r\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:1:const mongoose = require('mongoose')\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:2:const Schema = mongoose.Schema\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:6:    userId: {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:19:      default: 'created',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:33:    deleted: {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:44:module.exports = mongoose.model('VoiceCloning', VoiceCloningSchema)\nvoice-synthsizer-job-handler/recording/recording_model.js:1:const mongoose = require('mongoose')\nvoice-synthsizer-job-handler/recording/recording_model.js:2:const Schema = mongoose.Schema\nvoice-synthsizer-job-handler/recording/recording_model.js:5:    userId: {\nvoice-synthsizer-job-handler/recording/recording_model.js:11:      new mongoose.Schema(\nvoice-synthsizer-job-handler/recording/recording_model.js:62:      new mongoose.Schema(\nvoice-synthsizer-job-handler/recording/recording_model.js:79:      new mongoose.Schema(\nvoice-synthsizer-job-handler/recording/recording_model.js:108:    deleted: {\nvoice-synthsizer-job-handler/recording/recording_model.js:114:      new mongoose.Schema({\nvoice-synthsizer-job-handler/recording/recording_model.js:153:      new mongoose.Schema({\nvoice-synthsizer-job-handler/recording/recording_model.js:227:      new mongoose.Schema(\nvoice-synthsizer-job-handler/recording/recording_model.js:229:          recordingId: {\nvoice-synthsizer-job-handler/recording/recording_model.js:237:          salutationVideo: {\nvoice-synthsizer-job-handler/recording/recording_model.js:241:          salutationVideoProcessed: {\nvoice-synthsizer-job-handler/recording/recording_model.js:259:          deleted: {\nvoice-synthsizer-job-handler/recording/recording_model.js:299:      new mongoose.Schema({\nvoice-synthsizer-job-handler/recording/recording_model.js:406:module.exports = mongoose.model('Recordings', RecordingSchema)\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:3:const create = (VoiceCloningModel) => async (data) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:6:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:7:    return savedModel\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:11:      'ERROR - VOICE CLONING SERVICE > create',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:34:    const foundModel = await VoiceCloningModel.findOne({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:36:      deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:49:const find = (VoiceCloningModel) => async (filter) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:51:    const foundModels = await VoiceCloningModel.find({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:53:      deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:59:      'ERROR - VOICE CLONING SERVICE > find',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:66:const update = (VoiceCloningModel) => async (data) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:68:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:76:    return updatedModel\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:80:      'ERROR - VOICE CLONING SERVICE > update',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:87:const remove = (VoiceCloningModel) => async (filter) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:89:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:93:          deleted: true,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:98:    return updatedModel\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:102:      'ERROR - VOICE CLONING SERVICE > remove',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:109:const removeMany = (VoiceCloningModel) => async (filter) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:111:    const updatedModel = await VoiceCloningModel.updateMany(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:115:          deleted: true,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:120:    return updatedModel\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:124:      'ERROR - VOICE CLONING SERVICE > removeMany',\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:133:    create: create(VoiceCloningModel),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:136:    remove: remove(VoiceCloningModel),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:137:    removeMany: removeMany(VoiceCloningModel),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:138:    update: update(VoiceCloningModel),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:139:    find: find(VoiceCloningModel),\nvoice-synthsizer-job-handler/recording/index.js:1:const Recording = require('./recording_model')\nvoice-synthsizer-job-handler/index.js:10:const recordingModel = require('./recording')\nvoice-synthsizer-job-handler/index.js:11:const recordingSalutationModel = require('./recording_salutation')\nvoice-synthsizer-job-handler/index.js:13:const salutationService = require('./salutation')\nvoice-synthsizer-job-handler/index.js:15:AWS.config.update({ region: 'us-west-2' })\nvoice-synthsizer-job-handler/index.js:21:const mongoose = require('mongoose')\nvoice-synthsizer-job-handler/index.js:41:    mongoose.set('strictQuery', true)\nvoice-synthsizer-job-handler/index.js:42:    mongoose\nvoice-synthsizer-job-handler/index.js:45:        console.log('Connected to Mongo DB !')\nvoice-synthsizer-job-handler/index.js:72:          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\nvoice-synthsizer-job-handler/index.js:78:            salutationId,\nvoice-synthsizer-job-handler/index.js:79:            recordingId,\nvoice-synthsizer-job-handler/index.js:96:          const userAudioProfile = await userAudioProfileService.find({\nvoice-synthsizer-job-handler/index.js:101:            const { training_model_path, userId } = userAudioProfile[0]\nvoice-synthsizer-job-handler/index.js:129:              bucket: `recordings-${env}`,\nvoice-synthsizer-job-handler/index.js:130:              fileName: `${uuid()}_salutation_${firstName.replace(\nvoice-synthsizer-job-handler/index.js:141:            // Create new entry with the s3 path to salutation collection for the user and its profile id\nvoice-synthsizer-job-handler/index.js:142:            // upsert the salutation\nvoice-synthsizer-job-handler/index.js:143:            await salutationService.updateOrCreate(\nvoice-synthsizer-job-handler/index.js:146:                salutationVideo: greetingUploadResponse,\nvoice-synthsizer-job-handler/index.js:149:              userId\nvoice-synthsizer-job-handler/index.js:151:            // update the dynamic recordings for the current dynamic video with salutation url\nvoice-synthsizer-job-handler/index.js:152:            const salutationToUpdate = await recordingSalutationModel.findOne({\nvoice-synthsizer-job-handler/index.js:153:              _id: salutationId,\nvoice-synthsizer-job-handler/index.js:154:              deleted: false,\nvoice-synthsizer-job-handler/index.js:157:            const recordingToUpdate = await recordingModel.findOne({\nvoice-synthsizer-job-handler/index.js:158:              _id: recordingId,\nvoice-synthsizer-job-handler/index.js:159:              deleted: false,\nvoice-synthsizer-job-handler/index.js:163:              salutationToUpdate &&\nvoice-synthsizer-job-handler/index.js:164:              salutationToUpdate.deleted === false &&\nvoice-synthsizer-job-handler/index.js:165:              recordingToUpdate\nvoice-synthsizer-job-handler/index.js:169:              await recordingSalutationModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/index.js:171:                  _id: salutationId,\nvoice-synthsizer-job-handler/index.js:175:                    salutationVideo: greetingUploadResponse,\nvoice-synthsizer-job-handler/index.js:181:                originalGreeting: recordingToUpdate.masterSalutationVideoUrl,\nvoice-synthsizer-job-handler/index.js:183:                  recordingToUpdate.originalVideoUrl ||\nvoice-synthsizer-job-handler/index.js:184:                  recordingToUpdate.urls[0].url,\nvoice-synthsizer-job-handler/index.js:185:                cropTimestamp: recordingToUpdate.cropTimestamp,\nvoice-synthsizer-job-handler/index.js:189:                    greetingId: salutationToUpdate._id,\nvoice-synthsizer-job-handler/index.js:196:                recordingId: recordingToUpdate._id,\nvoice-synthsizer-job-handler/index.js:197:                salutation: salutationToUpdate._id,\nvoice-synthsizer-job-handler/index.js:198:                dynamicVideoType: recordingToUpdate.dynamicVideoType,\nvoice-synthsizer-job-handler/index.js:202:                recordingId: recordingToUpdate._id,\nvoice-synthsizer-job-handler/index.js:203:                userId: recordingToUpdate.userId,\nvoice-synthsizer-job-handler/index.js:204:                salutationId: salutationToUpdate._id,\nvoice-synthsizer-job-handler/index.js:208:              // create the job for the ai to create processing\nvoice-synthsizer-job-handler/index.js:215:            console.log(`[deleted] ${outputPath}${generatedFileName}`)\nvoice-synthsizer-job-handler/index.js:242:      mongoose.connection.close()\nvoice-synthsizer-job-handler/package.json:14:    \"mongoose\": \"^6.8.0\",\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:1:const mongoose = require('mongoose')\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:2:const Schema = mongoose.Schema\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:6:    userId: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:16:    recordingId: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:26:    salutationVideo: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:30:    salutationVideoProcessed: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:48:    deleted: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:71:const RecordingSalutationModel = mongoose.model(\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:72:  'recording_salutations',\r\nvoice-synthsizer-job-handler/recording_salutation/index.js:1:const RecordingSalutationModel = require('./recording_salutation_model')\r\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:1:const mongoose = require('mongoose')\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:2:const Schema = mongoose.Schema\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:6:    userId: {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:19:      default: 'created',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:29:    deleted: {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js:40:module.exports = mongoose.model('UserAudioProfile', UserAudioProfileSchema)\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:3:const create = (UserAudioProfileModel) => async (data) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:6:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:7:    return savedModel\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:11:      'ERROR - USER AUDIO PROFILE SERVICE > create',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:34:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:36:      deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:49:const find = (UserAudioProfileModel) => async (filter) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:51:    const foundModels = await UserAudioProfileModel.find({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:53:      deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:59:      'ERROR - USER AUDIO PROFILE SERVICE > find',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:66:const update = (UserAudioProfileModel) => async (data) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:68:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:75:    return updatedModel\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:79:      'ERROR - USER AUDIO PROFILE SERVICE > update',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:86:const remove = (UserAudioProfileModel) => async (filter) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:88:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:92:          deleted: true,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:97:    return updatedModel\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:101:      'ERROR - USER AUDIO PROFILE SERVICE > remove',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:108:const removeMany = (UserAudioProfileModel) => async (filter) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:110:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:114:          deleted: true,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:119:    return updatedModel\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:123:      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:132:    create: create(UserAudioProfileModel),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:135:    remove: remove(UserAudioProfileModel),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:136:    removeMany: removeMany(UserAudioProfileModel),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:137:    update: update(UserAudioProfileModel),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:138:    find: find(UserAudioProfileModel),\nvoice-synthsizer-job-handler/job/job_service.js:3:const create = (Job) => async (jobData) => {\nvoice-synthsizer-job-handler/job/job_service.js:6:    const savedJob = await newJob.save()\nvoice-synthsizer-job-handler/job/job_service.js:7:    return savedJob\nvoice-synthsizer-job-handler/job/job_service.js:11:      'ERROR - JOB SERVICE > create',\nvoice-synthsizer-job-handler/job/job_service.js:34:    const foundJob = await Job.findOne({\nvoice-synthsizer-job-handler/job/job_service.js:36:      deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js:49:const find = (Job) => async (filter) => {\nvoice-synthsizer-job-handler/job/job_service.js:51:    const foundJobs = await Job.find({\nvoice-synthsizer-job-handler/job/job_service.js:53:      deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js:59:      'ERROR - JOB SERVICE > find',\nvoice-synthsizer-job-handler/job/job_service.js:66:const update = (Job) => async (job) => {\nvoice-synthsizer-job-handler/job/job_service.js:68:    const updatedJob = await Job.findOneAndUpdate({ _id: job._id }, job, {\nvoice-synthsizer-job-handler/job/job_service.js:71:    return updatedJob\nvoice-synthsizer-job-handler/job/job_service.js:75:      'ERROR - JOB SERVICE > update',\nvoice-synthsizer-job-handler/job/job_service.js:82:const remove = (Job) => async (filter) => {\nvoice-synthsizer-job-handler/job/job_service.js:84:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:88:          deleted: true,\nvoice-synthsizer-job-handler/job/job_service.js:93:    return updatedJob\nvoice-synthsizer-job-handler/job/job_service.js:97:      'ERROR - JOB SERVICE > remove',\nvoice-synthsizer-job-handler/job/job_service.js:104:const removeMany = (Job) => async (filter) => {\nvoice-synthsizer-job-handler/job/job_service.js:106:    const updatedJob = await Job.updateMany(\nvoice-synthsizer-job-handler/job/job_service.js:110:          deleted: true,\nvoice-synthsizer-job-handler/job/job_service.js:115:    return updatedJob\nvoice-synthsizer-job-handler/job/job_service.js:119:      'ERROR - JOB SERVICE > removeMany',\nvoice-synthsizer-job-handler/job/job_service.js:128:    create: create(Job),\nvoice-synthsizer-job-handler/job/job_service.js:131:    remove: remove(Job),\nvoice-synthsizer-job-handler/job/job_service.js:132:    removeMany: removeMany(Job),\nvoice-synthsizer-job-handler/job/job_service.js:133:    update: update(Job),\nvoice-synthsizer-job-handler/job/job_service.js:134:    find: find(Job),\nvoice-synthsizer-job-handler/job/job_model.js:1:const mongoose = require('mongoose')\nvoice-synthsizer-job-handler/job/job_model.js:2:const Schema = mongoose.Schema\nvoice-synthsizer-job-handler/job/job_model.js:5:    recordingId: {\nvoice-synthsizer-job-handler/job/job_model.js:9:    userId: {\nvoice-synthsizer-job-handler/job/job_model.js:13:    salutationId: {\nvoice-synthsizer-job-handler/job/job_model.js:37:      default: 'created'\nvoice-synthsizer-job-handler/job/job_model.js:43:    deleted: {\nvoice-synthsizer-job-handler/job/job_model.js:54:module.exports = mongoose.model('Job', JobSchema)\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:3:const create = (UserAudioProfileModel) => async (data) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:6:    const savedModel = await newModel.save()\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:7:    return savedModel\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:11:      'ERROR - USER AUDIO PROFILE SERVICE > create',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:34:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:36:      deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:49:const find = (UserAudioProfileModel) => async (filter) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:51:    const foundModels = await UserAudioProfileModel.find({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:53:      deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:59:      'ERROR - USER AUDIO PROFILE SERVICE > find',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:66:const update = (UserAudioProfileModel) => async (data) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:69:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:76:    console.log('ua updatedModel', updatedModel)\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:77:    return updatedModel\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:81:      'ERROR - USER AUDIO PROFILE SERVICE > update',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:88:const remove = (UserAudioProfileModel) => async (filter) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:90:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:94:          deleted: true\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:99:    return updatedModel\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:103:      'ERROR - USER AUDIO PROFILE SERVICE > remove',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:110:const removeMany = (UserAudioProfileModel) => async (filter) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:112:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:116:          deleted: true\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:121:    return updatedModel\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:125:      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:134:    create: create(UserAudioProfileModel),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:137:    remove: remove(UserAudioProfileModel),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:138:    removeMany: removeMany(UserAudioProfileModel),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:139:    update: update(UserAudioProfileModel),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:140:    find: find(UserAudioProfileModel)\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:1:const mongoose = require('mongoose')\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:2:const Schema = mongoose.Schema\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:6:    userId: {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:19:      default: 'created',\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:29:    deleted: {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js:40:module.exports = mongoose.model('UserAudioProfile', UserAudioProfileSchema)\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_5","type":"agent_message","text":"The vulnerable paths are present in both workers: cloning updates records by `_id` alone, while synthesis looks up the audio profile, recording, and recording-salutation without a tenant predicate. I’m now mapping message fields and failure/acknowledgment behavior so the fix closes reads and writes consistently."}}
{"type":"item.started","item":{"id":"item_6","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,340p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_7","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-cloning-job-handler/index.js | sed -n '1,380p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_7","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-cloning-job-handler/index.js | sed -n '1,380p'\"","aggregated_output":"     1\tconst fs = require('fs')\n     2\tconst https = require('https')\n     3\tconst exec = require('child_process').exec\n     4\tconst AWS = require('aws-sdk')\n     5\t\n     6\tconst Bugsnag = require('@bugsnag/js')\n     7\tconst mongoose = require('mongoose')\n     8\tconst version = require('./package.json').version\n     9\tconst sqs = require('../app/services/sqs')\n    10\tconst s3 = require('../app/services/s3')\n    11\tconst voiceCloningService = require('./voice_cloning')\n    12\tconst userAudioProfileService = require('./user_audio_profile')\n    13\t\n    14\tAWS.config.update({ region: 'us-west-2' })\n    15\tconst sqsQueueUrl = process.env.SQS_URL\n    16\tconst mongoUriDev = process.env.MONGODB_URI_DEV\n    17\tconst mongoUriStaging = process.env.MONGODB_URI_STAGING\n    18\tconst mongoUriProd = process.env.MONGODB_URI_PROD\n    19\tlet throttleMessageFetching = true\n    20\tconst APP_ENV = process.env.POTION_APP_ENV\n    21\t\n    22\tconst cloudFrontUrlProd = process.env.CLOUDFRONT_URL_PROD\n    23\tconst cloudFrontUrlDev = process.env.CLOUDFRONT_URL_DEV\n    24\tconst cloudFrontUrlStaging = process.env.CLOUDFRONT_URL_STAGING\n    25\t\n    26\tconst updateUrl = (str, cloudFrontUrl) => {\n    27\t  const host = new URL(str).host\n    28\t  return str.replace(`https://${host}`, cloudFrontUrl)\n    29\t}\n    30\t\n    31\tfunction connectDB(dbUri, retryCount = 0) {\n    32\t  return new Promise((resolve, reject) => {\n    33\t    console.log('Connection Attempt : ', retryCount)\n    34\t    mongoose.set('strictQuery', true)\n    35\t    mongoose\n    36\t      .connect(dbUri)\n    37\t      .then((msg) => {\n    38\t        console.log('Connected to Mongo DB !')\n    39\t        resolve()\n    40\t      })\n    41\t      .catch((err) => {\n    42\t        console.log('Failed to connect dns mongo: ', err)\n    43\t        if (retryCount < 6) {\n    44\t          retryCount++\n    45\t          connectDB(dbUri, retryCount)\n    46\t        }\n    47\t      })\n    48\t  })\n    49\t}\n    50\t\n    51\tfunction execShellCommand(cmd, logPath) {\n    52\t  // const exec = require(\"child_process\").exec;\n    53\t  return new Promise((resolve, reject) => {\n    54\t    exec(cmd, { maxBuffer: 1024 * 1000000 }, async (error, stdout, stderr) => {\n    55\t      if (error) {\n    56\t        console.log('Error while proccessing python command', error)\n    57\t        reject(error)\n    58\t      }\n    59\t      // console.log('Stdout --- ', stdout)\n    60\t      // console.log('Stderror --- ', stderr)\n    61\t      await fs.promises.writeFile(`${logPath}/error.log`, stderr)\n    62\t      await fs.promises.writeFile(`${logPath}/info.log`, stdout)\n    63\t\n    64\t      resolve()\n    65\t    })\n    66\t  })\n    67\t}\n    68\t\n    69\tasync function getFile(waveUrl, path) {\n    70\t  return new Promise((resolve) => {\n    71\t    https.get(waveUrl, (res) => {\n    72\t      const writeStream = fs.createWriteStream(path)\n    73\t\n    74\t      res.pipe(writeStream)\n    75\t\n    76\t      writeStream.on('finish', () => {\n    77\t        writeStream.close()\n    78\t        resolve()\n    79\t      })\n    80\t    })\n    81\t  })\n    82\t}\n    83\t\n    84\tfunction pad(s) {\n    85\t  while (s.length < 3) s = '0' + s // IN future we will need padding to 4\n    86\t  return s\n    87\t}\n    88\t\n    89\tconst processQueue = () => {\n    90\t  /* eslint-disable no-async-promise-executor */\n    91\t  return new Promise(async (resolve, reject) => {\n    92\t    try {\n    93\t      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n    94\t\n    95\t      if (\n    96\t        typeof response.Messages !== 'undefined' &&\n    97\t        response.Messages.length > 0\n    98\t      ) {\n    99\t        throttleMessageFetching = false\n   100\t        const job = JSON.parse(response.Messages[0].Body)\n   101\t        const receiptHandle = response.Messages[0].ReceiptHandle\n   102\t        console.log('job===', job)\n   103\t\n   104\t        const { metadata, input, _id, userAudioProfileId } = job._doc\n   105\t        console.log('userAudioProfileId', userAudioProfileId)\n   106\t        console.log('_id', _id)\n   107\t        const { env } = job\n   108\t        console.log('env', env)\n   109\t\n   110\t        console.log('metadata------', metadata)\n   111\t        console.log('input', input)\n   112\t        const DB_URI =\n   113\t          env === 'production'\n   114\t            ? mongoUriProd\n   115\t            : env === 'staging'\n   116\t            ? mongoUriStaging\n   117\t            : mongoUriDev\n   118\t\n   119\t        console.log('DB_URI ', DB_URI)\n   120\t        await connectDB(DB_URI)\n   121\t\n   122\t        const cloudFrontUrl =\n   123\t          env === 'production'\n   124\t            ? cloudFrontUrlProd\n   125\t            : env === 'staging'\n   126\t            ? cloudFrontUrlStaging\n   127\t            : cloudFrontUrlDev\n   128\t\n   129\t        try {\n   130\t          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n   131\t\n   132\t          const { directoryName } = metadata\n   133\t          console.log('directoryName', directoryName)\n   134\t          const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   135\t          if (!fs.existsSync(logPath)) {\n   136\t            fs.mkdirSync(logPath, { recursive: true })\n   137\t          }\n   138\t          // update the db model to processing\n   139\t          await voiceCloningService.update({ _id, status: 'processing' })\n   140\t          await userAudioProfileService.update({\n   141\t            _id: userAudioProfileId,\n   142\t            status: 'processing',\n   143\t          })\n   144\t\n   145\t          // create directory for userid-useraudioprofileid if not exist\n   146\t          const rootPath = `/tmp/${directoryName}`\n   147\t          const wavePath = `${rootPath}/wav48/1`\n   148\t          if (!fs.existsSync(wavePath)) {\n   149\t            fs.mkdirSync(wavePath, { recursive: true })\n   150\t          }\n   151\t\n   152\t          const txtPath = `${rootPath}/txt/1`\n   153\t          if (!fs.existsSync(txtPath)) {\n   154\t            fs.mkdirSync(txtPath, { recursive: true })\n   155\t          }\n   156\t          // download the training data files and put it in respective directories\n   157\t          for (let index = 0; index < input.length; index++) {\n   158\t            const item = input[index]\n   159\t\n   160\t            const { waveUrl, originalText } = item\n   161\t            // download wave file\n   162\t            const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`\n   163\t\n   164\t            await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\n   165\t\n   166\t            const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`\n   167\t            await fs.promises.writeFile(txtFilePath, originalText)\n   168\t          }\n   169\t\n   170\t          const zipFileName = directoryName + '.tgz'\n   171\t\n   172\t          // /tmp/directoryName.tgz\n   173\t\n   174\t          await execShellCommand(\n   175\t            `cd /tmp && tar czvf ${zipFileName}  ${directoryName}`,\n   176\t            logPath\n   177\t          )\n   178\t          console.log('ZIP created ', zipFileName)\n   179\t\n   180\t          // re-sample audio\n   181\t          const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`\n   182\t          console.time(SAMPLING_LABEL)\n   183\t\n   184\t          const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   185\t\n   186\t          const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\n   187\t          console.log('samplingCommand ', samplingCommand)\n   188\t          const samplingResponse = await execShellCommand(\n   189\t            samplingCommand,\n   190\t            logPath\n   191\t          )\n   192\t          console.timeEnd(SAMPLING_LABEL)\n   193\t\n   194\t          // /mnt/efs/potion-voice/${env}/speakrs.pth\n   195\t          // /mnt/efs/potion-voice/${env}/txt\n   196\t          // /mnt/efs/potion-voice/${env}/${directoryName}/wav\n   197\t\n   198\t          const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`\n   199\t\n   200\t          const resultsPath = outPath + '/results'\n   201\t\n   202\t          //update pth file for cloning\n   203\t          // clone the voice\n   204\t          const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\n   205\t          console.time(VOICE_CLONING_LABEL)\n   206\t          const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\n   207\t            outPath + '/speakers.pth'\n   208\t          } --output_path ${resultsPath}`\n   209\t\n   210\t          console.log('Training Model Command', trainingModelCommand)\n   211\t          const trainingResponse = await execShellCommand(\n   212\t            trainingModelCommand,\n   213\t            logPath\n   214\t          )\n   215\t\n   216\t          console.timeEnd(VOICE_CLONING_LABEL)\n   217\t\n   218\t          let generatedDirectoryName = ''\n   219\t          fs.readdirSync(`${resultsPath}/`).forEach((file) => {\n   220\t            if (file.includes('vits_potion_clone'))\n   221\t              // use output from above to get right path and directory name\n   222\t              generatedDirectoryName = file\n   223\t          })\n   224\t\n   225\t          // minimize cloning model\n   226\t          const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`\n   227\t          console.time(VOICE_MINIMIZE_LABEL)\n   228\t          const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\n   229\t            resultsPath + '/' + generatedDirectoryName + '/'\n   230\t          } --voice_model_name checkpoint_365200.pth`\n   231\t\n   232\t          console.log(\n   233\t            'Minimize Cloning Model Command',\n   234\t            minimizeCloningModelCommand\n   235\t          )\n   236\t          const minimizeCloning = await execShellCommand(\n   237\t            minimizeCloningModelCommand,\n   238\t            logPath\n   239\t          )\n   240\t          console.timeEnd(VOICE_MINIMIZE_LABEL)\n   241\t\n   242\t          // Add the  code to update location of generated model and status into DB\n   243\t          await voiceCloningService.update({ _id, status: 'completed' })\n   244\t\n   245\t          const training_model_path = {\n   246\t            voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,\n   247\t            voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,\n   248\t            voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\n   249\t            voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,\n   250\t            voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,\n   251\t          }\n   252\t\n   253\t          await userAudioProfileService.update({\n   254\t            _id: userAudioProfileId,\n   255\t            status: 'completed',\n   256\t            training_model_path,\n   257\t          })\n   258\t\n   259\t          // add code to put that model into S3\n   260\t          let keys = Object.keys(training_model_path)\n   261\t\n   262\t          const training_model_s3_path = {}\n   263\t\n   264\t          for (let index = 0; index < keys.length; index++) {\n   265\t            const path = training_model_path[keys[index]]\n   266\t            const s3Path = await s3.upload({\n   267\t              filePath: path,\n   268\t              fileName: `${directoryName}/${path.split('/').pop()}`,\n   269\t              bucket: `potion-voice-users-training-model/${env}`,\n   270\t            })\n   271\t            training_model_s3_path[keys[index]] = s3Path\n   272\t          }\n   273\t          //  add S3 path to user audio profile model\n   274\t          await userAudioProfileService.update({\n   275\t            _id: userAudioProfileId,\n   276\t            training_model_s3_path,\n   277\t          })\n   278\t        } catch (error) {\n   279\t          console.log('error********************', error)\n   280\t          Bugsnag.notify(\n   281\t            new Error(\n   282\t              `Unable to train for voice cloning videos ` + JSON.stringify(job)\n   283\t            )\n   284\t          )\n   285\t          Bugsnag.notify(error)\n   286\t\n   287\t          // update the db to set status as error\n   288\t          await voiceCloningService.update({ _id, status: 'error' })\n   289\t          await userAudioProfileService.update({\n   290\t            _id: userAudioProfileId,\n   291\t            status: 'error',\n   292\t          })\n   293\t\n   294\t          resolve() // to continue working on new jobs\n   295\t        }\n   296\t      } else {\n   297\t        throttleMessageFetching = true\n   298\t      }\n   299\t      resolve()\n   300\t    } catch (error) {\n   301\t      console.error('Error while training voice clone', { error })\n   302\t      Bugsnag.notify(error)\n   303\t      resolve() // to continue working on new jobs\n   304\t    } finally {\n   305\t      mongoose.connection.close()\n   306\t    }\n   307\t  })\n   308\t}\n   309\t\n   310\tfunction sleep(ms) {\n   311\t  return new Promise((resolve) => {\n   312\t    setTimeout(resolve, ms)\n   313\t  })\n   314\t}\n   315\tconst init = async () => {\n   316\t  console.log('potion Voice Clone Process Started')\n   317\t  Bugsnag.start({\n   318\t    appVersion: APP_ENV + version,\n   319\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   320\t    releaseStage: process.env.NODE_ENV,\n   321\t  })\n   322\t\n   323\t  try {\n   324\t    while (true) {\n   325\t      await processQueue()\n   326\t      if (throttleMessageFetching) await sleep(2000)\n   327\t    }\n   328\t  } catch (error) {\n   329\t    Bugsnag.notify(error)\n   330\t  }\n   331\t}\n   332\tinit()\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_6","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,340p'\"","aggregated_output":"     1\tconst fs = require('fs')\n     2\tconst exec = require('child_process').exec\n     3\tconst AWS = require('aws-sdk')\n     4\tconst Bugsnag = require('@bugsnag/js')\n     5\tconst uuid = require('uuid').v4\n     6\tconst version = require('./package.json').version\n     7\tconst sqs = require('../app/services/sqs')\n     8\tconst s3 = require('../app/services/s3')\n     9\tconst userAudioProfileService = require('./user_audio_profile')\n    10\tconst recordingModel = require('./recording')\n    11\tconst recordingSalutationModel = require('./recording_salutation')\n    12\tconst jobService = require('./job')\n    13\tconst salutationService = require('./salutation')\n    14\tlet throttleMessageFetching = true\n    15\tAWS.config.update({ region: 'us-west-2' })\n    16\tconst sqsQueueUrl = process.env.SQS_URL\n    17\tconst mongoUriDev = process.env.MONGODB_URI_DEV\n    18\tconst mongoUriStaging = process.env.MONGODB_URI_STAGING\n    19\tconst mongoUriProd = process.env.MONGODB_URI_PROD\n    20\tconst APP_ENV = process.env.POTION_APP_ENV\n    21\tconst mongoose = require('mongoose')\n    22\t\n    23\tfunction execShellCommand(cmd) {\n    24\t  // const exec = require(\"child_process\").exec;\n    25\t  return new Promise((resolve, reject) => {\n    26\t    exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {\n    27\t      if (error) {\n    28\t        console.log('Error while processing python command', error)\n    29\t        reject(error)\n    30\t      }\n    31\t      console.log('Stdout --- ', stdout)\n    32\t      console.log('Std error --- ', stderr)\n    33\t      resolve(stdout || stderr)\n    34\t    })\n    35\t  })\n    36\t}\n    37\t\n    38\tfunction connectDB(dbUri, retryCount = 0) {\n    39\t  return new Promise((resolve, reject) => {\n    40\t    console.log('Connection Attempt : ', retryCount)\n    41\t    mongoose.set('strictQuery', true)\n    42\t    mongoose\n    43\t      .connect(dbUri)\n    44\t      .then((msg) => {\n    45\t        console.log('Connected to Mongo DB !')\n    46\t        resolve()\n    47\t      })\n    48\t      .catch((err) => {\n    49\t        console.log('Failed to connect dns mongo: ', err)\n    50\t        if (retryCount < 6) {\n    51\t          retryCount++\n    52\t          connectDB(dbUri, retryCount)\n    53\t        }\n    54\t      })\n    55\t  })\n    56\t}\n    57\t\n    58\tconst processQueue = () => {\n    59\t  /* eslint-disable no-async-promise-executor */\n    60\t  return new Promise(async (resolve, reject) => {\n    61\t    try {\n    62\t      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n    63\t\n    64\t      if (\n    65\t        typeof response.Messages !== 'undefined' &&\n    66\t        response.Messages.length > 0\n    67\t      ) {\n    68\t        throttleMessageFetching = false\n    69\t        const job = JSON.parse(response.Messages[0].Body)\n    70\t        const receiptHandle = response.Messages[0].ReceiptHandle\n    71\t        try {\n    72\t          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n    73\t\n    74\t          const {\n    75\t            userAudioProfileId,\n    76\t            text,\n    77\t            firstName,\n    78\t            salutationId,\n    79\t            recordingId,\n    80\t            baseUrlForPotionAi,\n    81\t            env,\n    82\t          } = job\n    83\t\n    84\t          const DB_URI =\n    85\t            env === 'production'\n    86\t              ? mongoUriProd\n    87\t              : env === 'staging'\n    88\t              ? mongoUriStaging\n    89\t              : mongoUriDev\n    90\t\n    91\t          console.log('DB_URI ', DB_URI)\n    92\t          await connectDB(DB_URI)\n    93\t\n    94\t          // read the path for the training model for the this users audio profile\n    95\t\n    96\t          const userAudioProfile = await userAudioProfileService.find({\n    97\t            _id: userAudioProfileId,\n    98\t            status: 'completed',\n    99\t          })\n   100\t          if (userAudioProfile) {\n   101\t            const { training_model_path, userId } = userAudioProfile[0]\n   102\t            const {\n   103\t              voice_model_light_path,\n   104\t              voice_model_config_light_path,\n   105\t              voice_model_speakers_file_path, // name for speakers embeddings file path\n   106\t            } = training_model_path\n   107\t\n   108\t            const outputPath = `/tmp/${uuid()}/`\n   109\t            if (!fs.existsSync(outputPath)) {\n   110\t              fs.mkdirSync(outputPath, { recursive: true })\n   111\t            }\n   112\t\n   113\t            const AI_COMMAND = `python3 ../voice-cloning/synthesize_speech.py --voice_model_path ${voice_model_light_path} --voice_model_config_path ${voice_model_config_light_path} --speaker_embeddings_path ${voice_model_speakers_file_path} --txt \"${text}\" --output_path ${outputPath}`\n   114\t            console.log('AI_COMMAND ', AI_COMMAND)\n   115\t\n   116\t            const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()\n   117\t            console.time(SYNTHESIZE_AI_LABEL)\n   118\t            const aiResponse = await execShellCommand(AI_COMMAND)\n   119\t            console.timeEnd(SYNTHESIZE_AI_LABEL)\n   120\t\n   121\t            let generatedFileName = ''\n   122\t            fs.readdirSync(`${outputPath}`).forEach((file) => {\n   123\t              if (file.includes('sr48000.wav')) generatedFileName = file\n   124\t            })\n   125\t\n   126\t            // upload the file to s3\n   127\t            const uploadParams = {\n   128\t              filePath: `${outputPath}${generatedFileName}`,\n   129\t              bucket: `recordings-${env}`,\n   130\t              fileName: `${uuid()}_salutation_${firstName.replace(\n   131\t                '-',\n   132\t                '_'\n   133\t              )}.wav`,\n   134\t              contentType: 'audio/x-wav',\n   135\t              fileType: 'wav',\n   136\t            }\n   137\t            console.time('Time to Upload video on S3')\n   138\t            const greetingUploadResponse = await s3.upload(uploadParams)\n   139\t            console.timeEnd('Time to Upload video on S3')\n   140\t\n   141\t            // Create new entry with the s3 path to salutation collection for the user and its profile id\n   142\t            // upsert the salutation\n   143\t            await salutationService.updateOrCreate(\n   144\t              {\n   145\t                firstName: firstName,\n   146\t                salutationVideo: greetingUploadResponse,\n   147\t                userAudioProfileId,\n   148\t              },\n   149\t              userId\n   150\t            )\n   151\t            // update the dynamic recordings for the current dynamic video with salutation url\n   152\t            const salutationToUpdate = await recordingSalutationModel.findOne({\n   153\t              _id: salutationId,\n   154\t              deleted: false,\n   155\t            })\n   156\t\n   157\t            const recordingToUpdate = await recordingModel.findOne({\n   158\t              _id: recordingId,\n   159\t              deleted: false,\n   160\t            })\n   161\t\n   162\t            if (\n   163\t              salutationToUpdate &&\n   164\t              salutationToUpdate.deleted === false &&\n   165\t              recordingToUpdate\n   166\t            ) {\n   167\t              const jobsToInsert = []\n   168\t\n   169\t              await recordingSalutationModel.findOneAndUpdate(\n   170\t                {\n   171\t                  _id: salutationId,\n   172\t                },\n   173\t                {\n   174\t                  $set: {\n   175\t                    salutationVideo: greetingUploadResponse,\n   176\t                  },\n   177\t                }\n   178\t              )\n   179\t\n   180\t              const jobData = {\n   181\t                originalGreeting: recordingToUpdate.masterSalutationVideoUrl,\n   182\t                originalVideo:\n   183\t                  recordingToUpdate.originalVideoUrl ||\n   184\t                  recordingToUpdate.urls[0].url,\n   185\t                cropTimestamp: recordingToUpdate.cropTimestamp,\n   186\t                greetingClips: [greetingUploadResponse],\n   187\t                greetingObjects: [\n   188\t                  {\n   189\t                    greetingId: salutationToUpdate._id,\n   190\t                    firstName: firstName,\n   191\t                    videoUrl: greetingUploadResponse,\n   192\t                  },\n   193\t                ],\n   194\t                requestOrigin: baseUrlForPotionAi,\n   195\t                environment: env,\n   196\t                recordingId: recordingToUpdate._id,\n   197\t                salutation: salutationToUpdate._id,\n   198\t                dynamicVideoType: recordingToUpdate.dynamicVideoType,\n   199\t              }\n   200\t              jobsToInsert.push({\n   201\t                firstName,\n   202\t                recordingId: recordingToUpdate._id,\n   203\t                userId: recordingToUpdate.userId,\n   204\t                salutationId: salutationToUpdate._id,\n   205\t                metadata: jobData,\n   206\t              })\n   207\t\n   208\t              // create the job for the ai to create processing\n   209\t              if (jobsToInsert.length) {\n   210\t                await jobService.insertMany(jobsToInsert)\n   211\t              }\n   212\t            }\n   213\t\n   214\t            fs.unlinkSync(`${outputPath}${generatedFileName}`)\n   215\t            console.log(`[deleted] ${outputPath}${generatedFileName}`)\n   216\t          } else {\n   217\t            Bugsnag.notify(\n   218\t              new Error(\n   219\t                `audio profile training model not found ` + JSON.stringify(job)\n   220\t              )\n   221\t            )\n   222\t\n   223\t            resolve() // to continue working on new jobs\n   224\t          }\n   225\t        } catch (error) {\n   226\t          console.error('Error while synthesizing audio', { error })\n   227\t          Bugsnag.notify(\n   228\t            new Error(`Unable to synthesize audio ` + JSON.stringify(job))\n   229\t          )\n   230\t          Bugsnag.notify(error)\n   231\t          resolve() // to continue working on new jobs\n   232\t        }\n   233\t      } else {\n   234\t        throttleMessageFetching = true\n   235\t      }\n   236\t      resolve()\n   237\t    } catch (error) {\n   238\t      console.error('Error while synthesizing audio', { error })\n   239\t      Bugsnag.notify(error)\n   240\t      resolve() // to continue working on new jobs\n   241\t    } finally {\n   242\t      mongoose.connection.close()\n   243\t    }\n   244\t  })\n   245\t}\n   246\t\n   247\tfunction sleep(ms) {\n   248\t  return new Promise((resolve) => {\n   249\t    setTimeout(resolve, ms)\n   250\t  })\n   251\t}\n   252\tconst init = async () => {\n   253\t  Bugsnag.start({\n   254\t    appVersion: APP_ENV + version,\n   255\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   256\t    releaseStage: process.env.NODE_ENV,\n   257\t  })\n   258\t  try {\n   259\t    while (true) {\n   260\t      await processQueue()\n   261\t      if (throttleMessageFetching) await sleep(2000)\n   262\t    }\n   263\t  } catch (error) {\n   264\t    Bugsnag.notify(error)\n   265\t  }\n   266\t}\n   267\tinit()\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_8","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do echo \"$f\"; nl -ba \"$f\"; done'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_8","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do echo \"$f\"; nl -ba \"$f\"; done'","aggregated_output":"voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (VoiceCloningModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new VoiceCloningModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - VOICE CLONING SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (VoiceCloningModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await VoiceCloningModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - VOICE CLONING SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (VoiceCloningModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await VoiceCloningModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - VOICE CLONING SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (VoiceCloningModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await VoiceCloningModel.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - VOICE CLONING SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (VoiceCloningModel) => async (data) => {\n    67\t  try {\n    68\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    69\t      { _id: data._id },\n    70\t      data,\n    71\t      {\n    72\t        new: true,\n    73\t      }\n    74\t    )\n    75\t\n    76\t    return updatedModel\n    77\t  } catch (error) {\n    78\t    const details = { data }\n    79\t    console.log(\n    80\t      'ERROR - VOICE CLONING SERVICE > update',\n    81\t      StringifyUtils.potionErrorObj(error, details)\n    82\t    )\n    83\t    throw error\n    84\t  }\n    85\t}\n    86\t\n    87\tconst remove = (VoiceCloningModel) => async (filter) => {\n    88\t  try {\n    89\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    90\t      { ...filter },\n    91\t      {\n    92\t        $set: {\n    93\t          deleted: true,\n    94\t        },\n    95\t      },\n    96\t      { new: true }\n    97\t    )\n    98\t    return updatedModel\n    99\t  } catch (error) {\n   100\t    const details = { filter }\n   101\t    console.log(\n   102\t      'ERROR - VOICE CLONING SERVICE > remove',\n   103\t      StringifyUtils.potionErrorObj(error, details)\n   104\t    )\n   105\t    throw error\n   106\t  }\n   107\t}\n   108\t\n   109\tconst removeMany = (VoiceCloningModel) => async (filter) => {\n   110\t  try {\n   111\t    const updatedModel = await VoiceCloningModel.updateMany(\n   112\t      { ...filter },\n   113\t      {\n   114\t        $set: {\n   115\t          deleted: true,\n   116\t        },\n   117\t      },\n   118\t      { new: true }\n   119\t    )\n   120\t    return updatedModel\n   121\t  } catch (error) {\n   122\t    const details = { filter }\n   123\t    console.log(\n   124\t      'ERROR - VOICE CLONING SERVICE > removeMany',\n   125\t      StringifyUtils.potionErrorObj(error, details)\n   126\t    )\n   127\t    throw error\n   128\t  }\n   129\t}\n   130\t\n   131\tmodule.exports = (VoiceCloningModel) => {\n   132\t  return {\n   133\t    create: create(VoiceCloningModel),\n   134\t    insertMany: insertMany(VoiceCloningModel),\n   135\t    read: read(VoiceCloningModel),\n   136\t    remove: remove(VoiceCloningModel),\n   137\t    removeMany: removeMany(VoiceCloningModel),\n   138\t    update: update(VoiceCloningModel),\n   139\t    find: find(VoiceCloningModel),\n   140\t  }\n   141\t}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (UserAudioProfileModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new UserAudioProfileModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - USER AUDIO PROFILE SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (UserAudioProfileModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await UserAudioProfileModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (UserAudioProfileModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await UserAudioProfileModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - USER AUDIO PROFILE SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (UserAudioProfileModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await UserAudioProfileModel.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - USER AUDIO PROFILE SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (UserAudioProfileModel) => async (data) => {\n    67\t  try {\n    68\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    69\t      { _id: data._id },\n    70\t      data,\n    71\t      {\n    72\t        new: true,\n    73\t      }\n    74\t    )\n    75\t    return updatedModel\n    76\t  } catch (error) {\n    77\t    const details = { data }\n    78\t    console.log(\n    79\t      'ERROR - USER AUDIO PROFILE SERVICE > update',\n    80\t      StringifyUtils.potionErrorObj(error, details)\n    81\t    )\n    82\t    throw error\n    83\t  }\n    84\t}\n    85\t\n    86\tconst remove = (UserAudioProfileModel) => async (filter) => {\n    87\t  try {\n    88\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    89\t      { ...filter },\n    90\t      {\n    91\t        $set: {\n    92\t          deleted: true,\n    93\t        },\n    94\t      },\n    95\t      { new: true }\n    96\t    )\n    97\t    return updatedModel\n    98\t  } catch (error) {\n    99\t    const details = { filter }\n   100\t    console.log(\n   101\t      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n   102\t      StringifyUtils.potionErrorObj(error, details)\n   103\t    )\n   104\t    throw error\n   105\t  }\n   106\t}\n   107\t\n   108\tconst removeMany = (UserAudioProfileModel) => async (filter) => {\n   109\t  try {\n   110\t    const updatedModel = await UserAudioProfileModel.updateMany(\n   111\t      { ...filter },\n   112\t      {\n   113\t        $set: {\n   114\t          deleted: true,\n   115\t        },\n   116\t      },\n   117\t      { new: true }\n   118\t    )\n   119\t    return updatedModel\n   120\t  } catch (error) {\n   121\t    const details = { filter }\n   122\t    console.log(\n   123\t      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n   124\t      StringifyUtils.potionErrorObj(error, details)\n   125\t    )\n   126\t    throw error\n   127\t  }\n   128\t}\n   129\t\n   130\tmodule.exports = (UserAudioProfileModel) => {\n   131\t  return {\n   132\t    create: create(UserAudioProfileModel),\n   133\t    insertMany: insertMany(UserAudioProfileModel),\n   134\t    read: read(UserAudioProfileModel),\n   135\t    remove: remove(UserAudioProfileModel),\n   136\t    removeMany: removeMany(UserAudioProfileModel),\n   137\t    update: update(UserAudioProfileModel),\n   138\t    find: find(UserAudioProfileModel),\n   139\t  }\n   140\t}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (UserAudioProfileModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new UserAudioProfileModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - USER AUDIO PROFILE SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (UserAudioProfileModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await UserAudioProfileModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (UserAudioProfileModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await UserAudioProfileModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - USER AUDIO PROFILE SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (UserAudioProfileModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await UserAudioProfileModel.find({\n    52\t      ...filter,\n    53\t      deleted: false\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - USER AUDIO PROFILE SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (UserAudioProfileModel) => async (data) => {\n    67\t  console.log('ua data', data)\n    68\t  try {\n    69\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    70\t      { _id: data._id },\n    71\t      data,\n    72\t      {\n    73\t        new: true\n    74\t      }\n    75\t    )\n    76\t    console.log('ua updatedModel', updatedModel)\n    77\t    return updatedModel\n    78\t  } catch (error) {\n    79\t    const details = { data }\n    80\t    console.log(\n    81\t      'ERROR - USER AUDIO PROFILE SERVICE > update',\n    82\t      StringifyUtils.potionErrorObj(error, details)\n    83\t    )\n    84\t    throw error\n    85\t  }\n    86\t}\n    87\t\n    88\tconst remove = (UserAudioProfileModel) => async (filter) => {\n    89\t  try {\n    90\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    91\t      { ...filter },\n    92\t      {\n    93\t        $set: {\n    94\t          deleted: true\n    95\t        }\n    96\t      },\n    97\t      { new: true }\n    98\t    )\n    99\t    return updatedModel\n   100\t  } catch (error) {\n   101\t    const details = { filter }\n   102\t    console.log(\n   103\t      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n   104\t      StringifyUtils.potionErrorObj(error, details)\n   105\t    )\n   106\t    throw error\n   107\t  }\n   108\t}\n   109\t\n   110\tconst removeMany = (UserAudioProfileModel) => async (filter) => {\n   111\t  try {\n   112\t    const updatedModel = await UserAudioProfileModel.updateMany(\n   113\t      { ...filter },\n   114\t      {\n   115\t        $set: {\n   116\t          deleted: true\n   117\t        }\n   118\t      },\n   119\t      { new: true }\n   120\t    )\n   121\t    return updatedModel\n   122\t  } catch (error) {\n   123\t    const details = { filter }\n   124\t    console.log(\n   125\t      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n   126\t      StringifyUtils.potionErrorObj(error, details)\n   127\t    )\n   128\t    throw error\n   129\t  }\n   130\t}\n   131\t\n   132\tmodule.exports = (UserAudioProfileModel) => {\n   133\t  return {\n   134\t    create: create(UserAudioProfileModel),\n   135\t    insertMany: insertMany(UserAudioProfileModel),\n   136\t    read: read(UserAudioProfileModel),\n   137\t    remove: remove(UserAudioProfileModel),\n   138\t    removeMany: removeMany(UserAudioProfileModel),\n   139\t    update: update(UserAudioProfileModel),\n   140\t    find: find(UserAudioProfileModel)\n   141\t  }\n   142\t}\nvoice-synthsizer-job-handler/salutation/salutation_service.js\n     1\tconst create = (Salutation) => async (salutationData, userId) => {\r\n     2\t  const newSalutation = new Salutation({ ...salutationData, userId })\r\n     3\t  const savedSalutation = await newSalutation.save()\r\n     4\t  return savedSalutation\r\n     5\t}\r\n     6\t\r\n     7\tconst read = (Salutation) => async (filter) => {\r\n     8\t  const foundSalutation = await Salutation.findOne({\r\n     9\t    ...filter,\r\n    10\t    deleted: false,\r\n    11\t  })\r\n    12\t  return foundSalutation\r\n    13\t}\r\n    14\t\r\n    15\tconst find = (Salutation) => async (filter) => {\r\n    16\t  const foundSalutations = await Salutation.find({\r\n    17\t    ...filter,\r\n    18\t    deleted: false,\r\n    19\t  })\r\n    20\t  return foundSalutations\r\n    21\t}\r\n    22\t\r\n    23\tconst update = (Salutation) => async (salutation, userId) => {\r\n    24\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    25\t    { _id: salutation._id, userId },\r\n    26\t    salutation,\r\n    27\t    { new: true }\r\n    28\t  )\r\n    29\t  return updatedSalutation\r\n    30\t}\r\n    31\t\r\n    32\tconst modify = (Salutation) => async (salutation) => {\r\n    33\t  const findQuery = salutation._id\r\n    34\t    ? { _id: salutation._id }\r\n    35\t    : { transcriptId: salutation.transcriptId }\r\n    36\t\r\n    37\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    38\t    findQuery,\r\n    39\t    salutation,\r\n    40\t    { new: true }\r\n    41\t  )\r\n    42\t  return updatedSalutation\r\n    43\t}\r\n    44\t\r\n    45\tconst updateOrCreate =\r\n    46\t  (Salutation) =>\r\n    47\t  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\n    48\t    const salutation = await read(Salutation)({\r\n    49\t      firstName,\r\n    50\t      userAudioProfileId,\r\n    51\t      userId,\r\n    52\t    })\r\n    53\t    if (salutation) {\r\n    54\t      salutation.salutationVideo = salutationVideo\r\n    55\t      return await update(Salutation)(salutation, userId)\r\n    56\t    } else {\r\n    57\t      return await create(Salutation)(\r\n    58\t        { firstName, salutationVideo, userAudioProfileId },\r\n    59\t        userId\r\n    60\t      )\r\n    61\t    }\r\n    62\t  }\r\n    63\t\r\n    64\tconst remove = (Salutation) => async (filter, userId) => {\r\n    65\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    66\t    { ...filter, userId },\r\n    67\t    {\r\n    68\t      $set: {\r\n    69\t        deleted: true,\r\n    70\t      },\r\n    71\t    },\r\n    72\t    { new: true }\r\n    73\t  )\r\n    74\t  return updatedSalutation\r\n    75\t}\r\n    76\t\r\n    77\tmodule.exports = (Salutation) => {\r\n    78\t  return {\r\n    79\t    create: create(Salutation),\r\n    80\t    read: read(Salutation),\r\n    81\t    remove: remove(Salutation),\r\n    82\t    update: update(Salutation),\r\n    83\t    updateOrCreate: updateOrCreate(Salutation),\r\n    84\t    find: find(Salutation),\r\n    85\t    modify: modify(Salutation),\r\n    86\t  }\r\n    87\t}\r\nvoice-synthsizer-job-handler/job/job_service.js\n     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (Job) => async (jobData) => {\n     4\t  try {\n     5\t    const newJob = new Job({ ...jobData })\n     6\t    const savedJob = await newJob.save()\n     7\t    return savedJob\n     8\t  } catch (error) {\n     9\t    const details = { jobData }\n    10\t    console.log(\n    11\t      'ERROR - JOB SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (Job) => async (jobData) => {\n    19\t  try {\n    20\t    const inserted = await Job.insertMany(jobData)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { jobData }\n    24\t    console.log(\n    25\t      'ERROR - JOB SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (Job) => async (filter) => {\n    33\t  try {\n    34\t    const foundJob = await Job.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundJob\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - JOB SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (Job) => async (filter) => {\n    50\t  try {\n    51\t    const foundJobs = await Job.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundJobs\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - JOB SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (Job) => async (job) => {\n    67\t  try {\n    68\t    const updatedJob = await Job.findOneAndUpdate({ _id: job._id }, job, {\n    69\t      new: true,\n    70\t    })\n    71\t    return updatedJob\n    72\t  } catch (error) {\n    73\t    const details = { job }\n    74\t    console.log(\n    75\t      'ERROR - JOB SERVICE > update',\n    76\t      StringifyUtils.potionErrorObj(error, details)\n    77\t    )\n    78\t    throw error\n    79\t  }\n    80\t}\n    81\t\n    82\tconst remove = (Job) => async (filter) => {\n    83\t  try {\n    84\t    const updatedJob = await Job.findOneAndUpdate(\n    85\t      { ...filter },\n    86\t      {\n    87\t        $set: {\n    88\t          deleted: true,\n    89\t        },\n    90\t      },\n    91\t      { new: true }\n    92\t    )\n    93\t    return updatedJob\n    94\t  } catch (error) {\n    95\t    const details = { filter }\n    96\t    console.log(\n    97\t      'ERROR - JOB SERVICE > remove',\n    98\t      StringifyUtils.potionErrorObj(error, details)\n    99\t    )\n   100\t    throw error\n   101\t  }\n   102\t}\n   103\t\n   104\tconst removeMany = (Job) => async (filter) => {\n   105\t  try {\n   106\t    const updatedJob = await Job.updateMany(\n   107\t      { ...filter },\n   108\t      {\n   109\t        $set: {\n   110\t          deleted: true,\n   111\t        },\n   112\t      },\n   113\t      { new: true }\n   114\t    )\n   115\t    return updatedJob\n   116\t  } catch (error) {\n   117\t    const details = { filter }\n   118\t    console.log(\n   119\t      'ERROR - JOB SERVICE > removeMany',\n   120\t      StringifyUtils.potionErrorObj(error, details)\n   121\t    )\n   122\t    throw error\n   123\t  }\n   124\t}\n   125\t\n   126\tmodule.exports = (Job) => {\n   127\t  return {\n   128\t    create: create(Job),\n   129\t    insertMany: insertMany(Job),\n   130\t    read: read(Job),\n   131\t    remove: remove(Job),\n   132\t    removeMany: removeMany(Job),\n   133\t    update: update(Job),\n   134\t    find: find(Job),\n   135\t  }\n   136\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_9","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"voice.?clon|synth|SQS|sqs|userAudioProfileId|salutationId|recordingId\\\" README.md app voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js' -g '*.md'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_10","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_model.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js voice-synthsizer-job-handler/salutation/salutation_model.js voice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js voice-synthsizer-job-handler/job/job_model.js; do echo \"$f\"; nl -ba \"$f\"; done'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_9","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"voice.?clon|synth|SQS|sqs|userAudioProfileId|salutationId|recordingId\\\" README.md app voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js' -g '*.md'\"","aggregated_output":"README.md:2:Potion's Text-to-Speech Service (multi-speaker baseline model training, voice cloning and speech synthesising)\nvoice-cloning-job-handler/index.js:9:const sqs = require('../app/services/sqs')\nvoice-cloning-job-handler/index.js:11:const voiceCloningService = require('./voice_cloning')\nvoice-cloning-job-handler/index.js:15:const sqsQueueUrl = process.env.SQS_URL\nvoice-cloning-job-handler/index.js:93:      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\nvoice-cloning-job-handler/index.js:104:        const { metadata, input, _id, userAudioProfileId } = job._doc\nvoice-cloning-job-handler/index.js:105:        console.log('userAudioProfileId', userAudioProfileId)\nvoice-cloning-job-handler/index.js:130:          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\nvoice-cloning-job-handler/index.js:141:            _id: userAudioProfileId,\nvoice-cloning-job-handler/index.js:186:          const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\nvoice-cloning-job-handler/index.js:204:          const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\nvoice-cloning-job-handler/index.js:206:          const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\nvoice-cloning-job-handler/index.js:228:          const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\nvoice-cloning-job-handler/index.js:254:            _id: userAudioProfileId,\nvoice-cloning-job-handler/index.js:275:            _id: userAudioProfileId,\nvoice-cloning-job-handler/index.js:282:              `Unable to train for voice cloning videos ` + JSON.stringify(job)\nvoice-cloning-job-handler/index.js:290:            _id: userAudioProfileId,\nvoice-cloning-job-handler/index.js:301:      console.error('Error while training voice clone', { error })\napp/services/voice_cloning/voice_cloning_model.js:11:    userAudioProfileId: {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_model.js:11:    userAudioProfileId: {\napp/services/voice_cloning/index.js:1:const VoiceCloning = require('./voice_cloning_model')\napp/services/voice_cloning/index.js:2:const VoiceCloningService = require('./voice_cloning_service')\nvoice-cloning-job-handler/voice_cloning/index.js:1:const VoiceCloning = require('./voice_cloning_model')\nvoice-cloning-job-handler/voice_cloning/index.js:2:const VoiceCloningService = require('./voice_cloning_service')\napp/services/sqs/index.js:3:const sqsService = require('./sqs_service')\napp/services/sqs/index.js:4:const sqs = new AWS.SQS({ apiVersion: '2012-11-05' })\napp/services/sqs/index.js:6:module.exports = sqsService\napp/services/sqs/sqs_service.js:3:const sqs = new AWS.SQS({ apiVersion: '2012-11-05' })\napp/services/sqs/sqs_service.js:7:const fetchMessageFromSQS = (sqsQueueUrl, waitTimeInSeconds = 0) => {\napp/services/sqs/sqs_service.js:11:      QueueUrl: sqsQueueUrl /* required */,\napp/services/sqs/sqs_service.js:13:    sqs.receiveMessage(params, function (err, data) {\napp/services/sqs/sqs_service.js:17:          `ERROR in fetchJobFromSQS : `,\napp/services/sqs/sqs_service.js:27:const deleteMessageFromSQS = (sqsQueueUrl, receiptHandle) => {\napp/services/sqs/sqs_service.js:31:      QueueUrl: sqsQueueUrl /* required */,\napp/services/sqs/sqs_service.js:33:    sqs.deleteMessage(params, function (err, data) {\napp/services/sqs/sqs_service.js:37:          `ERROR in sending delete request to AWS.SQS : `,\napp/services/sqs/sqs_service.js:42:          'Successfully sent delete request to AWS.SQS',\napp/services/sqs/sqs_service.js:51:const sendMessageToSQS = (sqsQueueUrl, message) => {\napp/services/sqs/sqs_service.js:55:      QueueUrl: sqsQueueUrl /* required */,\napp/services/sqs/sqs_service.js:61:    sqs.sendMessage(params, function (err, data) {\napp/services/sqs/sqs_service.js:65:          `ERROR in seding request to AWS.SQS : `,\napp/services/sqs/sqs_service.js:70:          'Successfully sent request to AWS.SQS',\napp/services/sqs/sqs_service.js:80:  fetchMessageFromSQS,\napp/services/sqs/sqs_service.js:81:  deleteMessageFromSQS,\napp/services/sqs/sqs_service.js:82:  sendMessageToSQS,\nvoice-synthsizer-job-handler/salutation/salutation_service.js:47:  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:50:      userAudioProfileId,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:58:        { firstName, salutationVideo, userAudioProfileId },\r\nvoice-synthsizer-job-handler/index.js:7:const sqs = require('../app/services/sqs')\nvoice-synthsizer-job-handler/index.js:16:const sqsQueueUrl = process.env.SQS_URL\nvoice-synthsizer-job-handler/index.js:62:      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\nvoice-synthsizer-job-handler/index.js:72:          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\nvoice-synthsizer-job-handler/index.js:75:            userAudioProfileId,\nvoice-synthsizer-job-handler/index.js:78:            salutationId,\nvoice-synthsizer-job-handler/index.js:79:            recordingId,\nvoice-synthsizer-job-handler/index.js:97:            _id: userAudioProfileId,\nvoice-synthsizer-job-handler/index.js:113:            const AI_COMMAND = `python3 ../voice-cloning/synthesize_speech.py --voice_model_path ${voice_model_light_path} --voice_model_config_path ${voice_model_config_light_path} --speaker_embeddings_path ${voice_model_speakers_file_path} --txt \"${text}\" --output_path ${outputPath}`\nvoice-synthsizer-job-handler/index.js:147:                userAudioProfileId,\nvoice-synthsizer-job-handler/index.js:153:              _id: salutationId,\nvoice-synthsizer-job-handler/index.js:158:              _id: recordingId,\nvoice-synthsizer-job-handler/index.js:171:                  _id: salutationId,\nvoice-synthsizer-job-handler/index.js:196:                recordingId: recordingToUpdate._id,\nvoice-synthsizer-job-handler/index.js:202:                recordingId: recordingToUpdate._id,\nvoice-synthsizer-job-handler/index.js:204:                salutationId: salutationToUpdate._id,\nvoice-synthsizer-job-handler/index.js:226:          console.error('Error while synthesizing audio', { error })\nvoice-synthsizer-job-handler/index.js:228:            new Error(`Unable to synthesize audio ` + JSON.stringify(job))\nvoice-synthsizer-job-handler/index.js:238:      console.error('Error while synthesizing audio', { error })\nvoice-synthsizer-job-handler/salutation/salutation_model.js:24:    userAudioProfileId: {\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js:16:    recordingId: {\r\nvoice-synthsizer-job-handler/recording/recording_model.js:229:          recordingId: {\nvoice-synthsizer-job-handler/job/job_model.js:5:    recordingId: {\nvoice-synthsizer-job-handler/job/job_model.js:13:    salutationId: {\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_10","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_model.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js voice-synthsizer-job-handler/salutation/salutation_model.js voice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js voice-synthsizer-job-handler/job/job_model.js; do echo \"$f\"; nl -ba \"$f\"; done'","aggregated_output":"voice-cloning-job-handler/voice_cloning/voice_cloning_model.js\n     1\tconst mongoose = require('mongoose')\n     2\tconst Schema = mongoose.Schema\n     3\t\n     4\tconst VoiceCloningSchema = Schema(\n     5\t  {\n     6\t    userId: {\n     7\t      type: Schema.Types.ObjectId,\n     8\t      ref: 'User',\n     9\t      required: true,\n    10\t    },\n    11\t    userAudioProfileId: {\n    12\t      type: Schema.Types.ObjectId,\n    13\t      ref: 'UserAudioProfile',\n    14\t      required: true,\n    15\t    },\n    16\t    status: {\n    17\t      type: String,\n    18\t      required: false,\n    19\t      default: 'created',\n    20\t    },\n    21\t    input: {\n    22\t      type: Schema.Types.Mixed,\n    23\t      default: null,\n    24\t    },\n    25\t    training_model: {\n    26\t      type: Schema.Types.Mixed,\n    27\t      default: null,\n    28\t    },\n    29\t    metadata: {\n    30\t      type: Schema.Types.Mixed,\n    31\t      default: null,\n    32\t    },\n    33\t    deleted: {\n    34\t      type: Boolean,\n    35\t      required: true,\n    36\t      default: false,\n    37\t    },\n    38\t  },\n    39\t  {\n    40\t    timestamps: true,\n    41\t  }\n    42\t)\n    43\t\n    44\tmodule.exports = mongoose.model('VoiceCloning', VoiceCloningSchema)\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_model.js\n     1\tconst mongoose = require('mongoose')\n     2\tconst Schema = mongoose.Schema\n     3\t\n     4\tconst UserAudioProfileSchema = Schema(\n     5\t  {\n     6\t    userId: {\n     7\t      type: Schema.Types.ObjectId,\n     8\t      ref: 'User',\n     9\t      required: true,\n    10\t    },\n    11\t    name: {\n    12\t      type: String,\n    13\t      required: true,\n    14\t      default: '',\n    15\t    },\n    16\t    status: {\n    17\t      type: String,\n    18\t      required: false,\n    19\t      default: 'created',\n    20\t    },\n    21\t    training_model_path: {\n    22\t      type: Schema.Types.Mixed,\n    23\t      default: null,\n    24\t    },\n    25\t    training_model_s3_path: {\n    26\t      type: Schema.Types.Mixed,\n    27\t      default: null,\n    28\t    },\n    29\t    deleted: {\n    30\t      type: Boolean,\n    31\t      required: true,\n    32\t      default: false,\n    33\t    },\n    34\t  },\n    35\t  {\n    36\t    timestamps: true,\n    37\t  }\n    38\t)\n    39\t\n    40\tmodule.exports = mongoose.model('UserAudioProfile', UserAudioProfileSchema)\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_model.js\n     1\tconst mongoose = require('mongoose')\n     2\tconst Schema = mongoose.Schema\n     3\t\n     4\tconst UserAudioProfileSchema = Schema(\n     5\t  {\n     6\t    userId: {\n     7\t      type: Schema.Types.ObjectId,\n     8\t      ref: 'User',\n     9\t      required: true,\n    10\t    },\n    11\t    name: {\n    12\t      type: String,\n    13\t      required: true,\n    14\t      default: '',\n    15\t    },\n    16\t    status: {\n    17\t      type: String,\n    18\t      required: false,\n    19\t      default: 'created',\n    20\t    },\n    21\t    training_model_path: {\n    22\t      type: Schema.Types.Mixed,\n    23\t      default: null,\n    24\t    },\n    25\t    training_model_s3_path: {\n    26\t      type: Schema.Types.Mixed,\n    27\t      default: null,\n    28\t    },\n    29\t    deleted: {\n    30\t      type: Boolean,\n    31\t      required: true,\n    32\t      default: false,\n    33\t    },\n    34\t  },\n    35\t  {\n    36\t    timestamps: true,\n    37\t  }\n    38\t)\n    39\t\n    40\tmodule.exports = mongoose.model('UserAudioProfile', UserAudioProfileSchema)\nvoice-synthsizer-job-handler/salutation/salutation_model.js\n     1\tconst mongoose = require('mongoose')\r\n     2\tconst Schema = mongoose.Schema\r\n     3\tconst SalutationSchema = Schema(\r\n     4\t  {\r\n     5\t    userId: {\r\n     6\t      type: Schema.Types.ObjectId,\r\n     7\t      ref: 'User',\r\n     8\t      required: true\r\n     9\t    },\r\n    10\t    firstName: {\r\n    11\t      type: String,\r\n    12\t      required: false,\r\n    13\t      default: ''\r\n    14\t    },\r\n    15\t    salutationVideo: {\r\n    16\t      type: String,\r\n    17\t      default: null\r\n    18\t    },\r\n    19\t    transcriptId: {\r\n    20\t      type: String,\r\n    21\t      default: null,\r\n    22\t      required: false\r\n    23\t    },\r\n    24\t    userAudioProfileId: {\r\n    25\t      type: Schema.Types.ObjectId,\r\n    26\t      default: null,\r\n    27\t      required: false\r\n    28\t    },\r\n    29\t    transcriptObj: {\r\n    30\t      type: Object,\r\n    31\t      default: null,\r\n    32\t      required: false\r\n    33\t    },\r\n    34\t    deleted: {\r\n    35\t      type: Boolean,\r\n    36\t      default: false\r\n    37\t    }\r\n    38\t  },\r\n    39\t  {\r\n    40\t    timestamps: true\r\n    41\t  }\r\n    42\t)\r\n    43\t\r\n    44\tmodule.exports = mongoose.model('Salutations', SalutationSchema)\r\nvoice-synthsizer-job-handler/recording_salutation/recording_salutation_model.js\n     1\tconst mongoose = require('mongoose')\r\n     2\tconst Schema = mongoose.Schema\r\n     3\t\r\n     4\tconst RecordingSalutationSchema = Schema(\r\n     5\t  {\r\n     6\t    userId: {\r\n     7\t      type: Schema.Types.ObjectId,\r\n     8\t      ref: 'User',\r\n     9\t      required: true\r\n    10\t    },\r\n    11\t    masterRecordingId: {\r\n    12\t      type: Schema.Types.ObjectId,\r\n    13\t      ref: 'Recordings',\r\n    14\t      required: true\r\n    15\t    },\r\n    16\t    recordingId: {\r\n    17\t      type: Schema.Types.ObjectId,\r\n    18\t      ref: 'Recordings',\r\n    19\t      required: false\r\n    20\t    },\r\n    21\t    firstName: {\r\n    22\t      type: String,\r\n    23\t      required: false,\r\n    24\t      default: ''\r\n    25\t    },\r\n    26\t    salutationVideo: {\r\n    27\t      type: String,\r\n    28\t      default: null\r\n    29\t    },\r\n    30\t    salutationVideoProcessed: {\r\n    31\t      type: String,\r\n    32\t      default: null\r\n    33\t    },\r\n    34\t    screenRecordingProcessed: {\r\n    35\t      type: String\r\n    36\t    },\r\n    37\t    transcriptId: {\r\n    38\t      type: String\r\n    39\t    },\r\n    40\t    processed: {\r\n    41\t      type: Boolean,\r\n    42\t      default: false\r\n    43\t    },\r\n    44\t    inProgress: {\r\n    45\t      type: Boolean,\r\n    46\t      default: false\r\n    47\t    },\r\n    48\t    deleted: {\r\n    49\t      type: Boolean,\r\n    50\t      default: false\r\n    51\t    },\r\n    52\t    backgroundScreenUrl: {\r\n    53\t      type: String\r\n    54\t    },\r\n    55\t    backgroundScreenFileUrl: {\r\n    56\t      type: String\r\n    57\t    },\r\n    58\t    slug: {\r\n    59\t      type: String\r\n    60\t    },\r\n    61\t    status: {\r\n    62\t      type: String,\r\n    63\t      default: null\r\n    64\t    }\r\n    65\t  },\r\n    66\t  {\r\n    67\t    timestamps: true\r\n    68\t  }\r\n    69\t)\r\n    70\t\r\n    71\tconst RecordingSalutationModel = mongoose.model(\r\n    72\t  'recording_salutations',\r\n    73\t  RecordingSalutationSchema\r\n    74\t)\r\n    75\t\r\n    76\tmodule.exports = RecordingSalutationModel\r\nvoice-synthsizer-job-handler/job/job_model.js\n     1\tconst mongoose = require('mongoose')\n     2\tconst Schema = mongoose.Schema\n     3\tconst JobSchema = Schema(\n     4\t  {\n     5\t    recordingId: {\n     6\t      type: Schema.Types.ObjectId,\n     7\t      required: false\n     8\t    },\n     9\t    userId: {\n    10\t      type: Schema.Types.ObjectId,\n    11\t      required: false\n    12\t    },\n    13\t    salutationId: {\n    14\t      type: Schema.Types.ObjectId,\n    15\t      required: false\n    16\t    },\n    17\t    type: {\n    18\t      type: String,\n    19\t      required: false,\n    20\t      default: 'ai-job'\n    21\t    },\n    22\t    firstName: {\n    23\t      type: String,\n    24\t      default: ''\n    25\t    },\n    26\t    weight: {\n    27\t      type: Number,\n    28\t      default: 0\n    29\t    },\n    30\t    email: {\n    31\t      type: String,\n    32\t      default: ''\n    33\t    },\n    34\t    status: {\n    35\t      type: String,\n    36\t      required: false,\n    37\t      default: 'created'\n    38\t    },\n    39\t    metadata: {\n    40\t      type: Schema.Types.Mixed,\n    41\t      default: null\n    42\t    },\n    43\t    deleted: {\n    44\t      type: Boolean,\n    45\t      required: true,\n    46\t      default: false\n    47\t    }\n    48\t  },\n    49\t  {\n    50\t    timestamps: true\n    51\t  }\n    52\t)\n    53\t\n    54\tmodule.exports = mongoose.model('Job', JobSchema)\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_11","type":"command_execution","command":"/bin/bash -lc 'nl -ba voice-cloning-job-handler/voice_cloning/voice_cloning_service.js && nl -ba voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_12","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,300p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_11","type":"command_execution","command":"/bin/bash -lc 'nl -ba voice-cloning-job-handler/voice_cloning/voice_cloning_service.js && nl -ba voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js'","aggregated_output":"     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (VoiceCloningModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new VoiceCloningModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - VOICE CLONING SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (VoiceCloningModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await VoiceCloningModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - VOICE CLONING SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (VoiceCloningModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await VoiceCloningModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - VOICE CLONING SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (VoiceCloningModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await VoiceCloningModel.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - VOICE CLONING SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (VoiceCloningModel) => async (data) => {\n    67\t  try {\n    68\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    69\t      { _id: data._id },\n    70\t      data,\n    71\t      {\n    72\t        new: true,\n    73\t      }\n    74\t    )\n    75\t\n    76\t    return updatedModel\n    77\t  } catch (error) {\n    78\t    const details = { data }\n    79\t    console.log(\n    80\t      'ERROR - VOICE CLONING SERVICE > update',\n    81\t      StringifyUtils.potionErrorObj(error, details)\n    82\t    )\n    83\t    throw error\n    84\t  }\n    85\t}\n    86\t\n    87\tconst remove = (VoiceCloningModel) => async (filter) => {\n    88\t  try {\n    89\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    90\t      { ...filter },\n    91\t      {\n    92\t        $set: {\n    93\t          deleted: true,\n    94\t        },\n    95\t      },\n    96\t      { new: true }\n    97\t    )\n    98\t    return updatedModel\n    99\t  } catch (error) {\n   100\t    const details = { filter }\n   101\t    console.log(\n   102\t      'ERROR - VOICE CLONING SERVICE > remove',\n   103\t      StringifyUtils.potionErrorObj(error, details)\n   104\t    )\n   105\t    throw error\n   106\t  }\n   107\t}\n   108\t\n   109\tconst removeMany = (VoiceCloningModel) => async (filter) => {\n   110\t  try {\n   111\t    const updatedModel = await VoiceCloningModel.updateMany(\n   112\t      { ...filter },\n   113\t      {\n   114\t        $set: {\n   115\t          deleted: true,\n   116\t        },\n   117\t      },\n   118\t      { new: true }\n   119\t    )\n   120\t    return updatedModel\n   121\t  } catch (error) {\n   122\t    const details = { filter }\n   123\t    console.log(\n   124\t      'ERROR - VOICE CLONING SERVICE > removeMany',\n   125\t      StringifyUtils.potionErrorObj(error, details)\n   126\t    )\n   127\t    throw error\n   128\t  }\n   129\t}\n   130\t\n   131\tmodule.exports = (VoiceCloningModel) => {\n   132\t  return {\n   133\t    create: create(VoiceCloningModel),\n   134\t    insertMany: insertMany(VoiceCloningModel),\n   135\t    read: read(VoiceCloningModel),\n   136\t    remove: remove(VoiceCloningModel),\n   137\t    removeMany: removeMany(VoiceCloningModel),\n   138\t    update: update(VoiceCloningModel),\n   139\t    find: find(VoiceCloningModel),\n   140\t  }\n   141\t}\n     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (UserAudioProfileModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new UserAudioProfileModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - USER AUDIO PROFILE SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (UserAudioProfileModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await UserAudioProfileModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (UserAudioProfileModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await UserAudioProfileModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - USER AUDIO PROFILE SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (UserAudioProfileModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await UserAudioProfileModel.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - USER AUDIO PROFILE SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (UserAudioProfileModel) => async (data) => {\n    67\t  try {\n    68\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    69\t      { _id: data._id },\n    70\t      data,\n    71\t      {\n    72\t        new: true,\n    73\t      }\n    74\t    )\n    75\t    return updatedModel\n    76\t  } catch (error) {\n    77\t    const details = { data }\n    78\t    console.log(\n    79\t      'ERROR - USER AUDIO PROFILE SERVICE > update',\n    80\t      StringifyUtils.potionErrorObj(error, details)\n    81\t    )\n    82\t    throw error\n    83\t  }\n    84\t}\n    85\t\n    86\tconst remove = (UserAudioProfileModel) => async (filter) => {\n    87\t  try {\n    88\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    89\t      { ...filter },\n    90\t      {\n    91\t        $set: {\n    92\t          deleted: true,\n    93\t        },\n    94\t      },\n    95\t      { new: true }\n    96\t    )\n    97\t    return updatedModel\n    98\t  } catch (error) {\n    99\t    const details = { filter }\n   100\t    console.log(\n   101\t      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n   102\t      StringifyUtils.potionErrorObj(error, details)\n   103\t    )\n   104\t    throw error\n   105\t  }\n   106\t}\n   107\t\n   108\tconst removeMany = (UserAudioProfileModel) => async (filter) => {\n   109\t  try {\n   110\t    const updatedModel = await UserAudioProfileModel.updateMany(\n   111\t      { ...filter },\n   112\t      {\n   113\t        $set: {\n   114\t          deleted: true,\n   115\t        },\n   116\t      },\n   117\t      { new: true }\n   118\t    )\n   119\t    return updatedModel\n   120\t  } catch (error) {\n   121\t    const details = { filter }\n   122\t    console.log(\n   123\t      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n   124\t      StringifyUtils.potionErrorObj(error, details)\n   125\t    )\n   126\t    throw error\n   127\t  }\n   128\t}\n   129\t\n   130\tmodule.exports = (UserAudioProfileModel) => {\n   131\t  return {\n   132\t    create: create(UserAudioProfileModel),\n   133\t    insertMany: insertMany(UserAudioProfileModel),\n   134\t    read: read(UserAudioProfileModel),\n   135\t    remove: remove(UserAudioProfileModel),\n   136\t    removeMany: removeMany(UserAudioProfileModel),\n   137\t    update: update(UserAudioProfileModel),\n   138\t    find: find(UserAudioProfileModel),\n   139\t  }\n   140\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_12","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,300p'\"","aggregated_output":"     1\tconst fs = require('fs')\n     2\tconst exec = require('child_process').exec\n     3\tconst AWS = require('aws-sdk')\n     4\tconst Bugsnag = require('@bugsnag/js')\n     5\tconst uuid = require('uuid').v4\n     6\tconst version = require('./package.json').version\n     7\tconst sqs = require('../app/services/sqs')\n     8\tconst s3 = require('../app/services/s3')\n     9\tconst userAudioProfileService = require('./user_audio_profile')\n    10\tconst recordingModel = require('./recording')\n    11\tconst recordingSalutationModel = require('./recording_salutation')\n    12\tconst jobService = require('./job')\n    13\tconst salutationService = require('./salutation')\n    14\tlet throttleMessageFetching = true\n    15\tAWS.config.update({ region: 'us-west-2' })\n    16\tconst sqsQueueUrl = process.env.SQS_URL\n    17\tconst mongoUriDev = process.env.MONGODB_URI_DEV\n    18\tconst mongoUriStaging = process.env.MONGODB_URI_STAGING\n    19\tconst mongoUriProd = process.env.MONGODB_URI_PROD\n    20\tconst APP_ENV = process.env.POTION_APP_ENV\n    21\tconst mongoose = require('mongoose')\n    22\t\n    23\tfunction execShellCommand(cmd) {\n    24\t  // const exec = require(\"child_process\").exec;\n    25\t  return new Promise((resolve, reject) => {\n    26\t    exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {\n    27\t      if (error) {\n    28\t        console.log('Error while processing python command', error)\n    29\t        reject(error)\n    30\t      }\n    31\t      console.log('Stdout --- ', stdout)\n    32\t      console.log('Std error --- ', stderr)\n    33\t      resolve(stdout || stderr)\n    34\t    })\n    35\t  })\n    36\t}\n    37\t\n    38\tfunction connectDB(dbUri, retryCount = 0) {\n    39\t  return new Promise((resolve, reject) => {\n    40\t    console.log('Connection Attempt : ', retryCount)\n    41\t    mongoose.set('strictQuery', true)\n    42\t    mongoose\n    43\t      .connect(dbUri)\n    44\t      .then((msg) => {\n    45\t        console.log('Connected to Mongo DB !')\n    46\t        resolve()\n    47\t      })\n    48\t      .catch((err) => {\n    49\t        console.log('Failed to connect dns mongo: ', err)\n    50\t        if (retryCount < 6) {\n    51\t          retryCount++\n    52\t          connectDB(dbUri, retryCount)\n    53\t        }\n    54\t      })\n    55\t  })\n    56\t}\n    57\t\n    58\tconst processQueue = () => {\n    59\t  /* eslint-disable no-async-promise-executor */\n    60\t  return new Promise(async (resolve, reject) => {\n    61\t    try {\n    62\t      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n    63\t\n    64\t      if (\n    65\t        typeof response.Messages !== 'undefined' &&\n    66\t        response.Messages.length > 0\n    67\t      ) {\n    68\t        throttleMessageFetching = false\n    69\t        const job = JSON.parse(response.Messages[0].Body)\n    70\t        const receiptHandle = response.Messages[0].ReceiptHandle\n    71\t        try {\n    72\t          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n    73\t\n    74\t          const {\n    75\t            userAudioProfileId,\n    76\t            text,\n    77\t            firstName,\n    78\t            salutationId,\n    79\t            recordingId,\n    80\t            baseUrlForPotionAi,\n    81\t            env,\n    82\t          } = job\n    83\t\n    84\t          const DB_URI =\n    85\t            env === 'production'\n    86\t              ? mongoUriProd\n    87\t              : env === 'staging'\n    88\t              ? mongoUriStaging\n    89\t              : mongoUriDev\n    90\t\n    91\t          console.log('DB_URI ', DB_URI)\n    92\t          await connectDB(DB_URI)\n    93\t\n    94\t          // read the path for the training model for the this users audio profile\n    95\t\n    96\t          const userAudioProfile = await userAudioProfileService.find({\n    97\t            _id: userAudioProfileId,\n    98\t            status: 'completed',\n    99\t          })\n   100\t          if (userAudioProfile) {\n   101\t            const { training_model_path, userId } = userAudioProfile[0]\n   102\t            const {\n   103\t              voice_model_light_path,\n   104\t              voice_model_config_light_path,\n   105\t              voice_model_speakers_file_path, // name for speakers embeddings file path\n   106\t            } = training_model_path\n   107\t\n   108\t            const outputPath = `/tmp/${uuid()}/`\n   109\t            if (!fs.existsSync(outputPath)) {\n   110\t              fs.mkdirSync(outputPath, { recursive: true })\n   111\t            }\n   112\t\n   113\t            const AI_COMMAND = `python3 ../voice-cloning/synthesize_speech.py --voice_model_path ${voice_model_light_path} --voice_model_config_path ${voice_model_config_light_path} --speaker_embeddings_path ${voice_model_speakers_file_path} --txt \"${text}\" --output_path ${outputPath}`\n   114\t            console.log('AI_COMMAND ', AI_COMMAND)\n   115\t\n   116\t            const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()\n   117\t            console.time(SYNTHESIZE_AI_LABEL)\n   118\t            const aiResponse = await execShellCommand(AI_COMMAND)\n   119\t            console.timeEnd(SYNTHESIZE_AI_LABEL)\n   120\t\n   121\t            let generatedFileName = ''\n   122\t            fs.readdirSync(`${outputPath}`).forEach((file) => {\n   123\t              if (file.includes('sr48000.wav')) generatedFileName = file\n   124\t            })\n   125\t\n   126\t            // upload the file to s3\n   127\t            const uploadParams = {\n   128\t              filePath: `${outputPath}${generatedFileName}`,\n   129\t              bucket: `recordings-${env}`,\n   130\t              fileName: `${uuid()}_salutation_${firstName.replace(\n   131\t                '-',\n   132\t                '_'\n   133\t              )}.wav`,\n   134\t              contentType: 'audio/x-wav',\n   135\t              fileType: 'wav',\n   136\t            }\n   137\t            console.time('Time to Upload video on S3')\n   138\t            const greetingUploadResponse = await s3.upload(uploadParams)\n   139\t            console.timeEnd('Time to Upload video on S3')\n   140\t\n   141\t            // Create new entry with the s3 path to salutation collection for the user and its profile id\n   142\t            // upsert the salutation\n   143\t            await salutationService.updateOrCreate(\n   144\t              {\n   145\t                firstName: firstName,\n   146\t                salutationVideo: greetingUploadResponse,\n   147\t                userAudioProfileId,\n   148\t              },\n   149\t              userId\n   150\t            )\n   151\t            // update the dynamic recordings for the current dynamic video with salutation url\n   152\t            const salutationToUpdate = await recordingSalutationModel.findOne({\n   153\t              _id: salutationId,\n   154\t              deleted: false,\n   155\t            })\n   156\t\n   157\t            const recordingToUpdate = await recordingModel.findOne({\n   158\t              _id: recordingId,\n   159\t              deleted: false,\n   160\t            })\n   161\t\n   162\t            if (\n   163\t              salutationToUpdate &&\n   164\t              salutationToUpdate.deleted === false &&\n   165\t              recordingToUpdate\n   166\t            ) {\n   167\t              const jobsToInsert = []\n   168\t\n   169\t              await recordingSalutationModel.findOneAndUpdate(\n   170\t                {\n   171\t                  _id: salutationId,\n   172\t                },\n   173\t                {\n   174\t                  $set: {\n   175\t                    salutationVideo: greetingUploadResponse,\n   176\t                  },\n   177\t                }\n   178\t              )\n   179\t\n   180\t              const jobData = {\n   181\t                originalGreeting: recordingToUpdate.masterSalutationVideoUrl,\n   182\t                originalVideo:\n   183\t                  recordingToUpdate.originalVideoUrl ||\n   184\t                  recordingToUpdate.urls[0].url,\n   185\t                cropTimestamp: recordingToUpdate.cropTimestamp,\n   186\t                greetingClips: [greetingUploadResponse],\n   187\t                greetingObjects: [\n   188\t                  {\n   189\t                    greetingId: salutationToUpdate._id,\n   190\t                    firstName: firstName,\n   191\t                    videoUrl: greetingUploadResponse,\n   192\t                  },\n   193\t                ],\n   194\t                requestOrigin: baseUrlForPotionAi,\n   195\t                environment: env,\n   196\t                recordingId: recordingToUpdate._id,\n   197\t                salutation: salutationToUpdate._id,\n   198\t                dynamicVideoType: recordingToUpdate.dynamicVideoType,\n   199\t              }\n   200\t              jobsToInsert.push({\n   201\t                firstName,\n   202\t                recordingId: recordingToUpdate._id,\n   203\t                userId: recordingToUpdate.userId,\n   204\t                salutationId: salutationToUpdate._id,\n   205\t                metadata: jobData,\n   206\t              })\n   207\t\n   208\t              // create the job for the ai to create processing\n   209\t              if (jobsToInsert.length) {\n   210\t                await jobService.insertMany(jobsToInsert)\n   211\t              }\n   212\t            }\n   213\t\n   214\t            fs.unlinkSync(`${outputPath}${generatedFileName}`)\n   215\t            console.log(`[deleted] ${outputPath}${generatedFileName}`)\n   216\t          } else {\n   217\t            Bugsnag.notify(\n   218\t              new Error(\n   219\t                `audio profile training model not found ` + JSON.stringify(job)\n   220\t              )\n   221\t            )\n   222\t\n   223\t            resolve() // to continue working on new jobs\n   224\t          }\n   225\t        } catch (error) {\n   226\t          console.error('Error while synthesizing audio', { error })\n   227\t          Bugsnag.notify(\n   228\t            new Error(`Unable to synthesize audio ` + JSON.stringify(job))\n   229\t          )\n   230\t          Bugsnag.notify(error)\n   231\t          resolve() // to continue working on new jobs\n   232\t        }\n   233\t      } else {\n   234\t        throttleMessageFetching = true\n   235\t      }\n   236\t      resolve()\n   237\t    } catch (error) {\n   238\t      console.error('Error while synthesizing audio', { error })\n   239\t      Bugsnag.notify(error)\n   240\t      resolve() // to continue working on new jobs\n   241\t    } finally {\n   242\t      mongoose.connection.close()\n   243\t    }\n   244\t  })\n   245\t}\n   246\t\n   247\tfunction sleep(ms) {\n   248\t  return new Promise((resolve) => {\n   249\t    setTimeout(resolve, ms)\n   250\t  })\n   251\t}\n   252\tconst init = async () => {\n   253\t  Bugsnag.start({\n   254\t    appVersion: APP_ENV + version,\n   255\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   256\t    releaseStage: process.env.NODE_ENV,\n   257\t  })\n   258\t  try {\n   259\t    while (true) {\n   260\t      await processQueue()\n   261\t      if (throttleMessageFetching) await sleep(2000)\n   262\t    }\n   263\t  } catch (error) {\n   264\t    Bugsnag.notify(error)\n   265\t  }\n   266\t}\n   267\tinit()\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_13","type":"command_execution","command":"/bin/bash -lc 'nl -ba voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js && nl -ba voice-synthsizer-job-handler/salutation/salutation_service.js'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_14","type":"command_execution","command":"/bin/bash -lc 'nl -ba app/services/voice_cloning/voice_cloning_service.js && nl -ba app/services/voice_cloning/voice_cloning_model.js && nl -ba app/services/sqs/sqs_service.js'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_13","type":"command_execution","command":"/bin/bash -lc 'nl -ba voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js && nl -ba voice-synthsizer-job-handler/salutation/salutation_service.js'","aggregated_output":"     1\tconst StringifyUtils = require('../../app/services/utils/logService')\n     2\t\n     3\tconst create = (UserAudioProfileModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new UserAudioProfileModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - USER AUDIO PROFILE SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (UserAudioProfileModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await UserAudioProfileModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (UserAudioProfileModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await UserAudioProfileModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - USER AUDIO PROFILE SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (UserAudioProfileModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await UserAudioProfileModel.find({\n    52\t      ...filter,\n    53\t      deleted: false\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - USER AUDIO PROFILE SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (UserAudioProfileModel) => async (data) => {\n    67\t  console.log('ua data', data)\n    68\t  try {\n    69\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    70\t      { _id: data._id },\n    71\t      data,\n    72\t      {\n    73\t        new: true\n    74\t      }\n    75\t    )\n    76\t    console.log('ua updatedModel', updatedModel)\n    77\t    return updatedModel\n    78\t  } catch (error) {\n    79\t    const details = { data }\n    80\t    console.log(\n    81\t      'ERROR - USER AUDIO PROFILE SERVICE > update',\n    82\t      StringifyUtils.potionErrorObj(error, details)\n    83\t    )\n    84\t    throw error\n    85\t  }\n    86\t}\n    87\t\n    88\tconst remove = (UserAudioProfileModel) => async (filter) => {\n    89\t  try {\n    90\t    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n    91\t      { ...filter },\n    92\t      {\n    93\t        $set: {\n    94\t          deleted: true\n    95\t        }\n    96\t      },\n    97\t      { new: true }\n    98\t    )\n    99\t    return updatedModel\n   100\t  } catch (error) {\n   101\t    const details = { filter }\n   102\t    console.log(\n   103\t      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n   104\t      StringifyUtils.potionErrorObj(error, details)\n   105\t    )\n   106\t    throw error\n   107\t  }\n   108\t}\n   109\t\n   110\tconst removeMany = (UserAudioProfileModel) => async (filter) => {\n   111\t  try {\n   112\t    const updatedModel = await UserAudioProfileModel.updateMany(\n   113\t      { ...filter },\n   114\t      {\n   115\t        $set: {\n   116\t          deleted: true\n   117\t        }\n   118\t      },\n   119\t      { new: true }\n   120\t    )\n   121\t    return updatedModel\n   122\t  } catch (error) {\n   123\t    const details = { filter }\n   124\t    console.log(\n   125\t      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n   126\t      StringifyUtils.potionErrorObj(error, details)\n   127\t    )\n   128\t    throw error\n   129\t  }\n   130\t}\n   131\t\n   132\tmodule.exports = (UserAudioProfileModel) => {\n   133\t  return {\n   134\t    create: create(UserAudioProfileModel),\n   135\t    insertMany: insertMany(UserAudioProfileModel),\n   136\t    read: read(UserAudioProfileModel),\n   137\t    remove: remove(UserAudioProfileModel),\n   138\t    removeMany: removeMany(UserAudioProfileModel),\n   139\t    update: update(UserAudioProfileModel),\n   140\t    find: find(UserAudioProfileModel)\n   141\t  }\n   142\t}\n     1\tconst create = (Salutation) => async (salutationData, userId) => {\r\n     2\t  const newSalutation = new Salutation({ ...salutationData, userId })\r\n     3\t  const savedSalutation = await newSalutation.save()\r\n     4\t  return savedSalutation\r\n     5\t}\r\n     6\t\r\n     7\tconst read = (Salutation) => async (filter) => {\r\n     8\t  const foundSalutation = await Salutation.findOne({\r\n     9\t    ...filter,\r\n    10\t    deleted: false,\r\n    11\t  })\r\n    12\t  return foundSalutation\r\n    13\t}\r\n    14\t\r\n    15\tconst find = (Salutation) => async (filter) => {\r\n    16\t  const foundSalutations = await Salutation.find({\r\n    17\t    ...filter,\r\n    18\t    deleted: false,\r\n    19\t  })\r\n    20\t  return foundSalutations\r\n    21\t}\r\n    22\t\r\n    23\tconst update = (Salutation) => async (salutation, userId) => {\r\n    24\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    25\t    { _id: salutation._id, userId },\r\n    26\t    salutation,\r\n    27\t    { new: true }\r\n    28\t  )\r\n    29\t  return updatedSalutation\r\n    30\t}\r\n    31\t\r\n    32\tconst modify = (Salutation) => async (salutation) => {\r\n    33\t  const findQuery = salutation._id\r\n    34\t    ? { _id: salutation._id }\r\n    35\t    : { transcriptId: salutation.transcriptId }\r\n    36\t\r\n    37\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    38\t    findQuery,\r\n    39\t    salutation,\r\n    40\t    { new: true }\r\n    41\t  )\r\n    42\t  return updatedSalutation\r\n    43\t}\r\n    44\t\r\n    45\tconst updateOrCreate =\r\n    46\t  (Salutation) =>\r\n    47\t  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\n    48\t    const salutation = await read(Salutation)({\r\n    49\t      firstName,\r\n    50\t      userAudioProfileId,\r\n    51\t      userId,\r\n    52\t    })\r\n    53\t    if (salutation) {\r\n    54\t      salutation.salutationVideo = salutationVideo\r\n    55\t      return await update(Salutation)(salutation, userId)\r\n    56\t    } else {\r\n    57\t      return await create(Salutation)(\r\n    58\t        { firstName, salutationVideo, userAudioProfileId },\r\n    59\t        userId\r\n    60\t      )\r\n    61\t    }\r\n    62\t  }\r\n    63\t\r\n    64\tconst remove = (Salutation) => async (filter, userId) => {\r\n    65\t  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    66\t    { ...filter, userId },\r\n    67\t    {\r\n    68\t      $set: {\r\n    69\t        deleted: true,\r\n    70\t      },\r\n    71\t    },\r\n    72\t    { new: true }\r\n    73\t  )\r\n    74\t  return updatedSalutation\r\n    75\t}\r\n    76\t\r\n    77\tmodule.exports = (Salutation) => {\r\n    78\t  return {\r\n    79\t    create: create(Salutation),\r\n    80\t    read: read(Salutation),\r\n    81\t    remove: remove(Salutation),\r\n    82\t    update: update(Salutation),\r\n    83\t    updateOrCreate: updateOrCreate(Salutation),\r\n    84\t    find: find(Salutation),\r\n    85\t    modify: modify(Salutation),\r\n    86\t  }\r\n    87\t}\r\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_14","type":"command_execution","command":"/bin/bash -lc 'nl -ba app/services/voice_cloning/voice_cloning_service.js && nl -ba app/services/voice_cloning/voice_cloning_model.js && nl -ba app/services/sqs/sqs_service.js'","aggregated_output":"     1\tconst StringifyUtils = require('../utils/logService')\n     2\t\n     3\tconst create = (VoiceCloningModel) => async (data) => {\n     4\t  try {\n     5\t    const newModel = new VoiceCloningModel({ ...data })\n     6\t    const savedModel = await newModel.save()\n     7\t    return savedModel\n     8\t  } catch (error) {\n     9\t    const details = { data }\n    10\t    console.log(\n    11\t      'ERROR - VOICE CLONING SERVICE > create',\n    12\t      StringifyUtils.potionErrorObj(error, details)\n    13\t    )\n    14\t    throw error\n    15\t  }\n    16\t}\n    17\t\n    18\tconst insertMany = (VoiceCloningModel) => async (data) => {\n    19\t  try {\n    20\t    const inserted = await VoiceCloningModel.insertMany(data)\n    21\t    return inserted\n    22\t  } catch (error) {\n    23\t    const details = { data }\n    24\t    console.log(\n    25\t      'ERROR - VOICE CLONING SERVICE > insertMany',\n    26\t      StringifyUtils.potionErrorObj(error, details)\n    27\t    )\n    28\t    throw error\n    29\t  }\n    30\t}\n    31\t\n    32\tconst read = (VoiceCloningModel) => async (filter) => {\n    33\t  try {\n    34\t    const foundModel = await VoiceCloningModel.findOne({\n    35\t      ...filter,\n    36\t      deleted: false,\n    37\t    })\n    38\t    return foundModel\n    39\t  } catch (error) {\n    40\t    const details = { filter }\n    41\t    console.log(\n    42\t      'ERROR - VOICE CLONING SERVICE > read',\n    43\t      StringifyUtils.potionErrorObj(error, details)\n    44\t    )\n    45\t    throw error\n    46\t  }\n    47\t}\n    48\t\n    49\tconst find = (VoiceCloningModel) => async (filter) => {\n    50\t  try {\n    51\t    const foundModels = await VoiceCloningModel.find({\n    52\t      ...filter,\n    53\t      deleted: false,\n    54\t    })\n    55\t    return foundModels\n    56\t  } catch (error) {\n    57\t    const details = { filter }\n    58\t    console.log(\n    59\t      'ERROR - VOICE CLONING SERVICE > find',\n    60\t      StringifyUtils.potionErrorObj(error, details)\n    61\t    )\n    62\t    throw error\n    63\t  }\n    64\t}\n    65\t\n    66\tconst update = (VoiceCloningModel) => async (data) => {\n    67\t  try {\n    68\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    69\t      { _id: data._id },\n    70\t      data,\n    71\t      {\n    72\t        new: true,\n    73\t      }\n    74\t    )\n    75\t    return updatedModel\n    76\t  } catch (error) {\n    77\t    const details = { data }\n    78\t    console.log(\n    79\t      'ERROR - VOICE CLONING SERVICE > update',\n    80\t      StringifyUtils.potionErrorObj(error, details)\n    81\t    )\n    82\t    throw error\n    83\t  }\n    84\t}\n    85\t\n    86\tconst remove = (VoiceCloningModel) => async (filter) => {\n    87\t  try {\n    88\t    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n    89\t      { ...filter },\n    90\t      {\n    91\t        $set: {\n    92\t          deleted: true,\n    93\t        },\n    94\t      },\n    95\t      { new: true }\n    96\t    )\n    97\t    return updatedModel\n    98\t  } catch (error) {\n    99\t    const details = { filter }\n   100\t    console.log(\n   101\t      'ERROR - VOICE CLONING SERVICE > remove',\n   102\t      StringifyUtils.potionErrorObj(error, details)\n   103\t    )\n   104\t    throw error\n   105\t  }\n   106\t}\n   107\t\n   108\tconst removeMany = (VoiceCloningModel) => async (filter) => {\n   109\t  try {\n   110\t    const updatedModel = await VoiceCloningModel.updateMany(\n   111\t      { ...filter },\n   112\t      {\n   113\t        $set: {\n   114\t          deleted: true,\n   115\t        },\n   116\t      },\n   117\t      { new: true }\n   118\t    )\n   119\t    return updatedModel\n   120\t  } catch (error) {\n   121\t    const details = { filter }\n   122\t    console.log(\n   123\t      'ERROR - VOICE CLONING SERVICE > removeMany',\n   124\t      StringifyUtils.potionErrorObj(error, details)\n   125\t    )\n   126\t    throw error\n   127\t  }\n   128\t}\n   129\t\n   130\tmodule.exports = (VoiceCloningModel) => {\n   131\t  return {\n   132\t    create: create(VoiceCloningModel),\n   133\t    insertMany: insertMany(VoiceCloningModel),\n   134\t    read: read(VoiceCloningModel),\n   135\t    remove: remove(VoiceCloningModel),\n   136\t    removeMany: removeMany(VoiceCloningModel),\n   137\t    update: update(VoiceCloningModel),\n   138\t    find: find(VoiceCloningModel),\n   139\t  }\n   140\t}\n     1\tconst mongoose = require('mongoose')\n     2\tconst Schema = mongoose.Schema\n     3\t\n     4\tconst VoiceCloningSchema = Schema(\n     5\t  {\n     6\t    userId: {\n     7\t      type: Schema.Types.ObjectId,\n     8\t      ref: 'User',\n     9\t      required: true,\n    10\t    },\n    11\t    userAudioProfileId: {\n    12\t      type: Schema.Types.ObjectId,\n    13\t      ref: 'UserAudioProfile',\n    14\t      required: true,\n    15\t    },\n    16\t    status: {\n    17\t      type: String,\n    18\t      required: false,\n    19\t      default: 'created',\n    20\t    },\n    21\t    input: {\n    22\t      type: Schema.Types.Mixed,\n    23\t      default: null,\n    24\t    },\n    25\t    training_model: {\n    26\t      type: Schema.Types.Mixed,\n    27\t      default: null,\n    28\t    },\n    29\t    metadata: {\n    30\t      type: Schema.Types.Mixed,\n    31\t      default: null,\n    32\t    },\n    33\t    deleted: {\n    34\t      type: Boolean,\n    35\t      required: true,\n    36\t      default: false,\n    37\t    },\n    38\t  },\n    39\t  {\n    40\t    timestamps: true,\n    41\t  }\n    42\t)\n    43\t\n    44\tmodule.exports = mongoose.model('VoiceCloning', VoiceCloningSchema)\n     1\tconst AWS = require('aws-sdk')\n     2\t\n     3\tconst sqs = new AWS.SQS({ apiVersion: '2012-11-05' })\n     4\t\n     5\tconst StringifyUtils = require('../utils/logService')\n     6\t\n     7\tconst fetchMessageFromSQS = (sqsQueueUrl, waitTimeInSeconds = 0) => {\n     8\t  return new Promise((resolve, reject) => {\n     9\t    const params = {\n    10\t      WaitTimeSeconds: waitTimeInSeconds,\n    11\t      QueueUrl: sqsQueueUrl /* required */,\n    12\t    }\n    13\t    sqs.receiveMessage(params, function (err, data) {\n    14\t      if (err) {\n    15\t        reject(err)\n    16\t        console.log(\n    17\t          `ERROR in fetchJobFromSQS : `,\n    18\t          StringifyUtils.stringifyError(err)\n    19\t        )\n    20\t      } else {\n    21\t        resolve(data)\n    22\t      }\n    23\t    })\n    24\t  })\n    25\t}\n    26\t\n    27\tconst deleteMessageFromSQS = (sqsQueueUrl, receiptHandle) => {\n    28\t  return new Promise((resolve, reject) => {\n    29\t    const params = {\n    30\t      ReceiptHandle: receiptHandle,\n    31\t      QueueUrl: sqsQueueUrl /* required */,\n    32\t    }\n    33\t    sqs.deleteMessage(params, function (err, data) {\n    34\t      if (err) {\n    35\t        reject(err)\n    36\t        console.log(\n    37\t          `ERROR in sending delete request to AWS.SQS : `,\n    38\t          StringifyUtils.stringifyError(err)\n    39\t        )\n    40\t      } else {\n    41\t        console.log(\n    42\t          'Successfully sent delete request to AWS.SQS',\n    43\t          StringifyUtils.stringifyError(data)\n    44\t        )\n    45\t        resolve(data)\n    46\t      }\n    47\t    })\n    48\t  })\n    49\t}\n    50\t\n    51\tconst sendMessageToSQS = (sqsQueueUrl, message) => {\n    52\t  return new Promise((resolve, reject) => {\n    53\t    const params = {\n    54\t      MessageBody: message,\n    55\t      QueueUrl: sqsQueueUrl /* required */,\n    56\t      // MessageGroupId:\n    57\t      //   process.env.POTION_APP_ENV ||\n    58\t      //   '' + `_` + uuidV4() + '_' + new Date().toISOString(),\n    59\t      // MessageDeduplicationId: uuidV4() + `_` + new Date().toISOString()\n    60\t    }\n    61\t    sqs.sendMessage(params, function (err, data) {\n    62\t      if (err) {\n    63\t        reject(err)\n    64\t        console.log(\n    65\t          `ERROR in seding request to AWS.SQS : `,\n    66\t          StringifyUtils.stringifyError(err)\n    67\t        )\n    68\t      } else {\n    69\t        console.log(\n    70\t          'Successfully sent request to AWS.SQS',\n    71\t          StringifyUtils.stringifyError(data)\n    72\t        )\n    73\t        resolve(data.Location)\n    74\t      }\n    75\t    })\n    76\t  })\n    77\t}\n    78\t\n    79\tmodule.exports = {\n    80\t  fetchMessageFromSQS,\n    81\t  deleteMessageFromSQS,\n    82\t  sendMessageToSQS,\n    83\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_15","type":"command_execution","command":"/bin/bash -lc \"find . -maxdepth 3 -type f \\\\( -iname '*test*' -o -iname '*spec*' -o -name 'package-lock.json' -o -name 'yarn.lock' \\\\) -print\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_15","type":"command_execution","command":"/bin/bash -lc \"find . -maxdepth 3 -type f \\\\( -iname '*test*' -o -iname '*spec*' -o -name 'package-lock.json' -o -name 'yarn.lock' \\\\) -print\"","aggregated_output":"./package-lock.json\n./node_modules/proxy-from-env/test.js\n./node_modules/isarray/test.js\n./node_modules/iserror/test.js\n./node_modules/memory-pager/test.js\n./node_modules/sparse-bitfield/test.js\n./node_modules/module-details-from-path/test.js\n./node_modules/git-node-fs/test.js\n./node_modules/safer-buffer/tests.js\n./node_modules/pump/test-browser.js\n./node_modules/pump/test-node.js\n./node_modules/stackframe/stackframe-tests.ts\n./node_modules/aws-sdk/buildspec.yml\n./node_modules/url/test.js\n./voice-cloning/assets/wgnd_2_0_unique_names_only_limited_special_chars.csv\n./voice-synthsizer-job-handler/package-lock.json\n./voice-synthsizer-job-handler/yarn.lock\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_16","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"sendMessageToSQS|MessageBody|JSON.stringify\\\\(.*job|SQS_URL\\\" . -g '\"'!node_modules/**'\"' -g '\"'!voice-cloning/**'\"'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_16","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"sendMessageToSQS|MessageBody|JSON.stringify\\\\(.*job|SQS_URL\\\" . -g '\"'!node_modules/**'\"' -g '\"'!voice-cloning/**'\"'\"","aggregated_output":"./voice-synthsizer-job-handler/pm2-development.yml:10:      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-synthesizer-ai-staging.fifo'\n./voice-synthsizer-job-handler/index.js:16:const sqsQueueUrl = process.env.SQS_URL\n./voice-synthsizer-job-handler/index.js:219:                `audio profile training model not found ` + JSON.stringify(job)\n./voice-synthsizer-job-handler/index.js:228:            new Error(`Unable to synthesize audio ` + JSON.stringify(job))\n./voice-synthsizer-job-handler/pm2-production.yml:10:      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-synthesizer-ai-production.fifo'\n./voice-cloning-job-handler/pm2-development.yml:11:      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-clone-ai-staging.fifo'\n./voice-cloning-job-handler/index.js:15:const sqsQueueUrl = process.env.SQS_URL\n./voice-cloning-job-handler/index.js:282:              `Unable to train for voice cloning videos ` + JSON.stringify(job)\n./app/services/sqs/sqs_service.js:51:const sendMessageToSQS = (sqsQueueUrl, message) => {\n./app/services/sqs/sqs_service.js:54:      MessageBody: message,\n./app/services/sqs/sqs_service.js:82:  sendMessageToSQS,\n./voice-cloning-job-handler/pm2-production.yml:11:      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-clone-ai-production.fifo'\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_17","type":"command_execution","command":"/bin/bash -lc 'git status --porcelain=v1 && git branch --show-current && git remote -v'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_18","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,140p' voice-synthsizer-job-handler/recording/recording_model.js && sed -n '1,100p' voice-cloning-job-handler/pm2-development.yml && sed -n '1,100p' voice-synthsizer-job-handler/pm2-development.yml\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_17","type":"command_execution","command":"/bin/bash -lc 'git status --porcelain=v1 && git branch --show-current && git remote -v'","aggregated_output":"master\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_18","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,140p' voice-synthsizer-job-handler/recording/recording_model.js && sed -n '1,100p' voice-cloning-job-handler/pm2-development.yml && sed -n '1,100p' voice-synthsizer-job-handler/pm2-development.yml\"","aggregated_output":"const mongoose = require('mongoose')\nconst Schema = mongoose.Schema\nconst RecordingSchema = Schema(\n  {\n    userId: {\n      type: Schema.Types.ObjectId,\n      ref: 'User',\n      required: true,\n    },\n    urls: [\n      new mongoose.Schema(\n        {\n          quality: {\n            type: String,\n            required: false,\n            default: '',\n          },\n          url: {\n            type: String,\n            required: false,\n            default: '',\n          },\n        },\n        { _id: false }\n      ),\n    ],\n    faceVideoUrl: {\n      type: String,\n      required: false,\n      default: '',\n    },\n    title: {\n      type: String,\n      required: false,\n      default: '',\n    },\n    type: {\n      type: String,\n      required: false,\n      default: 'video/webm',\n    },\n    duration: {\n      type: String,\n      required: false,\n      default: '',\n    },\n    screenRecording: {\n      type: Boolean,\n      required: false,\n      default: false,\n    },\n    uploadedRecording: {\n      type: Boolean,\n      required: false,\n      default: false,\n    },\n    ctaClickCount: {\n      type: Number,\n      default: 0,\n    },\n    previewThumbnails: [\n      new mongoose.Schema(\n        {\n          size: {\n            type: String,\n            required: false,\n            default: '',\n          },\n          url: {\n            type: String,\n            required: false,\n            default: '',\n          },\n        },\n        { _id: false }\n      ),\n    ],\n    previewGifs: [\n      new mongoose.Schema(\n        {\n          size: {\n            type: String,\n            required: false,\n            default: '',\n          },\n          url: {\n            type: String,\n            required: false,\n            default: '',\n          },\n        },\n        { _id: false }\n      ),\n    ],\n    previewGifsVersion: {\n      type: Number,\n      required: false,\n      default: 0,\n    },\n    videoInitialGifUrl: {\n      type: String,\n      require: false,\n    },\n    unfirlGifUrl: {\n      type: String,\n      require: false,\n    },\n    deleted: {\n      type: Boolean,\n      required: true,\n      default: '0',\n    },\n    subtitles: [\n      new mongoose.Schema({\n        kind: {\n          type: String,\n          required: true,\n          default: 'subtitles',\n        },\n        label: {\n          type: String,\n          required: true,\n          default: 'English',\n        },\n        srclang: {\n          type: String,\n          required: true,\n          default: 'en',\n        },\n        url: {\n          type: String,\n          required: false,\n          default: '',\n        },\n        transcriptId: {\n          type: String,\n          required: false,\n          default: '',\n        },\n        transcriptionPending: {\napps:\n  - name: training-model\n    script: index.js\n    watch: false\n    autorestart: true\n    instances: 1\n    time: true\n    env:\n      NODE_ENV: 'staging'\n      POTION_APP_ENV: 'staging'\n      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-clone-ai-staging.fifo'\n      BUGSNAG_BACKEND_KEY: '[REDACTED_generic-api-key]'\n      MONGODB_URI_DEV: 'mongodb+srv://[REDACTED_MONGO_USER_deve]:scrubbed_1@example.com7.mongodb.net/potion_development?retryWrites=true&w=majority'\n      MONGODB_URI_STAGING: 'mongodb+srv://[REDACTED_MONGO_USER_stag]:scrubbed_2@example.com7.mongodb.net/potion_staging?retryWrites=true&w=majority'\n      MONGODB_URI_PROD: ''\n      CLOUDFRONT_URL_PROD: 'https://videoassets.sendpotion.com'\n      CLOUDFRONT_URL_STAGING: ''\n      CLOUDFRONT_URL_DEV: 'https://d2rmbzmoml90gd.cloudfront.net'\napps:\n  - name: synthsizer-job\n    script: index.js\n    watch: false\n    autorestart: true\n    instances: 1\n    time: true\n    env:\n      NODE_ENV: 'production'\n      SQS_URL: 'https://sqs.us-west-2.amazonaws.com/[REDACTED_AWS_ACCOUNT_1961]/potion-voice-synthesizer-ai-staging.fifo'\n      APP_ENV: 'development'\n      BUGSNAG_BACKEND_KEY: '[REDACTED_generic-api-key]'\n      MONGODB_URI_DEV: 'mongodb+srv://[REDACTED_MONGO_USER_deve]:scrubbed_1@example.com7.mongodb.net/potion_development?retryWrites=true&w=majority'\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_19","type":"command_execution","command":"/bin/bash -lc 'node --version && npm --version && git log -5 --oneline --decorate'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_19","type":"command_execution","command":"/bin/bash -lc 'node --version && npm --version && git log -5 --oneline --decorate'","aggregated_output":"v14.21.3\n6.14.18\ned59a7a (HEAD -> master) initial\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_20","type":"agent_message","text":"I’m applying defense in depth at two layers: handlers will validate `userId` and authorize every referenced record before expensive work, while the worker-local service methods will require an explicit tenant scope so a future caller cannot accidentally fall back to `_id`-only access. Rejected messages will be acknowledged and contained as job-level failures."}}
{"type":"item.started","item":{"id":"item_21","type":"file_change","changes":[{"path":"/workspace/app/services/utils/jobValidation.js","kind":"add"},{"path":"/workspace/app/services/utils/tenantScope.js","kind":"add"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_21","type":"file_change","changes":[{"path":"/workspace/app/services/utils/jobValidation.js","kind":"add"},{"path":"/workspace/app/services/utils/tenantScope.js","kind":"add"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_22","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,200p' app/services/utils/tenantScope.js && sed -n '1,220p' app/services/utils/jobValidation.js && git status --short\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_22","type":"command_execution","command":"/bin/bash -lc \"sed -n '1,200p' app/services/utils/tenantScope.js && sed -n '1,220p' app/services/utils/jobValidation.js && git status --short\"","aggregated_output":"const requireUserId = (userId) => {\n  if (userId === undefined || userId === null || userId === '') {\n    throw new TypeError('userId is required for tenant-scoped database access')\n  }\n\n  return userId\n}\n\nconst scopeToUser = (filter, userId) => ({\n  ...filter,\n  userId: requireUserId(userId),\n})\n\nconst assignToUser = (data, userId) => ({\n  ...data,\n  userId: requireUserId(userId),\n})\n\nmodule.exports = {\n  assignToUser,\n  requireUserId,\n  scopeToUser,\n}\nconst mongoose = require('mongoose')\n\nclass RejectedJobError extends Error {\n  constructor(message) {\n    super(message)\n    this.name = 'RejectedJobError'\n  }\n}\n\nconst parseJobMessage = (body) => {\n  try {\n    return JSON.parse(body)\n  } catch (error) {\n    throw new RejectedJobError('Queue message body is not valid JSON')\n  }\n}\n\nconst requireJobObject = (value, fieldName) => {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) {\n    throw new RejectedJobError(`${fieldName} is required`)\n  }\n\n  return value\n}\n\nconst requireJobObjectId = (value, fieldName) => {\n  if (!mongoose.isValidObjectId(value)) {\n    throw new RejectedJobError(`${fieldName} must be a valid ObjectId`)\n  }\n\n  return value\n}\n\nconst requireJobString = (value, fieldName) => {\n  if (typeof value !== 'string' || value.trim() === '') {\n    throw new RejectedJobError(`${fieldName} is required`)\n  }\n\n  return value\n}\n\nmodule.exports = {\n  RejectedJobError,\n  parseJobMessage,\n  requireJobObject,\n  requireJobObjectId,\n  requireJobString,\n}\n?? app/services/utils/jobValidation.js\n?? app/services/utils/tenantScope.js\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_23","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_23","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_24","type":"file_change","changes":[{"path":"/workspace/voice-synthsizer-job-handler/job/job_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/salutation/salutation_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_24","type":"file_change","changes":[{"path":"/workspace/voice-synthsizer-job-handler/job/job_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/salutation/salutation_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_25","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_25","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_26","type":"file_change","changes":[{"path":"/workspace/voice-synthsizer-job-handler/index.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_26","type":"file_change","changes":[{"path":"/workspace/voice-synthsizer-job-handler/index.js","kind":"update"}],"status":"completed"}}
{"type":"item.completed","item":{"id":"item_27","type":"agent_message","text":"Both execution paths now authorize all referenced documents before doing filesystem, model, or S3 work. I’ve also moved malformed-message handling inside the per-poll boundary and made connection retries terminate cleanly; next I’m checking every Mongo call and exercising the tenant-scoping helpers with mocked models."}}
{"type":"item.started","item":{"id":"item_28","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(findOne|find|findOneAndUpdate|updateMany|insertMany|save)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_28","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(findOne|find|findOneAndUpdate|updateMany|insertMany|save)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js:8:  const savedSalutation = await newSalutation.save()\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:13:  const foundSalutation = await Salutation.findOne({\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:21:  const foundSalutations = await Salutation.find({\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:30:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:47:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:82:  const updatedSalutation = await Salutation.findOneAndUpdate(\r\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:10:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:24:    const inserted = await VoiceCloningModel.insertMany(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:40:    const foundModel = await VoiceCloningModel.findOne({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:57:    const foundModels = await VoiceCloningModel.find({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:75:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:99:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:124:    const updatedModel = await VoiceCloningModel.updateMany(\nvoice-synthsizer-job-handler/index.js:107:        recordingSalutationModel.findOne({\nvoice-synthsizer-job-handler/index.js:112:        recordingModel.findOne({\nvoice-synthsizer-job-handler/index.js:183:      await recordingSalutationModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/index.js:223:    await jobService.insertMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:10:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:24:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:40:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:57:    const foundModels = await UserAudioProfileModel.find({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:75:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:98:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:123:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-synthsizer-job-handler/job/job_service.js:10:    const savedJob = await newJob.save()\nvoice-synthsizer-job-handler/job/job_service.js:24:    const inserted = await Job.insertMany(\nvoice-synthsizer-job-handler/job/job_service.js:40:    const foundJob = await Job.findOne({\nvoice-synthsizer-job-handler/job/job_service.js:57:    const foundJobs = await Job.find({\nvoice-synthsizer-job-handler/job/job_service.js:75:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:98:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:123:    const updatedJob = await Job.updateMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:10:    const savedModel = await newModel.save()\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:24:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:40:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:57:    const foundModels = await UserAudioProfileModel.find({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:75:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:98:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:123:    const updatedModel = await UserAudioProfileModel.updateMany(\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_29","type":"command_execution","command":"/bin/bash -lc 'git diff --check && git diff --stat && git status --short'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_30","type":"command_execution","command":"/bin/bash -lc \"git diff -- voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js | sed -n '1,520p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_29","type":"command_execution","command":"/bin/bash -lc 'git diff --check && git diff --stat && git status --short'","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js:1: trailing whitespace.\n+const {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:2: trailing whitespace.\n+  assignToUser,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:3: trailing whitespace.\n+  scopeToUser,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:4: trailing whitespace.\n+} = require('../../app/services/utils/tenantScope')\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:5: trailing whitespace.\n+\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:7: trailing whitespace.\n+  const newSalutation = new Salutation(assignToUser(salutationData, userId))\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:12: trailing whitespace.\n+const read = (Salutation) => async (filter, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:14: trailing whitespace.\n+    ...scopeToUser(filter, userId),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:20: trailing whitespace.\n+const find = (Salutation) => async (filter, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:22: trailing whitespace.\n+    ...scopeToUser(filter, userId),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:29: trailing whitespace.\n+  const { _id, userId: ignoredUserId, ...updates } = salutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:31: trailing whitespace.\n+    {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:32: trailing whitespace.\n+      ...scopeToUser({ _id }, userId),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:33: trailing whitespace.\n+      deleted: false,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:34: trailing whitespace.\n+    },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:35: trailing whitespace.\n+    updates,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:41: trailing whitespace.\n+const modify = (Salutation) => async (salutation, userId) => {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:45: trailing whitespace.\n+  const { _id, userId: ignoredUserId, ...updates } = salutation\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:48: trailing whitespace.\n+    {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:49: trailing whitespace.\n+      ...scopeToUser(findQuery, userId),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:50: trailing whitespace.\n+      deleted: false,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:51: trailing whitespace.\n+    },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:52: trailing whitespace.\n+    updates,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:61: trailing whitespace.\n+    const salutation = await read(Salutation)(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:62: trailing whitespace.\n+      {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:63: trailing whitespace.\n+        firstName,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:64: trailing whitespace.\n+        userAudioProfileId,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:65: trailing whitespace.\n+      },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:66: trailing whitespace.\n+      userId\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:67: trailing whitespace.\n+    )\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:69: trailing whitespace.\n+      return await update(Salutation)(\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:70: trailing whitespace.\n+        { _id: salutation._id, salutationVideo },\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:71: trailing whitespace.\n+        userId\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:72: trailing whitespace.\n+      )\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:83: trailing whitespace.\n+    {\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:84: trailing whitespace.\n+      ...scopeToUser(filter, userId),\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:85: trailing whitespace.\n+      deleted: false,\r\nvoice-synthsizer-job-handler/salutation/salutation_service.js:86: trailing whitespace.\n+    },\r\n","exit_code":2,"status":"failed"}}
{"type":"item.completed","item":{"id":"item_30","type":"command_execution","command":"/bin/bash -lc \"git diff -- voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js | sed -n '1,520p'\"","aggregated_output":"diff --git a/voice-cloning-job-handler/index.js b/voice-cloning-job-handler/index.js\nindex 0995e23..c4a850d 100644\n--- a/voice-cloning-job-handler/index.js\n+++ b/voice-cloning-job-handler/index.js\n@@ -10,6 +10,13 @@ const sqs = require('../app/services/sqs')\n const s3 = require('../app/services/s3')\n const voiceCloningService = require('./voice_cloning')\n const userAudioProfileService = require('./user_audio_profile')\n+const {\n+  RejectedJobError,\n+  parseJobMessage,\n+  requireJobObject,\n+  requireJobObjectId,\n+  requireJobString,\n+} = require('../app/services/utils/jobValidation')\n \n AWS.config.update({ region: 'us-west-2' })\n const sqsQueueUrl = process.env.SQS_URL\n@@ -28,24 +35,21 @@ const updateUrl = (str, cloudFrontUrl) => {\n   return str.replace(`https://${host}`, cloudFrontUrl)\n }\n \n-function connectDB(dbUri, retryCount = 0) {\n-  return new Promise((resolve, reject) => {\n-    console.log('Connection Attempt : ', retryCount)\n-    mongoose.set('strictQuery', true)\n-    mongoose\n-      .connect(dbUri)\n-      .then((msg) => {\n-        console.log('Connected to Mongo DB !')\n-        resolve()\n-      })\n-      .catch((err) => {\n-        console.log('Failed to connect dns mongo: ', err)\n-        if (retryCount < 6) {\n-          retryCount++\n-          connectDB(dbUri, retryCount)\n-        }\n-      })\n-  })\n+async function connectDB(dbUri, retryCount = 0) {\n+  console.log('Connection Attempt : ', retryCount)\n+  mongoose.set('strictQuery', true)\n+\n+  try {\n+    await mongoose.connect(dbUri)\n+    console.log('Connected to Mongo DB !')\n+  } catch (error) {\n+    console.log('Failed to connect dns mongo: ', error)\n+    if (retryCount < 6) {\n+      return connectDB(dbUri, retryCount + 1)\n+    }\n+\n+    throw error\n+  }\n }\n \n function execShellCommand(cmd, logPath) {\n@@ -86,225 +90,260 @@ function pad(s) {\n   return s\n }\n \n-const processQueue = () => {\n-  /* eslint-disable no-async-promise-executor */\n-  return new Promise(async (resolve, reject) => {\n-    try {\n-      const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n-\n-      if (\n-        typeof response.Messages !== 'undefined' &&\n-        response.Messages.length > 0\n-      ) {\n-        throttleMessageFetching = false\n-        const job = JSON.parse(response.Messages[0].Body)\n-        const receiptHandle = response.Messages[0].ReceiptHandle\n-        console.log('job===', job)\n-\n-        const { metadata, input, _id, userAudioProfileId } = job._doc\n-        console.log('userAudioProfileId', userAudioProfileId)\n-        console.log('_id', _id)\n-        const { env } = job\n-        console.log('env', env)\n-\n-        console.log('metadata------', metadata)\n-        console.log('input', input)\n-        const DB_URI =\n-          env === 'production'\n-            ? mongoUriProd\n-            : env === 'staging'\n-            ? mongoUriStaging\n-            : mongoUriDev\n-\n-        console.log('DB_URI ', DB_URI)\n-        await connectDB(DB_URI)\n-\n-        const cloudFrontUrl =\n-          env === 'production'\n-            ? cloudFrontUrlProd\n-            : env === 'staging'\n-            ? cloudFrontUrlStaging\n-            : cloudFrontUrlDev\n-\n-        try {\n-          await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n-\n-          const { directoryName } = metadata\n-          console.log('directoryName', directoryName)\n-          const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n-          if (!fs.existsSync(logPath)) {\n-            fs.mkdirSync(logPath, { recursive: true })\n-          }\n-          // update the db model to processing\n-          await voiceCloningService.update({ _id, status: 'processing' })\n-          await userAudioProfileService.update({\n-            _id: userAudioProfileId,\n-            status: 'processing',\n-          })\n-\n-          // create directory for userid-useraudioprofileid if not exist\n-          const rootPath = `/tmp/${directoryName}`\n-          const wavePath = `${rootPath}/wav48/1`\n-          if (!fs.existsSync(wavePath)) {\n-            fs.mkdirSync(wavePath, { recursive: true })\n-          }\n-\n-          const txtPath = `${rootPath}/txt/1`\n-          if (!fs.existsSync(txtPath)) {\n-            fs.mkdirSync(txtPath, { recursive: true })\n-          }\n-          // download the training data files and put it in respective directories\n-          for (let index = 0; index < input.length; index++) {\n-            const item = input[index]\n-\n-            const { waveUrl, originalText } = item\n-            // download wave file\n-            const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`\n-\n-            await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\n-\n-            const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`\n-            await fs.promises.writeFile(txtFilePath, originalText)\n-          }\n-\n-          const zipFileName = directoryName + '.tgz'\n-\n-          // /tmp/directoryName.tgz\n-\n-          await execShellCommand(\n-            `cd /tmp && tar czvf ${zipFileName}  ${directoryName}`,\n-            logPath\n-          )\n-          console.log('ZIP created ', zipFileName)\n-\n-          // re-sample audio\n-          const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`\n-          console.time(SAMPLING_LABEL)\n-\n-          const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n-\n-          const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\n-          console.log('samplingCommand ', samplingCommand)\n-          const samplingResponse = await execShellCommand(\n-            samplingCommand,\n-            logPath\n-          )\n-          console.timeEnd(SAMPLING_LABEL)\n-\n-          // /mnt/efs/potion-voice/${env}/speakrs.pth\n-          // /mnt/efs/potion-voice/${env}/txt\n-          // /mnt/efs/potion-voice/${env}/${directoryName}/wav\n-\n-          const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`\n-\n-          const resultsPath = outPath + '/results'\n-\n-          //update pth file for cloning\n-          // clone the voice\n-          const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\n-          console.time(VOICE_CLONING_LABEL)\n-          const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\n-            outPath + '/speakers.pth'\n-          } --output_path ${resultsPath}`\n-\n-          console.log('Training Model Command', trainingModelCommand)\n-          const trainingResponse = await execShellCommand(\n-            trainingModelCommand,\n-            logPath\n-          )\n-\n-          console.timeEnd(VOICE_CLONING_LABEL)\n-\n-          let generatedDirectoryName = ''\n-          fs.readdirSync(`${resultsPath}/`).forEach((file) => {\n-            if (file.includes('vits_potion_clone'))\n-              // use output from above to get right path and directory name\n-              generatedDirectoryName = file\n-          })\n-\n-          // minimize cloning model\n-          const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`\n-          console.time(VOICE_MINIMIZE_LABEL)\n-          const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\n-            resultsPath + '/' + generatedDirectoryName + '/'\n-          } --voice_model_name checkpoint_365200.pth`\n-\n-          console.log(\n-            'Minimize Cloning Model Command',\n-            minimizeCloningModelCommand\n-          )\n-          const minimizeCloning = await execShellCommand(\n-            minimizeCloningModelCommand,\n-            logPath\n-          )\n-          console.timeEnd(VOICE_MINIMIZE_LABEL)\n-\n-          // Add the  code to update location of generated model and status into DB\n-          await voiceCloningService.update({ _id, status: 'completed' })\n-\n-          const training_model_path = {\n-            voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,\n-            voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,\n-            voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\n-            voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,\n-            voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,\n-          }\n-\n-          await userAudioProfileService.update({\n-            _id: userAudioProfileId,\n-            status: 'completed',\n-            training_model_path,\n-          })\n-\n-          // add code to put that model into S3\n-          let keys = Object.keys(training_model_path)\n-\n-          const training_model_s3_path = {}\n-\n-          for (let index = 0; index < keys.length; index++) {\n-            const path = training_model_path[keys[index]]\n-            const s3Path = await s3.upload({\n-              filePath: path,\n-              fileName: `${directoryName}/${path.split('/').pop()}`,\n-              bucket: `potion-voice-users-training-model/${env}`,\n-            })\n-            training_model_s3_path[keys[index]] = s3Path\n-          }\n-          //  add S3 path to user audio profile model\n-          await userAudioProfileService.update({\n-            _id: userAudioProfileId,\n-            training_model_s3_path,\n-          })\n-        } catch (error) {\n-          console.log('error********************', error)\n-          Bugsnag.notify(\n-            new Error(\n-              `Unable to train for voice cloning videos ` + JSON.stringify(job)\n-            )\n-          )\n-          Bugsnag.notify(error)\n-\n-          // update the db to set status as error\n-          await voiceCloningService.update({ _id, status: 'error' })\n-          await userAudioProfileService.update({\n-            _id: userAudioProfileId,\n-            status: 'error',\n-          })\n-\n-          resolve() // to continue working on new jobs\n-        }\n-      } else {\n-        throttleMessageFetching = true\n-      }\n-      resolve()\n-    } catch (error) {\n+const processQueue = async () => {\n+  let authorized = false\n+  let userId\n+  let voiceCloningId\n+  let userAudioProfileId\n+\n+  try {\n+    const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n+\n+    if (!response.Messages || response.Messages.length === 0) {\n+      throttleMessageFetching = true\n+      return\n+    }\n+\n+    throttleMessageFetching = false\n+    const message = response.Messages[0]\n+\n+    // Acknowledge before parsing so malformed or rejected jobs cannot poison the\n+    // polling loop. This preserves the worker's existing at-most-once behavior.\n+    await sqs.deleteMessageFromSQS(sqsQueueUrl, message.ReceiptHandle)\n+    const job = parseJobMessage(message.Body)\n+    const jobDocument = requireJobObject(job._doc, 'job._doc')\n+\n+    userId = requireJobObjectId(jobDocument.userId, 'userId')\n+    voiceCloningId = requireJobObjectId(jobDocument._id, '_id')\n+    userAudioProfileId = requireJobObjectId(\n+      jobDocument.userAudioProfileId,\n+      'userAudioProfileId'\n+    )\n+    const env = requireJobString(job.env, 'env')\n+    const DB_URI =\n+      env === 'production'\n+        ? mongoUriProd\n+        : env === 'staging'\n+        ? mongoUriStaging\n+        : mongoUriDev\n+\n+    await connectDB(DB_URI)\n+\n+    const [voiceCloning, userAudioProfile] = await Promise.all([\n+      voiceCloningService.read(\n+        { _id: voiceCloningId, userAudioProfileId },\n+        userId\n+      ),\n+      userAudioProfileService.read({ _id: userAudioProfileId }, userId),\n+    ])\n+\n+    if (!voiceCloning || !userAudioProfile) {\n+      throw new RejectedJobError(\n+        'Voice cloning job records were not found for the supplied userId'\n+      )\n+    }\n+\n+    authorized = true\n+    const metadata = requireJobObject(voiceCloning.metadata, 'metadata')\n+    const directoryName = requireJobString(\n+      metadata.directoryName,\n+      'metadata.directoryName'\n+    )\n+    const input = voiceCloning.input\n+    if (!Array.isArray(input)) {\n+      throw new RejectedJobError('input must be an array')\n+    }\n+\n+    const cloudFrontUrl =\n+      env === 'production'\n+        ? cloudFrontUrlProd\n+        : env === 'staging'\n+        ? cloudFrontUrlStaging\n+        : cloudFrontUrlDev\n+\n+    const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n+    if (!fs.existsSync(logPath)) {\n+      fs.mkdirSync(logPath, { recursive: true })\n+    }\n+\n+    const [processingJob, processingProfile] = await Promise.all([\n+      voiceCloningService.update(\n+        { _id: voiceCloningId, status: 'processing' },\n+        userId\n+      ),\n+      userAudioProfileService.update(\n+        { _id: userAudioProfileId, status: 'processing' },\n+        userId\n+      ),\n+    ])\n+    if (!processingJob || !processingProfile) {\n+      throw new RejectedJobError(\n+        'Voice cloning job records changed before processing'\n+      )\n+    }\n+\n+    // create directory for userid-useraudioprofileid if not exist\n+    const rootPath = `/tmp/${directoryName}`\n+    const wavePath = `${rootPath}/wav48/1`\n+    if (!fs.existsSync(wavePath)) {\n+      fs.mkdirSync(wavePath, { recursive: true })\n+    }\n+\n+    const txtPath = `${rootPath}/txt/1`\n+    if (!fs.existsSync(txtPath)) {\n+      fs.mkdirSync(txtPath, { recursive: true })\n+    }\n+    // download the training data files and put it in respective directories\n+    for (let index = 0; index < input.length; index++) {\n+      const item = input[index]\n+\n+      const { waveUrl, originalText } = item\n+      // download wave file\n+      const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`\n+\n+      await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\n+\n+      const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`\n+      await fs.promises.writeFile(txtFilePath, originalText)\n+    }\n+\n+    const zipFileName = directoryName + '.tgz'\n+\n+    // /tmp/directoryName.tgz\n+\n+    await execShellCommand(\n+      `cd /tmp && tar czvf ${zipFileName}  ${directoryName}`,\n+      logPath\n+    )\n+    console.log('ZIP created ', zipFileName)\n+\n+    // re-sample audio\n+    const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`\n+    console.time(SAMPLING_LABEL)\n+\n+    const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n+\n+    const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\n+    console.log('samplingCommand ', samplingCommand)\n+    await execShellCommand(samplingCommand, logPath)\n+    console.timeEnd(SAMPLING_LABEL)\n+\n+    // /mnt/efs/potion-voice/${env}/speakrs.pth\n+    // /mnt/efs/potion-voice/${env}/txt\n+    // /mnt/efs/potion-voice/${env}/${directoryName}/wav\n+\n+    const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`\n+\n+    const resultsPath = outPath + '/results'\n+\n+    //update pth file for cloning\n+    // clone the voice\n+    const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\n+    console.time(VOICE_CLONING_LABEL)\n+    const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\n+      outPath + '/speakers.pth'\n+    } --output_path ${resultsPath}`\n+\n+    console.log('Training Model Command', trainingModelCommand)\n+    await execShellCommand(trainingModelCommand, logPath)\n+\n+    console.timeEnd(VOICE_CLONING_LABEL)\n+\n+    let generatedDirectoryName = ''\n+    fs.readdirSync(`${resultsPath}/`).forEach((file) => {\n+      if (file.includes('vits_potion_clone'))\n+        // use output from above to get right path and directory name\n+        generatedDirectoryName = file\n+    })\n+\n+    // minimize cloning model\n+    const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`\n+    console.time(VOICE_MINIMIZE_LABEL)\n+    const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\n+      resultsPath + '/' + generatedDirectoryName + '/'\n+    } --voice_model_name checkpoint_365200.pth`\n+\n+    console.log(\n+      'Minimize Cloning Model Command',\n+      minimizeCloningModelCommand\n+    )\n+    await execShellCommand(minimizeCloningModelCommand, logPath)\n+    console.timeEnd(VOICE_MINIMIZE_LABEL)\n+\n+    // Add the code to update location of generated model and status into DB\n+    await voiceCloningService.update(\n+      { _id: voiceCloningId, status: 'completed' },\n+      userId\n+    )\n+\n+    const training_model_path = {\n+      voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,\n+      voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,\n+      voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\n+      voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,\n+      voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,\n+    }\n+\n+    await userAudioProfileService.update(\n+      {\n+        _id: userAudioProfileId,\n+        status: 'completed',\n+        training_model_path,\n+      },\n+      userId\n+    )\n+\n+    // add code to put that model into S3\n+    const keys = Object.keys(training_model_path)\n+    const training_model_s3_path = {}\n+\n+    for (let index = 0; index < keys.length; index++) {\n+      const path = training_model_path[keys[index]]\n+      const s3Path = await s3.upload({\n+        filePath: path,\n+        fileName: `${directoryName}/${path.split('/').pop()}`,\n+        bucket: `potion-voice-users-training-model/${env}`,\n+      })\n+      training_model_s3_path[keys[index]] = s3Path\n+    }\n+    // add S3 path to user audio profile model\n+    await userAudioProfileService.update(\n+      { _id: userAudioProfileId, training_model_s3_path },\n+      userId\n+    )\n+  } catch (error) {\n+    if (error instanceof RejectedJobError) {\n+      console.warn(`Rejected voice cloning job: ${error.message}`)\n+    } else {\n       console.error('Error while training voice clone', { error })\n       Bugsnag.notify(error)\n-      resolve() // to continue working on new jobs\n-    } finally {\n-      mongoose.connection.close()\n     }\n-  })\n+\n+    if (authorized) {\n+      const statusUpdates = await Promise.allSettled([\n+        voiceCloningService.update(\n+          { _id: voiceCloningId, status: 'error' },\n+          userId\n+        ),\n+        userAudioProfileService.update(\n+          { _id: userAudioProfileId, status: 'error' },\n+          userId\n+        ),\n+      ])\n+      statusUpdates\n+        .filter(({ status }) => status === 'rejected')\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_31","type":"command_execution","command":"/bin/bash -lc 'node --check voice-cloning-job-handler/index.js && node --check voice-synthsizer-job-handler/index.js && for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js app/services/utils/tenantScope.js app/services/utils/jobValidation.js; do node --check \"$f\" || exit 1; done'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_31","type":"command_execution","command":"/bin/bash -lc 'node --check voice-cloning-job-handler/index.js && node --check voice-synthsizer-job-handler/index.js && for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js app/services/utils/tenantScope.js app/services/utils/jobValidation.js; do node --check \"$f\" || exit 1; done'","aggregated_output":"","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_32","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,340p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_32","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-synthsizer-job-handler/index.js | sed -n '1,340p'\"","aggregated_output":"     1\tconst fs = require('fs')\n     2\tconst exec = require('child_process').exec\n     3\tconst AWS = require('aws-sdk')\n     4\tconst Bugsnag = require('@bugsnag/js')\n     5\tconst uuid = require('uuid').v4\n     6\tconst version = require('./package.json').version\n     7\tconst sqs = require('../app/services/sqs')\n     8\tconst s3 = require('../app/services/s3')\n     9\tconst userAudioProfileService = require('./user_audio_profile')\n    10\tconst recordingModel = require('./recording')\n    11\tconst recordingSalutationModel = require('./recording_salutation')\n    12\tconst jobService = require('./job')\n    13\tconst salutationService = require('./salutation')\n    14\tconst {\n    15\t  RejectedJobError,\n    16\t  parseJobMessage,\n    17\t  requireJobObject,\n    18\t  requireJobObjectId,\n    19\t  requireJobString,\n    20\t} = require('../app/services/utils/jobValidation')\n    21\tlet throttleMessageFetching = true\n    22\tAWS.config.update({ region: 'us-west-2' })\n    23\tconst sqsQueueUrl = process.env.SQS_URL\n    24\tconst mongoUriDev = process.env.MONGODB_URI_DEV\n    25\tconst mongoUriStaging = process.env.MONGODB_URI_STAGING\n    26\tconst mongoUriProd = process.env.MONGODB_URI_PROD\n    27\tconst APP_ENV = process.env.POTION_APP_ENV\n    28\tconst mongoose = require('mongoose')\n    29\t\n    30\tfunction execShellCommand(cmd) {\n    31\t  // const exec = require(\"child_process\").exec;\n    32\t  return new Promise((resolve, reject) => {\n    33\t    exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {\n    34\t      if (error) {\n    35\t        console.log('Error while processing python command', error)\n    36\t        reject(error)\n    37\t      }\n    38\t      console.log('Stdout --- ', stdout)\n    39\t      console.log('Std error --- ', stderr)\n    40\t      resolve(stdout || stderr)\n    41\t    })\n    42\t  })\n    43\t}\n    44\t\n    45\tasync function connectDB(dbUri, retryCount = 0) {\n    46\t  console.log('Connection Attempt : ', retryCount)\n    47\t  mongoose.set('strictQuery', true)\n    48\t\n    49\t  try {\n    50\t    await mongoose.connect(dbUri)\n    51\t    console.log('Connected to Mongo DB !')\n    52\t  } catch (error) {\n    53\t    console.log('Failed to connect dns mongo: ', error)\n    54\t    if (retryCount < 6) {\n    55\t      return connectDB(dbUri, retryCount + 1)\n    56\t    }\n    57\t\n    58\t    throw error\n    59\t  }\n    60\t}\n    61\t\n    62\tconst processQueue = async () => {\n    63\t  try {\n    64\t    const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n    65\t\n    66\t    if (!response.Messages || response.Messages.length === 0) {\n    67\t      throttleMessageFetching = true\n    68\t      return\n    69\t    }\n    70\t\n    71\t    throttleMessageFetching = false\n    72\t    const message = response.Messages[0]\n    73\t\n    74\t    // Acknowledge before parsing so malformed or rejected jobs cannot poison the\n    75\t    // polling loop. This preserves the worker's existing at-most-once behavior.\n    76\t    await sqs.deleteMessageFromSQS(sqsQueueUrl, message.ReceiptHandle)\n    77\t    const job = requireJobObject(parseJobMessage(message.Body), 'job')\n    78\t\n    79\t    const userId = requireJobObjectId(job.userId, 'userId')\n    80\t    const userAudioProfileId = requireJobObjectId(\n    81\t      job.userAudioProfileId,\n    82\t      'userAudioProfileId'\n    83\t    )\n    84\t    const salutationId = requireJobObjectId(job.salutationId, 'salutationId')\n    85\t    const recordingId = requireJobObjectId(job.recordingId, 'recordingId')\n    86\t    const text = requireJobString(job.text, 'text')\n    87\t    const firstName = requireJobString(job.firstName, 'firstName')\n    88\t    const env = requireJobString(job.env, 'env')\n    89\t    const { baseUrlForPotionAi } = job\n    90\t\n    91\t    const DB_URI =\n    92\t      env === 'production'\n    93\t        ? mongoUriProd\n    94\t        : env === 'staging'\n    95\t        ? mongoUriStaging\n    96\t        : mongoUriDev\n    97\t\n    98\t    await connectDB(DB_URI)\n    99\t\n   100\t    // Authorize every referenced record before voice synthesis or S3 writes.\n   101\t    const [userAudioProfile, salutationToUpdate, recordingToUpdate] =\n   102\t      await Promise.all([\n   103\t        userAudioProfileService.read(\n   104\t          { _id: userAudioProfileId, status: 'completed' },\n   105\t          userId\n   106\t        ),\n   107\t        recordingSalutationModel.findOne({\n   108\t          _id: salutationId,\n   109\t          userId,\n   110\t          deleted: false,\n   111\t        }),\n   112\t        recordingModel.findOne({\n   113\t          _id: recordingId,\n   114\t          userId,\n   115\t          deleted: false,\n   116\t        }),\n   117\t      ])\n   118\t\n   119\t    if (!userAudioProfile || !salutationToUpdate || !recordingToUpdate) {\n   120\t      throw new RejectedJobError(\n   121\t        'Synthesizer job records were not found for the supplied userId'\n   122\t      )\n   123\t    }\n   124\t\n   125\t    const trainingModelPath = requireJobObject(\n   126\t      userAudioProfile.training_model_path,\n   127\t      'training_model_path'\n   128\t    )\n   129\t    const voiceModelLightPath = requireJobString(\n   130\t      trainingModelPath.voice_model_light_path,\n   131\t      'training_model_path.voice_model_light_path'\n   132\t    )\n   133\t    const voiceModelConfigLightPath = requireJobString(\n   134\t      trainingModelPath.voice_model_config_light_path,\n   135\t      'training_model_path.voice_model_config_light_path'\n   136\t    )\n   137\t    const voiceModelSpeakersFilePath = requireJobString(\n   138\t      trainingModelPath.voice_model_speakers_file_path,\n   139\t      'training_model_path.voice_model_speakers_file_path'\n   140\t    )\n   141\t\n   142\t    const outputPath = `/tmp/${uuid()}/`\n   143\t    if (!fs.existsSync(outputPath)) {\n   144\t      fs.mkdirSync(outputPath, { recursive: true })\n   145\t    }\n   146\t\n   147\t    const AI_COMMAND = `python3 ../voice-cloning/synthesize_speech.py --voice_model_path ${voiceModelLightPath} --voice_model_config_path ${voiceModelConfigLightPath} --speaker_embeddings_path ${voiceModelSpeakersFilePath} --txt \"${text}\" --output_path ${outputPath}`\n   148\t    console.log('AI_COMMAND ', AI_COMMAND)\n   149\t\n   150\t    const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()\n   151\t    console.time(SYNTHESIZE_AI_LABEL)\n   152\t    await execShellCommand(AI_COMMAND)\n   153\t    console.timeEnd(SYNTHESIZE_AI_LABEL)\n   154\t\n   155\t    let generatedFileName = ''\n   156\t    fs.readdirSync(`${outputPath}`).forEach((file) => {\n   157\t      if (file.includes('sr48000.wav')) generatedFileName = file\n   158\t    })\n   159\t\n   160\t    // upload the file to s3\n   161\t    const uploadParams = {\n   162\t      filePath: `${outputPath}${generatedFileName}`,\n   163\t      bucket: `recordings-${env}`,\n   164\t      fileName: `${uuid()}_salutation_${firstName.replace('-', '_')}.wav`,\n   165\t      contentType: 'audio/x-wav',\n   166\t      fileType: 'wav',\n   167\t    }\n   168\t    console.time('Time to Upload video on S3')\n   169\t    const greetingUploadResponse = await s3.upload(uploadParams)\n   170\t    console.timeEnd('Time to Upload video on S3')\n   171\t\n   172\t    // Create or update the per-user cached salutation.\n   173\t    await salutationService.updateOrCreate(\n   174\t      {\n   175\t        firstName,\n   176\t        salutationVideo: greetingUploadResponse,\n   177\t        userAudioProfileId,\n   178\t      },\n   179\t      userId\n   180\t    )\n   181\t\n   182\t    const updatedSalutation =\n   183\t      await recordingSalutationModel.findOneAndUpdate(\n   184\t        {\n   185\t          _id: salutationId,\n   186\t          userId,\n   187\t          deleted: false,\n   188\t        },\n   189\t        {\n   190\t          $set: {\n   191\t            salutationVideo: greetingUploadResponse,\n   192\t          },\n   193\t        },\n   194\t        { new: true }\n   195\t      )\n   196\t\n   197\t    if (!updatedSalutation) {\n   198\t      throw new RejectedJobError(\n   199\t        'Recording salutation changed before it could be updated'\n   200\t      )\n   201\t    }\n   202\t\n   203\t    const jobData = {\n   204\t      originalGreeting: recordingToUpdate.masterSalutationVideoUrl,\n   205\t      originalVideo:\n   206\t        recordingToUpdate.originalVideoUrl || recordingToUpdate.urls[0].url,\n   207\t      cropTimestamp: recordingToUpdate.cropTimestamp,\n   208\t      greetingClips: [greetingUploadResponse],\n   209\t      greetingObjects: [\n   210\t        {\n   211\t          greetingId: updatedSalutation._id,\n   212\t          firstName,\n   213\t          videoUrl: greetingUploadResponse,\n   214\t        },\n   215\t      ],\n   216\t      requestOrigin: baseUrlForPotionAi,\n   217\t      environment: env,\n   218\t      recordingId: recordingToUpdate._id,\n   219\t      salutation: updatedSalutation._id,\n   220\t      dynamicVideoType: recordingToUpdate.dynamicVideoType,\n   221\t    }\n   222\t\n   223\t    await jobService.insertMany(\n   224\t      [\n   225\t        {\n   226\t          firstName,\n   227\t          recordingId: recordingToUpdate._id,\n   228\t          salutationId: updatedSalutation._id,\n   229\t          metadata: jobData,\n   230\t        },\n   231\t      ],\n   232\t      userId\n   233\t    )\n   234\t\n   235\t    fs.unlinkSync(`${outputPath}${generatedFileName}`)\n   236\t    console.log(`[deleted] ${outputPath}${generatedFileName}`)\n   237\t  } catch (error) {\n   238\t    if (error instanceof RejectedJobError) {\n   239\t      console.warn(`Rejected voice synthesizer job: ${error.message}`)\n   240\t    } else {\n   241\t      console.error('Error while synthesizing audio', { error })\n   242\t      Bugsnag.notify(error)\n   243\t    }\n   244\t  } finally {\n   245\t    if (mongoose.connection.readyState !== 0) {\n   246\t      try {\n   247\t        await mongoose.connection.close()\n   248\t      } catch (error) {\n   249\t        console.error('Unable to close Mongo DB connection', { error })\n   250\t        Bugsnag.notify(error)\n   251\t      }\n   252\t    }\n   253\t  }\n   254\t}\n   255\t\n   256\tfunction sleep(ms) {\n   257\t  return new Promise((resolve) => {\n   258\t    setTimeout(resolve, ms)\n   259\t  })\n   260\t}\n   261\tconst init = async () => {\n   262\t  Bugsnag.start({\n   263\t    appVersion: APP_ENV + version,\n   264\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   265\t    releaseStage: process.env.NODE_ENV,\n   266\t  })\n   267\t  try {\n   268\t    while (true) {\n   269\t      await processQueue()\n   270\t      if (throttleMessageFetching) await sleep(2000)\n   271\t    }\n   272\t  } catch (error) {\n   273\t    Bugsnag.notify(error)\n   274\t  }\n   275\t}\n   276\tif (require.main === module) {\n   277\t  init()\n   278\t}\n   279\t\n   280\tmodule.exports = {\n   281\t  connectDB,\n   282\t  processQueue,\n   283\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_33","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-cloning-job-handler/index.js | sed -n '1,430p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_33","type":"command_execution","command":"/bin/bash -lc \"nl -ba voice-cloning-job-handler/index.js | sed -n '1,430p'\"","aggregated_output":"     1\tconst fs = require('fs')\n     2\tconst https = require('https')\n     3\tconst exec = require('child_process').exec\n     4\tconst AWS = require('aws-sdk')\n     5\t\n     6\tconst Bugsnag = require('@bugsnag/js')\n     7\tconst mongoose = require('mongoose')\n     8\tconst version = require('./package.json').version\n     9\tconst sqs = require('../app/services/sqs')\n    10\tconst s3 = require('../app/services/s3')\n    11\tconst voiceCloningService = require('./voice_cloning')\n    12\tconst userAudioProfileService = require('./user_audio_profile')\n    13\tconst {\n    14\t  RejectedJobError,\n    15\t  parseJobMessage,\n    16\t  requireJobObject,\n    17\t  requireJobObjectId,\n    18\t  requireJobString,\n    19\t} = require('../app/services/utils/jobValidation')\n    20\t\n    21\tAWS.config.update({ region: 'us-west-2' })\n    22\tconst sqsQueueUrl = process.env.SQS_URL\n    23\tconst mongoUriDev = process.env.MONGODB_URI_DEV\n    24\tconst mongoUriStaging = process.env.MONGODB_URI_STAGING\n    25\tconst mongoUriProd = process.env.MONGODB_URI_PROD\n    26\tlet throttleMessageFetching = true\n    27\tconst APP_ENV = process.env.POTION_APP_ENV\n    28\t\n    29\tconst cloudFrontUrlProd = process.env.CLOUDFRONT_URL_PROD\n    30\tconst cloudFrontUrlDev = process.env.CLOUDFRONT_URL_DEV\n    31\tconst cloudFrontUrlStaging = process.env.CLOUDFRONT_URL_STAGING\n    32\t\n    33\tconst updateUrl = (str, cloudFrontUrl) => {\n    34\t  const host = new URL(str).host\n    35\t  return str.replace(`https://${host}`, cloudFrontUrl)\n    36\t}\n    37\t\n    38\tasync function connectDB(dbUri, retryCount = 0) {\n    39\t  console.log('Connection Attempt : ', retryCount)\n    40\t  mongoose.set('strictQuery', true)\n    41\t\n    42\t  try {\n    43\t    await mongoose.connect(dbUri)\n    44\t    console.log('Connected to Mongo DB !')\n    45\t  } catch (error) {\n    46\t    console.log('Failed to connect dns mongo: ', error)\n    47\t    if (retryCount < 6) {\n    48\t      return connectDB(dbUri, retryCount + 1)\n    49\t    }\n    50\t\n    51\t    throw error\n    52\t  }\n    53\t}\n    54\t\n    55\tfunction execShellCommand(cmd, logPath) {\n    56\t  // const exec = require(\"child_process\").exec;\n    57\t  return new Promise((resolve, reject) => {\n    58\t    exec(cmd, { maxBuffer: 1024 * 1000000 }, async (error, stdout, stderr) => {\n    59\t      if (error) {\n    60\t        console.log('Error while proccessing python command', error)\n    61\t        reject(error)\n    62\t      }\n    63\t      // console.log('Stdout --- ', stdout)\n    64\t      // console.log('Stderror --- ', stderr)\n    65\t      await fs.promises.writeFile(`${logPath}/error.log`, stderr)\n    66\t      await fs.promises.writeFile(`${logPath}/info.log`, stdout)\n    67\t\n    68\t      resolve()\n    69\t    })\n    70\t  })\n    71\t}\n    72\t\n    73\tasync function getFile(waveUrl, path) {\n    74\t  return new Promise((resolve) => {\n    75\t    https.get(waveUrl, (res) => {\n    76\t      const writeStream = fs.createWriteStream(path)\n    77\t\n    78\t      res.pipe(writeStream)\n    79\t\n    80\t      writeStream.on('finish', () => {\n    81\t        writeStream.close()\n    82\t        resolve()\n    83\t      })\n    84\t    })\n    85\t  })\n    86\t}\n    87\t\n    88\tfunction pad(s) {\n    89\t  while (s.length < 3) s = '0' + s // IN future we will need padding to 4\n    90\t  return s\n    91\t}\n    92\t\n    93\tconst processQueue = async () => {\n    94\t  let authorized = false\n    95\t  let userId\n    96\t  let voiceCloningId\n    97\t  let userAudioProfileId\n    98\t\n    99\t  try {\n   100\t    const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n   101\t\n   102\t    if (!response.Messages || response.Messages.length === 0) {\n   103\t      throttleMessageFetching = true\n   104\t      return\n   105\t    }\n   106\t\n   107\t    throttleMessageFetching = false\n   108\t    const message = response.Messages[0]\n   109\t\n   110\t    // Acknowledge before parsing so malformed or rejected jobs cannot poison the\n   111\t    // polling loop. This preserves the worker's existing at-most-once behavior.\n   112\t    await sqs.deleteMessageFromSQS(sqsQueueUrl, message.ReceiptHandle)\n   113\t    const job = parseJobMessage(message.Body)\n   114\t    const jobDocument = requireJobObject(job._doc, 'job._doc')\n   115\t\n   116\t    userId = requireJobObjectId(jobDocument.userId, 'userId')\n   117\t    voiceCloningId = requireJobObjectId(jobDocument._id, '_id')\n   118\t    userAudioProfileId = requireJobObjectId(\n   119\t      jobDocument.userAudioProfileId,\n   120\t      'userAudioProfileId'\n   121\t    )\n   122\t    const env = requireJobString(job.env, 'env')\n   123\t    const DB_URI =\n   124\t      env === 'production'\n   125\t        ? mongoUriProd\n   126\t        : env === 'staging'\n   127\t        ? mongoUriStaging\n   128\t        : mongoUriDev\n   129\t\n   130\t    await connectDB(DB_URI)\n   131\t\n   132\t    const [voiceCloning, userAudioProfile] = await Promise.all([\n   133\t      voiceCloningService.read(\n   134\t        { _id: voiceCloningId, userAudioProfileId },\n   135\t        userId\n   136\t      ),\n   137\t      userAudioProfileService.read({ _id: userAudioProfileId }, userId),\n   138\t    ])\n   139\t\n   140\t    if (!voiceCloning || !userAudioProfile) {\n   141\t      throw new RejectedJobError(\n   142\t        'Voice cloning job records were not found for the supplied userId'\n   143\t      )\n   144\t    }\n   145\t\n   146\t    authorized = true\n   147\t    const metadata = requireJobObject(voiceCloning.metadata, 'metadata')\n   148\t    const directoryName = requireJobString(\n   149\t      metadata.directoryName,\n   150\t      'metadata.directoryName'\n   151\t    )\n   152\t    const input = voiceCloning.input\n   153\t    if (!Array.isArray(input)) {\n   154\t      throw new RejectedJobError('input must be an array')\n   155\t    }\n   156\t\n   157\t    const cloudFrontUrl =\n   158\t      env === 'production'\n   159\t        ? cloudFrontUrlProd\n   160\t        : env === 'staging'\n   161\t        ? cloudFrontUrlStaging\n   162\t        : cloudFrontUrlDev\n   163\t\n   164\t    const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   165\t    if (!fs.existsSync(logPath)) {\n   166\t      fs.mkdirSync(logPath, { recursive: true })\n   167\t    }\n   168\t\n   169\t    const [processingJob, processingProfile] = await Promise.all([\n   170\t      voiceCloningService.update(\n   171\t        { _id: voiceCloningId, status: 'processing' },\n   172\t        userId\n   173\t      ),\n   174\t      userAudioProfileService.update(\n   175\t        { _id: userAudioProfileId, status: 'processing' },\n   176\t        userId\n   177\t      ),\n   178\t    ])\n   179\t    if (!processingJob || !processingProfile) {\n   180\t      throw new RejectedJobError(\n   181\t        'Voice cloning job records changed before processing'\n   182\t      )\n   183\t    }\n   184\t\n   185\t    // create directory for userid-useraudioprofileid if not exist\n   186\t    const rootPath = `/tmp/${directoryName}`\n   187\t    const wavePath = `${rootPath}/wav48/1`\n   188\t    if (!fs.existsSync(wavePath)) {\n   189\t      fs.mkdirSync(wavePath, { recursive: true })\n   190\t    }\n   191\t\n   192\t    const txtPath = `${rootPath}/txt/1`\n   193\t    if (!fs.existsSync(txtPath)) {\n   194\t      fs.mkdirSync(txtPath, { recursive: true })\n   195\t    }\n   196\t    // download the training data files and put it in respective directories\n   197\t    for (let index = 0; index < input.length; index++) {\n   198\t      const item = input[index]\n   199\t\n   200\t      const { waveUrl, originalText } = item\n   201\t      // download wave file\n   202\t      const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`\n   203\t\n   204\t      await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\n   205\t\n   206\t      const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`\n   207\t      await fs.promises.writeFile(txtFilePath, originalText)\n   208\t    }\n   209\t\n   210\t    const zipFileName = directoryName + '.tgz'\n   211\t\n   212\t    // /tmp/directoryName.tgz\n   213\t\n   214\t    await execShellCommand(\n   215\t      `cd /tmp && tar czvf ${zipFileName}  ${directoryName}`,\n   216\t      logPath\n   217\t    )\n   218\t    console.log('ZIP created ', zipFileName)\n   219\t\n   220\t    // re-sample audio\n   221\t    const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`\n   222\t    console.time(SAMPLING_LABEL)\n   223\t\n   224\t    const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   225\t\n   226\t    const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\n   227\t    console.log('samplingCommand ', samplingCommand)\n   228\t    await execShellCommand(samplingCommand, logPath)\n   229\t    console.timeEnd(SAMPLING_LABEL)\n   230\t\n   231\t    // /mnt/efs/potion-voice/${env}/speakrs.pth\n   232\t    // /mnt/efs/potion-voice/${env}/txt\n   233\t    // /mnt/efs/potion-voice/${env}/${directoryName}/wav\n   234\t\n   235\t    const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`\n   236\t\n   237\t    const resultsPath = outPath + '/results'\n   238\t\n   239\t    //update pth file for cloning\n   240\t    // clone the voice\n   241\t    const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\n   242\t    console.time(VOICE_CLONING_LABEL)\n   243\t    const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\n   244\t      outPath + '/speakers.pth'\n   245\t    } --output_path ${resultsPath}`\n   246\t\n   247\t    console.log('Training Model Command', trainingModelCommand)\n   248\t    await execShellCommand(trainingModelCommand, logPath)\n   249\t\n   250\t    console.timeEnd(VOICE_CLONING_LABEL)\n   251\t\n   252\t    let generatedDirectoryName = ''\n   253\t    fs.readdirSync(`${resultsPath}/`).forEach((file) => {\n   254\t      if (file.includes('vits_potion_clone'))\n   255\t        // use output from above to get right path and directory name\n   256\t        generatedDirectoryName = file\n   257\t    })\n   258\t\n   259\t    // minimize cloning model\n   260\t    const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`\n   261\t    console.time(VOICE_MINIMIZE_LABEL)\n   262\t    const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\n   263\t      resultsPath + '/' + generatedDirectoryName + '/'\n   264\t    } --voice_model_name checkpoint_365200.pth`\n   265\t\n   266\t    console.log(\n   267\t      'Minimize Cloning Model Command',\n   268\t      minimizeCloningModelCommand\n   269\t    )\n   270\t    await execShellCommand(minimizeCloningModelCommand, logPath)\n   271\t    console.timeEnd(VOICE_MINIMIZE_LABEL)\n   272\t\n   273\t    // Add the code to update location of generated model and status into DB\n   274\t    await voiceCloningService.update(\n   275\t      { _id: voiceCloningId, status: 'completed' },\n   276\t      userId\n   277\t    )\n   278\t\n   279\t    const training_model_path = {\n   280\t      voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,\n   281\t      voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,\n   282\t      voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\n   283\t      voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,\n   284\t      voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,\n   285\t    }\n   286\t\n   287\t    await userAudioProfileService.update(\n   288\t      {\n   289\t        _id: userAudioProfileId,\n   290\t        status: 'completed',\n   291\t        training_model_path,\n   292\t      },\n   293\t      userId\n   294\t    )\n   295\t\n   296\t    // add code to put that model into S3\n   297\t    const keys = Object.keys(training_model_path)\n   298\t    const training_model_s3_path = {}\n   299\t\n   300\t    for (let index = 0; index < keys.length; index++) {\n   301\t      const path = training_model_path[keys[index]]\n   302\t      const s3Path = await s3.upload({\n   303\t        filePath: path,\n   304\t        fileName: `${directoryName}/${path.split('/').pop()}`,\n   305\t        bucket: `potion-voice-users-training-model/${env}`,\n   306\t      })\n   307\t      training_model_s3_path[keys[index]] = s3Path\n   308\t    }\n   309\t    // add S3 path to user audio profile model\n   310\t    await userAudioProfileService.update(\n   311\t      { _id: userAudioProfileId, training_model_s3_path },\n   312\t      userId\n   313\t    )\n   314\t  } catch (error) {\n   315\t    if (error instanceof RejectedJobError) {\n   316\t      console.warn(`Rejected voice cloning job: ${error.message}`)\n   317\t    } else {\n   318\t      console.error('Error while training voice clone', { error })\n   319\t      Bugsnag.notify(error)\n   320\t    }\n   321\t\n   322\t    if (authorized) {\n   323\t      const statusUpdates = await Promise.allSettled([\n   324\t        voiceCloningService.update(\n   325\t          { _id: voiceCloningId, status: 'error' },\n   326\t          userId\n   327\t        ),\n   328\t        userAudioProfileService.update(\n   329\t          { _id: userAudioProfileId, status: 'error' },\n   330\t          userId\n   331\t        ),\n   332\t      ])\n   333\t      statusUpdates\n   334\t        .filter(({ status }) => status === 'rejected')\n   335\t        .forEach(({ reason }) => Bugsnag.notify(reason))\n   336\t    }\n   337\t  } finally {\n   338\t    if (mongoose.connection.readyState !== 0) {\n   339\t      try {\n   340\t        await mongoose.connection.close()\n   341\t      } catch (error) {\n   342\t        console.error('Unable to close Mongo DB connection', { error })\n   343\t        Bugsnag.notify(error)\n   344\t      }\n   345\t    }\n   346\t  }\n   347\t}\n   348\t\n   349\tfunction sleep(ms) {\n   350\t  return new Promise((resolve) => {\n   351\t    setTimeout(resolve, ms)\n   352\t  })\n   353\t}\n   354\tconst init = async () => {\n   355\t  console.log('potion Voice Clone Process Started')\n   356\t  Bugsnag.start({\n   357\t    appVersion: APP_ENV + version,\n   358\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   359\t    releaseStage: process.env.NODE_ENV,\n   360\t  })\n   361\t\n   362\t  try {\n   363\t    while (true) {\n   364\t      await processQueue()\n   365\t      if (throttleMessageFetching) await sleep(2000)\n   366\t    }\n   367\t  } catch (error) {\n   368\t    Bugsnag.notify(error)\n   369\t  }\n   370\t}\n   371\tif (require.main === module) {\n   372\t  init()\n   373\t}\n   374\t\n   375\tmodule.exports = {\n   376\t  connectDB,\n   377\t  processQueue,\n   378\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_34","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do echo \"$f\"; sed -n '\"'1,240p' \\\"\"'$f\"; done'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_34","type":"command_execution","command":"/bin/bash -lc 'for f in voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do echo \"$f\"; sed -n '\"'1,240p' \\\"\"'$f\"; done'","aggregated_output":"voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\nconst StringifyUtils = require('../../app/services/utils/logService')\nconst {\n  assignToUser,\n  scopeToUser,\n} = require('../../app/services/utils/tenantScope')\n\nconst create = (VoiceCloningModel) => async (data, userId) => {\n  try {\n    const newModel = new VoiceCloningModel(assignToUser(data, userId))\n    const savedModel = await newModel.save()\n    return savedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > create',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst insertMany = (VoiceCloningModel) => async (data, userId) => {\n  try {\n    const inserted = await VoiceCloningModel.insertMany(\n      data.map((item) => assignToUser(item, userId))\n    )\n    return inserted\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > insertMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst read = (VoiceCloningModel) => async (filter, userId) => {\n  try {\n    const foundModel = await VoiceCloningModel.findOne({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > read',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst find = (VoiceCloningModel) => async (filter, userId) => {\n  try {\n    const foundModels = await VoiceCloningModel.find({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundModels\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > find',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst update = (VoiceCloningModel) => async (data, userId) => {\n  try {\n    const { _id, userId: ignoredUserId, ...updates } = data\n    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n      {\n        ...scopeToUser({ _id }, userId),\n        deleted: false,\n      },\n      updates,\n      {\n        new: true,\n      }\n    )\n\n    return updatedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > update',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst remove = (VoiceCloningModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > remove',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst removeMany = (VoiceCloningModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await VoiceCloningModel.updateMany(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - VOICE CLONING SERVICE > removeMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nmodule.exports = (VoiceCloningModel) => {\n  return {\n    create: create(VoiceCloningModel),\n    insertMany: insertMany(VoiceCloningModel),\n    read: read(VoiceCloningModel),\n    remove: remove(VoiceCloningModel),\n    removeMany: removeMany(VoiceCloningModel),\n    update: update(VoiceCloningModel),\n    find: find(VoiceCloningModel),\n  }\n}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\nconst StringifyUtils = require('../../app/services/utils/logService')\nconst {\n  assignToUser,\n  scopeToUser,\n} = require('../../app/services/utils/tenantScope')\n\nconst create = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\n    const savedModel = await newModel.save()\n    return savedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > create',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst insertMany = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const inserted = await UserAudioProfileModel.insertMany(\n      data.map((item) => assignToUser(item, userId))\n    )\n    return inserted\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst read = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const foundModel = await UserAudioProfileModel.findOne({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > read',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst find = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const foundModels = await UserAudioProfileModel.find({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundModels\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > find',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst update = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const { _id, userId: ignoredUserId, ...updates } = data\n    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n      {\n        ...scopeToUser({ _id }, userId),\n        deleted: false,\n      },\n      updates,\n      {\n        new: true,\n      }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > update',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst remove = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst removeMany = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await UserAudioProfileModel.updateMany(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nmodule.exports = (UserAudioProfileModel) => {\n  return {\n    create: create(UserAudioProfileModel),\n    insertMany: insertMany(UserAudioProfileModel),\n    read: read(UserAudioProfileModel),\n    remove: remove(UserAudioProfileModel),\n    removeMany: removeMany(UserAudioProfileModel),\n    update: update(UserAudioProfileModel),\n    find: find(UserAudioProfileModel),\n  }\n}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\nconst StringifyUtils = require('../../app/services/utils/logService')\nconst {\n  assignToUser,\n  scopeToUser,\n} = require('../../app/services/utils/tenantScope')\n\nconst create = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\n    const savedModel = await newModel.save()\n    return savedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > create',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst insertMany = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const inserted = await UserAudioProfileModel.insertMany(\n      data.map((item) => assignToUser(item, userId))\n    )\n    return inserted\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > insertMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst read = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const foundModel = await UserAudioProfileModel.findOne({\n      ...scopeToUser(filter, userId),\n      deleted: false\n    })\n    return foundModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > read',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst find = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const foundModels = await UserAudioProfileModel.find({\n      ...scopeToUser(filter, userId),\n      deleted: false\n    })\n    return foundModels\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > find',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst update = (UserAudioProfileModel) => async (data, userId) => {\n  try {\n    const { _id, userId: ignoredUserId, ...updates } = data\n    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n      {\n        ...scopeToUser({ _id }, userId),\n        deleted: false\n      },\n      updates,\n      {\n        new: true\n      }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { data }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > update',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst remove = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false\n      },\n      {\n        $set: {\n          deleted: true\n        }\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > remove',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst removeMany = (UserAudioProfileModel) => async (filter, userId) => {\n  try {\n    const updatedModel = await UserAudioProfileModel.updateMany(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false\n      },\n      {\n        $set: {\n          deleted: true\n        }\n      },\n      { new: true }\n    )\n    return updatedModel\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - USER AUDIO PROFILE SERVICE > removeMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nmodule.exports = (UserAudioProfileModel) => {\n  return {\n    create: create(UserAudioProfileModel),\n    insertMany: insertMany(UserAudioProfileModel),\n    read: read(UserAudioProfileModel),\n    remove: remove(UserAudioProfileModel),\n    removeMany: removeMany(UserAudioProfileModel),\n    update: update(UserAudioProfileModel),\n    find: find(UserAudioProfileModel)\n  }\n}\nvoice-synthsizer-job-handler/salutation/salutation_service.js\nconst {\r\n  assignToUser,\r\n  scopeToUser,\r\n} = require('../../app/services/utils/tenantScope')\r\n\r\nconst create = (Salutation) => async (salutationData, userId) => {\r\n  const newSalutation = new Salutation(assignToUser(salutationData, userId))\r\n  const savedSalutation = await newSalutation.save()\r\n  return savedSalutation\r\n}\r\n\r\nconst read = (Salutation) => async (filter, userId) => {\r\n  const foundSalutation = await Salutation.findOne({\r\n    ...scopeToUser(filter, userId),\r\n    deleted: false,\r\n  })\r\n  return foundSalutation\r\n}\r\n\r\nconst find = (Salutation) => async (filter, userId) => {\r\n  const foundSalutations = await Salutation.find({\r\n    ...scopeToUser(filter, userId),\r\n    deleted: false,\r\n  })\r\n  return foundSalutations\r\n}\r\n\r\nconst update = (Salutation) => async (salutation, userId) => {\r\n  const { _id, userId: ignoredUserId, ...updates } = salutation\r\n  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    {\r\n      ...scopeToUser({ _id }, userId),\r\n      deleted: false,\r\n    },\r\n    updates,\r\n    { new: true }\r\n  )\r\n  return updatedSalutation\r\n}\r\n\r\nconst modify = (Salutation) => async (salutation, userId) => {\r\n  const findQuery = salutation._id\r\n    ? { _id: salutation._id }\r\n    : { transcriptId: salutation.transcriptId }\r\n  const { _id, userId: ignoredUserId, ...updates } = salutation\r\n\r\n  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    {\r\n      ...scopeToUser(findQuery, userId),\r\n      deleted: false,\r\n    },\r\n    updates,\r\n    { new: true }\r\n  )\r\n  return updatedSalutation\r\n}\r\n\r\nconst updateOrCreate =\r\n  (Salutation) =>\r\n  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\n    const salutation = await read(Salutation)(\r\n      {\r\n        firstName,\r\n        userAudioProfileId,\r\n      },\r\n      userId\r\n    )\r\n    if (salutation) {\r\n      return await update(Salutation)(\r\n        { _id: salutation._id, salutationVideo },\r\n        userId\r\n      )\r\n    } else {\r\n      return await create(Salutation)(\r\n        { firstName, salutationVideo, userAudioProfileId },\r\n        userId\r\n      )\r\n    }\r\n  }\r\n\r\nconst remove = (Salutation) => async (filter, userId) => {\r\n  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n    {\r\n      ...scopeToUser(filter, userId),\r\n      deleted: false,\r\n    },\r\n    {\r\n      $set: {\r\n        deleted: true,\r\n      },\r\n    },\r\n    { new: true }\r\n  )\r\n  return updatedSalutation\r\n}\r\n\r\nmodule.exports = (Salutation) => {\r\n  return {\r\n    create: create(Salutation),\r\n    read: read(Salutation),\r\n    remove: remove(Salutation),\r\n    update: update(Salutation),\r\n    updateOrCreate: updateOrCreate(Salutation),\r\n    find: find(Salutation),\r\n    modify: modify(Salutation),\r\n  }\r\n}\r\nvoice-synthsizer-job-handler/job/job_service.js\nconst StringifyUtils = require('../../app/services/utils/logService')\nconst {\n  assignToUser,\n  scopeToUser,\n} = require('../../app/services/utils/tenantScope')\n\nconst create = (Job) => async (jobData, userId) => {\n  try {\n    const newJob = new Job(assignToUser(jobData, userId))\n    const savedJob = await newJob.save()\n    return savedJob\n  } catch (error) {\n    const details = { jobData }\n    console.log(\n      'ERROR - JOB SERVICE > create',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst insertMany = (Job) => async (jobData, userId) => {\n  try {\n    const inserted = await Job.insertMany(\n      jobData.map((item) => assignToUser(item, userId))\n    )\n    return inserted\n  } catch (error) {\n    const details = { jobData }\n    console.log(\n      'ERROR - JOB SERVICE > insertMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst read = (Job) => async (filter, userId) => {\n  try {\n    const foundJob = await Job.findOne({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundJob\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - JOB SERVICE > read',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst find = (Job) => async (filter, userId) => {\n  try {\n    const foundJobs = await Job.find({\n      ...scopeToUser(filter, userId),\n      deleted: false,\n    })\n    return foundJobs\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - JOB SERVICE > find',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst update = (Job) => async (job, userId) => {\n  try {\n    const { _id, userId: ignoredUserId, ...updates } = job\n    const updatedJob = await Job.findOneAndUpdate(\n      {\n        ...scopeToUser({ _id }, userId),\n        deleted: false,\n      },\n      updates,\n      {\n        new: true,\n      }\n    )\n    return updatedJob\n  } catch (error) {\n    const details = { job }\n    console.log(\n      'ERROR - JOB SERVICE > update',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst remove = (Job) => async (filter, userId) => {\n  try {\n    const updatedJob = await Job.findOneAndUpdate(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedJob\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - JOB SERVICE > remove',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nconst removeMany = (Job) => async (filter, userId) => {\n  try {\n    const updatedJob = await Job.updateMany(\n      {\n        ...scopeToUser(filter, userId),\n        deleted: false,\n      },\n      {\n        $set: {\n          deleted: true,\n        },\n      },\n      { new: true }\n    )\n    return updatedJob\n  } catch (error) {\n    const details = { filter }\n    console.log(\n      'ERROR - JOB SERVICE > removeMany',\n      StringifyUtils.potionErrorObj(error, details)\n    )\n    throw error\n  }\n}\n\nmodule.exports = (Job) => {\n  return {\n    create: create(Job),\n    insertMany: insertMany(Job),\n    read: read(Job),\n    remove: remove(Job),\n    removeMany: removeMany(Job),\n    update: update(Job),\n    find: find(Job),\n  }\n}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_35","type":"command_execution","command":"/bin/bash -lc 'git diff --numstat && file voice-synthsizer-job-handler/salutation/salutation_service.js'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_35","type":"command_execution","command":"/bin/bash -lc 'git diff --numstat && file voice-synthsizer-job-handler/salutation/salutation_service.js'","aggregated_output":"281\t235\tvoice-cloning-job-handler/index.js\n31\t15\tvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n31\t15\tvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n200\t184\tvoice-synthsizer-job-handler/index.js\n36\t16\tvoice-synthsizer-job-handler/job/job_service.js\n38\t18\tvoice-synthsizer-job-handler/salutation/salutation_service.js\n31\t17\tvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\nvoice-synthsizer-job-handler/salutation/salutation_service.js: ASCII text, with CRLF line terminators\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_36","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/job/job_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/salutation/salutation_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_36","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"},{"path":"/workspace/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/job/job_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/salutation/salutation_service.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_37","type":"command_execution","command":"/bin/bash -lc \"sed -i 's/\\\\r\"'$//'\"' voice-synthsizer-job-handler/salutation/salutation_service.js\ngit diff --check\nfile voice-synthsizer-job-handler/salutation/salutation_service.js\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_37","type":"command_execution","command":"/bin/bash -lc \"sed -i 's/\\\\r\"'$//'\"' voice-synthsizer-job-handler/salutation/salutation_service.js\ngit diff --check\nfile voice-synthsizer-job-handler/salutation/salutation_service.js\"","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js: ASCII text\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_38","type":"command_execution","command":"/bin/bash -lc \"git diff -- app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js | sed -n '1,800p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_38","type":"command_execution","command":"/bin/bash -lc \"git diff -- app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js | sed -n '1,800p'\"","aggregated_output":"diff --git a/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js b/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\nindex e76643d..a7d1fad 100644\n--- a/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n+++ b/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n@@ -1,8 +1,13 @@\n const StringifyUtils = require('../../app/services/utils/logService')\n+const {\n+  assignToUser,\n+  scopeToUser,\n+  withoutTenantIdentity,\n+} = require('../../app/services/utils/tenantScope')\n \n-const create = (UserAudioProfileModel) => async (data) => {\n+const create = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n-    const newModel = new UserAudioProfileModel({ ...data })\n+    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\n     const savedModel = await newModel.save()\n     return savedModel\n   } catch (error) {\n@@ -15,9 +20,11 @@ const create = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const insertMany = (UserAudioProfileModel) => async (data) => {\n+const insertMany = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n-    const inserted = await UserAudioProfileModel.insertMany(data)\n+    const inserted = await UserAudioProfileModel.insertMany(\n+      data.map((item) => assignToUser(item, userId))\n+    )\n     return inserted\n   } catch (error) {\n     const details = { data }\n@@ -29,10 +36,10 @@ const insertMany = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const read = (UserAudioProfileModel) => async (filter) => {\n+const read = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const foundModel = await UserAudioProfileModel.findOne({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundModel\n@@ -46,10 +53,10 @@ const read = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const find = (UserAudioProfileModel) => async (filter) => {\n+const find = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const foundModels = await UserAudioProfileModel.find({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundModels\n@@ -63,11 +70,15 @@ const find = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const update = (UserAudioProfileModel) => async (data) => {\n+const update = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n+    const updates = withoutTenantIdentity(data)\n     const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n-      { _id: data._id },\n-      data,\n+      {\n+        ...scopeToUser({ _id: data._id }, userId),\n+        deleted: false,\n+      },\n+      updates,\n       {\n         new: true,\n       }\n@@ -83,10 +94,13 @@ const update = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const remove = (UserAudioProfileModel) => async (filter) => {\n+const remove = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\n@@ -105,10 +119,13 @@ const remove = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const removeMany = (UserAudioProfileModel) => async (filter) => {\n+const removeMany = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await UserAudioProfileModel.updateMany(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\ndiff --git a/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js b/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\nindex 329638e..eea54b1 100644\n--- a/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n+++ b/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n@@ -1,8 +1,13 @@\n const StringifyUtils = require('../../app/services/utils/logService')\n+const {\n+  assignToUser,\n+  scopeToUser,\n+  withoutTenantIdentity,\n+} = require('../../app/services/utils/tenantScope')\n \n-const create = (VoiceCloningModel) => async (data) => {\n+const create = (VoiceCloningModel) => async (data, userId) => {\n   try {\n-    const newModel = new VoiceCloningModel({ ...data })\n+    const newModel = new VoiceCloningModel(assignToUser(data, userId))\n     const savedModel = await newModel.save()\n     return savedModel\n   } catch (error) {\n@@ -15,9 +20,11 @@ const create = (VoiceCloningModel) => async (data) => {\n   }\n }\n \n-const insertMany = (VoiceCloningModel) => async (data) => {\n+const insertMany = (VoiceCloningModel) => async (data, userId) => {\n   try {\n-    const inserted = await VoiceCloningModel.insertMany(data)\n+    const inserted = await VoiceCloningModel.insertMany(\n+      data.map((item) => assignToUser(item, userId))\n+    )\n     return inserted\n   } catch (error) {\n     const details = { data }\n@@ -29,10 +36,10 @@ const insertMany = (VoiceCloningModel) => async (data) => {\n   }\n }\n \n-const read = (VoiceCloningModel) => async (filter) => {\n+const read = (VoiceCloningModel) => async (filter, userId) => {\n   try {\n     const foundModel = await VoiceCloningModel.findOne({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundModel\n@@ -46,10 +53,10 @@ const read = (VoiceCloningModel) => async (filter) => {\n   }\n }\n \n-const find = (VoiceCloningModel) => async (filter) => {\n+const find = (VoiceCloningModel) => async (filter, userId) => {\n   try {\n     const foundModels = await VoiceCloningModel.find({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundModels\n@@ -63,11 +70,15 @@ const find = (VoiceCloningModel) => async (filter) => {\n   }\n }\n \n-const update = (VoiceCloningModel) => async (data) => {\n+const update = (VoiceCloningModel) => async (data, userId) => {\n   try {\n+    const updates = withoutTenantIdentity(data)\n     const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n-      { _id: data._id },\n-      data,\n+      {\n+        ...scopeToUser({ _id: data._id }, userId),\n+        deleted: false,\n+      },\n+      updates,\n       {\n         new: true,\n       }\n@@ -84,10 +95,13 @@ const update = (VoiceCloningModel) => async (data) => {\n   }\n }\n \n-const remove = (VoiceCloningModel) => async (filter) => {\n+const remove = (VoiceCloningModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await VoiceCloningModel.findOneAndUpdate(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\n@@ -106,10 +120,13 @@ const remove = (VoiceCloningModel) => async (filter) => {\n   }\n }\n \n-const removeMany = (VoiceCloningModel) => async (filter) => {\n+const removeMany = (VoiceCloningModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await VoiceCloningModel.updateMany(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\ndiff --git a/voice-synthsizer-job-handler/job/job_service.js b/voice-synthsizer-job-handler/job/job_service.js\nindex 44189af..e6ebb44 100644\n--- a/voice-synthsizer-job-handler/job/job_service.js\n+++ b/voice-synthsizer-job-handler/job/job_service.js\n@@ -1,8 +1,13 @@\n const StringifyUtils = require('../../app/services/utils/logService')\n+const {\n+  assignToUser,\n+  scopeToUser,\n+  withoutTenantIdentity,\n+} = require('../../app/services/utils/tenantScope')\n \n-const create = (Job) => async (jobData) => {\n+const create = (Job) => async (jobData, userId) => {\n   try {\n-    const newJob = new Job({ ...jobData })\n+    const newJob = new Job(assignToUser(jobData, userId))\n     const savedJob = await newJob.save()\n     return savedJob\n   } catch (error) {\n@@ -15,9 +20,11 @@ const create = (Job) => async (jobData) => {\n   }\n }\n \n-const insertMany = (Job) => async (jobData) => {\n+const insertMany = (Job) => async (jobData, userId) => {\n   try {\n-    const inserted = await Job.insertMany(jobData)\n+    const inserted = await Job.insertMany(\n+      jobData.map((item) => assignToUser(item, userId))\n+    )\n     return inserted\n   } catch (error) {\n     const details = { jobData }\n@@ -29,10 +36,10 @@ const insertMany = (Job) => async (jobData) => {\n   }\n }\n \n-const read = (Job) => async (filter) => {\n+const read = (Job) => async (filter, userId) => {\n   try {\n     const foundJob = await Job.findOne({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundJob\n@@ -46,10 +53,10 @@ const read = (Job) => async (filter) => {\n   }\n }\n \n-const find = (Job) => async (filter) => {\n+const find = (Job) => async (filter, userId) => {\n   try {\n     const foundJobs = await Job.find({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false,\n     })\n     return foundJobs\n@@ -63,11 +70,19 @@ const find = (Job) => async (filter) => {\n   }\n }\n \n-const update = (Job) => async (job) => {\n+const update = (Job) => async (job, userId) => {\n   try {\n-    const updatedJob = await Job.findOneAndUpdate({ _id: job._id }, job, {\n-      new: true,\n-    })\n+    const updates = withoutTenantIdentity(job)\n+    const updatedJob = await Job.findOneAndUpdate(\n+      {\n+        ...scopeToUser({ _id: job._id }, userId),\n+        deleted: false,\n+      },\n+      updates,\n+      {\n+        new: true,\n+      }\n+    )\n     return updatedJob\n   } catch (error) {\n     const details = { job }\n@@ -79,10 +94,13 @@ const update = (Job) => async (job) => {\n   }\n }\n \n-const remove = (Job) => async (filter) => {\n+const remove = (Job) => async (filter, userId) => {\n   try {\n     const updatedJob = await Job.findOneAndUpdate(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\n@@ -101,10 +119,13 @@ const remove = (Job) => async (filter) => {\n   }\n }\n \n-const removeMany = (Job) => async (filter) => {\n+const removeMany = (Job) => async (filter, userId) => {\n   try {\n     const updatedJob = await Job.updateMany(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false,\n+      },\n       {\n         $set: {\n           deleted: true,\ndiff --git a/voice-synthsizer-job-handler/salutation/salutation_service.js b/voice-synthsizer-job-handler/salutation/salutation_service.js\nindex 2d84f78..b236210 100644\n--- a/voice-synthsizer-job-handler/salutation/salutation_service.js\n+++ b/voice-synthsizer-job-handler/salutation/salutation_service.js\n@@ -1,87 +1,108 @@\n-const create = (Salutation) => async (salutationData, userId) => {\r\n-  const newSalutation = new Salutation({ ...salutationData, userId })\r\n-  const savedSalutation = await newSalutation.save()\r\n-  return savedSalutation\r\n-}\r\n-\r\n-const read = (Salutation) => async (filter) => {\r\n-  const foundSalutation = await Salutation.findOne({\r\n-    ...filter,\r\n-    deleted: false,\r\n-  })\r\n-  return foundSalutation\r\n-}\r\n-\r\n-const find = (Salutation) => async (filter) => {\r\n-  const foundSalutations = await Salutation.find({\r\n-    ...filter,\r\n-    deleted: false,\r\n-  })\r\n-  return foundSalutations\r\n-}\r\n-\r\n-const update = (Salutation) => async (salutation, userId) => {\r\n-  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n-    { _id: salutation._id, userId },\r\n-    salutation,\r\n-    { new: true }\r\n-  )\r\n-  return updatedSalutation\r\n-}\r\n-\r\n-const modify = (Salutation) => async (salutation) => {\r\n-  const findQuery = salutation._id\r\n-    ? { _id: salutation._id }\r\n-    : { transcriptId: salutation.transcriptId }\r\n-\r\n-  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n-    findQuery,\r\n-    salutation,\r\n-    { new: true }\r\n-  )\r\n-  return updatedSalutation\r\n-}\r\n-\r\n-const updateOrCreate =\r\n-  (Salutation) =>\r\n-  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\r\n-    const salutation = await read(Salutation)({\r\n-      firstName,\r\n-      userAudioProfileId,\r\n-      userId,\r\n-    })\r\n-    if (salutation) {\r\n-      salutation.salutationVideo = salutationVideo\r\n-      return await update(Salutation)(salutation, userId)\r\n-    } else {\r\n-      return await create(Salutation)(\r\n-        { firstName, salutationVideo, userAudioProfileId },\r\n-        userId\r\n-      )\r\n-    }\r\n-  }\r\n-\r\n-const remove = (Salutation) => async (filter, userId) => {\r\n-  const updatedSalutation = await Salutation.findOneAndUpdate(\r\n-    { ...filter, userId },\r\n-    {\r\n-      $set: {\r\n-        deleted: true,\r\n-      },\r\n-    },\r\n-    { new: true }\r\n-  )\r\n-  return updatedSalutation\r\n-}\r\n-\r\n-module.exports = (Salutation) => {\r\n-  return {\r\n-    create: create(Salutation),\r\n-    read: read(Salutation),\r\n-    remove: remove(Salutation),\r\n-    update: update(Salutation),\r\n-    updateOrCreate: updateOrCreate(Salutation),\r\n-    find: find(Salutation),\r\n-    modify: modify(Salutation),\r\n-  }\r\n-}\r\n+const {\n+  assignToUser,\n+  scopeToUser,\n+  withoutTenantIdentity,\n+} = require('../../app/services/utils/tenantScope')\n+\n+const create = (Salutation) => async (salutationData, userId) => {\n+  const newSalutation = new Salutation(assignToUser(salutationData, userId))\n+  const savedSalutation = await newSalutation.save()\n+  return savedSalutation\n+}\n+\n+const read = (Salutation) => async (filter, userId) => {\n+  const foundSalutation = await Salutation.findOne({\n+    ...scopeToUser(filter, userId),\n+    deleted: false,\n+  })\n+  return foundSalutation\n+}\n+\n+const find = (Salutation) => async (filter, userId) => {\n+  const foundSalutations = await Salutation.find({\n+    ...scopeToUser(filter, userId),\n+    deleted: false,\n+  })\n+  return foundSalutations\n+}\n+\n+const update = (Salutation) => async (salutation, userId) => {\n+  const updates = withoutTenantIdentity(salutation)\n+  const updatedSalutation = await Salutation.findOneAndUpdate(\n+    {\n+      ...scopeToUser({ _id: salutation._id }, userId),\n+      deleted: false,\n+    },\n+    updates,\n+    { new: true }\n+  )\n+  return updatedSalutation\n+}\n+\n+const modify = (Salutation) => async (salutation, userId) => {\n+  const findQuery = salutation._id\n+    ? { _id: salutation._id }\n+    : { transcriptId: salutation.transcriptId }\n+  const updates = withoutTenantIdentity(salutation)\n+\n+  const updatedSalutation = await Salutation.findOneAndUpdate(\n+    {\n+      ...scopeToUser(findQuery, userId),\n+      deleted: false,\n+    },\n+    updates,\n+    { new: true }\n+  )\n+  return updatedSalutation\n+}\n+\n+const updateOrCreate =\n+  (Salutation) =>\n+  async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {\n+    const salutation = await read(Salutation)(\n+      {\n+        firstName,\n+        userAudioProfileId,\n+      },\n+      userId\n+    )\n+    if (salutation) {\n+      return await update(Salutation)(\n+        { _id: salutation._id, salutationVideo },\n+        userId\n+      )\n+    } else {\n+      return await create(Salutation)(\n+        { firstName, salutationVideo, userAudioProfileId },\n+        userId\n+      )\n+    }\n+  }\n+\n+const remove = (Salutation) => async (filter, userId) => {\n+  const updatedSalutation = await Salutation.findOneAndUpdate(\n+    {\n+      ...scopeToUser(filter, userId),\n+      deleted: false,\n+    },\n+    {\n+      $set: {\n+        deleted: true,\n+      },\n+    },\n+    { new: true }\n+  )\n+  return updatedSalutation\n+}\n+\n+module.exports = (Salutation) => {\n+  return {\n+    create: create(Salutation),\n+    read: read(Salutation),\n+    remove: remove(Salutation),\n+    update: update(Salutation),\n+    updateOrCreate: updateOrCreate(Salutation),\n+    find: find(Salutation),\n+    modify: modify(Salutation),\n+  }\n+}\ndiff --git a/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js b/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\nindex 18416d7..546a728 100644\n--- a/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n+++ b/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n@@ -1,8 +1,13 @@\n const StringifyUtils = require('../../app/services/utils/logService')\n+const {\n+  assignToUser,\n+  scopeToUser,\n+  withoutTenantIdentity,\n+} = require('../../app/services/utils/tenantScope')\n \n-const create = (UserAudioProfileModel) => async (data) => {\n+const create = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n-    const newModel = new UserAudioProfileModel({ ...data })\n+    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\n     const savedModel = await newModel.save()\n     return savedModel\n   } catch (error) {\n@@ -15,9 +20,11 @@ const create = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const insertMany = (UserAudioProfileModel) => async (data) => {\n+const insertMany = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n-    const inserted = await UserAudioProfileModel.insertMany(data)\n+    const inserted = await UserAudioProfileModel.insertMany(\n+      data.map((item) => assignToUser(item, userId))\n+    )\n     return inserted\n   } catch (error) {\n     const details = { data }\n@@ -29,10 +36,10 @@ const insertMany = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const read = (UserAudioProfileModel) => async (filter) => {\n+const read = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const foundModel = await UserAudioProfileModel.findOne({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false\n     })\n     return foundModel\n@@ -46,10 +53,10 @@ const read = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const find = (UserAudioProfileModel) => async (filter) => {\n+const find = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const foundModels = await UserAudioProfileModel.find({\n-      ...filter,\n+      ...scopeToUser(filter, userId),\n       deleted: false\n     })\n     return foundModels\n@@ -63,17 +70,19 @@ const find = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const update = (UserAudioProfileModel) => async (data) => {\n-  console.log('ua data', data)\n+const update = (UserAudioProfileModel) => async (data, userId) => {\n   try {\n+    const updates = withoutTenantIdentity(data)\n     const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n-      { _id: data._id },\n-      data,\n+      {\n+        ...scopeToUser({ _id: data._id }, userId),\n+        deleted: false\n+      },\n+      updates,\n       {\n         new: true\n       }\n     )\n-    console.log('ua updatedModel', updatedModel)\n     return updatedModel\n   } catch (error) {\n     const details = { data }\n@@ -85,10 +94,13 @@ const update = (UserAudioProfileModel) => async (data) => {\n   }\n }\n \n-const remove = (UserAudioProfileModel) => async (filter) => {\n+const remove = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false\n+      },\n       {\n         $set: {\n           deleted: true\n@@ -107,10 +119,13 @@ const remove = (UserAudioProfileModel) => async (filter) => {\n   }\n }\n \n-const removeMany = (UserAudioProfileModel) => async (filter) => {\n+const removeMany = (UserAudioProfileModel) => async (filter, userId) => {\n   try {\n     const updatedModel = await UserAudioProfileModel.updateMany(\n-      { ...filter },\n+      {\n+        ...scopeToUser(filter, userId),\n+        deleted: false\n+      },\n       {\n         $set: {\n           deleted: true\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_39","type":"command_execution","command":"/bin/bash -lc \"rg -n -U \\\"findOne\\\\(\\\\{[\"'^}]*_id:[''^}]*'\"\\\\}\\\\)|findOneAndUpdate\\\\(\\\\s*\\\\{[\"'^}]*_id:[''^}]*'\"\\\\}\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_39","type":"command_execution","command":"/bin/bash -lc \"rg -n -U \\\"findOne\\\\(\\\\{[\"'^}]*_id:[''^}]*'\"\\\\}\\\\)|findOneAndUpdate\\\\(\\\\s*\\\\{[\"'^}]*_id:[''^}]*'\"\\\\}\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js:31:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js:32:    {\nvoice-synthsizer-job-handler/salutation/salutation_service.js:33:      ...scopeToUser({ _id: salutation._id }, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:76:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:77:      {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:78:        ...scopeToUser({ _id: data._id }, userId),\nvoice-synthsizer-job-handler/index.js:107:        recordingSalutationModel.findOne({\nvoice-synthsizer-job-handler/index.js:108:          _id: salutationId,\nvoice-synthsizer-job-handler/index.js:109:          userId,\nvoice-synthsizer-job-handler/index.js:110:          deleted: false,\nvoice-synthsizer-job-handler/index.js:111:        }),\nvoice-synthsizer-job-handler/index.js:112:        recordingModel.findOne({\nvoice-synthsizer-job-handler/index.js:113:          _id: recordingId,\nvoice-synthsizer-job-handler/index.js:114:          userId,\nvoice-synthsizer-job-handler/index.js:115:          deleted: false,\nvoice-synthsizer-job-handler/index.js:116:        }),\nvoice-synthsizer-job-handler/index.js:183:      await recordingSalutationModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/index.js:184:        {\nvoice-synthsizer-job-handler/index.js:185:          _id: salutationId,\nvoice-synthsizer-job-handler/index.js:186:          userId,\nvoice-synthsizer-job-handler/index.js:187:          deleted: false,\nvoice-synthsizer-job-handler/index.js:188:        },\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:77:      {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:78:        ...scopeToUser({ _id: data._id }, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:77:      {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:78:        ...scopeToUser({ _id: data._id }, userId),\nvoice-synthsizer-job-handler/job/job_service.js:76:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:77:      {\nvoice-synthsizer-job-handler/job/job_service.js:78:        ...scopeToUser({ _id: job._id }, userId),\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_40","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"(voiceCloningService|userAudioProfileService|salutationService|jobService)\\\\.(create|insertMany|read|find|update|remove|removeMany|modify|updateOrCreate)\\\" . -g '\"'!node_modules/**'\"'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_40","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"(voiceCloningService|userAudioProfileService|salutationService|jobService)\\\\.(create|insertMany|read|find|update|remove|removeMany|modify|updateOrCreate)\\\" . -g '\"'!node_modules/**'\"'\"","aggregated_output":"./voice-synthsizer-job-handler/index.js:103:        userAudioProfileService.read(\n./voice-synthsizer-job-handler/index.js:173:    await salutationService.updateOrCreate(\n./voice-synthsizer-job-handler/index.js:223:    await jobService.insertMany(\n./voice-cloning-job-handler/index.js:133:      voiceCloningService.read(\n./voice-cloning-job-handler/index.js:137:      userAudioProfileService.read({ _id: userAudioProfileId }, userId),\n./voice-cloning-job-handler/index.js:170:      voiceCloningService.update(\n./voice-cloning-job-handler/index.js:174:      userAudioProfileService.update(\n./voice-cloning-job-handler/index.js:274:    await voiceCloningService.update(\n./voice-cloning-job-handler/index.js:287:    await userAudioProfileService.update(\n./voice-cloning-job-handler/index.js:310:    await userAudioProfileService.update(\n./voice-cloning-job-handler/index.js:324:        voiceCloningService.update(\n./voice-cloning-job-handler/index.js:328:        userAudioProfileService.update(\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_41","type":"command_execution","command":"/bin/bash -lc 'for f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js; do node --check \"$f\" || exit 1; done\ngit diff --check'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_41","type":"command_execution","command":"/bin/bash -lc 'for f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js; do node --check \"$f\" || exit 1; done\ngit diff --check'","aggregated_output":"","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_42","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst tenantId = 'tenant-a'\nconst calls = {}\n\nfunction FakeModel(data) {\n  calls.constructed = data\n  this.save = async () => data\n}\nFakeModel.findOne = async (filter) => {\n  calls.findOne = filter\n  return filter\n}\nFakeModel.find = async (filter) => {\n  calls.find = filter\n  return [filter]\n}\nFakeModel.findOneAndUpdate = async (filter, update, options) => {\n  calls.findOneAndUpdate = { filter, update, options }\n  return { filter, update }\n}\nFakeModel.updateMany = async (filter, update) => {\n  calls.updateMany = { filter, update }\n  return calls.updateMany\n}\nFakeModel.insertMany = async (documents) => {\n  calls.insertMany = documents\n  return documents\n}\n\nconst serviceFactories = [\n  require('./voice-cloning-job-handler/voice_cloning/voice_cloning_service'),\n  require('./voice-cloning-job-handler/user_audio_profile/user_audio_profile_service'),\n  require('./voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service'),\n  require('./voice-synthsizer-job-handler/job/job_service'),\n]\n\n;(async () => {\n  for (const makeService of serviceFactories) {\n    const service = makeService(FakeModel)\n    await service.read({ _id: 'record-a', userId: 'tenant-b' }, tenantId)\n    assert.deepStrictEqual(calls.findOne, {\n      _id: 'record-a',\n      userId: tenantId,\n      deleted: false,\n    })\n\n    await service.update(\n      { _id: 'record-a', userId: 'tenant-b', status: 'completed' },\n      tenantId\n    )\n    assert.deepStrictEqual(calls.findOneAndUpdate.filter, {\n      _id: 'record-a',\n      userId: tenantId,\n      deleted: false,\n    })\n    assert.deepStrictEqual(calls.findOneAndUpdate.update, {\n      status: 'completed',\n    })\n\n    await assert.rejects(service.read({ _id: 'record-a' }), /userId is required/)\n  }\n\n  const salutationService = require('./voice-synthsizer-job-handler/salutation/salutation_service')(FakeModel)\n  await salutationService.modify(\n    { _id: 'salutation-a', userId: 'tenant-b', salutationVideo: 'video' },\n    tenantId\n  )\n  assert.deepStrictEqual(calls.findOneAndUpdate.filter, {\n    _id: 'salutation-a',\n    userId: tenantId,\n    deleted: false,\n  })\n  assert.deepStrictEqual(calls.findOneAndUpdate.update, {\n    salutationVideo: 'video',\n  })\n\n  await salutationService.create({ userId: 'tenant-b', firstName: 'Ada' }, tenantId)\n  assert.strictEqual(calls.constructed.userId, tenantId)\n\n  console.log('tenant service assertions passed')\n})().catch((error) => {\n  console.error(error)\n  process.exitCode = 1\n})\nNODE\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_42","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst tenantId = 'tenant-a'\nconst calls = {}\n\nfunction FakeModel(data) {\n  calls.constructed = data\n  this.save = async () => data\n}\nFakeModel.findOne = async (filter) => {\n  calls.findOne = filter\n  return filter\n}\nFakeModel.find = async (filter) => {\n  calls.find = filter\n  return [filter]\n}\nFakeModel.findOneAndUpdate = async (filter, update, options) => {\n  calls.findOneAndUpdate = { filter, update, options }\n  return { filter, update }\n}\nFakeModel.updateMany = async (filter, update) => {\n  calls.updateMany = { filter, update }\n  return calls.updateMany\n}\nFakeModel.insertMany = async (documents) => {\n  calls.insertMany = documents\n  return documents\n}\n\nconst serviceFactories = [\n  require('./voice-cloning-job-handler/voice_cloning/voice_cloning_service'),\n  require('./voice-cloning-job-handler/user_audio_profile/user_audio_profile_service'),\n  require('./voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service'),\n  require('./voice-synthsizer-job-handler/job/job_service'),\n]\n\n;(async () => {\n  for (const makeService of serviceFactories) {\n    const service = makeService(FakeModel)\n    await service.read({ _id: 'record-a', userId: 'tenant-b' }, tenantId)\n    assert.deepStrictEqual(calls.findOne, {\n      _id: 'record-a',\n      userId: tenantId,\n      deleted: false,\n    })\n\n    await service.update(\n      { _id: 'record-a', userId: 'tenant-b', status: 'completed' },\n      tenantId\n    )\n    assert.deepStrictEqual(calls.findOneAndUpdate.filter, {\n      _id: 'record-a',\n      userId: tenantId,\n      deleted: false,\n    })\n    assert.deepStrictEqual(calls.findOneAndUpdate.update, {\n      status: 'completed',\n    })\n\n    await assert.rejects(service.read({ _id: 'record-a' }), /userId is required/)\n  }\n\n  const salutationService = require('./voice-synthsizer-job-handler/salutation/salutation_service')(FakeModel)\n  await salutationService.modify(\n    { _id: 'salutation-a', userId: 'tenant-b', salutationVideo: 'video' },\n    tenantId\n  )\n  assert.deepStrictEqual(calls.findOneAndUpdate.filter, {\n    _id: 'salutation-a',\n    userId: tenantId,\n    deleted: false,\n  })\n  assert.deepStrictEqual(calls.findOneAndUpdate.update, {\n    salutationVideo: 'video',\n  })\n\n  await salutationService.create({ userId: 'tenant-b', firstName: 'Ada' }, tenantId)\n  assert.strictEqual(calls.constructed.userId, tenantId)\n\n  console.log('tenant service assertions passed')\n})().catch((error) => {\n  console.error(error)\n  process.exitCode = 1\n})\nNODE\"","aggregated_output":"ERROR - VOICE CLONING SERVICE > read {\"error\":\"{\\\"stack\\\":\\\"TypeError: userId is required for tenant-scoped database access\\\\n    at requireUserId (/workspace/app/services/utils/tenantScope.js:3:11)\\\\n    at scopeToUser (/workspace/app/services/utils/tenantScope.js:11:11)\\\\n    at Object.read (/workspace/voice-cloning-job-handler/voice_cloning/voice_cloning_service.js:42:10)\\\\n    at [stdin]:60:34\\\\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\\\",\\\"message\\\":\\\"userId is required for tenant-scoped database access\\\"}\",\"details\":{\"filter\":{\"_id\":\"record-a\"}}}\nERROR - USER AUDIO PROFILE SERVICE > read {\"error\":\"{\\\"stack\\\":\\\"TypeError: userId is required for tenant-scoped database access\\\\n    at requireUserId (/workspace/app/services/utils/tenantScope.js:3:11)\\\\n    at scopeToUser (/workspace/app/services/utils/tenantScope.js:11:11)\\\\n    at Object.read (/workspace/voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:42:10)\\\\n    at [stdin]:60:34\\\\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\\\",\\\"message\\\":\\\"userId is required for tenant-scoped database access\\\"}\",\"details\":{\"filter\":{\"_id\":\"record-a\"}}}\nERROR - USER AUDIO PROFILE SERVICE > read {\"error\":\"{\\\"stack\\\":\\\"TypeError: userId is required for tenant-scoped database access\\\\n    at requireUserId (/workspace/app/services/utils/tenantScope.js:3:11)\\\\n    at scopeToUser (/workspace/app/services/utils/tenantScope.js:11:11)\\\\n    at Object.read (/workspace/voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:42:10)\\\\n    at [stdin]:60:34\\\\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\\\",\\\"message\\\":\\\"userId is required for tenant-scoped database access\\\"}\",\"details\":{\"filter\":{\"_id\":\"record-a\"}}}\nERROR - JOB SERVICE > read {\"error\":\"{\\\"stack\\\":\\\"TypeError: userId is required for tenant-scoped database access\\\\n    at requireUserId (/workspace/app/services/utils/tenantScope.js:3:11)\\\\n    at scopeToUser (/workspace/app/services/utils/tenantScope.js:11:11)\\\\n    at Object.read (/workspace/voice-synthsizer-job-handler/job/job_service.js:42:10)\\\\n    at [stdin]:60:34\\\\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\\\",\\\"message\\\":\\\"userId is required for tenant-scoped database access\\\"}\",\"details\":{\"filter\":{\"_id\":\"record-a\"}}}\ntenant service assertions passed\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_43","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst voiceCloningService = require('./voice-cloning-job-handler/voice_cloning')\nconst userAudioProfileService = require('./voice-cloning-job-handler/user_audio_profile')\n\nconst userId = '64b000000000000000000001'\nconst cloningId = '64b000000000000000000002'\nconst profileId = '64b000000000000000000003'\nlet acknowledged = false\nlet cloningRead\nlet profileRead\n\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [\n    {\n      ReceiptHandle: 'receipt',\n      Body: JSON.stringify({\n        _doc: { _id: cloningId, userAudioProfileId: profileId, userId },\n        env: 'staging',\n      }),\n    },\n  ],\n})\nsqs.deleteMessageFromSQS = async () => {\n  acknowledged = true\n}\nmongoose.connect = async () => mongoose\nvoiceCloningService.read = async (filter, tenant) => {\n  cloningRead = { filter, tenant }\n  return null\n}\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\n\nconst { processQueue } = require('./voice-cloning-job-handler/index')\n\nprocessQueue()\n  .then(() => {\n    assert.strictEqual(acknowledged, true)\n    assert.deepStrictEqual(cloningRead, {\n      filter: { _id: cloningId, userAudioProfileId: profileId },\n      tenant: userId,\n    })\n    assert.deepStrictEqual(profileRead, {\n      filter: { _id: profileId },\n      tenant: userId,\n    })\n    console.log('cloning rejection assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst sqs = require('./app/services/sqs')\nlet acknowledged = false\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [{ ReceiptHandle: 'receipt', Body: '{not-json' }],\n})\nsqs.deleteMessageFromSQS = async () => {\n  acknowledged = true\n}\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue()\n  .then(() => {\n    assert.strictEqual(acknowledged, true)\n    console.log('malformed synthesizer job assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_43","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst voiceCloningService = require('./voice-cloning-job-handler/voice_cloning')\nconst userAudioProfileService = require('./voice-cloning-job-handler/user_audio_profile')\n\nconst userId = '64b000000000000000000001'\nconst cloningId = '64b000000000000000000002'\nconst profileId = '64b000000000000000000003'\nlet acknowledged = false\nlet cloningRead\nlet profileRead\n\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [\n    {\n      ReceiptHandle: 'receipt',\n      Body: JSON.stringify({\n        _doc: { _id: cloningId, userAudioProfileId: profileId, userId },\n        env: 'staging',\n      }),\n    },\n  ],\n})\nsqs.deleteMessageFromSQS = async () => {\n  acknowledged = true\n}\nmongoose.connect = async () => mongoose\nvoiceCloningService.read = async (filter, tenant) => {\n  cloningRead = { filter, tenant }\n  return null\n}\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\n\nconst { processQueue } = require('./voice-cloning-job-handler/index')\n\nprocessQueue()\n  .then(() => {\n    assert.strictEqual(acknowledged, true)\n    assert.deepStrictEqual(cloningRead, {\n      filter: { _id: cloningId, userAudioProfileId: profileId },\n      tenant: userId,\n    })\n    assert.deepStrictEqual(profileRead, {\n      filter: { _id: profileId },\n      tenant: userId,\n    })\n    console.log('cloning rejection assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst sqs = require('./app/services/sqs')\nlet acknowledged = false\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [{ ReceiptHandle: 'receipt', Body: '{not-json' }],\n})\nsqs.deleteMessageFromSQS = async () => {\n  acknowledged = true\n}\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue()\n  .then(() => {\n    assert.strictEqual(acknowledged, true)\n    console.log('malformed synthesizer job assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\"","aggregated_output":"Connection Attempt :  0\nConnected to Mongo DB !\nRejected voice cloning job: Voice cloning job records were not found for the supplied userId\ncloning rejection assertions passed\nRejected voice synthesizer job: Queue message body is not valid JSON\nmalformed synthesizer job assertions passed\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_44","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst userAudioProfileService = require('./voice-synthsizer-job-handler/user_audio_profile')\nconst recordingModel = require('./voice-synthsizer-job-handler/recording')\nconst recordingSalutationModel = require('./voice-synthsizer-job-handler/recording_salutation')\n\nconst userId = '64b000000000000000000001'\nconst profileId = '64b000000000000000000002'\nconst salutationId = '64b000000000000000000003'\nconst recordingId = '64b000000000000000000004'\nlet profileRead\nlet salutationRead\nlet recordingRead\n\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [\n    {\n      ReceiptHandle: 'receipt',\n      Body: JSON.stringify({\n        userId,\n        userAudioProfileId: profileId,\n        salutationId,\n        recordingId,\n        text: 'Hello',\n        firstName: 'Ada',\n        env: 'staging',\n      }),\n    },\n  ],\n})\nsqs.deleteMessageFromSQS = async () => undefined\nmongoose.connect = async () => mongoose\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\nrecordingSalutationModel.findOne = async (filter) => {\n  salutationRead = filter\n  return null\n}\nrecordingModel.findOne = async (filter) => {\n  recordingRead = filter\n  return null\n}\n\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue()\n  .then(() => {\n    assert.deepStrictEqual(profileRead, {\n      filter: { _id: profileId, status: 'completed' },\n      tenant: userId,\n    })\n    assert.deepStrictEqual(salutationRead, {\n      _id: salutationId,\n      userId,\n      deleted: false,\n    })\n    assert.deepStrictEqual(recordingRead, {\n      _id: recordingId,\n      userId,\n      deleted: false,\n    })\n    console.log('synthesizer authorization assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_44","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst userAudioProfileService = require('./voice-synthsizer-job-handler/user_audio_profile')\nconst recordingModel = require('./voice-synthsizer-job-handler/recording')\nconst recordingSalutationModel = require('./voice-synthsizer-job-handler/recording_salutation')\n\nconst userId = '64b000000000000000000001'\nconst profileId = '64b000000000000000000002'\nconst salutationId = '64b000000000000000000003'\nconst recordingId = '64b000000000000000000004'\nlet profileRead\nlet salutationRead\nlet recordingRead\n\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [\n    {\n      ReceiptHandle: 'receipt',\n      Body: JSON.stringify({\n        userId,\n        userAudioProfileId: profileId,\n        salutationId,\n        recordingId,\n        text: 'Hello',\n        firstName: 'Ada',\n        env: 'staging',\n      }),\n    },\n  ],\n})\nsqs.deleteMessageFromSQS = async () => undefined\nmongoose.connect = async () => mongoose\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\nrecordingSalutationModel.findOne = async (filter) => {\n  salutationRead = filter\n  return null\n}\nrecordingModel.findOne = async (filter) => {\n  recordingRead = filter\n  return null\n}\n\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue()\n  .then(() => {\n    assert.deepStrictEqual(profileRead, {\n      filter: { _id: profileId, status: 'completed' },\n      tenant: userId,\n    })\n    assert.deepStrictEqual(salutationRead, {\n      _id: salutationId,\n      userId,\n      deleted: false,\n    })\n    assert.deepStrictEqual(recordingRead, {\n      _id: recordingId,\n      userId,\n      deleted: false,\n    })\n    console.log('synthesizer authorization assertions passed')\n  })\n  .catch((error) => {\n    console.error(error)\n    process.exitCode = 1\n  })\nNODE\"","aggregated_output":"Connection Attempt :  0\nConnected to Mongo DB !\nRejected voice synthesizer job: Synthesizer job records were not found for the supplied userId\nsynthesizer authorization assertions passed\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_45","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_45","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_46","type":"file_change","changes":[{"path":"/workspace/app/services/utils/jobValidation.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_46","type":"file_change","changes":[{"path":"/workspace/app/services/utils/jobValidation.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_47","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_47","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"}],"status":"completed"}}
{"type":"item.completed","item":{"id":"item_48","type":"agent_message","text":"The first verification pass is clean, including mocked cross-tenant filters and malformed-message containment. I’m tightening acknowledgment timing so malformed/unauthorized messages are removed, while transient database failures remain retryable and valid jobs retain the workers’ existing pre-processing acknowledgment behavior."}}
{"type":"item.started","item":{"id":"item_49","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/index.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_49","type":"file_change","changes":[{"path":"/workspace/voice-cloning-job-handler/index.js","kind":"update"},{"path":"/workspace/voice-synthsizer-job-handler/index.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_50","type":"command_execution","command":"/bin/bash -lc 'cat README.md && wc -l README.md && git diff --check && git status --short'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_50","type":"command_execution","command":"/bin/bash -lc 'cat README.md && wc -l README.md && git diff --check && git status --short'","aggregated_output":"# potion-voice\nPotion's Text-to-Speech Service (multi-speaker baseline model training, voice cloning and speech synthesising)\n2 README.md\n M voice-cloning-job-handler/index.js\n M voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n M voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n M voice-synthsizer-job-handler/index.js\n M voice-synthsizer-job-handler/job/job_service.js\n M voice-synthsizer-job-handler/salutation/salutation_service.js\n M voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n?? app/services/utils/jobValidation.js\n?? app/services/utils/tenantScope.js\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_51","type":"command_execution","command":"/bin/bash -lc 'git diff --stat && git status --short'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_51","type":"command_execution","command":"/bin/bash -lc 'git diff --stat && git status --short'","aggregated_output":" voice-cloning-job-handler/index.js                 | 532 ++++++++++++---------\n .../user_audio_profile_service.js                  |  47 +-\n .../voice_cloning/voice_cloning_service.js         |  47 +-\n voice-synthsizer-job-handler/index.js              | 401 +++++++++-------\n voice-synthsizer-job-handler/job/job_service.js    |  53 +-\n .../salutation/salutation_service.js               | 195 ++++----\n .../user_audio_profile_service.js                  |  49 +-\n 7 files changed, 757 insertions(+), 567 deletions(-)\n M voice-cloning-job-handler/index.js\n M voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n M voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n M voice-synthsizer-job-handler/index.js\n M voice-synthsizer-job-handler/job/job_service.js\n M voice-synthsizer-job-handler/salutation/salutation_service.js\n M voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n?? app/services/utils/jobValidation.js\n?? app/services/utils/tenantScope.js\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_52","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(findOne|find|findOneAndUpdate|updateMany|insertMany|save)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js' -C 4\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_52","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(findOne|find|findOneAndUpdate|updateMany|insertMany|save)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js' -C 4\"","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js-5-} = require('../../app/services/utils/tenantScope')\nvoice-synthsizer-job-handler/salutation/salutation_service.js-6-\nvoice-synthsizer-job-handler/salutation/salutation_service.js-7-const create = (Salutation) => async (salutationData, userId) => {\nvoice-synthsizer-job-handler/salutation/salutation_service.js-8-  const newSalutation = new Salutation(assignToUser(salutationData, userId))\nvoice-synthsizer-job-handler/salutation/salutation_service.js:9:  const savedSalutation = await newSalutation.save()\nvoice-synthsizer-job-handler/salutation/salutation_service.js-10-  return savedSalutation\nvoice-synthsizer-job-handler/salutation/salutation_service.js-11-}\nvoice-synthsizer-job-handler/salutation/salutation_service.js-12-\nvoice-synthsizer-job-handler/salutation/salutation_service.js-13-const read = (Salutation) => async (filter, userId) => {\nvoice-synthsizer-job-handler/salutation/salutation_service.js:14:  const foundSalutation = await Salutation.findOne({\nvoice-synthsizer-job-handler/salutation/salutation_service.js-15-    ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/salutation/salutation_service.js-16-    deleted: false,\nvoice-synthsizer-job-handler/salutation/salutation_service.js-17-  })\nvoice-synthsizer-job-handler/salutation/salutation_service.js-18-  return foundSalutation\nvoice-synthsizer-job-handler/salutation/salutation_service.js-19-}\nvoice-synthsizer-job-handler/salutation/salutation_service.js-20-\nvoice-synthsizer-job-handler/salutation/salutation_service.js-21-const find = (Salutation) => async (filter, userId) => {\nvoice-synthsizer-job-handler/salutation/salutation_service.js:22:  const foundSalutations = await Salutation.find({\nvoice-synthsizer-job-handler/salutation/salutation_service.js-23-    ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/salutation/salutation_service.js-24-    deleted: false,\nvoice-synthsizer-job-handler/salutation/salutation_service.js-25-  })\nvoice-synthsizer-job-handler/salutation/salutation_service.js-26-  return foundSalutations\nvoice-synthsizer-job-handler/salutation/salutation_service.js-27-}\nvoice-synthsizer-job-handler/salutation/salutation_service.js-28-\nvoice-synthsizer-job-handler/salutation/salutation_service.js-29-const update = (Salutation) => async (salutation, userId) => {\nvoice-synthsizer-job-handler/salutation/salutation_service.js-30-  const updates = withoutTenantIdentity(salutation)\nvoice-synthsizer-job-handler/salutation/salutation_service.js:31:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js-32-    {\nvoice-synthsizer-job-handler/salutation/salutation_service.js-33-      ...scopeToUser({ _id: salutation._id }, userId),\nvoice-synthsizer-job-handler/salutation/salutation_service.js-34-      deleted: false,\nvoice-synthsizer-job-handler/salutation/salutation_service.js-35-    },\n--\nvoice-synthsizer-job-handler/salutation/salutation_service.js-44-    ? { _id: salutation._id }\nvoice-synthsizer-job-handler/salutation/salutation_service.js-45-    : { transcriptId: salutation.transcriptId }\nvoice-synthsizer-job-handler/salutation/salutation_service.js-46-  const updates = withoutTenantIdentity(salutation)\nvoice-synthsizer-job-handler/salutation/salutation_service.js-47-\nvoice-synthsizer-job-handler/salutation/salutation_service.js:48:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js-49-    {\nvoice-synthsizer-job-handler/salutation/salutation_service.js-50-      ...scopeToUser(findQuery, userId),\nvoice-synthsizer-job-handler/salutation/salutation_service.js-51-      deleted: false,\nvoice-synthsizer-job-handler/salutation/salutation_service.js-52-    },\n--\nvoice-synthsizer-job-handler/salutation/salutation_service.js-79-    }\nvoice-synthsizer-job-handler/salutation/salutation_service.js-80-  }\nvoice-synthsizer-job-handler/salutation/salutation_service.js-81-\nvoice-synthsizer-job-handler/salutation/salutation_service.js-82-const remove = (Salutation) => async (filter, userId) => {\nvoice-synthsizer-job-handler/salutation/salutation_service.js:83:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js-84-    {\nvoice-synthsizer-job-handler/salutation/salutation_service.js-85-      ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/salutation/salutation_service.js-86-      deleted: false,\nvoice-synthsizer-job-handler/salutation/salutation_service.js-87-    },\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-7-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-8-const create = (VoiceCloningModel) => async (data, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-9-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-10-    const newModel = new VoiceCloningModel(assignToUser(data, userId))\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:11:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-12-    return savedModel\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-13-  } catch (error) {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-14-    const details = { data }\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-15-    console.log(\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-21-}\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-22-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-23-const insertMany = (VoiceCloningModel) => async (data, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-24-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:25:    const inserted = await VoiceCloningModel.insertMany(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-26-      data.map((item) => assignToUser(item, userId))\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-27-    )\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-28-    return inserted\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-29-  } catch (error) {\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-37-}\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-38-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-39-const read = (VoiceCloningModel) => async (filter, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-40-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:41:    const foundModel = await VoiceCloningModel.findOne({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-42-      ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-43-      deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-44-    })\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-45-    return foundModel\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-54-}\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-55-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-56-const find = (VoiceCloningModel) => async (filter, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-57-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:58:    const foundModels = await VoiceCloningModel.find({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-59-      ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-60-      deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-61-    })\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-62-    return foundModels\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-72-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-73-const update = (VoiceCloningModel) => async (data, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-74-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-75-    const updates = withoutTenantIdentity(data)\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:76:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-77-      {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-78-        ...scopeToUser({ _id: data._id }, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-79-        deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-80-      },\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-96-}\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-97-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-98-const remove = (VoiceCloningModel) => async (filter, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-99-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:100:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-101-      {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-102-        ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-103-        deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-104-      },\n--\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-121-}\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-122-\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-123-const removeMany = (VoiceCloningModel) => async (filter, userId) => {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-124-  try {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:125:    const updatedModel = await VoiceCloningModel.updateMany(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-126-      {\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-127-        ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-128-        deleted: false,\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js-129-      },\n--\nvoice-synthsizer-job-handler/index.js-110-        userAudioProfileService.read(\nvoice-synthsizer-job-handler/index.js-111-          { _id: userAudioProfileId, status: 'completed' },\nvoice-synthsizer-job-handler/index.js-112-          userId\nvoice-synthsizer-job-handler/index.js-113-        ),\nvoice-synthsizer-job-handler/index.js:114:        recordingSalutationModel.findOne({\nvoice-synthsizer-job-handler/index.js-115-          _id: salutationId,\nvoice-synthsizer-job-handler/index.js-116-          userId,\nvoice-synthsizer-job-handler/index.js-117-          deleted: false,\nvoice-synthsizer-job-handler/index.js-118-        }),\nvoice-synthsizer-job-handler/index.js:119:        recordingModel.findOne({\nvoice-synthsizer-job-handler/index.js-120-          _id: recordingId,\nvoice-synthsizer-job-handler/index.js-121-          userId,\nvoice-synthsizer-job-handler/index.js-122-          deleted: false,\nvoice-synthsizer-job-handler/index.js-123-        }),\n--\nvoice-synthsizer-job-handler/index.js-190-      userId\nvoice-synthsizer-job-handler/index.js-191-    )\nvoice-synthsizer-job-handler/index.js-192-\nvoice-synthsizer-job-handler/index.js-193-    const updatedSalutation =\nvoice-synthsizer-job-handler/index.js:194:      await recordingSalutationModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/index.js-195-        {\nvoice-synthsizer-job-handler/index.js-196-          _id: salutationId,\nvoice-synthsizer-job-handler/index.js-197-          userId,\nvoice-synthsizer-job-handler/index.js-198-          deleted: false,\n--\nvoice-synthsizer-job-handler/index.js-230-      salutation: updatedSalutation._id,\nvoice-synthsizer-job-handler/index.js-231-      dynamicVideoType: recordingToUpdate.dynamicVideoType,\nvoice-synthsizer-job-handler/index.js-232-    }\nvoice-synthsizer-job-handler/index.js-233-\nvoice-synthsizer-job-handler/index.js:234:    await jobService.insertMany(\nvoice-synthsizer-job-handler/index.js-235-      [\nvoice-synthsizer-job-handler/index.js-236-        {\nvoice-synthsizer-job-handler/index.js-237-          firstName,\nvoice-synthsizer-job-handler/index.js-238-          recordingId: recordingToUpdate._id,\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-7-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-8-const create = (UserAudioProfileModel) => async (data, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-9-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-10-    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:11:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-12-    return savedModel\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-13-  } catch (error) {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-14-    const details = { data }\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-15-    console.log(\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-21-}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-22-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-23-const insertMany = (UserAudioProfileModel) => async (data, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-24-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:25:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-26-      data.map((item) => assignToUser(item, userId))\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-27-    )\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-28-    return inserted\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-29-  } catch (error) {\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-37-}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-38-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-39-const read = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-40-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:41:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-42-      ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-43-      deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-44-    })\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-45-    return foundModel\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-54-}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-55-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-56-const find = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-57-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:58:    const foundModels = await UserAudioProfileModel.find({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-59-      ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-60-      deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-61-    })\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-62-    return foundModels\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-72-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-73-const update = (UserAudioProfileModel) => async (data, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-74-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-75-    const updates = withoutTenantIdentity(data)\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-77-      {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-78-        ...scopeToUser({ _id: data._id }, userId),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-79-        deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-80-      },\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-95-}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-96-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-97-const remove = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-98-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:99:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-100-      {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-101-        ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-102-        deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-103-      },\n--\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-120-}\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-121-\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-122-const removeMany = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-123-  try {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:124:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-125-      {\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-126-        ...scopeToUser(filter, userId),\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-127-        deleted: false,\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js-128-      },\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-7-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-8-const create = (UserAudioProfileModel) => async (data, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-9-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-10-    const newModel = new UserAudioProfileModel(assignToUser(data, userId))\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:11:    const savedModel = await newModel.save()\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-12-    return savedModel\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-13-  } catch (error) {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-14-    const details = { data }\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-15-    console.log(\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-21-}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-22-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-23-const insertMany = (UserAudioProfileModel) => async (data, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-24-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:25:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-26-      data.map((item) => assignToUser(item, userId))\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-27-    )\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-28-    return inserted\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-29-  } catch (error) {\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-37-}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-38-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-39-const read = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-40-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:41:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-42-      ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-43-      deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-44-    })\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-45-    return foundModel\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-54-}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-55-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-56-const find = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-57-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:58:    const foundModels = await UserAudioProfileModel.find({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-59-      ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-60-      deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-61-    })\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-62-    return foundModels\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-72-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-73-const update = (UserAudioProfileModel) => async (data, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-74-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-75-    const updates = withoutTenantIdentity(data)\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-77-      {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-78-        ...scopeToUser({ _id: data._id }, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-79-        deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-80-      },\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-95-}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-96-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-97-const remove = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-98-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:99:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-100-      {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-101-        ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-102-        deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-103-      },\n--\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-120-}\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-121-\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-122-const removeMany = (UserAudioProfileModel) => async (filter, userId) => {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-123-  try {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:124:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-125-      {\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-126-        ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-127-        deleted: false\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js-128-      },\n--\nvoice-synthsizer-job-handler/job/job_service.js-7-\nvoice-synthsizer-job-handler/job/job_service.js-8-const create = (Job) => async (jobData, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-9-  try {\nvoice-synthsizer-job-handler/job/job_service.js-10-    const newJob = new Job(assignToUser(jobData, userId))\nvoice-synthsizer-job-handler/job/job_service.js:11:    const savedJob = await newJob.save()\nvoice-synthsizer-job-handler/job/job_service.js-12-    return savedJob\nvoice-synthsizer-job-handler/job/job_service.js-13-  } catch (error) {\nvoice-synthsizer-job-handler/job/job_service.js-14-    const details = { jobData }\nvoice-synthsizer-job-handler/job/job_service.js-15-    console.log(\n--\nvoice-synthsizer-job-handler/job/job_service.js-21-}\nvoice-synthsizer-job-handler/job/job_service.js-22-\nvoice-synthsizer-job-handler/job/job_service.js-23-const insertMany = (Job) => async (jobData, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-24-  try {\nvoice-synthsizer-job-handler/job/job_service.js:25:    const inserted = await Job.insertMany(\nvoice-synthsizer-job-handler/job/job_service.js-26-      jobData.map((item) => assignToUser(item, userId))\nvoice-synthsizer-job-handler/job/job_service.js-27-    )\nvoice-synthsizer-job-handler/job/job_service.js-28-    return inserted\nvoice-synthsizer-job-handler/job/job_service.js-29-  } catch (error) {\n--\nvoice-synthsizer-job-handler/job/job_service.js-37-}\nvoice-synthsizer-job-handler/job/job_service.js-38-\nvoice-synthsizer-job-handler/job/job_service.js-39-const read = (Job) => async (filter, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-40-  try {\nvoice-synthsizer-job-handler/job/job_service.js:41:    const foundJob = await Job.findOne({\nvoice-synthsizer-job-handler/job/job_service.js-42-      ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/job/job_service.js-43-      deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js-44-    })\nvoice-synthsizer-job-handler/job/job_service.js-45-    return foundJob\n--\nvoice-synthsizer-job-handler/job/job_service.js-54-}\nvoice-synthsizer-job-handler/job/job_service.js-55-\nvoice-synthsizer-job-handler/job/job_service.js-56-const find = (Job) => async (filter, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-57-  try {\nvoice-synthsizer-job-handler/job/job_service.js:58:    const foundJobs = await Job.find({\nvoice-synthsizer-job-handler/job/job_service.js-59-      ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/job/job_service.js-60-      deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js-61-    })\nvoice-synthsizer-job-handler/job/job_service.js-62-    return foundJobs\n--\nvoice-synthsizer-job-handler/job/job_service.js-72-\nvoice-synthsizer-job-handler/job/job_service.js-73-const update = (Job) => async (job, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-74-  try {\nvoice-synthsizer-job-handler/job/job_service.js-75-    const updates = withoutTenantIdentity(job)\nvoice-synthsizer-job-handler/job/job_service.js:76:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js-77-      {\nvoice-synthsizer-job-handler/job/job_service.js-78-        ...scopeToUser({ _id: job._id }, userId),\nvoice-synthsizer-job-handler/job/job_service.js-79-        deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js-80-      },\n--\nvoice-synthsizer-job-handler/job/job_service.js-95-}\nvoice-synthsizer-job-handler/job/job_service.js-96-\nvoice-synthsizer-job-handler/job/job_service.js-97-const remove = (Job) => async (filter, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-98-  try {\nvoice-synthsizer-job-handler/job/job_service.js:99:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js-100-      {\nvoice-synthsizer-job-handler/job/job_service.js-101-        ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/job/job_service.js-102-        deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js-103-      },\n--\nvoice-synthsizer-job-handler/job/job_service.js-120-}\nvoice-synthsizer-job-handler/job/job_service.js-121-\nvoice-synthsizer-job-handler/job/job_service.js-122-const removeMany = (Job) => async (filter, userId) => {\nvoice-synthsizer-job-handler/job/job_service.js-123-  try {\nvoice-synthsizer-job-handler/job/job_service.js:124:    const updatedJob = await Job.updateMany(\nvoice-synthsizer-job-handler/job/job_service.js-125-      {\nvoice-synthsizer-job-handler/job/job_service.js-126-        ...scopeToUser(filter, userId),\nvoice-synthsizer-job-handler/job/job_service.js-127-        deleted: false,\nvoice-synthsizer-job-handler/job/job_service.js-128-      },\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_53","type":"command_execution","command":"/bin/bash -lc 'for f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js; do node --check \"$f\" || exit 1; done\ngit diff --check'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_53","type":"command_execution","command":"/bin/bash -lc 'for f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js; do node --check \"$f\" || exit 1; done\ngit diff --check'","aggregated_output":"","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_54","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(aggregate|bulkWrite|count|countDocuments|deleteMany|deleteOne|distinct|exists|findById|findByIdAndUpdate|findOne|find|findOneAndDelete|findOneAndRemove|findOneAndReplace|findOneAndUpdate|insertMany|replaceOne|save|updateMany|updateOne)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_54","type":"command_execution","command":"/bin/bash -lc \"rg -n \\\"\\\\.(aggregate|bulkWrite|count|countDocuments|deleteMany|deleteOne|distinct|exists|findById|findByIdAndUpdate|findOne|find|findOneAndDelete|findOneAndRemove|findOneAndReplace|findOneAndUpdate|insertMany|replaceOne|save|updateMany|updateOne)\\\\(\\\" voice-cloning-job-handler voice-synthsizer-job-handler -g '*.js'\"","aggregated_output":"voice-synthsizer-job-handler/salutation/salutation_service.js:9:  const savedSalutation = await newSalutation.save()\nvoice-synthsizer-job-handler/salutation/salutation_service.js:14:  const foundSalutation = await Salutation.findOne({\nvoice-synthsizer-job-handler/salutation/salutation_service.js:22:  const foundSalutations = await Salutation.find({\nvoice-synthsizer-job-handler/salutation/salutation_service.js:31:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js:48:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-synthsizer-job-handler/salutation/salutation_service.js:83:  const updatedSalutation = await Salutation.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:11:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:25:    const inserted = await VoiceCloningModel.insertMany(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:41:    const foundModel = await VoiceCloningModel.findOne({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:58:    const foundModels = await VoiceCloningModel.find({\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:76:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:100:    const updatedModel = await VoiceCloningModel.findOneAndUpdate(\nvoice-cloning-job-handler/voice_cloning/voice_cloning_service.js:125:    const updatedModel = await VoiceCloningModel.updateMany(\nvoice-synthsizer-job-handler/index.js:114:        recordingSalutationModel.findOne({\nvoice-synthsizer-job-handler/index.js:119:        recordingModel.findOne({\nvoice-synthsizer-job-handler/index.js:194:      await recordingSalutationModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/index.js:234:    await jobService.insertMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:11:    const savedModel = await newModel.save()\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:25:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:41:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:58:    const foundModels = await UserAudioProfileModel.find({\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:99:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js:124:    const updatedModel = await UserAudioProfileModel.updateMany(\nvoice-synthsizer-job-handler/job/job_service.js:11:    const savedJob = await newJob.save()\nvoice-synthsizer-job-handler/job/job_service.js:25:    const inserted = await Job.insertMany(\nvoice-synthsizer-job-handler/job/job_service.js:41:    const foundJob = await Job.findOne({\nvoice-synthsizer-job-handler/job/job_service.js:58:    const foundJobs = await Job.find({\nvoice-synthsizer-job-handler/job/job_service.js:76:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:99:    const updatedJob = await Job.findOneAndUpdate(\nvoice-synthsizer-job-handler/job/job_service.js:124:    const updatedJob = await Job.updateMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:11:    const savedModel = await newModel.save()\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:25:    const inserted = await UserAudioProfileModel.insertMany(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:41:    const foundModel = await UserAudioProfileModel.findOne({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:58:    const foundModels = await UserAudioProfileModel.find({\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:76:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:99:    const updatedModel = await UserAudioProfileModel.findOneAndUpdate(\nvoice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js:124:    const updatedModel = await UserAudioProfileModel.updateMany(\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_55","type":"agent_message","text":"The query audit is now exhaustive across both worker directories: every read/update/delete helper either injects `userId` centrally or includes it directly, and tenant identity cannot be changed through an update payload. I’m on the final regression pass now (syntax, malformed jobs, unauthorized records, and acknowledgment behavior)."}}
{"type":"item.started","item":{"id":"item_56","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst {\n  scopeToUser,\n  withoutTenantIdentity,\n} = require('./app/services/utils/tenantScope')\nconst {\n  RejectedJobError,\n  parseJobMessage,\n  requireJobObjectId,\n} = require('./app/services/utils/jobValidation')\n\nassert.deepStrictEqual(scopeToUser({ userId: 'other', _id: 'record' }, 'tenant'), {\n  userId: 'tenant',\n  _id: 'record',\n})\nassert.deepStrictEqual(\n  withoutTenantIdentity({ _id: 'record', userId: 'other', status: 'done' }),\n  { status: 'done' }\n)\nassert.throws(\n  () => withoutTenantIdentity({ _id: 'record', \"'$set: { userId: '\"'other' } }),\n  /update operators/\n)\nassert.throws(() => scopeToUser({ _id: 'record' }), /userId is required/)\nassert.throws(() => parseJobMessage('{broken'), RejectedJobError)\nassert.throws(() => requireJobObjectId(123, 'userId'), RejectedJobError)\nassert.throws(() => requireJobObjectId('abcdefghijkl', 'userId'), RejectedJobError)\nassert.strictEqual(\n  requireJobObjectId('64b000000000000000000001', 'userId'),\n  '64b000000000000000000001'\n)\nconsole.log('tenant utility assertions passed')\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst voiceCloningService = require('./voice-cloning-job-handler/voice_cloning')\nconst userAudioProfileService = require('./voice-cloning-job-handler/user_audio_profile')\n\nconst userId = '64b000000000000000000001'\nconst cloningId = '64b000000000000000000002'\nconst profileId = '64b000000000000000000003'\nlet acknowledged = false\nlet cloningRead\nlet profileRead\nsqs.fetchMessageFromSQS = async () => ({ Messages: [{\n  ReceiptHandle: 'receipt',\n  Body: JSON.stringify({\n    _doc: { _id: cloningId, userAudioProfileId: profileId, userId },\n    env: 'staging',\n  }),\n}] })\nsqs.deleteMessageFromSQS = async () => { acknowledged = true }\nmongoose.connect = async () => mongoose\nvoiceCloningService.read = async (filter, tenant) => {\n  cloningRead = { filter, tenant }\n  return null\n}\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\nconst { processQueue } = require('./voice-cloning-job-handler/index')\nprocessQueue().then(() => {\n  assert.strictEqual(acknowledged, true)\n  assert.deepStrictEqual(cloningRead, {\n    filter: { _id: cloningId, userAudioProfileId: profileId }, tenant: userId,\n  })\n  assert.deepStrictEqual(profileRead, {\n    filter: { _id: profileId }, tenant: userId,\n  })\n  console.log('cloning authorization rejection assertions passed')\n}).catch((error) => { console.error(error); process.exitCode = 1 })\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst sqs = require('./app/services/sqs')\nlet acknowledged = false\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [{ ReceiptHandle: 'receipt', Body: '{not-json' }],\n})\nsqs.deleteMessageFromSQS = async () => { acknowledged = true }\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue().then(() => {\n  assert.strictEqual(acknowledged, true)\n  console.log('malformed synthesizer job assertions passed')\n}).catch((error) => { console.error(error); process.exitCode = 1 })\nNODE\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_56","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst {\n  scopeToUser,\n  withoutTenantIdentity,\n} = require('./app/services/utils/tenantScope')\nconst {\n  RejectedJobError,\n  parseJobMessage,\n  requireJobObjectId,\n} = require('./app/services/utils/jobValidation')\n\nassert.deepStrictEqual(scopeToUser({ userId: 'other', _id: 'record' }, 'tenant'), {\n  userId: 'tenant',\n  _id: 'record',\n})\nassert.deepStrictEqual(\n  withoutTenantIdentity({ _id: 'record', userId: 'other', status: 'done' }),\n  { status: 'done' }\n)\nassert.throws(\n  () => withoutTenantIdentity({ _id: 'record', \"'$set: { userId: '\"'other' } }),\n  /update operators/\n)\nassert.throws(() => scopeToUser({ _id: 'record' }), /userId is required/)\nassert.throws(() => parseJobMessage('{broken'), RejectedJobError)\nassert.throws(() => requireJobObjectId(123, 'userId'), RejectedJobError)\nassert.throws(() => requireJobObjectId('abcdefghijkl', 'userId'), RejectedJobError)\nassert.strictEqual(\n  requireJobObjectId('64b000000000000000000001', 'userId'),\n  '64b000000000000000000001'\n)\nconsole.log('tenant utility assertions passed')\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst mongoose = require('mongoose')\nconst sqs = require('./app/services/sqs')\nconst voiceCloningService = require('./voice-cloning-job-handler/voice_cloning')\nconst userAudioProfileService = require('./voice-cloning-job-handler/user_audio_profile')\n\nconst userId = '64b000000000000000000001'\nconst cloningId = '64b000000000000000000002'\nconst profileId = '64b000000000000000000003'\nlet acknowledged = false\nlet cloningRead\nlet profileRead\nsqs.fetchMessageFromSQS = async () => ({ Messages: [{\n  ReceiptHandle: 'receipt',\n  Body: JSON.stringify({\n    _doc: { _id: cloningId, userAudioProfileId: profileId, userId },\n    env: 'staging',\n  }),\n}] })\nsqs.deleteMessageFromSQS = async () => { acknowledged = true }\nmongoose.connect = async () => mongoose\nvoiceCloningService.read = async (filter, tenant) => {\n  cloningRead = { filter, tenant }\n  return null\n}\nuserAudioProfileService.read = async (filter, tenant) => {\n  profileRead = { filter, tenant }\n  return null\n}\nconst { processQueue } = require('./voice-cloning-job-handler/index')\nprocessQueue().then(() => {\n  assert.strictEqual(acknowledged, true)\n  assert.deepStrictEqual(cloningRead, {\n    filter: { _id: cloningId, userAudioProfileId: profileId }, tenant: userId,\n  })\n  assert.deepStrictEqual(profileRead, {\n    filter: { _id: profileId }, tenant: userId,\n  })\n  console.log('cloning authorization rejection assertions passed')\n}).catch((error) => { console.error(error); process.exitCode = 1 })\nNODE\nnode <<'NODE'\nconst assert = require('assert')\nconst sqs = require('./app/services/sqs')\nlet acknowledged = false\nsqs.fetchMessageFromSQS = async () => ({\n  Messages: [{ ReceiptHandle: 'receipt', Body: '{not-json' }],\n})\nsqs.deleteMessageFromSQS = async () => { acknowledged = true }\nconst { processQueue } = require('./voice-synthsizer-job-handler/index')\nprocessQueue().then(() => {\n  assert.strictEqual(acknowledged, true)\n  console.log('malformed synthesizer job assertions passed')\n}).catch((error) => { console.error(error); process.exitCode = 1 })\nNODE\"","aggregated_output":"tenant utility assertions passed\nConnection Attempt :  0\nConnected to Mongo DB !\nRejected voice cloning job: Voice cloning job records were not found for the supplied userId\ncloning authorization rejection assertions passed\nRejected voice synthesizer job: Queue message body is not valid JSON\nmalformed synthesizer job assertions passed\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_57","type":"command_execution","command":"/bin/bash -lc 'git diff --stat HEAD && git status --short'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.started","item":{"id":"item_58","type":"command_execution","command":"/bin/bash -lc \"nl -ba app/services/utils/tenantScope.js && nl -ba app/services/utils/jobValidation.js && nl -ba voice-synthsizer-job-handler/index.js | sed -n '55,285p' && nl -ba voice-cloning-job-handler/index.js | sed -n '90,365p'\"","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_57","type":"command_execution","command":"/bin/bash -lc 'git diff --stat HEAD && git status --short'","aggregated_output":" voice-cloning-job-handler/index.js                 | 532 ++++++++++++---------\n .../user_audio_profile_service.js                  |  47 +-\n .../voice_cloning/voice_cloning_service.js         |  47 +-\n voice-synthsizer-job-handler/index.js              | 401 +++++++++-------\n voice-synthsizer-job-handler/job/job_service.js    |  53 +-\n .../salutation/salutation_service.js               | 195 ++++----\n .../user_audio_profile_service.js                  |  49 +-\n 7 files changed, 757 insertions(+), 567 deletions(-)\n M voice-cloning-job-handler/index.js\n M voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js\n M voice-cloning-job-handler/voice_cloning/voice_cloning_service.js\n M voice-synthsizer-job-handler/index.js\n M voice-synthsizer-job-handler/job/job_service.js\n M voice-synthsizer-job-handler/salutation/salutation_service.js\n M voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js\n?? app/services/utils/jobValidation.js\n?? app/services/utils/tenantScope.js\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_58","type":"command_execution","command":"/bin/bash -lc \"nl -ba app/services/utils/tenantScope.js && nl -ba app/services/utils/jobValidation.js && nl -ba voice-synthsizer-job-handler/index.js | sed -n '55,285p' && nl -ba voice-cloning-job-handler/index.js | sed -n '90,365p'\"","aggregated_output":"     1\tconst requireUserId = (userId) => {\n     2\t  if (userId === undefined || userId === null || userId === '') {\n     3\t    throw new TypeError('userId is required for tenant-scoped database access')\n     4\t  }\n     5\t\n     6\t  return userId\n     7\t}\n     8\t\n     9\tconst scopeToUser = (filter, userId) => ({\n    10\t  ...filter,\n    11\t  userId: requireUserId(userId),\n    12\t})\n    13\t\n    14\tconst assignToUser = (data, userId) => ({\n    15\t  ...data,\n    16\t  userId: requireUserId(userId),\n    17\t})\n    18\t\n    19\tconst withoutTenantIdentity = (data) => {\n    20\t  const updates = { ...data }\n    21\t  delete updates._id\n    22\t  delete updates.userId\n    23\t\n    24\t  if (Object.keys(updates).some((key) => key.startsWith('$'))) {\n    25\t    throw new TypeError('MongoDB update operators are not allowed')\n    26\t  }\n    27\t\n    28\t  return updates\n    29\t}\n    30\t\n    31\tmodule.exports = {\n    32\t  assignToUser,\n    33\t  requireUserId,\n    34\t  scopeToUser,\n    35\t  withoutTenantIdentity,\n    36\t}\n     1\tconst mongoose = require('mongoose')\n     2\t\n     3\tclass RejectedJobError extends Error {\n     4\t  constructor(message) {\n     5\t    super(message)\n     6\t    this.name = 'RejectedJobError'\n     7\t  }\n     8\t}\n     9\t\n    10\tconst parseJobMessage = (body) => {\n    11\t  try {\n    12\t    return JSON.parse(body)\n    13\t  } catch (error) {\n    14\t    throw new RejectedJobError('Queue message body is not valid JSON')\n    15\t  }\n    16\t}\n    17\t\n    18\tconst requireJobObject = (value, fieldName) => {\n    19\t  if (!value || typeof value !== 'object' || Array.isArray(value)) {\n    20\t    throw new RejectedJobError(`${fieldName} is required`)\n    21\t  }\n    22\t\n    23\t  return value\n    24\t}\n    25\t\n    26\tconst requireJobObjectId = (value, fieldName) => {\n    27\t  const isObjectId = value instanceof mongoose.Types.ObjectId\n    28\t  const isObjectIdString =\n    29\t    typeof value === 'string' && /^[a-fA-F0-9]{24}$/.test(value)\n    30\t\n    31\t  if (!isObjectId && !isObjectIdString) {\n    32\t    throw new RejectedJobError(`${fieldName} must be a valid ObjectId`)\n    33\t  }\n    34\t\n    35\t  return value\n    36\t}\n    37\t\n    38\tconst requireJobString = (value, fieldName) => {\n    39\t  if (typeof value !== 'string' || value.trim() === '') {\n    40\t    throw new RejectedJobError(`${fieldName} is required`)\n    41\t  }\n    42\t\n    43\t  return value\n    44\t}\n    45\t\n    46\tmodule.exports = {\n    47\t  RejectedJobError,\n    48\t  parseJobMessage,\n    49\t  requireJobObject,\n    50\t  requireJobObjectId,\n    51\t  requireJobString,\n    52\t}\n    55\t      return connectDB(dbUri, retryCount + 1)\n    56\t    }\n    57\t\n    58\t    throw error\n    59\t  }\n    60\t}\n    61\t\n    62\tconst processQueue = async () => {\n    63\t  let receiptHandle\n    64\t  let acknowledged = false\n    65\t\n    66\t  const acknowledgeMessage = async () => {\n    67\t    if (!acknowledged && receiptHandle) {\n    68\t      await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n    69\t      acknowledged = true\n    70\t    }\n    71\t  }\n    72\t\n    73\t  try {\n    74\t    const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n    75\t\n    76\t    if (!response.Messages || response.Messages.length === 0) {\n    77\t      throttleMessageFetching = true\n    78\t      return\n    79\t    }\n    80\t\n    81\t    throttleMessageFetching = false\n    82\t    const message = response.Messages[0]\n    83\t    receiptHandle = message.ReceiptHandle\n    84\t    const job = requireJobObject(parseJobMessage(message.Body), 'job')\n    85\t\n    86\t    const userId = requireJobObjectId(job.userId, 'userId')\n    87\t    const userAudioProfileId = requireJobObjectId(\n    88\t      job.userAudioProfileId,\n    89\t      'userAudioProfileId'\n    90\t    )\n    91\t    const salutationId = requireJobObjectId(job.salutationId, 'salutationId')\n    92\t    const recordingId = requireJobObjectId(job.recordingId, 'recordingId')\n    93\t    const text = requireJobString(job.text, 'text')\n    94\t    const firstName = requireJobString(job.firstName, 'firstName')\n    95\t    const env = requireJobString(job.env, 'env')\n    96\t    const { baseUrlForPotionAi } = job\n    97\t\n    98\t    const DB_URI =\n    99\t      env === 'production'\n   100\t        ? mongoUriProd\n   101\t        : env === 'staging'\n   102\t        ? mongoUriStaging\n   103\t        : mongoUriDev\n   104\t\n   105\t    await connectDB(DB_URI)\n   106\t\n   107\t    // Authorize every referenced record before voice synthesis or S3 writes.\n   108\t    const [userAudioProfile, salutationToUpdate, recordingToUpdate] =\n   109\t      await Promise.all([\n   110\t        userAudioProfileService.read(\n   111\t          { _id: userAudioProfileId, status: 'completed' },\n   112\t          userId\n   113\t        ),\n   114\t        recordingSalutationModel.findOne({\n   115\t          _id: salutationId,\n   116\t          userId,\n   117\t          deleted: false,\n   118\t        }),\n   119\t        recordingModel.findOne({\n   120\t          _id: recordingId,\n   121\t          userId,\n   122\t          deleted: false,\n   123\t        }),\n   124\t      ])\n   125\t\n   126\t    if (!userAudioProfile || !salutationToUpdate || !recordingToUpdate) {\n   127\t      throw new RejectedJobError(\n   128\t        'Synthesizer job records were not found for the supplied userId'\n   129\t      )\n   130\t    }\n   131\t\n   132\t    const trainingModelPath = requireJobObject(\n   133\t      userAudioProfile.training_model_path,\n   134\t      'training_model_path'\n   135\t    )\n   136\t    const voiceModelLightPath = requireJobString(\n   137\t      trainingModelPath.voice_model_light_path,\n   138\t      'training_model_path.voice_model_light_path'\n   139\t    )\n   140\t    const voiceModelConfigLightPath = requireJobString(\n   141\t      trainingModelPath.voice_model_config_light_path,\n   142\t      'training_model_path.voice_model_config_light_path'\n   143\t    )\n   144\t    const voiceModelSpeakersFilePath = requireJobString(\n   145\t      trainingModelPath.voice_model_speakers_file_path,\n   146\t      'training_model_path.voice_model_speakers_file_path'\n   147\t    )\n   148\t\n   149\t    // Keep the existing at-most-once processing behavior once the job and all\n   150\t    // tenant-owned records have been validated.\n   151\t    await acknowledgeMessage()\n   152\t\n   153\t    const outputPath = `/tmp/${uuid()}/`\n   154\t    if (!fs.existsSync(outputPath)) {\n   155\t      fs.mkdirSync(outputPath, { recursive: true })\n   156\t    }\n   157\t\n   158\t    const AI_COMMAND = `python3 ../voice-cloning/synthesize_speech.py --voice_model_path ${voiceModelLightPath} --voice_model_config_path ${voiceModelConfigLightPath} --speaker_embeddings_path ${voiceModelSpeakersFilePath} --txt \"${text}\" --output_path ${outputPath}`\n   159\t    console.log('AI_COMMAND ', AI_COMMAND)\n   160\t\n   161\t    const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()\n   162\t    console.time(SYNTHESIZE_AI_LABEL)\n   163\t    await execShellCommand(AI_COMMAND)\n   164\t    console.timeEnd(SYNTHESIZE_AI_LABEL)\n   165\t\n   166\t    let generatedFileName = ''\n   167\t    fs.readdirSync(`${outputPath}`).forEach((file) => {\n   168\t      if (file.includes('sr48000.wav')) generatedFileName = file\n   169\t    })\n   170\t\n   171\t    // upload the file to s3\n   172\t    const uploadParams = {\n   173\t      filePath: `${outputPath}${generatedFileName}`,\n   174\t      bucket: `recordings-${env}`,\n   175\t      fileName: `${uuid()}_salutation_${firstName.replace('-', '_')}.wav`,\n   176\t      contentType: 'audio/x-wav',\n   177\t      fileType: 'wav',\n   178\t    }\n   179\t    console.time('Time to Upload video on S3')\n   180\t    const greetingUploadResponse = await s3.upload(uploadParams)\n   181\t    console.timeEnd('Time to Upload video on S3')\n   182\t\n   183\t    // Create or update the per-user cached salutation.\n   184\t    await salutationService.updateOrCreate(\n   185\t      {\n   186\t        firstName,\n   187\t        salutationVideo: greetingUploadResponse,\n   188\t        userAudioProfileId,\n   189\t      },\n   190\t      userId\n   191\t    )\n   192\t\n   193\t    const updatedSalutation =\n   194\t      await recordingSalutationModel.findOneAndUpdate(\n   195\t        {\n   196\t          _id: salutationId,\n   197\t          userId,\n   198\t          deleted: false,\n   199\t        },\n   200\t        {\n   201\t          $set: {\n   202\t            salutationVideo: greetingUploadResponse,\n   203\t          },\n   204\t        },\n   205\t        { new: true }\n   206\t      )\n   207\t\n   208\t    if (!updatedSalutation) {\n   209\t      throw new RejectedJobError(\n   210\t        'Recording salutation changed before it could be updated'\n   211\t      )\n   212\t    }\n   213\t\n   214\t    const jobData = {\n   215\t      originalGreeting: recordingToUpdate.masterSalutationVideoUrl,\n   216\t      originalVideo:\n   217\t        recordingToUpdate.originalVideoUrl || recordingToUpdate.urls[0].url,\n   218\t      cropTimestamp: recordingToUpdate.cropTimestamp,\n   219\t      greetingClips: [greetingUploadResponse],\n   220\t      greetingObjects: [\n   221\t        {\n   222\t          greetingId: updatedSalutation._id,\n   223\t          firstName,\n   224\t          videoUrl: greetingUploadResponse,\n   225\t        },\n   226\t      ],\n   227\t      requestOrigin: baseUrlForPotionAi,\n   228\t      environment: env,\n   229\t      recordingId: recordingToUpdate._id,\n   230\t      salutation: updatedSalutation._id,\n   231\t      dynamicVideoType: recordingToUpdate.dynamicVideoType,\n   232\t    }\n   233\t\n   234\t    await jobService.insertMany(\n   235\t      [\n   236\t        {\n   237\t          firstName,\n   238\t          recordingId: recordingToUpdate._id,\n   239\t          salutationId: updatedSalutation._id,\n   240\t          metadata: jobData,\n   241\t        },\n   242\t      ],\n   243\t      userId\n   244\t    )\n   245\t\n   246\t    fs.unlinkSync(`${outputPath}${generatedFileName}`)\n   247\t    console.log(`[deleted] ${outputPath}${generatedFileName}`)\n   248\t  } catch (error) {\n   249\t    if (error instanceof RejectedJobError) {\n   250\t      console.warn(`Rejected voice synthesizer job: ${error.message}`)\n   251\t      try {\n   252\t        await acknowledgeMessage()\n   253\t      } catch (acknowledgementError) {\n   254\t        console.error('Unable to acknowledge rejected voice synthesizer job', {\n   255\t          error: acknowledgementError,\n   256\t        })\n   257\t        Bugsnag.notify(acknowledgementError)\n   258\t      }\n   259\t    } else {\n   260\t      console.error('Error while synthesizing audio', { error })\n   261\t      Bugsnag.notify(error)\n   262\t    }\n   263\t  } finally {\n   264\t    if (mongoose.connection.readyState !== 0) {\n   265\t      try {\n   266\t        await mongoose.connection.close()\n   267\t      } catch (error) {\n   268\t        console.error('Unable to close Mongo DB connection', { error })\n   269\t        Bugsnag.notify(error)\n   270\t      }\n   271\t    }\n   272\t  }\n   273\t}\n   274\t\n   275\tfunction sleep(ms) {\n   276\t  return new Promise((resolve) => {\n   277\t    setTimeout(resolve, ms)\n   278\t  })\n   279\t}\n   280\tconst init = async () => {\n   281\t  Bugsnag.start({\n   282\t    appVersion: APP_ENV + version,\n   283\t    apiKey: process.env.BUGSNAG_BACKEND_KEY,\n   284\t    releaseStage: process.env.NODE_ENV,\n   285\t  })\n    90\t  return s\n    91\t}\n    92\t\n    93\tconst processQueue = async () => {\n    94\t  let authorized = false\n    95\t  let userId\n    96\t  let voiceCloningId\n    97\t  let userAudioProfileId\n    98\t  let receiptHandle\n    99\t  let acknowledged = false\n   100\t\n   101\t  const acknowledgeMessage = async () => {\n   102\t    if (!acknowledged && receiptHandle) {\n   103\t      await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)\n   104\t      acknowledged = true\n   105\t    }\n   106\t  }\n   107\t\n   108\t  try {\n   109\t    const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)\n   110\t\n   111\t    if (!response.Messages || response.Messages.length === 0) {\n   112\t      throttleMessageFetching = true\n   113\t      return\n   114\t    }\n   115\t\n   116\t    throttleMessageFetching = false\n   117\t    const message = response.Messages[0]\n   118\t    receiptHandle = message.ReceiptHandle\n   119\t    const job = requireJobObject(parseJobMessage(message.Body), 'job')\n   120\t    const jobDocument = requireJobObject(job._doc, 'job._doc')\n   121\t\n   122\t    userId = requireJobObjectId(jobDocument.userId, 'userId')\n   123\t    voiceCloningId = requireJobObjectId(jobDocument._id, '_id')\n   124\t    userAudioProfileId = requireJobObjectId(\n   125\t      jobDocument.userAudioProfileId,\n   126\t      'userAudioProfileId'\n   127\t    )\n   128\t    const env = requireJobString(job.env, 'env')\n   129\t    const DB_URI =\n   130\t      env === 'production'\n   131\t        ? mongoUriProd\n   132\t        : env === 'staging'\n   133\t        ? mongoUriStaging\n   134\t        : mongoUriDev\n   135\t\n   136\t    await connectDB(DB_URI)\n   137\t\n   138\t    const [voiceCloning, userAudioProfile] = await Promise.all([\n   139\t      voiceCloningService.read(\n   140\t        { _id: voiceCloningId, userAudioProfileId },\n   141\t        userId\n   142\t      ),\n   143\t      userAudioProfileService.read({ _id: userAudioProfileId }, userId),\n   144\t    ])\n   145\t\n   146\t    if (!voiceCloning || !userAudioProfile) {\n   147\t      throw new RejectedJobError(\n   148\t        'Voice cloning job records were not found for the supplied userId'\n   149\t      )\n   150\t    }\n   151\t\n   152\t    authorized = true\n   153\t    const metadata = requireJobObject(voiceCloning.metadata, 'metadata')\n   154\t    const directoryName = requireJobString(\n   155\t      metadata.directoryName,\n   156\t      'metadata.directoryName'\n   157\t    )\n   158\t    const input = voiceCloning.input\n   159\t    if (!Array.isArray(input)) {\n   160\t      throw new RejectedJobError('input must be an array')\n   161\t    }\n   162\t\n   163\t    const cloudFrontUrl =\n   164\t      env === 'production'\n   165\t        ? cloudFrontUrlProd\n   166\t        : env === 'staging'\n   167\t        ? cloudFrontUrlStaging\n   168\t        : cloudFrontUrlDev\n   169\t\n   170\t    // Keep the existing at-most-once processing behavior once the job and all\n   171\t    // tenant-owned records have been validated.\n   172\t    await acknowledgeMessage()\n   173\t\n   174\t    const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   175\t    if (!fs.existsSync(logPath)) {\n   176\t      fs.mkdirSync(logPath, { recursive: true })\n   177\t    }\n   178\t\n   179\t    const [processingJob, processingProfile] = await Promise.all([\n   180\t      voiceCloningService.update(\n   181\t        { _id: voiceCloningId, status: 'processing' },\n   182\t        userId\n   183\t      ),\n   184\t      userAudioProfileService.update(\n   185\t        { _id: userAudioProfileId, status: 'processing' },\n   186\t        userId\n   187\t      ),\n   188\t    ])\n   189\t    if (!processingJob || !processingProfile) {\n   190\t      throw new RejectedJobError(\n   191\t        'Voice cloning job records changed before processing'\n   192\t      )\n   193\t    }\n   194\t\n   195\t    // create directory for userid-useraudioprofileid if not exist\n   196\t    const rootPath = `/tmp/${directoryName}`\n   197\t    const wavePath = `${rootPath}/wav48/1`\n   198\t    if (!fs.existsSync(wavePath)) {\n   199\t      fs.mkdirSync(wavePath, { recursive: true })\n   200\t    }\n   201\t\n   202\t    const txtPath = `${rootPath}/txt/1`\n   203\t    if (!fs.existsSync(txtPath)) {\n   204\t      fs.mkdirSync(txtPath, { recursive: true })\n   205\t    }\n   206\t    // download the training data files and put it in respective directories\n   207\t    for (let index = 0; index < input.length; index++) {\n   208\t      const item = input[index]\n   209\t\n   210\t      const { waveUrl, originalText } = item\n   211\t      // download wave file\n   212\t      const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`\n   213\t\n   214\t      await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)\n   215\t\n   216\t      const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`\n   217\t      await fs.promises.writeFile(txtFilePath, originalText)\n   218\t    }\n   219\t\n   220\t    const zipFileName = directoryName + '.tgz'\n   221\t\n   222\t    // /tmp/directoryName.tgz\n   223\t\n   224\t    await execShellCommand(\n   225\t      `cd /tmp && tar czvf ${zipFileName}  ${directoryName}`,\n   226\t      logPath\n   227\t    )\n   228\t    console.log('ZIP created ', zipFileName)\n   229\t\n   230\t    // re-sample audio\n   231\t    const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`\n   232\t    console.time(SAMPLING_LABEL)\n   233\t\n   234\t    const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`\n   235\t\n   236\t    const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`\n   237\t    console.log('samplingCommand ', samplingCommand)\n   238\t    await execShellCommand(samplingCommand, logPath)\n   239\t    console.timeEnd(SAMPLING_LABEL)\n   240\t\n   241\t    // /mnt/efs/potion-voice/${env}/speakrs.pth\n   242\t    // /mnt/efs/potion-voice/${env}/txt\n   243\t    // /mnt/efs/potion-voice/${env}/${directoryName}/wav\n   244\t\n   245\t    const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`\n   246\t\n   247\t    const resultsPath = outPath + '/results'\n   248\t\n   249\t    //update pth file for cloning\n   250\t    // clone the voice\n   251\t    const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`\n   252\t    console.time(VOICE_CLONING_LABEL)\n   253\t    const trainingModelCommand = `python3 ../voice-cloning/clone_voice.py --baseline_model_path ../voice-cloning/pretrained-models/checkpoint_365000.pth --speaker_dataset_path ${outPath} --speaker_embeddings_path ${\n   254\t      outPath + '/speakers.pth'\n   255\t    } --output_path ${resultsPath}`\n   256\t\n   257\t    console.log('Training Model Command', trainingModelCommand)\n   258\t    await execShellCommand(trainingModelCommand, logPath)\n   259\t\n   260\t    console.timeEnd(VOICE_CLONING_LABEL)\n   261\t\n   262\t    let generatedDirectoryName = ''\n   263\t    fs.readdirSync(`${resultsPath}/`).forEach((file) => {\n   264\t      if (file.includes('vits_potion_clone'))\n   265\t        // use output from above to get right path and directory name\n   266\t        generatedDirectoryName = file\n   267\t    })\n   268\t\n   269\t    // minimize cloning model\n   270\t    const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`\n   271\t    console.time(VOICE_MINIMIZE_LABEL)\n   272\t    const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${\n   273\t      resultsPath + '/' + generatedDirectoryName + '/'\n   274\t    } --voice_model_name checkpoint_365200.pth`\n   275\t\n   276\t    console.log(\n   277\t      'Minimize Cloning Model Command',\n   278\t      minimizeCloningModelCommand\n   279\t    )\n   280\t    await execShellCommand(minimizeCloningModelCommand, logPath)\n   281\t    console.timeEnd(VOICE_MINIMIZE_LABEL)\n   282\t\n   283\t    // Add the code to update location of generated model and status into DB\n   284\t    await voiceCloningService.update(\n   285\t      { _id: voiceCloningId, status: 'completed' },\n   286\t      userId\n   287\t    )\n   288\t\n   289\t    const training_model_path = {\n   290\t      voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,\n   291\t      voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,\n   292\t      voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings\n   293\t      voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,\n   294\t      voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,\n   295\t    }\n   296\t\n   297\t    await userAudioProfileService.update(\n   298\t      {\n   299\t        _id: userAudioProfileId,\n   300\t        status: 'completed',\n   301\t        training_model_path,\n   302\t      },\n   303\t      userId\n   304\t    )\n   305\t\n   306\t    // add code to put that model into S3\n   307\t    const keys = Object.keys(training_model_path)\n   308\t    const training_model_s3_path = {}\n   309\t\n   310\t    for (let index = 0; index < keys.length; index++) {\n   311\t      const path = training_model_path[keys[index]]\n   312\t      const s3Path = await s3.upload({\n   313\t        filePath: path,\n   314\t        fileName: `${directoryName}/${path.split('/').pop()}`,\n   315\t        bucket: `potion-voice-users-training-model/${env}`,\n   316\t      })\n   317\t      training_model_s3_path[keys[index]] = s3Path\n   318\t    }\n   319\t    // add S3 path to user audio profile model\n   320\t    await userAudioProfileService.update(\n   321\t      { _id: userAudioProfileId, training_model_s3_path },\n   322\t      userId\n   323\t    )\n   324\t  } catch (error) {\n   325\t    if (error instanceof RejectedJobError) {\n   326\t      console.warn(`Rejected voice cloning job: ${error.message}`)\n   327\t      try {\n   328\t        await acknowledgeMessage()\n   329\t      } catch (acknowledgementError) {\n   330\t        console.error('Unable to acknowledge rejected voice cloning job', {\n   331\t          error: acknowledgementError,\n   332\t        })\n   333\t        Bugsnag.notify(acknowledgementError)\n   334\t      }\n   335\t    } else {\n   336\t      console.error('Error while training voice clone', { error })\n   337\t      Bugsnag.notify(error)\n   338\t    }\n   339\t\n   340\t    if (authorized) {\n   341\t      const statusUpdates = await Promise.allSettled([\n   342\t        voiceCloningService.update(\n   343\t          { _id: voiceCloningId, status: 'error' },\n   344\t          userId\n   345\t        ),\n   346\t        userAudioProfileService.update(\n   347\t          { _id: userAudioProfileId, status: 'error' },\n   348\t          userId\n   349\t        ),\n   350\t      ])\n   351\t      statusUpdates\n   352\t        .filter(({ status }) => status === 'rejected')\n   353\t        .forEach(({ reason }) => Bugsnag.notify(reason))\n   354\t    }\n   355\t  } finally {\n   356\t    if (mongoose.connection.readyState !== 0) {\n   357\t      try {\n   358\t        await mongoose.connection.close()\n   359\t      } catch (error) {\n   360\t        console.error('Unable to close Mongo DB connection', { error })\n   361\t        Bugsnag.notify(error)\n   362\t      }\n   363\t    }\n   364\t  }\n   365\t}\n","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_59","type":"command_execution","command":"/bin/bash -lc 'git diff --check && for f in $(git status --short | awk '\"'{print \"'$2}'\"' | rg '\\\\.js\"'$'\"'); do node --check \\\"\"'$f\" || exit 1; done'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_59","type":"command_execution","command":"/bin/bash -lc 'git diff --check && for f in $(git status --short | awk '\"'{print \"'$2}'\"' | rg '\\\\.js\"'$'\"'); do node --check \\\"\"'$f\" || exit 1; done'","aggregated_output":"","exit_code":0,"status":"completed"}}
{"type":"item.started","item":{"id":"item_60","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"}],"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_60","type":"file_change","changes":[{"path":"/workspace/app/services/utils/tenantScope.js","kind":"update"}],"status":"completed"}}
{"type":"item.started","item":{"id":"item_61","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst {\n  scopeToUser,\n  withoutTenantIdentity,\n} = require('./app/services/utils/tenantScope')\nconst tenantId = '64b000000000000000000001'\nassert.deepStrictEqual(\n  scopeToUser({ userId: '64b000000000000000000002', _id: 'record' }, tenantId),\n  { userId: tenantId, _id: 'record' }\n)\nassert.throws(\n  () => scopeToUser({ _id: 'record' }, { \"'$ne: null }),\n  /valid userId/\n)\nassert.deepStrictEqual(\n  withoutTenantIdentity({ _id: '\"'record', userId: 'other', status: 'done' }),\n  { status: 'done' }\n)\nassert.throws(\n  () => withoutTenantIdentity({ _id: 'record', \"'$set: { userId: '\"'other' } }),\n  /update operators/\n)\nconsole.log('strict tenant utility assertions passed')\nNODE\nfor f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do node --check \\\"\"'$f\" || exit 1; done\ngit diff --check'","aggregated_output":"","exit_code":null,"status":"in_progress"}}
{"type":"item.completed","item":{"id":"item_61","type":"command_execution","command":"/bin/bash -lc \"node <<'NODE'\nconst assert = require('assert')\nconst {\n  scopeToUser,\n  withoutTenantIdentity,\n} = require('./app/services/utils/tenantScope')\nconst tenantId = '64b000000000000000000001'\nassert.deepStrictEqual(\n  scopeToUser({ userId: '64b000000000000000000002', _id: 'record' }, tenantId),\n  { userId: tenantId, _id: 'record' }\n)\nassert.throws(\n  () => scopeToUser({ _id: 'record' }, { \"'$ne: null }),\n  /valid userId/\n)\nassert.deepStrictEqual(\n  withoutTenantIdentity({ _id: '\"'record', userId: 'other', status: 'done' }),\n  { status: 'done' }\n)\nassert.throws(\n  () => withoutTenantIdentity({ _id: 'record', \"'$set: { userId: '\"'other' } }),\n  /update operators/\n)\nconsole.log('strict tenant utility assertions passed')\nNODE\nfor f in app/services/utils/tenantScope.js app/services/utils/jobValidation.js voice-cloning-job-handler/index.js voice-synthsizer-job-handler/index.js voice-cloning-job-handler/voice_cloning/voice_cloning_service.js voice-cloning-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service.js voice-synthsizer-job-handler/salutation/salutation_service.js voice-synthsizer-job-handler/job/job_service.js; do node --check \\\"\"'$f\" || exit 1; done\ngit diff --check'","aggregated_output":"strict tenant utility assertions passed\n","exit_code":0,"status":"completed"}}
{"type":"item.completed","item":{"id":"item_62","type":"agent_message","text":"Implemented multi-tenant isolation across both workers.\n\n- All MongoDB reads/mutations now require valid `userId` scoping.\n- Workers authorize every referenced record before processing.\n- Malformed/unauthorized jobs are acknowledged and contained; transient DB failures remain retryable.\n- Update payloads cannot alter tenant identity.\n- Syntax checks and mocked isolation/resilience assertions passed.\n\nKey files: [cloning worker](/workspace/voice-cloning-job-handler/index.js:93), [synthesizer worker](/workspace/voice-synthsizer-job-handler/index.js:62), [tenant scope](/workspace/app/services/utils/tenantScope.js:1).\n\nQueue producers must now include `userId` (`job.userId` for synthesis and `job._doc.userId` for cloning)."}}
{"type":"turn.completed","usage":{"input_tokens":2365074,"cached_input_tokens":2241832,"cache_write_input_tokens":123149,"output_tokens":43113,"reasoning_output_tokens":19050}}
