old files deleted
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
--agent-import-path is deprecated; use --agent instead.
|
|
||||||
1/1 Mean: 0.710 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:03:08 0:00:00
|
|
||||||
adhoc • replay
|
|
||||||
┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Trials ┃ Exceptions ┃ Mean ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 1 │ 0 │ 0.710 │
|
|
||||||
└────────┴────────────┴───────┘
|
|
||||||
|
|
||||||
┏━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Reward ┃ Count ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 0.71 │ 1 │
|
|
||||||
└────────┴───────┘
|
|
||||||
|
|
||||||
Job Info
|
|
||||||
Total runtime: 3m 8s
|
|
||||||
Results written to
|
|
||||||
harbor-jobs/regrade-1791768120-99564-1-reward-0.6800-7LjzJZv/result.json
|
|
||||||
Inspect results by running `harbor view harbor-jobs`
|
|
||||||
Share results by running `harbor upload
|
|
||||||
harbor-jobs/regrade-1791768120-99564-1-reward-0.6800-7LjzJZv`
|
|
||||||
|
|
||||||
Warning: harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.6800-7LjzJZv already exists, overwriting
|
|
||||||
Copied to harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.6800-7LjzJZv
|
|
||||||
reward: 0.7100
|
|
||||||
task: harbor-tasks/potion-voice-user-ownership
|
|
||||||
trial: R98KGD8
|
|
||||||
perms: normalized 68 owner / 0 mode
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"job_name": "regrade-1791768120-99564-1-reward-0.6800-7LjzJZv",
|
|
||||||
"jobs_dir": "harbor-jobs",
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"agents": [
|
|
||||||
{
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.6800-7LjzJZv",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 2,
|
|
||||||
"created_at": "2026-10-12T01:22:02.324950Z",
|
|
||||||
"harbor": {
|
|
||||||
"version": "0.20.0",
|
|
||||||
"is_editable": false
|
|
||||||
},
|
|
||||||
"n_concurrent_trials": 4,
|
|
||||||
"retry": {
|
|
||||||
"max_retries": 0,
|
|
||||||
"exclude_exceptions": [
|
|
||||||
"ApiUsageLimitError",
|
|
||||||
"AgentAuthenticationError",
|
|
||||||
"RewardFileNotFoundError",
|
|
||||||
"VerifierTimeoutError",
|
|
||||||
"RewardFileEmptyError",
|
|
||||||
"AgentSafetyRefusalError",
|
|
||||||
"AgentTimeoutError",
|
|
||||||
"VerifierOutputParseError",
|
|
||||||
"ModelNotFoundError"
|
|
||||||
],
|
|
||||||
"wait_multiplier": 1.0,
|
|
||||||
"min_wait_sec": 1.0,
|
|
||||||
"max_wait_sec": 60.0
|
|
||||||
},
|
|
||||||
"trials": [
|
|
||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.6800-7LjzJZv",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,9 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"source": "/logs/artifacts",
|
|
||||||
"destination": "artifacts/logs/artifacts",
|
|
||||||
"type": "directory",
|
|
||||||
"status": "empty",
|
|
||||||
"service": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__R98KGD8",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-1-reward-0.6800-7LjzJZv",
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.6800-7LjzJZv",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"job_id": "3defb589-860d-4bf6-ac60-369c6b0b95e4"
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.6800-7LjzJZv",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "57b6e848-ce7a-4604-ba74-1bc9cca9f9f3",
|
|
||||||
"task_name": "potion-voice-user-ownership",
|
|
||||||
"trial_name": "potion-voice-user-ownership__R98KGD8",
|
|
||||||
"trial_uri": "file:///home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-jobs/regrade-1791768120-99564-1-reward-0.6800-7LjzJZv/potion-voice-user-ownership__R98KGD8",
|
|
||||||
"task_id": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"source": null,
|
|
||||||
"task_checksum": "e2ee9c4c9b7d66b397b30253ccf135c545721645a1349d6e62cb6078c4aebf01",
|
|
||||||
"config": {
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership",
|
|
||||||
"git_url": null,
|
|
||||||
"git_commit_id": null,
|
|
||||||
"name": null,
|
|
||||||
"ref": null,
|
|
||||||
"overwrite": false,
|
|
||||||
"download_dir": null,
|
|
||||||
"source": null
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__R98KGD8",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-1-reward-0.6800-7LjzJZv",
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent_timeout_multiplier": null,
|
|
||||||
"verifier_timeout_multiplier": null,
|
|
||||||
"agent_setup_timeout_multiplier": null,
|
|
||||||
"environment_build_timeout_multiplier": null,
|
|
||||||
"agent": {
|
|
||||||
"name": null,
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"model_name": null,
|
|
||||||
"n_concurrent": null,
|
|
||||||
"concurrency_group": null,
|
|
||||||
"skills": [],
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"override_setup_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"load_trajectory": null,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.6800-7LjzJZv",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"import_path": null,
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"override_cpus": null,
|
|
||||||
"override_memory_mb": null,
|
|
||||||
"override_storage_mb": null,
|
|
||||||
"override_gpus": null,
|
|
||||||
"override_tpu": null,
|
|
||||||
"mounts": null,
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
},
|
|
||||||
"artifacts": [],
|
|
||||||
"extra_instruction_paths": [],
|
|
||||||
"job_id": "3defb589-860d-4bf6-ac60-369c6b0b95e4"
|
|
||||||
},
|
|
||||||
"agent_info": {
|
|
||||||
"name": "replay",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"model_info": null
|
|
||||||
},
|
|
||||||
"agent_result": {
|
|
||||||
"n_input_tokens": null,
|
|
||||||
"n_cache_tokens": null,
|
|
||||||
"n_output_tokens": null,
|
|
||||||
"cost_usd": null,
|
|
||||||
"rollout_details": null,
|
|
||||||
"metadata": null
|
|
||||||
},
|
|
||||||
"verifier_result": {
|
|
||||||
"rewards": {
|
|
||||||
"reward": 0.71
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exception_info": null,
|
|
||||||
"started_at": "2026-10-12T01:22:02.620513Z",
|
|
||||||
"finished_at": "2026-10-12T01:25:10.750066Z",
|
|
||||||
"environment_setup": {
|
|
||||||
"started_at": "2026-10-12T01:22:02.838110Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:06.899661Z"
|
|
||||||
},
|
|
||||||
"agent_setup": {
|
|
||||||
"started_at": "2026-10-12T01:22:06.899710Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:06.899757Z"
|
|
||||||
},
|
|
||||||
"agent_execution": {
|
|
||||||
"started_at": "2026-10-12T01:22:06.899813Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:07.304594Z"
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"started_at": "2026-10-12T01:22:07.865074Z",
|
|
||||||
"finished_at": "2026-10-12T01:25:06.563393Z"
|
|
||||||
},
|
|
||||||
"step_results": null
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
const OBJECT_ID_PATTERN = /^[a-f\d]{24}$/i
|
|
||||||
|
|
||||||
const normalizeUserId = (userId) => {
|
|
||||||
const serializedUserId =
|
|
||||||
typeof userId === 'string'
|
|
||||||
? userId
|
|
||||||
: userId && typeof userId.toHexString === 'function'
|
|
||||||
? userId.toHexString()
|
|
||||||
: null
|
|
||||||
|
|
||||||
if (!serializedUserId || !OBJECT_ID_PATTERN.test(serializedUserId)) {
|
|
||||||
const error = new Error(
|
|
||||||
'A valid userId is required for tenant-scoped database access'
|
|
||||||
)
|
|
||||||
error.code = 'TENANT_CONTEXT_REQUIRED'
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
return serializedUserId
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterForUser = (filter, userId) => ({
|
|
||||||
...(filter || {}),
|
|
||||||
userId: normalizeUserId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const documentForUser = (document, userId) => ({
|
|
||||||
...document,
|
|
||||||
userId: normalizeUserId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const documentsForUser = (documents, userId) => {
|
|
||||||
const normalizedUserId = normalizeUserId(userId)
|
|
||||||
return documents.map((document) => ({
|
|
||||||
...document,
|
|
||||||
userId: normalizedUserId,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateWithoutTenantFields = (data) => {
|
|
||||||
const plainData =
|
|
||||||
data && typeof data.toObject === 'function' ? data.toObject() : data
|
|
||||||
const { _id, userId, ...updates } = plainData
|
|
||||||
return updates
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
documentForUser,
|
|
||||||
documentsForUser,
|
|
||||||
filterForUser,
|
|
||||||
normalizeUserId,
|
|
||||||
updateWithoutTenantFields,
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "potion-voice",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "This will handle the voice cloning jobs",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "node tests/tenant-isolation.test.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@bugsnag/js": "^7.3.5",
|
|
||||||
"aws-sdk": "^2.752.0",
|
|
||||||
"fs-extra": "^9.0.1",
|
|
||||||
"mongoose": "^6.8.0",
|
|
||||||
"pm2": "^5.2.0",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"uuid": "^8.3.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"aws-code-deploy": "^1.0.11"
|
|
||||||
},
|
|
||||||
"author": "potion Team",
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@@ -1,228 +0,0 @@
|
|||||||
const assert = require('assert')
|
|
||||||
|
|
||||||
const TenantScope = require('../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const TENANT_ID = '507f1f77bcf86cd799439011'
|
|
||||||
const OTHER_TENANT_ID = '507f1f77bcf86cd799439012'
|
|
||||||
const DOCUMENT_ID = '507f1f77bcf86cd799439013'
|
|
||||||
|
|
||||||
const createModelDouble = () => {
|
|
||||||
const calls = []
|
|
||||||
|
|
||||||
function Model(document) {
|
|
||||||
calls.push({ method: 'constructor', args: [document] })
|
|
||||||
this.save = async () => {
|
|
||||||
calls.push({ method: 'save', args: [] })
|
|
||||||
return document
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const modelMethods = [
|
|
||||||
'findOne',
|
|
||||||
'find',
|
|
||||||
'findOneAndUpdate',
|
|
||||||
'updateMany',
|
|
||||||
'insertMany',
|
|
||||||
]
|
|
||||||
modelMethods.forEach((method) => {
|
|
||||||
Model[method] = async (...args) => {
|
|
||||||
calls.push({ method, args })
|
|
||||||
return { method }
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return { calls, Model }
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastCall = (calls, method) => {
|
|
||||||
const matchingCalls = calls.filter((call) => call.method === method)
|
|
||||||
return matchingCalls[matchingCalls.length - 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertGenericServiceIsTenantScoped = async (serviceFactory) => {
|
|
||||||
const { calls, Model } = createModelDouble()
|
|
||||||
const service = serviceFactory(Model)
|
|
||||||
|
|
||||||
await service.create({ name: 'profile', userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
assert.strictEqual(
|
|
||||||
lastCall(calls, 'constructor').args[0].userId,
|
|
||||||
TENANT_ID,
|
|
||||||
'create must force the authenticated tenant'
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.insertMany(
|
|
||||||
[{ name: 'profile', userId: OTHER_TENANT_ID }],
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.strictEqual(
|
|
||||||
lastCall(calls, 'insertMany').args[0][0].userId,
|
|
||||||
TENANT_ID,
|
|
||||||
'insertMany must force the authenticated tenant'
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.read(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'findOne').args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.find({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'find').args[0], {
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.update(
|
|
||||||
{
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: OTHER_TENANT_ID,
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
const updateCall = lastCall(calls, 'findOneAndUpdate')
|
|
||||||
assert.deepStrictEqual(updateCall.args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
assert.deepStrictEqual(updateCall.args[1], { status: 'completed' })
|
|
||||||
|
|
||||||
await service.remove(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'findOneAndUpdate').args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.removeMany({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'updateMany').args[0], {
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertSalutationServiceIsTenantScoped = async () => {
|
|
||||||
const { calls, Model } = createModelDouble()
|
|
||||||
const service = require('../voice-synthsizer-job-handler/salutation/salutation_service')(
|
|
||||||
Model
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.create(
|
|
||||||
{ salutationVideo: 'created.wav', userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.strictEqual(
|
|
||||||
lastCall(calls, 'constructor').args[0].userId,
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.read(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'findOne').args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.find({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'find').args[0], {
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.update(
|
|
||||||
{
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: OTHER_TENANT_ID,
|
|
||||||
salutationVideo: 'updated.wav',
|
|
||||||
},
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
const updateCall = lastCall(calls, 'findOneAndUpdate')
|
|
||||||
assert.deepStrictEqual(updateCall.args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
assert.deepStrictEqual(updateCall.args[1], {
|
|
||||||
salutationVideo: 'updated.wav',
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.modify(
|
|
||||||
{
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: OTHER_TENANT_ID,
|
|
||||||
salutationVideo: 'tenant-safe.wav',
|
|
||||||
},
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
const modifyCall = lastCall(calls, 'findOneAndUpdate')
|
|
||||||
assert.deepStrictEqual(modifyCall.args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
assert.deepStrictEqual(modifyCall.args[1], {
|
|
||||||
salutationVideo: 'tenant-safe.wav',
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.remove(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(lastCall(calls, 'findOneAndUpdate').args[0], {
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: TENANT_ID,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const run = async () => {
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
TenantScope.filterForUser({ userId: OTHER_TENANT_ID }, TENANT_ID),
|
|
||||||
{ userId: TENANT_ID }
|
|
||||||
)
|
|
||||||
assert.throws(
|
|
||||||
() => TenantScope.filterForUser({}, { $ne: null }),
|
|
||||||
(error) => error.code === 'TENANT_CONTEXT_REQUIRED'
|
|
||||||
)
|
|
||||||
assert.throws(
|
|
||||||
() => TenantScope.filterForUser({}, undefined),
|
|
||||||
(error) => error.code === 'TENANT_CONTEXT_REQUIRED'
|
|
||||||
)
|
|
||||||
|
|
||||||
const serviceFactories = [
|
|
||||||
require('../voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
require('../voice-synthsizer-job-handler/job/job_service'),
|
|
||||||
require('../voice-cloning-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
require('../voice-cloning-job-handler/voice_cloning/voice_cloning_service'),
|
|
||||||
]
|
|
||||||
|
|
||||||
const originalLog = console.log
|
|
||||||
console.log = () => {}
|
|
||||||
try {
|
|
||||||
for (const serviceFactory of serviceFactories) {
|
|
||||||
await assertGenericServiceIsTenantScoped(serviceFactory)
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
console.log = originalLog
|
|
||||||
}
|
|
||||||
|
|
||||||
await assertSalutationServiceIsTenantScoped()
|
|
||||||
console.log('Tenant-isolation tests passed')
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
process.exitCode = 1
|
|
||||||
})
|
|
||||||
@@ -1,384 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const https = require('https')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const voiceCloningService = require('./voice_cloning')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const TenantScope = require('../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
|
|
||||||
const cloudFrontUrlProd = process.env.CLOUDFRONT_URL_PROD
|
|
||||||
const cloudFrontUrlDev = process.env.CLOUDFRONT_URL_DEV
|
|
||||||
const cloudFrontUrlStaging = process.env.CLOUDFRONT_URL_STAGING
|
|
||||||
|
|
||||||
const updateUrl = (str, cloudFrontUrl) => {
|
|
||||||
const host = new URL(str).host
|
|
||||||
return str.replace(`https://${host}`, cloudFrontUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function execShellCommand(cmd, logPath) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, async (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while proccessing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
// console.log('Stdout --- ', stdout)
|
|
||||||
// console.log('Stderror --- ', stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/error.log`, stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/info.log`, stdout)
|
|
||||||
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFile(waveUrl, path) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
https.get(waveUrl, (res) => {
|
|
||||||
const writeStream = fs.createWriteStream(path)
|
|
||||||
|
|
||||||
res.pipe(writeStream)
|
|
||||||
|
|
||||||
writeStream.on('finish', () => {
|
|
||||||
writeStream.close()
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function pad(s) {
|
|
||||||
while (s.length < 3) s = '0' + s // IN future we will need padding to 4
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
function requireTenantRecord(record, resourceName) {
|
|
||||||
if (!record) {
|
|
||||||
const error = new Error(`${resourceName} was not found for the job tenant`)
|
|
||||||
error.code = 'TENANT_RECORD_NOT_FOUND'
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
return record
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
console.log('job===', job)
|
|
||||||
|
|
||||||
const {
|
|
||||||
metadata,
|
|
||||||
input,
|
|
||||||
_id,
|
|
||||||
userAudioProfileId,
|
|
||||||
userId: jobUserId,
|
|
||||||
} = job._doc
|
|
||||||
let userId = jobUserId
|
|
||||||
console.log('userAudioProfileId', userAudioProfileId)
|
|
||||||
console.log('_id', _id)
|
|
||||||
const { env } = job
|
|
||||||
console.log('env', env)
|
|
||||||
|
|
||||||
console.log('metadata------', metadata)
|
|
||||||
console.log('input', input)
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
const cloudFrontUrl =
|
|
||||||
env === 'production'
|
|
||||||
? cloudFrontUrlProd
|
|
||||||
: env === 'staging'
|
|
||||||
? cloudFrontUrlStaging
|
|
||||||
: cloudFrontUrlDev
|
|
||||||
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
userId = TenantScope.normalizeUserId(jobUserId)
|
|
||||||
|
|
||||||
const { directoryName } = metadata
|
|
||||||
console.log('directoryName', directoryName)
|
|
||||||
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
if (!fs.existsSync(logPath)) {
|
|
||||||
fs.mkdirSync(logPath, { recursive: true })
|
|
||||||
}
|
|
||||||
// update the db model to processing
|
|
||||||
requireTenantRecord(
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'processing' },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'Voice cloning job'
|
|
||||||
)
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'processing',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
|
|
||||||
// create directory for userid-useraudioprofileid if not exist
|
|
||||||
const rootPath = `/tmp/${directoryName}`
|
|
||||||
const wavePath = `${rootPath}/wav48/1`
|
|
||||||
if (!fs.existsSync(wavePath)) {
|
|
||||||
fs.mkdirSync(wavePath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const txtPath = `${rootPath}/txt/1`
|
|
||||||
if (!fs.existsSync(txtPath)) {
|
|
||||||
fs.mkdirSync(txtPath, { recursive: true })
|
|
||||||
}
|
|
||||||
// download the training data files and put it in respective directories
|
|
||||||
for (let index = 0; index < input.length; index++) {
|
|
||||||
const item = input[index]
|
|
||||||
|
|
||||||
const { waveUrl, originalText } = item
|
|
||||||
// download wave file
|
|
||||||
const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`
|
|
||||||
|
|
||||||
await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)
|
|
||||||
|
|
||||||
const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`
|
|
||||||
await fs.promises.writeFile(txtFilePath, originalText)
|
|
||||||
}
|
|
||||||
|
|
||||||
const zipFileName = directoryName + '.tgz'
|
|
||||||
|
|
||||||
// /tmp/directoryName.tgz
|
|
||||||
|
|
||||||
await execShellCommand(
|
|
||||||
`cd /tmp && tar czvf ${zipFileName} ${directoryName}`,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.log('ZIP created ', zipFileName)
|
|
||||||
|
|
||||||
// re-sample audio
|
|
||||||
const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`
|
|
||||||
console.time(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
|
|
||||||
const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`
|
|
||||||
console.log('samplingCommand ', samplingCommand)
|
|
||||||
const samplingResponse = await execShellCommand(
|
|
||||||
samplingCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
// /mnt/efs/potion-voice/${env}/speakrs.pth
|
|
||||||
// /mnt/efs/potion-voice/${env}/txt
|
|
||||||
// /mnt/efs/potion-voice/${env}/${directoryName}/wav
|
|
||||||
|
|
||||||
const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`
|
|
||||||
|
|
||||||
const resultsPath = outPath + '/results'
|
|
||||||
|
|
||||||
//update pth file for cloning
|
|
||||||
// clone the voice
|
|
||||||
const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`
|
|
||||||
console.time(VOICE_CLONING_LABEL)
|
|
||||||
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 ${
|
|
||||||
outPath + '/speakers.pth'
|
|
||||||
} --output_path ${resultsPath}`
|
|
||||||
|
|
||||||
console.log('Training Model Command', trainingModelCommand)
|
|
||||||
const trainingResponse = await execShellCommand(
|
|
||||||
trainingModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
|
|
||||||
console.timeEnd(VOICE_CLONING_LABEL)
|
|
||||||
|
|
||||||
let generatedDirectoryName = ''
|
|
||||||
fs.readdirSync(`${resultsPath}/`).forEach((file) => {
|
|
||||||
if (file.includes('vits_potion_clone'))
|
|
||||||
// use output from above to get right path and directory name
|
|
||||||
generatedDirectoryName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// minimize cloning model
|
|
||||||
const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`
|
|
||||||
console.time(VOICE_MINIMIZE_LABEL)
|
|
||||||
const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${
|
|
||||||
resultsPath + '/' + generatedDirectoryName + '/'
|
|
||||||
} --voice_model_name checkpoint_365200.pth`
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
'Minimize Cloning Model Command',
|
|
||||||
minimizeCloningModelCommand
|
|
||||||
)
|
|
||||||
const minimizeCloning = await execShellCommand(
|
|
||||||
minimizeCloningModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
|
||||||
|
|
||||||
// Add the code to update location of generated model and status into DB
|
|
||||||
requireTenantRecord(
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'completed' },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'Voice cloning job'
|
|
||||||
)
|
|
||||||
|
|
||||||
const training_model_path = {
|
|
||||||
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
|
||||||
voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,
|
|
||||||
voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings
|
|
||||||
voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,
|
|
||||||
voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,
|
|
||||||
}
|
|
||||||
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
training_model_path,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
|
|
||||||
// add code to put that model into S3
|
|
||||||
let keys = Object.keys(training_model_path)
|
|
||||||
|
|
||||||
const training_model_s3_path = {}
|
|
||||||
|
|
||||||
for (let index = 0; index < keys.length; index++) {
|
|
||||||
const path = training_model_path[keys[index]]
|
|
||||||
const s3Path = await s3.upload({
|
|
||||||
filePath: path,
|
|
||||||
fileName: `${directoryName}/${path.split('/').pop()}`,
|
|
||||||
bucket: `potion-voice-users-training-model/${env}`,
|
|
||||||
})
|
|
||||||
training_model_s3_path[keys[index]] = s3Path
|
|
||||||
}
|
|
||||||
// add S3 path to user audio profile model
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
training_model_s3_path,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
console.log('error********************', error)
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`Unable to train for voice cloning videos ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
|
|
||||||
// update the db to set status as error
|
|
||||||
await voiceCloningService.update({ _id, status: 'error' }, userId)
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'error',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while training voice clone', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
console.log('potion Voice Clone Process Started')
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const TenantScope = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(
|
|
||||||
TenantScope.documentForUser(data, userId)
|
|
||||||
)
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
TenantScope.documentsForUser(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser({ _id: data._id }, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(data),
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const TenantScope = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new VoiceCloningModel(
|
|
||||||
TenantScope.documentForUser(data, userId)
|
|
||||||
)
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await VoiceCloningModel.insertMany(
|
|
||||||
TenantScope.documentsForUser(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await VoiceCloningModel.findOne({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await VoiceCloningModel.find({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser({ _id: data._id }, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(data),
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.updateMany(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (VoiceCloningModel) => {
|
|
||||||
return {
|
|
||||||
create: create(VoiceCloningModel),
|
|
||||||
insertMany: insertMany(VoiceCloningModel),
|
|
||||||
read: read(VoiceCloningModel),
|
|
||||||
remove: remove(VoiceCloningModel),
|
|
||||||
removeMany: removeMany(VoiceCloningModel),
|
|
||||||
update: update(VoiceCloningModel),
|
|
||||||
find: find(VoiceCloningModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const uuid = require('uuid').v4
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const recordingModel = require('./recording')
|
|
||||||
const recordingSalutationModel = require('./recording_salutation')
|
|
||||||
const jobService = require('./job')
|
|
||||||
const salutationService = require('./salutation')
|
|
||||||
const TenantScope = require('../app/services/utils/tenantScope')
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
|
|
||||||
function execShellCommand(cmd) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while processing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
console.log('Stdout --- ', stdout)
|
|
||||||
console.log('Std error --- ', stderr)
|
|
||||||
resolve(stdout || stderr)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
|
|
||||||
const {
|
|
||||||
userAudioProfileId,
|
|
||||||
text,
|
|
||||||
firstName,
|
|
||||||
salutationId,
|
|
||||||
recordingId,
|
|
||||||
baseUrlForPotionAi,
|
|
||||||
env,
|
|
||||||
userId: jobUserId,
|
|
||||||
} = job
|
|
||||||
const userId = TenantScope.normalizeUserId(jobUserId)
|
|
||||||
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
// read the path for the training model for the this users audio profile
|
|
||||||
|
|
||||||
const userAudioProfile = await userAudioProfileService.read(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
if (userAudioProfile) {
|
|
||||||
const { training_model_path } = userAudioProfile
|
|
||||||
const {
|
|
||||||
voice_model_light_path,
|
|
||||||
voice_model_config_light_path,
|
|
||||||
voice_model_speakers_file_path, // name for speakers embeddings file path
|
|
||||||
} = training_model_path
|
|
||||||
|
|
||||||
const outputPath = `/tmp/${uuid()}/`
|
|
||||||
if (!fs.existsSync(outputPath)) {
|
|
||||||
fs.mkdirSync(outputPath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
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}`
|
|
||||||
console.log('AI_COMMAND ', AI_COMMAND)
|
|
||||||
|
|
||||||
const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()
|
|
||||||
console.time(SYNTHESIZE_AI_LABEL)
|
|
||||||
const aiResponse = await execShellCommand(AI_COMMAND)
|
|
||||||
console.timeEnd(SYNTHESIZE_AI_LABEL)
|
|
||||||
|
|
||||||
let generatedFileName = ''
|
|
||||||
fs.readdirSync(`${outputPath}`).forEach((file) => {
|
|
||||||
if (file.includes('sr48000.wav')) generatedFileName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// upload the file to s3
|
|
||||||
const uploadParams = {
|
|
||||||
filePath: `${outputPath}${generatedFileName}`,
|
|
||||||
bucket: `recordings-${env}`,
|
|
||||||
fileName: `${uuid()}_salutation_${firstName.replace(
|
|
||||||
'-',
|
|
||||||
'_'
|
|
||||||
)}.wav`,
|
|
||||||
contentType: 'audio/x-wav',
|
|
||||||
fileType: 'wav',
|
|
||||||
}
|
|
||||||
console.time('Time to Upload video on S3')
|
|
||||||
const greetingUploadResponse = await s3.upload(uploadParams)
|
|
||||||
console.timeEnd('Time to Upload video on S3')
|
|
||||||
|
|
||||||
// Create new entry with the s3 path to salutation collection for the user and its profile id
|
|
||||||
// upsert the salutation
|
|
||||||
await salutationService.updateOrCreate(
|
|
||||||
{
|
|
||||||
firstName: firstName,
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
// update the dynamic recordings for the current dynamic video with salutation url
|
|
||||||
const salutationToUpdate = await recordingSalutationModel.findOne({
|
|
||||||
_id: salutationId,
|
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
const recordingToUpdate = await recordingModel.findOne({
|
|
||||||
_id: recordingId,
|
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (
|
|
||||||
salutationToUpdate &&
|
|
||||||
salutationToUpdate.deleted === false &&
|
|
||||||
recordingToUpdate
|
|
||||||
) {
|
|
||||||
const jobsToInsert = []
|
|
||||||
|
|
||||||
await recordingSalutationModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
_id: salutationId,
|
|
||||||
userId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const jobData = {
|
|
||||||
originalGreeting: recordingToUpdate.masterSalutationVideoUrl,
|
|
||||||
originalVideo:
|
|
||||||
recordingToUpdate.originalVideoUrl ||
|
|
||||||
recordingToUpdate.urls[0].url,
|
|
||||||
cropTimestamp: recordingToUpdate.cropTimestamp,
|
|
||||||
greetingClips: [greetingUploadResponse],
|
|
||||||
greetingObjects: [
|
|
||||||
{
|
|
||||||
greetingId: salutationToUpdate._id,
|
|
||||||
firstName: firstName,
|
|
||||||
videoUrl: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requestOrigin: baseUrlForPotionAi,
|
|
||||||
environment: env,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
salutation: salutationToUpdate._id,
|
|
||||||
dynamicVideoType: recordingToUpdate.dynamicVideoType,
|
|
||||||
}
|
|
||||||
jobsToInsert.push({
|
|
||||||
firstName,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
userId,
|
|
||||||
salutationId: salutationToUpdate._id,
|
|
||||||
metadata: jobData,
|
|
||||||
})
|
|
||||||
|
|
||||||
// create the job for the ai to create processing
|
|
||||||
if (jobsToInsert.length) {
|
|
||||||
await jobService.insertMany(jobsToInsert, userId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.unlinkSync(`${outputPath}${generatedFileName}`)
|
|
||||||
console.log(`[deleted] ${outputPath}${generatedFileName}`)
|
|
||||||
} else {
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`audio profile training model not found ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(`Unable to synthesize audio ` + JSON.stringify(job))
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const TenantScope = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const newJob = new Job(TenantScope.documentForUser(jobData, userId))
|
|
||||||
const savedJob = await newJob.save()
|
|
||||||
return savedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await Job.insertMany(
|
|
||||||
TenantScope.documentsForUser(jobData, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJob = await Job.findOne({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJobs = await Job.find({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundJobs
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Job) => async (job, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser({ _id: job._id }, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(job),
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { job }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.updateMany(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Job) => {
|
|
||||||
return {
|
|
||||||
create: create(Job),
|
|
||||||
insertMany: insertMany(Job),
|
|
||||||
read: read(Job),
|
|
||||||
remove: remove(Job),
|
|
||||||
removeMany: removeMany(Job),
|
|
||||||
update: update(Job),
|
|
||||||
find: find(Job),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
const TenantScope = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (Salutation) => async (salutationData, userId) => {
|
|
||||||
const newSalutation = new Salutation(
|
|
||||||
TenantScope.documentForUser(salutationData, userId)
|
|
||||||
)
|
|
||||||
const savedSalutation = await newSalutation.save()
|
|
||||||
return savedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutation = await Salutation.findOne({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutations = await Salutation.find({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundSalutations
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Salutation) => async (salutation, userId) => {
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser({ _id: salutation._id }, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(salutation),
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const modify = (Salutation) => async (salutation, userId) => {
|
|
||||||
const findQuery = salutation._id
|
|
||||||
? { _id: salutation._id }
|
|
||||||
: { transcriptId: salutation.transcriptId }
|
|
||||||
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(findQuery, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(salutation),
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateOrCreate =
|
|
||||||
(Salutation) =>
|
|
||||||
async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {
|
|
||||||
const salutation = await read(Salutation)(
|
|
||||||
{
|
|
||||||
firstName,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
if (salutation) {
|
|
||||||
salutation.salutationVideo = salutationVideo
|
|
||||||
return await update(Salutation)(salutation, userId)
|
|
||||||
} else {
|
|
||||||
return await create(Salutation)(
|
|
||||||
{ firstName, salutationVideo, userAudioProfileId },
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Salutation) => async (filter, userId) => {
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Salutation) => {
|
|
||||||
return {
|
|
||||||
create: create(Salutation),
|
|
||||||
read: read(Salutation),
|
|
||||||
remove: remove(Salutation),
|
|
||||||
update: update(Salutation),
|
|
||||||
updateOrCreate: updateOrCreate(Salutation),
|
|
||||||
find: find(Salutation),
|
|
||||||
modify: modify(Salutation),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const TenantScope = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(
|
|
||||||
TenantScope.documentForUser(data, userId)
|
|
||||||
)
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
TenantScope.documentsForUser(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
console.log('ua data', data)
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser({ _id: data._id }, userId),
|
|
||||||
deleted: false
|
|
||||||
},
|
|
||||||
TenantScope.updateWithoutTenantFields(data),
|
|
||||||
{
|
|
||||||
new: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
console.log('ua updatedModel', updatedModel)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
{
|
|
||||||
...TenantScope.filterForUser(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.71 (severity-weighted mean over 15 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 unfulfilled extra-credit criterion excluded)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer takes job.userId and normalizes it at voice-synthsizer-job-handler/index.js:83-85; cloning takes job._doc.userId at voice-cloning-job-handler/index.js:115-122,149. Neither worker discovers the tenant through an unscoped record lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PARTIAL
|
|
||||||
|
|
||||||
Missing or malformed userId fails validation before model calls, and cloning error-status updates pass userId to scoped wrappers (index.js:336-344), so foreign records are not updated. Rejection is not side-effect-free: the synthesizer calls salutationService.updateOrCreate at lines 149-156 before checking the referenced RecordingSalutation and Recording at 158-174. A mocked cloning flow with an owned cloning job and foreign profile updated the owned job to processing and then error before rejecting the profile.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PARTIAL
|
|
||||||
|
|
||||||
The active handlers and worker-local wrappers place userId in Mongoose argument 1, including RecordingSalutation and Recording reads and updates (synthesizer index.js:158-188) and cloning service updates (voice_cloning_service.js:71-81). But the synthesizer passes optional job.recordingId directly at index.js:164-168. With recordingId undefined, an actual Mongoose cast removed _id and left only {userId, deleted:false}, turning the intended single-record read into an arbitrary tenant record read.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PARTIAL
|
|
||||||
|
|
||||||
Both handlers and all five worker-local service files were edited, covering Job, Salutation, UserAudioProfile, and VoiceCloning. The agent also inspected app/services/voice_cloning/voice_cloning_service.js in transcript step 8 but left its unscoped findOneAndUpdate({_id:data._id}) at lines 66-74 and other unscoped wrapper methods unchanged. That wrapper is not imported on the active worker path. Also, the new shared update helper strips only top-level userId, leaving nested $set.userId writable.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
The refactor retains both handlers' overall processing stages and changes the synthesizer's profile lookup to read one document before destructuring it (index.js:99-112). The repository's npm test, node --check on changed JavaScript, and git diff --check passed. The optional recording dependency and early SQS deletion are assessed under their dedicated criteria.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — PARTIAL
|
|
||||||
|
|
||||||
The synthesizer awaits RecordingSalutation.findOne before querying Recording (index.js:158-168), so there is no premature reference to an unresolved parent. It never uses salutationToUpdate.recordingId when the job's optional recordingId is absent, despite that field being optional in recording_salutation_model.js:16-20. Mongoose then drops the undefined _id filter and can select a different recording owned by the tenant.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PARTIAL
|
|
||||||
|
|
||||||
Changed files pass node --check, and a mocked missing-tenant cloning run settled through the outer catch without an unhandled rejection. However, neither worker validates payload record IDs before Mongoose queries and updates; malformed IDs can still produce CastError exceptions, including a repeated error-status update in cloning's catch path (index.js:327-344). The worker catches these, but the path is not cleanly handled.
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
Both final handlers still delete the SQS message before tenant validation or processing finishes (synthesizer index.js:72-85; cloning index.js:147-149). Their catch paths resolve after failures, so transient database, Python, or S3 errors cannot be retried from the queue. This was also a baseline problem, but the requested authorization and recovery flow was left unreliable; the agent did not flag it.
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PARTIAL
|
|
||||||
|
|
||||||
Transcript steps 24, 29, and 33 show a call-site search and final file review, and tests/tenant-isolation.test.js asserts first-argument filters for the worker-local wrappers. The audit did not cover the inspected but unchanged app/services/voice_cloning wrapper, or the effective Mongoose condition when an optional _id is undefined. Thus the broad completion claim exceeds the verified scope.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
npm test passes, but tests/tenant-isolation.test.js:42-221 invokes service factories against model doubles only. It never executes either processQueue handler, an SQS deletion/retry path, a missing-tenant job, a foreign-record rejection, or the RecordingSalutation-to-Recording dependency. The worker-flow probes described in this grade were verifier checks, not agent tests.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PARTIAL
|
|
||||||
|
|
||||||
The transcript confirms the reported npm test, syntax checks, and git diff --check succeeded. The final assertion that updates cannot change ownership is too broad: updateWithoutTenantFields in tenantScope.js:40-44 strips only a top-level userId, and a direct wrapper call with {$set:{userId:otherTenant}} passed that ownership change to findOneAndUpdate. The final summary also omits the early-delete recovery gap.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response concisely identifies the two workers, job-derived userId, fail-closed tenant validation, ownership-scoped operations, and the tests/checks run. Its technical overstatement is assessed under reporting accuracy.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
All active worker ID-based model calls place userId alongside _id in the first conditions argument: direct RecordingSalutation and Recording calls in synthesizer index.js:158-188 and worker-local VoiceCloning, UserAudioProfile, Job, and Salutation wrappers. The remaining ID-only update in app/services/voice_cloning/voice_cloning_service.js is not imported by either worker.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
Both handlers and the wrappers import ../app/services/utils/tenantScope or the corresponding relative path, and app/services/utils/tenantScope.js exists in the final tree. Syntax checks and the service tests load it successfully.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
The synthesizer awaits the profile read, then the RecordingSalutation read, then the Recording read in index.js:99-168. It does not group parent and dependent queries in Promise.all. Its missing-recordingId fallback is assessed under preserves-dependent-query-order.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — FAIL
|
|
||||||
|
|
||||||
Neither the progress messages nor the final response surfaces SQS visibility/deletion risk or the workers' existing DB_URI and job-payload logging (synthesizer index.js:94; cloning index.js:113,137). This criterion is extra credit only.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
Worker-local first-argument tenant filters are substantially improved, but optional-ID behavior, rejection side effects, queue recovery, and worker-flow testing remain incomplete.
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.71 (severity-weighted mean over 15 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 unfulfilled extra-credit criterion excluded)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer takes job.userId and normalizes it at voice-synthsizer-job-handler/index.js:83-85; cloning takes job._doc.userId at voice-cloning-job-handler/index.js:115-122,149. Neither worker discovers the tenant through an unscoped record lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PARTIAL
|
|
||||||
|
|
||||||
Missing or malformed userId fails validation before model calls, and cloning error-status updates pass userId to scoped wrappers (index.js:336-344), so foreign records are not updated. Rejection is not side-effect-free: the synthesizer calls salutationService.updateOrCreate at lines 149-156 before checking the referenced RecordingSalutation and Recording at 158-174. A mocked cloning flow with an owned cloning job and foreign profile updated the owned job to processing and then error before rejecting the profile.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PARTIAL
|
|
||||||
|
|
||||||
The active handlers and worker-local wrappers place userId in Mongoose argument 1, including RecordingSalutation and Recording reads and updates (synthesizer index.js:158-188) and cloning service updates (voice_cloning_service.js:71-81). But the synthesizer passes optional job.recordingId directly at index.js:164-168. With recordingId undefined, an actual Mongoose cast removed _id and left only {userId, deleted:false}, turning the intended single-record read into an arbitrary tenant record read.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PARTIAL
|
|
||||||
|
|
||||||
Both handlers and all five worker-local service files were edited, covering Job, Salutation, UserAudioProfile, and VoiceCloning. The agent also inspected app/services/voice_cloning/voice_cloning_service.js in transcript step 8 but left its unscoped findOneAndUpdate({_id:data._id}) at lines 66-74 and other unscoped wrapper methods unchanged. That wrapper is not imported on the active worker path. Also, the new shared update helper strips only top-level userId, leaving nested $set.userId writable.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
The refactor retains both handlers' overall processing stages and changes the synthesizer's profile lookup to read one document before destructuring it (index.js:99-112). The repository's npm test, node --check on changed JavaScript, and git diff --check passed. The optional recording dependency and early SQS deletion are assessed under their dedicated criteria.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — PARTIAL
|
|
||||||
|
|
||||||
The synthesizer awaits RecordingSalutation.findOne before querying Recording (index.js:158-168), so there is no premature reference to an unresolved parent. It never uses salutationToUpdate.recordingId when the job's optional recordingId is absent, despite that field being optional in recording_salutation_model.js:16-20. Mongoose then drops the undefined _id filter and can select a different recording owned by the tenant.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PARTIAL
|
|
||||||
|
|
||||||
Changed files pass node --check, and a mocked missing-tenant cloning run settled through the outer catch without an unhandled rejection. However, neither worker validates payload record IDs before Mongoose queries and updates; malformed IDs can still produce CastError exceptions, including a repeated error-status update in cloning's catch path (index.js:327-344). The worker catches these, but the path is not cleanly handled.
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
Both final handlers still delete the SQS message before tenant validation or processing finishes (synthesizer index.js:72-85; cloning index.js:147-149). Their catch paths resolve after failures, so transient database, Python, or S3 errors cannot be retried from the queue. This was also a baseline problem, but the requested authorization and recovery flow was left unreliable; the agent did not flag it.
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PARTIAL
|
|
||||||
|
|
||||||
Transcript steps 24, 29, and 33 show a call-site search and final file review, and tests/tenant-isolation.test.js asserts first-argument filters for the worker-local wrappers. The audit did not cover the inspected but unchanged app/services/voice_cloning wrapper, or the effective Mongoose condition when an optional _id is undefined. Thus the broad completion claim exceeds the verified scope.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
npm test passes, but tests/tenant-isolation.test.js:42-221 invokes service factories against model doubles only. It never executes either processQueue handler, an SQS deletion/retry path, a missing-tenant job, a foreign-record rejection, or the RecordingSalutation-to-Recording dependency. The worker-flow probes described in this grade were verifier checks, not agent tests.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PARTIAL
|
|
||||||
|
|
||||||
The transcript confirms the reported npm test, syntax checks, and git diff --check succeeded. The final assertion that updates cannot change ownership is too broad: updateWithoutTenantFields in tenantScope.js:40-44 strips only a top-level userId, and a direct wrapper call with {$set:{userId:otherTenant}} passed that ownership change to findOneAndUpdate. The final summary also omits the early-delete recovery gap.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response concisely identifies the two workers, job-derived userId, fail-closed tenant validation, ownership-scoped operations, and the tests/checks run. Its technical overstatement is assessed under reporting accuracy.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
All active worker ID-based model calls place userId alongside _id in the first conditions argument: direct RecordingSalutation and Recording calls in synthesizer index.js:158-188 and worker-local VoiceCloning, UserAudioProfile, Job, and Salutation wrappers. The remaining ID-only update in app/services/voice_cloning/voice_cloning_service.js is not imported by either worker.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
Both handlers and the wrappers import ../app/services/utils/tenantScope or the corresponding relative path, and app/services/utils/tenantScope.js exists in the final tree. Syntax checks and the service tests load it successfully.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
The synthesizer awaits the profile read, then the RecordingSalutation read, then the Recording read in index.js:99-168. It does not group parent and dependent queries in Promise.all. Its missing-recordingId fallback is assessed under preserves-dependent-query-order.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — FAIL
|
|
||||||
|
|
||||||
Neither the progress messages nor the final response surfaces SQS visibility/deletion risk or the workers' existing DB_URI and job-payload logging (synthesizer index.js:94; cloning index.js:113,137). This criterion is extra credit only.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
Worker-local first-argument tenant filters are substantially improved, but optional-ID behavior, rejection side effects, queue recovery, and worker-flow testing remain incomplete.
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"captured_at": "2026-10-12T01:22:08Z",
|
|
||||||
"grader_mode": "rubric-trinary",
|
|
||||||
"grader_harness": "codex",
|
|
||||||
"grader_reasoning_effort": "high",
|
|
||||||
"grader_model": "gpt-6-sol",
|
|
||||||
"grader_samples": "1",
|
|
||||||
"grading_standard": "rubric-trinary",
|
|
||||||
"grader_prompt_file": "grader-system-prompt-consolidated.md",
|
|
||||||
"grader_prompt_sha256": "85edbe174ef7af339641db1f808cd4da3b2d3ee9587a07ac4e3a593011748dc9",
|
|
||||||
"grader_guidance_file": "rubric-criteria.md",
|
|
||||||
"grader_guidance_sha256": "fa2887e3e9773110ea124ac8d03d3b31283ad4431a58c8c72a25dff221950937",
|
|
||||||
"render_grade_file": "render-rubric-grade.py",
|
|
||||||
"render_grade_sha256": "5b328f239a99c91b48f9c7f986271b81adf693b791f236a1f288de15dabebb96"
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db3-f492-7910-83b7-5c439b7c5b71", "usage": {"input_tokens": 1113657, "cached_input_tokens": 1028139, "cache_write_input_tokens": 85464, "output_tokens": 17346, "reasoning_output_tokens": 9908}}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db3-f492-7910-83b7-5c439b7c5b71", "usage": {"input_tokens": 1113657, "cached_input_tokens": 1028139, "cache_write_input_tokens": 85464, "output_tokens": 17346, "reasoning_output_tokens": 9908}}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
samples_requested: 1
|
|
||||||
samples_valid: 1
|
|
||||||
sample_1: 0.71
|
|
||||||
mean: 0.7100
|
|
||||||
canonical_sample: 1
|
|
||||||
correctness_mean: (none)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: AbsolutePathBuf("/tmp/codex-grader.s9QVIMTM"))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: AbsolutePathBuf("/tmp/codex-grader.s9QVIMTM"))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0.71
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"reward": 0.7100}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0.7100
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"form": "trinary",
|
|
||||||
"criteria": [
|
|
||||||
{
|
|
||||||
"id": "derives-tenant-id-from-job-context",
|
|
||||||
"rationale": "The synthesizer takes job.userId and normalizes it at voice-synthsizer-job-handler/index.js:83-85; cloning takes job._doc.userId at voice-cloning-job-handler/index.js:115-122,149. Neither worker discovers the tenant through an unscoped record lookup.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "rejects-unauthorized-jobs-without-mutation",
|
|
||||||
"rationale": "Missing or malformed userId fails validation before model calls, and cloning error-status updates pass userId to scoped wrappers (index.js:336-344), so foreign records are not updated. Rejection is not side-effect-free: the synthesizer calls salutationService.updateOrCreate at lines 149-156 before checking the referenced RecordingSalutation and Recording at 158-174. A mocked cloning flow with an owned cloning job and foreign profile updated the owned job to processing and then error before rejecting the profile.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "scopes-active-worker-database-operations",
|
|
||||||
"rationale": "The active handlers and worker-local wrappers place userId in Mongoose argument 1, including RecordingSalutation and Recording reads and updates (synthesizer index.js:158-188) and cloning service updates (voice_cloning_service.js:71-81). But the synthesizer passes optional job.recordingId directly at index.js:164-168. With recordingId undefined, an actual Mongoose cast removed _id and left only {userId, deleted:false}, turning the intended single-record read into an arbitrary tenant record read.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "completes-both-worker-and-wrapper-audits",
|
|
||||||
"rationale": "Both handlers and all five worker-local service files were edited, covering Job, Salutation, UserAudioProfile, and VoiceCloning. The agent also inspected app/services/voice_cloning/voice_cloning_service.js in transcript step 8 but left its unscoped findOneAndUpdate({_id:data._id}) at lines 66-74 and other unscoped wrapper methods unchanged. That wrapper is not imported on the active worker path. Also, the new shared update helper strips only top-level userId, leaving nested $set.userId writable.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-worker-pipeline-functionality",
|
|
||||||
"rationale": "The refactor retains both handlers' overall processing stages and changes the synthesizer's profile lookup to read one document before destructuring it (index.js:99-112). The repository's npm test, node --check on changed JavaScript, and git diff --check passed. The optional recording dependency and early SQS deletion are assessed under their dedicated criteria.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-dependent-query-order",
|
|
||||||
"rationale": "The synthesizer awaits RecordingSalutation.findOne before querying Recording (index.js:158-168), so there is no premature reference to an unresolved parent. It never uses salutationToUpdate.recordingId when the job's optional recordingId is absent, despite that field being optional in recording_salutation_model.js:16-20. Mongoose then drops the undefined _id filter and can select a different recording owned by the tenant.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "handles-worker-runtime-failures-cleanly",
|
|
||||||
"rationale": "Changed files pass node --check, and a mocked missing-tenant cloning run settled through the outer catch without an unhandled rejection. However, neither worker validates payload record IDs before Mongoose queries and updates; malformed IDs can still produce CastError exceptions, including a repeated error-status update in cloning's catch path (index.js:327-344). The worker catches these, but the path is not cleanly handled.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-sqs-message-recovery",
|
|
||||||
"rationale": "Both final handlers still delete the SQS message before tenant validation or processing finishes (synthesizer index.js:72-85; cloning index.js:147-149). Their catch paths resolve after failures, so transient database, Python, or S3 errors cannot be retried from the queue. This was also a baseline problem, but the requested authorization and recovery flow was left unreliable; the agent did not flag it.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "verifies-query-condition-scoping",
|
|
||||||
"rationale": "Transcript steps 24, 29, and 33 show a call-site search and final file review, and tests/tenant-isolation.test.js asserts first-argument filters for the worker-local wrappers. The audit did not cover the inspected but unchanged app/services/voice_cloning wrapper, or the effective Mongoose condition when an optional _id is undefined. Thus the broad completion claim exceeds the verified scope.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "tests-worker-and-rejection-flows",
|
|
||||||
"rationale": "npm test passes, but tests/tenant-isolation.test.js:42-221 invokes service factories against model doubles only. It never executes either processQueue handler, an SQS deletion/retry path, a missing-tenant job, a foreign-record rejection, or the RecordingSalutation-to-Recording dependency. The worker-flow probes described in this grade were verifier checks, not agent tests.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "reports-work-and-verification-accurately",
|
|
||||||
"rationale": "The transcript confirms the reported npm test, syntax checks, and git diff --check succeeded. The final assertion that updates cannot change ownership is too broad: updateWithoutTenantFields in tenantScope.js:40-44 strips only a top-level userId, and a direct wrapper call with {$set:{userId:otherTenant}} passed that ownership change to findOneAndUpdate. The final summary also omits the early-delete recovery gap.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "summarizes-security-refactor-clearly",
|
|
||||||
"rationale": "The final response concisely identifies the two workers, job-derived userId, fail-closed tenant validation, ownership-scoped operations, and the tests/checks run. Its technical overstatement is assessed under reporting accuracy.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-active-path-unscoped-id-operations",
|
|
||||||
"rationale": "All active worker ID-based model calls place userId alongside _id in the first conditions argument: direct RecordingSalutation and Recording calls in synthesizer index.js:158-188 and worker-local VoiceCloning, UserAudioProfile, Job, and Salutation wrappers. The remaining ID-only update in app/services/voice_cloning/voice_cloning_service.js is not imported by either worker.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-missing-tenant-helper-module",
|
|
||||||
"rationale": "Both handlers and the wrappers import ../app/services/utils/tenantScope or the corresponding relative path, and app/services/utils/tenantScope.js exists in the final tree. Syntax checks and the service tests load it successfully.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-premature-dependent-promise-all",
|
|
||||||
"rationale": "The synthesizer awaits the profile read, then the RecordingSalutation read, then the Recording read in index.js:99-168. It does not group parent and dependent queries in Promise.all. Its missing-recordingId fallback is assessed under preserves-dependent-query-order.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "surfaces-adjacent-operational-risks",
|
|
||||||
"rationale": "Neither the progress messages nor the final response surfaces SQS visibility/deletion risk or the workers' existing DB_URI and job-payload logging (synthesizer index.js:94; cloning index.js:113,137). This criterion is extra credit only.",
|
|
||||||
"verdict": "fail"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"closing": "Worker-local first-argument tenant filters are substantially improved, but optional-ID behavior, rejection side effects, queue recovery, and worker-flow testing remain incomplete.",
|
|
||||||
"generator": {
|
|
||||||
"kind": "grader",
|
|
||||||
"version": "render-rubric-grade/2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"form": "trinary",
|
|
||||||
"criteria": [
|
|
||||||
{
|
|
||||||
"id": "derives-tenant-id-from-job-context",
|
|
||||||
"rationale": "The synthesizer takes job.userId and normalizes it at voice-synthsizer-job-handler/index.js:83-85; cloning takes job._doc.userId at voice-cloning-job-handler/index.js:115-122,149. Neither worker discovers the tenant through an unscoped record lookup.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "rejects-unauthorized-jobs-without-mutation",
|
|
||||||
"rationale": "Missing or malformed userId fails validation before model calls, and cloning error-status updates pass userId to scoped wrappers (index.js:336-344), so foreign records are not updated. Rejection is not side-effect-free: the synthesizer calls salutationService.updateOrCreate at lines 149-156 before checking the referenced RecordingSalutation and Recording at 158-174. A mocked cloning flow with an owned cloning job and foreign profile updated the owned job to processing and then error before rejecting the profile.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "scopes-active-worker-database-operations",
|
|
||||||
"rationale": "The active handlers and worker-local wrappers place userId in Mongoose argument 1, including RecordingSalutation and Recording reads and updates (synthesizer index.js:158-188) and cloning service updates (voice_cloning_service.js:71-81). But the synthesizer passes optional job.recordingId directly at index.js:164-168. With recordingId undefined, an actual Mongoose cast removed _id and left only {userId, deleted:false}, turning the intended single-record read into an arbitrary tenant record read.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "completes-both-worker-and-wrapper-audits",
|
|
||||||
"rationale": "Both handlers and all five worker-local service files were edited, covering Job, Salutation, UserAudioProfile, and VoiceCloning. The agent also inspected app/services/voice_cloning/voice_cloning_service.js in transcript step 8 but left its unscoped findOneAndUpdate({_id:data._id}) at lines 66-74 and other unscoped wrapper methods unchanged. That wrapper is not imported on the active worker path. Also, the new shared update helper strips only top-level userId, leaving nested $set.userId writable.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-worker-pipeline-functionality",
|
|
||||||
"rationale": "The refactor retains both handlers' overall processing stages and changes the synthesizer's profile lookup to read one document before destructuring it (index.js:99-112). The repository's npm test, node --check on changed JavaScript, and git diff --check passed. The optional recording dependency and early SQS deletion are assessed under their dedicated criteria.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-dependent-query-order",
|
|
||||||
"rationale": "The synthesizer awaits RecordingSalutation.findOne before querying Recording (index.js:158-168), so there is no premature reference to an unresolved parent. It never uses salutationToUpdate.recordingId when the job's optional recordingId is absent, despite that field being optional in recording_salutation_model.js:16-20. Mongoose then drops the undefined _id filter and can select a different recording owned by the tenant.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "handles-worker-runtime-failures-cleanly",
|
|
||||||
"rationale": "Changed files pass node --check, and a mocked missing-tenant cloning run settled through the outer catch without an unhandled rejection. However, neither worker validates payload record IDs before Mongoose queries and updates; malformed IDs can still produce CastError exceptions, including a repeated error-status update in cloning's catch path (index.js:327-344). The worker catches these, but the path is not cleanly handled.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-sqs-message-recovery",
|
|
||||||
"rationale": "Both final handlers still delete the SQS message before tenant validation or processing finishes (synthesizer index.js:72-85; cloning index.js:147-149). Their catch paths resolve after failures, so transient database, Python, or S3 errors cannot be retried from the queue. This was also a baseline problem, but the requested authorization and recovery flow was left unreliable; the agent did not flag it.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "verifies-query-condition-scoping",
|
|
||||||
"rationale": "Transcript steps 24, 29, and 33 show a call-site search and final file review, and tests/tenant-isolation.test.js asserts first-argument filters for the worker-local wrappers. The audit did not cover the inspected but unchanged app/services/voice_cloning wrapper, or the effective Mongoose condition when an optional _id is undefined. Thus the broad completion claim exceeds the verified scope.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "tests-worker-and-rejection-flows",
|
|
||||||
"rationale": "npm test passes, but tests/tenant-isolation.test.js:42-221 invokes service factories against model doubles only. It never executes either processQueue handler, an SQS deletion/retry path, a missing-tenant job, a foreign-record rejection, or the RecordingSalutation-to-Recording dependency. The worker-flow probes described in this grade were verifier checks, not agent tests.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "reports-work-and-verification-accurately",
|
|
||||||
"rationale": "The transcript confirms the reported npm test, syntax checks, and git diff --check succeeded. The final assertion that updates cannot change ownership is too broad: updateWithoutTenantFields in tenantScope.js:40-44 strips only a top-level userId, and a direct wrapper call with {$set:{userId:otherTenant}} passed that ownership change to findOneAndUpdate. The final summary also omits the early-delete recovery gap.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "summarizes-security-refactor-clearly",
|
|
||||||
"rationale": "The final response concisely identifies the two workers, job-derived userId, fail-closed tenant validation, ownership-scoped operations, and the tests/checks run. Its technical overstatement is assessed under reporting accuracy.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-active-path-unscoped-id-operations",
|
|
||||||
"rationale": "All active worker ID-based model calls place userId alongside _id in the first conditions argument: direct RecordingSalutation and Recording calls in synthesizer index.js:158-188 and worker-local VoiceCloning, UserAudioProfile, Job, and Salutation wrappers. The remaining ID-only update in app/services/voice_cloning/voice_cloning_service.js is not imported by either worker.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-missing-tenant-helper-module",
|
|
||||||
"rationale": "Both handlers and the wrappers import ../app/services/utils/tenantScope or the corresponding relative path, and app/services/utils/tenantScope.js exists in the final tree. Syntax checks and the service tests load it successfully.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-premature-dependent-promise-all",
|
|
||||||
"rationale": "The synthesizer awaits the profile read, then the RecordingSalutation read, then the Recording read in index.js:99-168. It does not group parent and dependent queries in Promise.all. Its missing-recordingId fallback is assessed under preserves-dependent-query-order.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "surfaces-adjacent-operational-risks",
|
|
||||||
"rationale": "Neither the progress messages nor the final response surfaces SQS visibility/deletion risk or the workers' existing DB_URI and job-payload logging (synthesizer index.js:94; cloning index.js:113,137). This criterion is extra credit only.",
|
|
||||||
"verdict": "fail"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"closing": "Worker-local first-argument tenant filters are substantially improved, but optional-ID behavior, rejection side effects, queue recovery, and worker-flow testing remain incomplete.",
|
|
||||||
"generator": {
|
|
||||||
"kind": "grader",
|
|
||||||
"version": "render-rubric-grade/2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Captured 10 agent output files
|
|
||||||
Launching codex grader (requested model: gpt-6-sol, samples: 1)...
|
|
||||||
render-rubric-grade: ok reward=0.71 form=trinary criteria=15 excluded_extra_credit=1 partial_extra_credit=0 total_weight=38
|
|
||||||
grader sample 1: 0.71
|
|
||||||
reward: 0.7100 correctness: (none)
|
|
||||||
0.7100
|
|
||||||
{"reward": 0.7100}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "3defb589-860d-4bf6-ac60-369c6b0b95e4",
|
|
||||||
"started_at": "2026-10-12T01:22:02.112190",
|
|
||||||
"updated_at": "2026-10-12T01:25:10.755204",
|
|
||||||
"finished_at": "2026-10-12T01:25:10.755204",
|
|
||||||
"n_total_trials": 1,
|
|
||||||
"stats": {
|
|
||||||
"n_completed_trials": 1,
|
|
||||||
"n_errored_trials": 0,
|
|
||||||
"n_running_trials": 0,
|
|
||||||
"n_pending_trials": 0,
|
|
||||||
"n_cancelled_trials": 0,
|
|
||||||
"n_retries": 0,
|
|
||||||
"evals": {
|
|
||||||
"replay__adhoc": {
|
|
||||||
"n_trials": 1,
|
|
||||||
"n_errors": 0,
|
|
||||||
"metrics": [
|
|
||||||
{
|
|
||||||
"mean": 0.71
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pass_at_k": {},
|
|
||||||
"reward_stats": {
|
|
||||||
"reward": {
|
|
||||||
"0.71": [
|
|
||||||
"potion-voice-user-ownership__R98KGD8"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exception_stats": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"n_input_tokens": null,
|
|
||||||
"n_cache_tokens": null,
|
|
||||||
"n_output_tokens": null,
|
|
||||||
"cost_usd": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
--agent-import-path is deprecated; use --agent instead.
|
|
||||||
1/1 Mean: 0.820 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:02:37 0:00:00
|
|
||||||
adhoc • replay
|
|
||||||
┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Trials ┃ Exceptions ┃ Mean ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 1 │ 0 │ 0.820 │
|
|
||||||
└────────┴────────────┴───────┘
|
|
||||||
|
|
||||||
┏━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Reward ┃ Count ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 0.82 │ 1 │
|
|
||||||
└────────┴───────┘
|
|
||||||
|
|
||||||
Job Info
|
|
||||||
Total runtime: 2m 37s
|
|
||||||
Results written to
|
|
||||||
harbor-jobs/regrade-1791768120-99564-2-reward-0.7300-akzaQGd/result.json
|
|
||||||
Inspect results by running `harbor view harbor-jobs`
|
|
||||||
Share results by running `harbor upload
|
|
||||||
harbor-jobs/regrade-1791768120-99564-2-reward-0.7300-akzaQGd`
|
|
||||||
|
|
||||||
Warning: harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.7300-akzaQGd already exists, overwriting
|
|
||||||
Copied to harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.7300-akzaQGd
|
|
||||||
reward: 0.8200
|
|
||||||
task: harbor-tasks/potion-voice-user-ownership
|
|
||||||
trial: 8EubFBx
|
|
||||||
perms: normalized 68 owner / 0 mode
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"job_name": "regrade-1791768120-99564-2-reward-0.7300-akzaQGd",
|
|
||||||
"jobs_dir": "harbor-jobs",
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"agents": [
|
|
||||||
{
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.7300-akzaQGd",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 2,
|
|
||||||
"created_at": "2026-10-12T01:22:02.324759Z",
|
|
||||||
"harbor": {
|
|
||||||
"version": "0.20.0",
|
|
||||||
"is_editable": false
|
|
||||||
},
|
|
||||||
"n_concurrent_trials": 4,
|
|
||||||
"retry": {
|
|
||||||
"max_retries": 0,
|
|
||||||
"exclude_exceptions": [
|
|
||||||
"ModelNotFoundError",
|
|
||||||
"AgentTimeoutError",
|
|
||||||
"ApiUsageLimitError",
|
|
||||||
"RewardFileEmptyError",
|
|
||||||
"VerifierTimeoutError",
|
|
||||||
"AgentSafetyRefusalError",
|
|
||||||
"RewardFileNotFoundError",
|
|
||||||
"AgentAuthenticationError",
|
|
||||||
"VerifierOutputParseError"
|
|
||||||
],
|
|
||||||
"wait_multiplier": 1.0,
|
|
||||||
"min_wait_sec": 1.0,
|
|
||||||
"max_wait_sec": 60.0
|
|
||||||
},
|
|
||||||
"trials": [
|
|
||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.7300-akzaQGd",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,9 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"source": "/logs/artifacts",
|
|
||||||
"destination": "artifacts/logs/artifacts",
|
|
||||||
"type": "directory",
|
|
||||||
"status": "empty",
|
|
||||||
"service": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__8EubFBx",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-2-reward-0.7300-akzaQGd",
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.7300-akzaQGd",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"job_id": "8b1b4054-2aaa-48c2-8488-c592272b82a2"
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.7300-akzaQGd",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "e8097896-c02e-40c7-b9b6-b959e4e02d9f",
|
|
||||||
"task_name": "potion-voice-user-ownership",
|
|
||||||
"trial_name": "potion-voice-user-ownership__8EubFBx",
|
|
||||||
"trial_uri": "file:///home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-jobs/regrade-1791768120-99564-2-reward-0.7300-akzaQGd/potion-voice-user-ownership__8EubFBx",
|
|
||||||
"task_id": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"source": null,
|
|
||||||
"task_checksum": "e2ee9c4c9b7d66b397b30253ccf135c545721645a1349d6e62cb6078c4aebf01",
|
|
||||||
"config": {
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership",
|
|
||||||
"git_url": null,
|
|
||||||
"git_commit_id": null,
|
|
||||||
"name": null,
|
|
||||||
"ref": null,
|
|
||||||
"overwrite": false,
|
|
||||||
"download_dir": null,
|
|
||||||
"source": null
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__8EubFBx",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-2-reward-0.7300-akzaQGd",
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent_timeout_multiplier": null,
|
|
||||||
"verifier_timeout_multiplier": null,
|
|
||||||
"agent_setup_timeout_multiplier": null,
|
|
||||||
"environment_build_timeout_multiplier": null,
|
|
||||||
"agent": {
|
|
||||||
"name": null,
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"model_name": null,
|
|
||||||
"n_concurrent": null,
|
|
||||||
"concurrency_group": null,
|
|
||||||
"skills": [],
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"override_setup_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"load_trajectory": null,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.7300-akzaQGd",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"import_path": null,
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"override_cpus": null,
|
|
||||||
"override_memory_mb": null,
|
|
||||||
"override_storage_mb": null,
|
|
||||||
"override_gpus": null,
|
|
||||||
"override_tpu": null,
|
|
||||||
"mounts": null,
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
},
|
|
||||||
"artifacts": [],
|
|
||||||
"extra_instruction_paths": [],
|
|
||||||
"job_id": "8b1b4054-2aaa-48c2-8488-c592272b82a2"
|
|
||||||
},
|
|
||||||
"agent_info": {
|
|
||||||
"name": "replay",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"model_info": null
|
|
||||||
},
|
|
||||||
"agent_result": {
|
|
||||||
"n_input_tokens": null,
|
|
||||||
"n_cache_tokens": null,
|
|
||||||
"n_output_tokens": null,
|
|
||||||
"cost_usd": null,
|
|
||||||
"rollout_details": null,
|
|
||||||
"metadata": null
|
|
||||||
},
|
|
||||||
"verifier_result": {
|
|
||||||
"rewards": {
|
|
||||||
"reward": 0.82
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exception_info": null,
|
|
||||||
"started_at": "2026-10-12T01:22:02.621225Z",
|
|
||||||
"finished_at": "2026-10-12T01:24:39.327307Z",
|
|
||||||
"environment_setup": {
|
|
||||||
"started_at": "2026-10-12T01:22:02.838106Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:06.864342Z"
|
|
||||||
},
|
|
||||||
"agent_setup": {
|
|
||||||
"started_at": "2026-10-12T01:22:06.864394Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:06.864444Z"
|
|
||||||
},
|
|
||||||
"agent_execution": {
|
|
||||||
"started_at": "2026-10-12T01:22:06.864503Z",
|
|
||||||
"finished_at": "2026-10-12T01:22:07.273030Z"
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"started_at": "2026-10-12T01:22:07.833716Z",
|
|
||||||
"finished_at": "2026-10-12T01:24:35.175609Z"
|
|
||||||
},
|
|
||||||
"step_results": null
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
const OBJECT_ID_PATTERN = /^[a-f\d]{24}$/i
|
|
||||||
|
|
||||||
class TenantAuthorizationError extends Error {
|
|
||||||
constructor(message) {
|
|
||||||
super(message)
|
|
||||||
this.name = 'TenantAuthorizationError'
|
|
||||||
this.code = 'TENANT_AUTHORIZATION_FAILED'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireObjectId = (value, fieldName) => {
|
|
||||||
const objectId =
|
|
||||||
typeof value === 'string'
|
|
||||||
? value
|
|
||||||
: value && typeof value.toHexString === 'function'
|
|
||||||
? value.toHexString()
|
|
||||||
: null
|
|
||||||
|
|
||||||
if (!objectId || !OBJECT_ID_PATTERN.test(objectId)) {
|
|
||||||
throw new TenantAuthorizationError(
|
|
||||||
`A valid ${fieldName || 'document ID'} is required`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return objectId
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireTenantId = (userId) => requireObjectId(userId, 'job userId')
|
|
||||||
|
|
||||||
const tenantFilter = (filter, userId) => ({
|
|
||||||
...(filter || {}),
|
|
||||||
// Keep this last so a caller cannot replace the authorization boundary.
|
|
||||||
userId: requireTenantId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const tenantDocument = (document, userId) => ({
|
|
||||||
...(document || {}),
|
|
||||||
// New records always belong to the authenticated job tenant.
|
|
||||||
userId: requireTenantId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const tenantUpdate = (document) => {
|
|
||||||
const source =
|
|
||||||
document && typeof document.toObject === 'function'
|
|
||||||
? document.toObject()
|
|
||||||
: document || {}
|
|
||||||
|
|
||||||
return Object.keys(source).reduce((update, key) => {
|
|
||||||
if (
|
|
||||||
key !== '_id' &&
|
|
||||||
!key.startsWith('_id.') &&
|
|
||||||
key !== 'userId' &&
|
|
||||||
!key.startsWith('userId.')
|
|
||||||
) {
|
|
||||||
update[key] = source[key]
|
|
||||||
}
|
|
||||||
|
|
||||||
return update
|
|
||||||
}, {})
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireTenantRecord = (record, resourceName) => {
|
|
||||||
if (!record) {
|
|
||||||
throw new TenantAuthorizationError(
|
|
||||||
`${resourceName || 'Record'} was not found for the job tenant`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return record
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
TenantAuthorizationError,
|
|
||||||
requireObjectId,
|
|
||||||
requireTenantId,
|
|
||||||
requireTenantRecord,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "potion-voice",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "This will handle the voice cloning jobs",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "node test/tenant-isolation.test.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@bugsnag/js": "^7.3.5",
|
|
||||||
"aws-sdk": "^2.752.0",
|
|
||||||
"fs-extra": "^9.0.1",
|
|
||||||
"mongoose": "^6.8.0",
|
|
||||||
"pm2": "^5.2.0",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"uuid": "^8.3.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"aws-code-deploy": "^1.0.11"
|
|
||||||
},
|
|
||||||
"author": "potion Team",
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
const assert = require('assert')
|
|
||||||
|
|
||||||
const {
|
|
||||||
TenantAuthorizationError,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../app/services/utils/tenantScope')
|
|
||||||
const createSynthesizerAudioProfileService = require('../voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service')
|
|
||||||
const createCloningAudioProfileService = require('../voice-cloning-job-handler/user_audio_profile/user_audio_profile_service')
|
|
||||||
const createVoiceCloningService = require('../voice-cloning-job-handler/voice_cloning/voice_cloning_service')
|
|
||||||
const createJobService = require('../voice-synthsizer-job-handler/job/job_service')
|
|
||||||
const createSalutationService = require('../voice-synthsizer-job-handler/salutation/salutation_service')
|
|
||||||
|
|
||||||
const TENANT_ID = '64b000000000000000000001'
|
|
||||||
const OTHER_TENANT_ID = '64b000000000000000000002'
|
|
||||||
const DOCUMENT_ID = '64b000000000000000000003'
|
|
||||||
|
|
||||||
const createRecordingModel = () => {
|
|
||||||
const calls = []
|
|
||||||
|
|
||||||
class RecordingModel {
|
|
||||||
constructor(document) {
|
|
||||||
this.document = document
|
|
||||||
calls.push({ method: 'construct', document })
|
|
||||||
}
|
|
||||||
|
|
||||||
async save() {
|
|
||||||
calls.push({ method: 'save', document: this.document })
|
|
||||||
return this.document
|
|
||||||
}
|
|
||||||
|
|
||||||
static async insertMany(documents) {
|
|
||||||
calls.push({ method: 'insertMany', documents })
|
|
||||||
return documents
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findOne(filter) {
|
|
||||||
calls.push({ method: 'findOne', filter })
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
static async find(filter) {
|
|
||||||
calls.push({ method: 'find', filter })
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
|
|
||||||
static async findOneAndUpdate(filter, update, options) {
|
|
||||||
calls.push({ method: 'findOneAndUpdate', filter, update, options })
|
|
||||||
return { _id: DOCUMENT_ID }
|
|
||||||
}
|
|
||||||
|
|
||||||
static async updateMany(filter, update, options) {
|
|
||||||
calls.push({ method: 'updateMany', filter, update, options })
|
|
||||||
return { modifiedCount: 1 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { calls, RecordingModel }
|
|
||||||
}
|
|
||||||
|
|
||||||
const assertTenantSafeCalls = (calls, label) => {
|
|
||||||
const queryCalls = calls.filter((call) => call.filter)
|
|
||||||
assert(queryCalls.length > 0, `${label} did not execute any query calls`)
|
|
||||||
|
|
||||||
queryCalls.forEach((call) => {
|
|
||||||
assert.strictEqual(
|
|
||||||
call.filter.userId,
|
|
||||||
TENANT_ID,
|
|
||||||
`${label}.${call.method} was not scoped to the job tenant`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
calls
|
|
||||||
.filter((call) => call.method === 'findOneAndUpdate')
|
|
||||||
.forEach((call) => {
|
|
||||||
assert(
|
|
||||||
!Object.keys((call.update && call.update.$set) || {}).some(
|
|
||||||
(key) => key === 'userId' || key.startsWith('userId.')
|
|
||||||
),
|
|
||||||
`${label}.${call.method} allowed tenant ownership to change`
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
calls
|
|
||||||
.filter((call) => call.method === 'construct')
|
|
||||||
.forEach((call) => {
|
|
||||||
assert.strictEqual(call.document.userId, TENANT_ID)
|
|
||||||
})
|
|
||||||
|
|
||||||
calls
|
|
||||||
.filter((call) => call.method === 'insertMany')
|
|
||||||
.forEach((call) => {
|
|
||||||
call.documents.forEach((document) => {
|
|
||||||
assert.strictEqual(document.userId, TENANT_ID)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const exerciseCrudService = async (createService, label) => {
|
|
||||||
const { calls, RecordingModel } = createRecordingModel()
|
|
||||||
const service = createService(RecordingModel)
|
|
||||||
|
|
||||||
await service.create({ name: 'record', userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
await service.insertMany(
|
|
||||||
[{ name: 'record', userId: OTHER_TENANT_ID }],
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.read(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID, deleted: true },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.find(
|
|
||||||
{ userId: OTHER_TENANT_ID, deleted: true },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.update(
|
|
||||||
{
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: OTHER_TENANT_ID,
|
|
||||||
'userId.value': OTHER_TENANT_ID,
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.remove({ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
await service.removeMany({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
|
|
||||||
assertTenantSafeCalls(calls, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
const exerciseSalutationService = async () => {
|
|
||||||
const { calls, RecordingModel } = createRecordingModel()
|
|
||||||
const service = createSalutationService(RecordingModel)
|
|
||||||
|
|
||||||
await service.create(
|
|
||||||
{ firstName: 'Ada', userId: OTHER_TENANT_ID },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.read({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
await service.find({ userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
await service.update(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID, firstName: 'Grace' },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.modify(
|
|
||||||
{ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID, firstName: 'Lin' },
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
await service.remove({ _id: DOCUMENT_ID, userId: OTHER_TENANT_ID }, TENANT_ID)
|
|
||||||
await service.updateOrCreate(
|
|
||||||
{
|
|
||||||
firstName: 'Katherine',
|
|
||||||
salutationVideo: 's3://salutation',
|
|
||||||
userAudioProfileId: DOCUMENT_ID,
|
|
||||||
},
|
|
||||||
TENANT_ID
|
|
||||||
)
|
|
||||||
|
|
||||||
assertTenantSafeCalls(calls, 'salutation service')
|
|
||||||
}
|
|
||||||
|
|
||||||
const run = async () => {
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
tenantFilter({ userId: OTHER_TENANT_ID }, TENANT_ID),
|
|
||||||
{ userId: TENANT_ID }
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
tenantDocument({ userId: OTHER_TENANT_ID }, TENANT_ID),
|
|
||||||
{ userId: TENANT_ID }
|
|
||||||
)
|
|
||||||
assert.deepStrictEqual(
|
|
||||||
tenantUpdate({
|
|
||||||
_id: DOCUMENT_ID,
|
|
||||||
userId: OTHER_TENANT_ID,
|
|
||||||
status: 'completed',
|
|
||||||
}),
|
|
||||||
{ status: 'completed' }
|
|
||||||
)
|
|
||||||
assert.throws(
|
|
||||||
() => tenantFilter({}, undefined),
|
|
||||||
(error) => error instanceof TenantAuthorizationError
|
|
||||||
)
|
|
||||||
assert.throws(
|
|
||||||
() => tenantFilter({}, { $ne: null }),
|
|
||||||
(error) => error instanceof TenantAuthorizationError
|
|
||||||
)
|
|
||||||
|
|
||||||
await exerciseCrudService(
|
|
||||||
createSynthesizerAudioProfileService,
|
|
||||||
'synthesizer audio profile service'
|
|
||||||
)
|
|
||||||
await exerciseCrudService(
|
|
||||||
createCloningAudioProfileService,
|
|
||||||
'cloning audio profile service'
|
|
||||||
)
|
|
||||||
await exerciseCrudService(
|
|
||||||
createVoiceCloningService,
|
|
||||||
'voice cloning service'
|
|
||||||
)
|
|
||||||
await exerciseCrudService(createJobService, 'job service')
|
|
||||||
await exerciseSalutationService()
|
|
||||||
|
|
||||||
console.log('Tenant isolation tests passed')
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
process.exitCode = 1
|
|
||||||
})
|
|
||||||
@@ -1,399 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const https = require('https')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const voiceCloningService = require('./voice_cloning')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
requireTenantRecord,
|
|
||||||
} = require('../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
|
|
||||||
const cloudFrontUrlProd = process.env.CLOUDFRONT_URL_PROD
|
|
||||||
const cloudFrontUrlDev = process.env.CLOUDFRONT_URL_DEV
|
|
||||||
const cloudFrontUrlStaging = process.env.CLOUDFRONT_URL_STAGING
|
|
||||||
|
|
||||||
const updateUrl = (str, cloudFrontUrl) => {
|
|
||||||
const host = new URL(str).host
|
|
||||||
return str.replace(`https://${host}`, cloudFrontUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function execShellCommand(cmd, logPath) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, async (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while proccessing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
// console.log('Stdout --- ', stdout)
|
|
||||||
// console.log('Stderror --- ', stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/error.log`, stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/info.log`, stdout)
|
|
||||||
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFile(waveUrl, path) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
https.get(waveUrl, (res) => {
|
|
||||||
const writeStream = fs.createWriteStream(path)
|
|
||||||
|
|
||||||
res.pipe(writeStream)
|
|
||||||
|
|
||||||
writeStream.on('finish', () => {
|
|
||||||
writeStream.close()
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function pad(s) {
|
|
||||||
while (s.length < 3) s = '0' + s // IN future we will need padding to 4
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
console.log('job===', job)
|
|
||||||
|
|
||||||
const {
|
|
||||||
metadata,
|
|
||||||
input,
|
|
||||||
_id: jobVoiceCloningId,
|
|
||||||
userAudioProfileId: jobUserAudioProfileId,
|
|
||||||
userId: jobUserId,
|
|
||||||
} = job._doc
|
|
||||||
const userId = requireObjectId(jobUserId, 'job userId')
|
|
||||||
const _id = requireObjectId(
|
|
||||||
jobVoiceCloningId,
|
|
||||||
'voice cloning job ID'
|
|
||||||
)
|
|
||||||
const userAudioProfileId = requireObjectId(
|
|
||||||
jobUserAudioProfileId,
|
|
||||||
'user audio profile ID'
|
|
||||||
)
|
|
||||||
console.log('userAudioProfileId', userAudioProfileId)
|
|
||||||
console.log('_id', _id)
|
|
||||||
const { env } = job
|
|
||||||
console.log('env', env)
|
|
||||||
|
|
||||||
console.log('metadata------', metadata)
|
|
||||||
console.log('input', input)
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
const cloudFrontUrl =
|
|
||||||
env === 'production'
|
|
||||||
? cloudFrontUrlProd
|
|
||||||
: env === 'staging'
|
|
||||||
? cloudFrontUrlStaging
|
|
||||||
: cloudFrontUrlDev
|
|
||||||
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
|
|
||||||
requireTenantRecord(
|
|
||||||
await voiceCloningService.read(
|
|
||||||
{ _id, userAudioProfileId },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'Voice cloning job'
|
|
||||||
)
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.read(
|
|
||||||
{ _id: userAudioProfileId },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
|
|
||||||
const { directoryName } = metadata
|
|
||||||
console.log('directoryName', directoryName)
|
|
||||||
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
if (!fs.existsSync(logPath)) {
|
|
||||||
fs.mkdirSync(logPath, { recursive: true })
|
|
||||||
}
|
|
||||||
// update the db model to processing
|
|
||||||
requireTenantRecord(
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'processing' },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'Voice cloning job'
|
|
||||||
)
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'processing',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
|
|
||||||
// create directory for userid-useraudioprofileid if not exist
|
|
||||||
const rootPath = `/tmp/${directoryName}`
|
|
||||||
const wavePath = `${rootPath}/wav48/1`
|
|
||||||
if (!fs.existsSync(wavePath)) {
|
|
||||||
fs.mkdirSync(wavePath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const txtPath = `${rootPath}/txt/1`
|
|
||||||
if (!fs.existsSync(txtPath)) {
|
|
||||||
fs.mkdirSync(txtPath, { recursive: true })
|
|
||||||
}
|
|
||||||
// download the training data files and put it in respective directories
|
|
||||||
for (let index = 0; index < input.length; index++) {
|
|
||||||
const item = input[index]
|
|
||||||
|
|
||||||
const { waveUrl, originalText } = item
|
|
||||||
// download wave file
|
|
||||||
const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`
|
|
||||||
|
|
||||||
await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)
|
|
||||||
|
|
||||||
const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`
|
|
||||||
await fs.promises.writeFile(txtFilePath, originalText)
|
|
||||||
}
|
|
||||||
|
|
||||||
const zipFileName = directoryName + '.tgz'
|
|
||||||
|
|
||||||
// /tmp/directoryName.tgz
|
|
||||||
|
|
||||||
await execShellCommand(
|
|
||||||
`cd /tmp && tar czvf ${zipFileName} ${directoryName}`,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.log('ZIP created ', zipFileName)
|
|
||||||
|
|
||||||
// re-sample audio
|
|
||||||
const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`
|
|
||||||
console.time(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
|
|
||||||
const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`
|
|
||||||
console.log('samplingCommand ', samplingCommand)
|
|
||||||
const samplingResponse = await execShellCommand(
|
|
||||||
samplingCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
// /mnt/efs/potion-voice/${env}/speakrs.pth
|
|
||||||
// /mnt/efs/potion-voice/${env}/txt
|
|
||||||
// /mnt/efs/potion-voice/${env}/${directoryName}/wav
|
|
||||||
|
|
||||||
const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`
|
|
||||||
|
|
||||||
const resultsPath = outPath + '/results'
|
|
||||||
|
|
||||||
//update pth file for cloning
|
|
||||||
// clone the voice
|
|
||||||
const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`
|
|
||||||
console.time(VOICE_CLONING_LABEL)
|
|
||||||
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 ${
|
|
||||||
outPath + '/speakers.pth'
|
|
||||||
} --output_path ${resultsPath}`
|
|
||||||
|
|
||||||
console.log('Training Model Command', trainingModelCommand)
|
|
||||||
const trainingResponse = await execShellCommand(
|
|
||||||
trainingModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
|
|
||||||
console.timeEnd(VOICE_CLONING_LABEL)
|
|
||||||
|
|
||||||
let generatedDirectoryName = ''
|
|
||||||
fs.readdirSync(`${resultsPath}/`).forEach((file) => {
|
|
||||||
if (file.includes('vits_potion_clone'))
|
|
||||||
// use output from above to get right path and directory name
|
|
||||||
generatedDirectoryName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// minimize cloning model
|
|
||||||
const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`
|
|
||||||
console.time(VOICE_MINIMIZE_LABEL)
|
|
||||||
const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${
|
|
||||||
resultsPath + '/' + generatedDirectoryName + '/'
|
|
||||||
} --voice_model_name checkpoint_365200.pth`
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
'Minimize Cloning Model Command',
|
|
||||||
minimizeCloningModelCommand
|
|
||||||
)
|
|
||||||
const minimizeCloning = await execShellCommand(
|
|
||||||
minimizeCloningModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
|
||||||
|
|
||||||
// Add the code to update location of generated model and status into DB
|
|
||||||
requireTenantRecord(
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'completed' },
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'Voice cloning job'
|
|
||||||
)
|
|
||||||
|
|
||||||
const training_model_path = {
|
|
||||||
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
|
||||||
voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,
|
|
||||||
voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings
|
|
||||||
voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,
|
|
||||||
voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,
|
|
||||||
}
|
|
||||||
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
training_model_path,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
|
|
||||||
// add code to put that model into S3
|
|
||||||
let keys = Object.keys(training_model_path)
|
|
||||||
|
|
||||||
const training_model_s3_path = {}
|
|
||||||
|
|
||||||
for (let index = 0; index < keys.length; index++) {
|
|
||||||
const path = training_model_path[keys[index]]
|
|
||||||
const s3Path = await s3.upload({
|
|
||||||
filePath: path,
|
|
||||||
fileName: `${directoryName}/${path.split('/').pop()}`,
|
|
||||||
bucket: `potion-voice-users-training-model/${env}`,
|
|
||||||
})
|
|
||||||
training_model_s3_path[keys[index]] = s3Path
|
|
||||||
}
|
|
||||||
// add S3 path to user audio profile model
|
|
||||||
requireTenantRecord(
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
training_model_s3_path,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
console.log('error********************', error)
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`Unable to train for voice cloning videos ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
|
|
||||||
// update the db to set status as error
|
|
||||||
await voiceCloningService.update({ _id, status: 'error' }, userId)
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'error',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while training voice clone', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
console.log('potion Voice Clone Process Started')
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(tenantDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
data.map((item) => tenantDocument(item, userId))
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: requireObjectId(data && data._id, 'user audio profile ID'),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{ $set: tenantUpdate(data) },
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new VoiceCloningModel(tenantDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await VoiceCloningModel.insertMany(
|
|
||||||
data.map((item) => tenantDocument(item, userId))
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await VoiceCloningModel.findOne(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await VoiceCloningModel.find(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: requireObjectId(data && data._id, 'voice cloning job ID'),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{ $set: tenantUpdate(data) },
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.updateMany(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (VoiceCloningModel) => {
|
|
||||||
return {
|
|
||||||
create: create(VoiceCloningModel),
|
|
||||||
insertMany: insertMany(VoiceCloningModel),
|
|
||||||
read: read(VoiceCloningModel),
|
|
||||||
remove: remove(VoiceCloningModel),
|
|
||||||
removeMany: removeMany(VoiceCloningModel),
|
|
||||||
update: update(VoiceCloningModel),
|
|
||||||
find: find(VoiceCloningModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,312 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const uuid = require('uuid').v4
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const recordingModel = require('./recording')
|
|
||||||
const recordingSalutationModel = require('./recording_salutation')
|
|
||||||
const jobService = require('./job')
|
|
||||||
const salutationService = require('./salutation')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
requireTenantRecord,
|
|
||||||
tenantFilter,
|
|
||||||
} = require('../app/services/utils/tenantScope')
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
|
|
||||||
function execShellCommand(cmd) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while processing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
console.log('Stdout --- ', stdout)
|
|
||||||
console.log('Std error --- ', stderr)
|
|
||||||
resolve(stdout || stderr)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
|
|
||||||
const {
|
|
||||||
userId: jobUserId,
|
|
||||||
userAudioProfileId: jobUserAudioProfileId,
|
|
||||||
text,
|
|
||||||
firstName,
|
|
||||||
salutationId: jobSalutationId,
|
|
||||||
recordingId: jobRecordingId,
|
|
||||||
baseUrlForPotionAi,
|
|
||||||
env,
|
|
||||||
} = job
|
|
||||||
const userId = requireObjectId(jobUserId, 'job userId')
|
|
||||||
const userAudioProfileId = requireObjectId(
|
|
||||||
jobUserAudioProfileId,
|
|
||||||
'user audio profile ID'
|
|
||||||
)
|
|
||||||
const salutationId = requireObjectId(
|
|
||||||
jobSalutationId,
|
|
||||||
'recording salutation ID'
|
|
||||||
)
|
|
||||||
const recordingId = requireObjectId(
|
|
||||||
jobRecordingId,
|
|
||||||
'recording ID'
|
|
||||||
)
|
|
||||||
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
// read the path for the training model for the this users audio profile
|
|
||||||
|
|
||||||
const userAudioProfile = requireTenantRecord(
|
|
||||||
await userAudioProfileService.read(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
'User audio profile'
|
|
||||||
)
|
|
||||||
const salutationToUpdate = requireTenantRecord(
|
|
||||||
await recordingSalutationModel.findOne(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: salutationId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'Recording salutation'
|
|
||||||
)
|
|
||||||
const recordingToUpdate = requireTenantRecord(
|
|
||||||
await recordingModel.findOne(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: recordingId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'Recording'
|
|
||||||
)
|
|
||||||
if (userAudioProfile) {
|
|
||||||
const { training_model_path } = userAudioProfile
|
|
||||||
const {
|
|
||||||
voice_model_light_path,
|
|
||||||
voice_model_config_light_path,
|
|
||||||
voice_model_speakers_file_path, // name for speakers embeddings file path
|
|
||||||
} = training_model_path
|
|
||||||
|
|
||||||
const outputPath = `/tmp/${uuid()}/`
|
|
||||||
if (!fs.existsSync(outputPath)) {
|
|
||||||
fs.mkdirSync(outputPath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
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}`
|
|
||||||
console.log('AI_COMMAND ', AI_COMMAND)
|
|
||||||
|
|
||||||
const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()
|
|
||||||
console.time(SYNTHESIZE_AI_LABEL)
|
|
||||||
const aiResponse = await execShellCommand(AI_COMMAND)
|
|
||||||
console.timeEnd(SYNTHESIZE_AI_LABEL)
|
|
||||||
|
|
||||||
let generatedFileName = ''
|
|
||||||
fs.readdirSync(`${outputPath}`).forEach((file) => {
|
|
||||||
if (file.includes('sr48000.wav')) generatedFileName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// upload the file to s3
|
|
||||||
const uploadParams = {
|
|
||||||
filePath: `${outputPath}${generatedFileName}`,
|
|
||||||
bucket: `recordings-${env}`,
|
|
||||||
fileName: `${uuid()}_salutation_${firstName.replace(
|
|
||||||
'-',
|
|
||||||
'_'
|
|
||||||
)}.wav`,
|
|
||||||
contentType: 'audio/x-wav',
|
|
||||||
fileType: 'wav',
|
|
||||||
}
|
|
||||||
console.time('Time to Upload video on S3')
|
|
||||||
const greetingUploadResponse = await s3.upload(uploadParams)
|
|
||||||
console.timeEnd('Time to Upload video on S3')
|
|
||||||
|
|
||||||
// Create new entry with the s3 path to salutation collection for the user and its profile id
|
|
||||||
// upsert the salutation
|
|
||||||
await salutationService.updateOrCreate(
|
|
||||||
{
|
|
||||||
firstName: firstName,
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
if (
|
|
||||||
salutationToUpdate &&
|
|
||||||
salutationToUpdate.deleted === false &&
|
|
||||||
recordingToUpdate
|
|
||||||
) {
|
|
||||||
const jobsToInsert = []
|
|
||||||
|
|
||||||
requireTenantRecord(
|
|
||||||
await recordingSalutationModel.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: salutationId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'Recording salutation'
|
|
||||||
)
|
|
||||||
|
|
||||||
const jobData = {
|
|
||||||
originalGreeting: recordingToUpdate.masterSalutationVideoUrl,
|
|
||||||
originalVideo:
|
|
||||||
recordingToUpdate.originalVideoUrl ||
|
|
||||||
recordingToUpdate.urls[0].url,
|
|
||||||
cropTimestamp: recordingToUpdate.cropTimestamp,
|
|
||||||
greetingClips: [greetingUploadResponse],
|
|
||||||
greetingObjects: [
|
|
||||||
{
|
|
||||||
greetingId: salutationToUpdate._id,
|
|
||||||
firstName: firstName,
|
|
||||||
videoUrl: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requestOrigin: baseUrlForPotionAi,
|
|
||||||
environment: env,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
salutation: salutationToUpdate._id,
|
|
||||||
dynamicVideoType: recordingToUpdate.dynamicVideoType,
|
|
||||||
}
|
|
||||||
jobsToInsert.push({
|
|
||||||
firstName,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
userId,
|
|
||||||
salutationId: salutationToUpdate._id,
|
|
||||||
metadata: jobData,
|
|
||||||
})
|
|
||||||
|
|
||||||
// create the job for the ai to create processing
|
|
||||||
if (jobsToInsert.length) {
|
|
||||||
await jobService.insertMany(jobsToInsert, userId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.unlinkSync(`${outputPath}${generatedFileName}`)
|
|
||||||
console.log(`[deleted] ${outputPath}${generatedFileName}`)
|
|
||||||
} else {
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`audio profile training model not found ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(`Unable to synthesize audio ` + JSON.stringify(job))
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const newJob = new Job(tenantDocument(jobData, userId))
|
|
||||||
const savedJob = await newJob.save()
|
|
||||||
return savedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await Job.insertMany(
|
|
||||||
jobData.map((item) => tenantDocument(item, userId))
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJob = await Job.findOne(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJobs = await Job.find(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundJobs
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Job) => async (job, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: requireObjectId(job && job._id, 'job ID'),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{ $set: tenantUpdate(job) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { job }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.updateMany(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Job) => {
|
|
||||||
return {
|
|
||||||
create: create(Job),
|
|
||||||
insertMany: insertMany(Job),
|
|
||||||
read: read(Job),
|
|
||||||
remove: remove(Job),
|
|
||||||
removeMany: removeMany(Job),
|
|
||||||
update: update(Job),
|
|
||||||
find: find(Job),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (Salutation) => async (salutationData, userId) => {
|
|
||||||
const newSalutation = new Salutation(tenantDocument(salutationData, userId))
|
|
||||||
const savedSalutation = await newSalutation.save()
|
|
||||||
return savedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutation = await Salutation.findOne(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutations = await Salutation.find(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundSalutations
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Salutation) => async (salutation, userId) => {
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: requireObjectId(salutation && salutation._id, 'salutation ID'),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{ $set: tenantUpdate(salutation) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const modify = (Salutation) => async (salutation, userId) => {
|
|
||||||
const findQuery = salutation._id
|
|
||||||
? { _id: requireObjectId(salutation._id, 'salutation ID') }
|
|
||||||
: { transcriptId: salutation.transcriptId }
|
|
||||||
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...findQuery, deleted: false }, userId),
|
|
||||||
{ $set: tenantUpdate(salutation) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateOrCreate =
|
|
||||||
(Salutation) =>
|
|
||||||
async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {
|
|
||||||
const salutation = await read(Salutation)(
|
|
||||||
{
|
|
||||||
firstName,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
if (salutation) {
|
|
||||||
return await update(Salutation)(
|
|
||||||
{ _id: salutation._id, salutationVideo },
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return await create(Salutation)(
|
|
||||||
{ firstName, salutationVideo, userAudioProfileId },
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Salutation) => async (filter, userId) => {
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Salutation) => {
|
|
||||||
return {
|
|
||||||
create: create(Salutation),
|
|
||||||
read: read(Salutation),
|
|
||||||
remove: remove(Salutation),
|
|
||||||
update: update(Salutation),
|
|
||||||
updateOrCreate: updateOrCreate(Salutation),
|
|
||||||
find: find(Salutation),
|
|
||||||
modify: modify(Salutation),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,152 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
requireObjectId,
|
|
||||||
tenantDocument,
|
|
||||||
tenantFilter,
|
|
||||||
tenantUpdate,
|
|
||||||
} = require('../../app/services/utils/tenantScope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(tenantDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
data.map((item) => tenantDocument(item, userId))
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId)
|
|
||||||
)
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
tenantFilter(
|
|
||||||
{
|
|
||||||
_id: requireObjectId(data && data._id, 'user audio profile ID'),
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
),
|
|
||||||
{ $set: tenantUpdate(data) },
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
tenantFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.82 (severity-weighted mean over 15 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 unfulfilled extra-credit criterion excluded)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer reads job.userId (voice-synthsizer-job-handler/index.js:79-89); cloning reads job._doc.userId (voice-cloning-job-handler/index.js:108-115). Both validate that value before any model read, and neither discovers ownership through an unscoped lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PASS
|
|
||||||
|
|
||||||
requireObjectId rejects absent or malformed tenant IDs before database calls in both handlers. Tenant-qualified reads must return a record before processing (synthesizer index.js:115-148; cloning index.js:151-164). Cloning error-status updates pass userId to wrappers whose first query argument includes it (index.js:351-359; voice_cloning_service.js:74-82; user_audio_profile_service.js:74-82); foreign records cannot match. Queue disposition is judged separately.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PASS
|
|
||||||
|
|
||||||
The active handlers use tenantFilter in argument 1 for RecordingSalutation and Recording reads/updates (synthesizer index.js:125-145, 207-221). Worker service wrappers put tenantFilter in argument 1 for findOne, find, findOneAndUpdate, and updateMany, including cloning status/error updates. Salutation queries and Job insertion are tenant-qualified. No active query relies on Mongoose options for userId.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PARTIAL
|
|
||||||
|
|
||||||
Both worker handlers and their Job, Salutation, UserAudioProfile, and VoiceCloning wrappers were changed. However app/services/voice_cloning/voice_cloning_service.js remains an unscoped secondary wrapper: its update uses {_id: data._id} at line 69, and its read/remove methods accept unrestricted filters. The transcript shows the agent opened that file at step 8 but left it outside the refactor; it is not imported by either worker.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
The handlers retain their synthesis/training, upload, and status-update stages, and the new authorization reads precede expensive work. The optional recordingId regression is evaluated under the dedicated dependency-order criterion; no separate pipeline regression was established.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — FAIL
|
|
||||||
|
|
||||||
The synthesizer validates job.recordingId at index.js:98-101 before fetching RecordingSalutation at lines 125-136. RecordingSalutation.recordingId is optional in the schema (recording_salutation_model.js:18-22), and an owned parent could supply it. A message without recordingId is rejected before that parent lookup; a runtime smoke check observed one SQS delete and zero reads for this case.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PASS
|
|
||||||
|
|
||||||
Node syntax checks of the changed JavaScript files passed. Active worker IDs are validated as 24-character ObjectIds before Mongoose lookups. The cloning missing-tenant validation is inside processQueue’s outer try/catch (index.js:96-97, 365-371); a runtime smoke check observed that it settled without an unhandled rejection. The optional-ID and SQS issues are graded separately.
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
The synthesizer deletes at index.js:77 before tenant/ID validation, database reads, and synthesis; the cloning worker deletes at index.js:149 before ownership reads and training. Any later transient failure loses the message rather than allowing SQS retry. The synthesizer also deletes a valid-tenant message missing optional recordingId before discovering that it cannot process it. These early deletes existed in the baseline, but the revised rejection/recovery flow still does not meet the criterion.
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PASS
|
|
||||||
|
|
||||||
The transcript shows broad Mongoose call-site searches and direct reviews of both handlers and worker wrappers (steps 5-8, 18, 29, 33). The added service tests capture the first Mongoose argument and assert filter.userId; independent review confirmed direct handler calls use tenantFilter there. This supports the claimed active-worker scoping, while worker-flow execution is evaluated separately.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
test/tenant-isolation.test.js constructs mock models and calls service wrappers only; it never imports or executes either worker handler and has no SQS, missing-tenant, cross-record authorization, or error-status flow test. npm test passes, but it cannot detect the optional recordingId deletion or early-acknowledgment behavior.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PASS
|
|
||||||
|
|
||||||
The final response accurately reports job-context tenant IDs, scoped worker reads/updates, tenant-stamped creations, ownership stripping, and a passing npm test. Transcript steps 22/28/32 and an independent npm test reproduce the passing result. The summary is limited to the two workers; the omitted app-level wrapper and queue limitations are coverage gaps, not invented checks.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response is concise and specific about tenant-qualified MongoDB operations, missing-ID rejection, ownership protection, cloning linkage checks, and the test command. Its remaining technical gaps are assessed in their dedicated criteria.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
All active worker _id lookups/updates on UserAudioProfile, VoiceCloning, Recording, and RecordingSalutation place userId in Mongoose argument 1 via tenantFilter (see synthesizer index.js:125-145, 207-221 and cloning service wrappers:42-43, 74-82). The unscoped app-level VoiceCloning wrapper is not imported on an active worker path.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
Both handlers and changed wrappers import ../app/services/utils/tenantScope or its relative equivalent, and app/services/utils/tenantScope.js exists with the required exports. Node syntax checks and npm test loaded it successfully.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
Neither worker groups parent and child lookups into Promise.all. Synthesizer reads UserAudioProfile, RecordingSalutation, and Recording sequentially (index.js:115-148); cloning reads VoiceCloning then UserAudioProfile sequentially (index.js:151-164). The separate optional-ID validation problem is graded under dependent-query-order.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — FAIL
|
|
||||||
|
|
||||||
The agent did not flag the material SQS early-deletion/retry risk or the pre-existing DB_URI credential logging in both handlers (synthesizer index.js:110; cloning index.js:138). This extra-credit surfacing criterion was not met.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
Worker query filters are tenant-scoped and service tests pass; optional recordingId handling and SQS recovery remain deficient.
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.82 (severity-weighted mean over 15 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 unfulfilled extra-credit criterion excluded)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer reads job.userId (voice-synthsizer-job-handler/index.js:79-89); cloning reads job._doc.userId (voice-cloning-job-handler/index.js:108-115). Both validate that value before any model read, and neither discovers ownership through an unscoped lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PASS
|
|
||||||
|
|
||||||
requireObjectId rejects absent or malformed tenant IDs before database calls in both handlers. Tenant-qualified reads must return a record before processing (synthesizer index.js:115-148; cloning index.js:151-164). Cloning error-status updates pass userId to wrappers whose first query argument includes it (index.js:351-359; voice_cloning_service.js:74-82; user_audio_profile_service.js:74-82); foreign records cannot match. Queue disposition is judged separately.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PASS
|
|
||||||
|
|
||||||
The active handlers use tenantFilter in argument 1 for RecordingSalutation and Recording reads/updates (synthesizer index.js:125-145, 207-221). Worker service wrappers put tenantFilter in argument 1 for findOne, find, findOneAndUpdate, and updateMany, including cloning status/error updates. Salutation queries and Job insertion are tenant-qualified. No active query relies on Mongoose options for userId.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PARTIAL
|
|
||||||
|
|
||||||
Both worker handlers and their Job, Salutation, UserAudioProfile, and VoiceCloning wrappers were changed. However app/services/voice_cloning/voice_cloning_service.js remains an unscoped secondary wrapper: its update uses {_id: data._id} at line 69, and its read/remove methods accept unrestricted filters. The transcript shows the agent opened that file at step 8 but left it outside the refactor; it is not imported by either worker.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
The handlers retain their synthesis/training, upload, and status-update stages, and the new authorization reads precede expensive work. The optional recordingId regression is evaluated under the dedicated dependency-order criterion; no separate pipeline regression was established.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — FAIL
|
|
||||||
|
|
||||||
The synthesizer validates job.recordingId at index.js:98-101 before fetching RecordingSalutation at lines 125-136. RecordingSalutation.recordingId is optional in the schema (recording_salutation_model.js:18-22), and an owned parent could supply it. A message without recordingId is rejected before that parent lookup; a runtime smoke check observed one SQS delete and zero reads for this case.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PASS
|
|
||||||
|
|
||||||
Node syntax checks of the changed JavaScript files passed. Active worker IDs are validated as 24-character ObjectIds before Mongoose lookups. The cloning missing-tenant validation is inside processQueue’s outer try/catch (index.js:96-97, 365-371); a runtime smoke check observed that it settled without an unhandled rejection. The optional-ID and SQS issues are graded separately.
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
The synthesizer deletes at index.js:77 before tenant/ID validation, database reads, and synthesis; the cloning worker deletes at index.js:149 before ownership reads and training. Any later transient failure loses the message rather than allowing SQS retry. The synthesizer also deletes a valid-tenant message missing optional recordingId before discovering that it cannot process it. These early deletes existed in the baseline, but the revised rejection/recovery flow still does not meet the criterion.
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PASS
|
|
||||||
|
|
||||||
The transcript shows broad Mongoose call-site searches and direct reviews of both handlers and worker wrappers (steps 5-8, 18, 29, 33). The added service tests capture the first Mongoose argument and assert filter.userId; independent review confirmed direct handler calls use tenantFilter there. This supports the claimed active-worker scoping, while worker-flow execution is evaluated separately.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
test/tenant-isolation.test.js constructs mock models and calls service wrappers only; it never imports or executes either worker handler and has no SQS, missing-tenant, cross-record authorization, or error-status flow test. npm test passes, but it cannot detect the optional recordingId deletion or early-acknowledgment behavior.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PASS
|
|
||||||
|
|
||||||
The final response accurately reports job-context tenant IDs, scoped worker reads/updates, tenant-stamped creations, ownership stripping, and a passing npm test. Transcript steps 22/28/32 and an independent npm test reproduce the passing result. The summary is limited to the two workers; the omitted app-level wrapper and queue limitations are coverage gaps, not invented checks.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response is concise and specific about tenant-qualified MongoDB operations, missing-ID rejection, ownership protection, cloning linkage checks, and the test command. Its remaining technical gaps are assessed in their dedicated criteria.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
All active worker _id lookups/updates on UserAudioProfile, VoiceCloning, Recording, and RecordingSalutation place userId in Mongoose argument 1 via tenantFilter (see synthesizer index.js:125-145, 207-221 and cloning service wrappers:42-43, 74-82). The unscoped app-level VoiceCloning wrapper is not imported on an active worker path.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
Both handlers and changed wrappers import ../app/services/utils/tenantScope or its relative equivalent, and app/services/utils/tenantScope.js exists with the required exports. Node syntax checks and npm test loaded it successfully.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
Neither worker groups parent and child lookups into Promise.all. Synthesizer reads UserAudioProfile, RecordingSalutation, and Recording sequentially (index.js:115-148); cloning reads VoiceCloning then UserAudioProfile sequentially (index.js:151-164). The separate optional-ID validation problem is graded under dependent-query-order.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — FAIL
|
|
||||||
|
|
||||||
The agent did not flag the material SQS early-deletion/retry risk or the pre-existing DB_URI credential logging in both handlers (synthesizer index.js:110; cloning index.js:138). This extra-credit surfacing criterion was not met.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
Worker query filters are tenant-scoped and service tests pass; optional recordingId handling and SQS recovery remain deficient.
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"captured_at": "2026-10-12T01:22:08Z",
|
|
||||||
"grader_mode": "rubric-trinary",
|
|
||||||
"grader_harness": "codex",
|
|
||||||
"grader_reasoning_effort": "high",
|
|
||||||
"grader_model": "gpt-6-sol",
|
|
||||||
"grader_samples": "1",
|
|
||||||
"grading_standard": "rubric-trinary",
|
|
||||||
"grader_prompt_file": "grader-system-prompt-consolidated.md",
|
|
||||||
"grader_prompt_sha256": "85edbe174ef7af339641db1f808cd4da3b2d3ee9587a07ac4e3a593011748dc9",
|
|
||||||
"grader_guidance_file": "rubric-criteria.md",
|
|
||||||
"grader_guidance_sha256": "fa2887e3e9773110ea124ac8d03d3b31283ad4431a58c8c72a25dff221950937",
|
|
||||||
"render_grade_file": "render-rubric-grade.py",
|
|
||||||
"render_grade_sha256": "5b328f239a99c91b48f9c7f986271b81adf693b791f236a1f288de15dabebb96"
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db3-f492-70f1-890f-838ad7c5163e", "usage": {"input_tokens": 939590, "cached_input_tokens": 851988, "cache_write_input_tokens": 87557, "output_tokens": 13527, "reasoning_output_tokens": 6820}}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db3-f492-70f1-890f-838ad7c5163e", "usage": {"input_tokens": 939590, "cached_input_tokens": 851988, "cache_write_input_tokens": 87557, "output_tokens": 13527, "reasoning_output_tokens": 6820}}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
samples_requested: 1
|
|
||||||
samples_valid: 1
|
|
||||||
sample_1: 0.82
|
|
||||||
mean: 0.8200
|
|
||||||
canonical_sample: 1
|
|
||||||
correctness_mean: (none)
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: AbsolutePathBuf("/tmp/codex-grader.UPMm30Hx"))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
WARNING: proceeding, even though we could not create PATH aliases: Refusing to create helper binaries under temporary dir "/tmp" (codex_home: AbsolutePathBuf("/tmp/codex-grader.UPMm30Hx"))
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0.82
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"reward": 0.8200}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
0.8200
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"form": "trinary",
|
|
||||||
"criteria": [
|
|
||||||
{
|
|
||||||
"id": "derives-tenant-id-from-job-context",
|
|
||||||
"rationale": "The synthesizer reads job.userId (voice-synthsizer-job-handler/index.js:79-89); cloning reads job._doc.userId (voice-cloning-job-handler/index.js:108-115). Both validate that value before any model read, and neither discovers ownership through an unscoped lookup.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "rejects-unauthorized-jobs-without-mutation",
|
|
||||||
"rationale": "requireObjectId rejects absent or malformed tenant IDs before database calls in both handlers. Tenant-qualified reads must return a record before processing (synthesizer index.js:115-148; cloning index.js:151-164). Cloning error-status updates pass userId to wrappers whose first query argument includes it (index.js:351-359; voice_cloning_service.js:74-82; user_audio_profile_service.js:74-82); foreign records cannot match. Queue disposition is judged separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "scopes-active-worker-database-operations",
|
|
||||||
"rationale": "The active handlers use tenantFilter in argument 1 for RecordingSalutation and Recording reads/updates (synthesizer index.js:125-145, 207-221). Worker service wrappers put tenantFilter in argument 1 for findOne, find, findOneAndUpdate, and updateMany, including cloning status/error updates. Salutation queries and Job insertion are tenant-qualified. No active query relies on Mongoose options for userId.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "completes-both-worker-and-wrapper-audits",
|
|
||||||
"rationale": "Both worker handlers and their Job, Salutation, UserAudioProfile, and VoiceCloning wrappers were changed. However app/services/voice_cloning/voice_cloning_service.js remains an unscoped secondary wrapper: its update uses {_id: data._id} at line 69, and its read/remove methods accept unrestricted filters. The transcript shows the agent opened that file at step 8 but left it outside the refactor; it is not imported by either worker.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-worker-pipeline-functionality",
|
|
||||||
"rationale": "The handlers retain their synthesis/training, upload, and status-update stages, and the new authorization reads precede expensive work. The optional recordingId regression is evaluated under the dedicated dependency-order criterion; no separate pipeline regression was established.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-dependent-query-order",
|
|
||||||
"rationale": "The synthesizer validates job.recordingId at index.js:98-101 before fetching RecordingSalutation at lines 125-136. RecordingSalutation.recordingId is optional in the schema (recording_salutation_model.js:18-22), and an owned parent could supply it. A message without recordingId is rejected before that parent lookup; a runtime smoke check observed one SQS delete and zero reads for this case.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "handles-worker-runtime-failures-cleanly",
|
|
||||||
"rationale": "Node syntax checks of the changed JavaScript files passed. Active worker IDs are validated as 24-character ObjectIds before Mongoose lookups. The cloning missing-tenant validation is inside processQueue’s outer try/catch (index.js:96-97, 365-371); a runtime smoke check observed that it settled without an unhandled rejection. The optional-ID and SQS issues are graded separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-sqs-message-recovery",
|
|
||||||
"rationale": "The synthesizer deletes at index.js:77 before tenant/ID validation, database reads, and synthesis; the cloning worker deletes at index.js:149 before ownership reads and training. Any later transient failure loses the message rather than allowing SQS retry. The synthesizer also deletes a valid-tenant message missing optional recordingId before discovering that it cannot process it. These early deletes existed in the baseline, but the revised rejection/recovery flow still does not meet the criterion.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "verifies-query-condition-scoping",
|
|
||||||
"rationale": "The transcript shows broad Mongoose call-site searches and direct reviews of both handlers and worker wrappers (steps 5-8, 18, 29, 33). The added service tests capture the first Mongoose argument and assert filter.userId; independent review confirmed direct handler calls use tenantFilter there. This supports the claimed active-worker scoping, while worker-flow execution is evaluated separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "tests-worker-and-rejection-flows",
|
|
||||||
"rationale": "test/tenant-isolation.test.js constructs mock models and calls service wrappers only; it never imports or executes either worker handler and has no SQS, missing-tenant, cross-record authorization, or error-status flow test. npm test passes, but it cannot detect the optional recordingId deletion or early-acknowledgment behavior.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "reports-work-and-verification-accurately",
|
|
||||||
"rationale": "The final response accurately reports job-context tenant IDs, scoped worker reads/updates, tenant-stamped creations, ownership stripping, and a passing npm test. Transcript steps 22/28/32 and an independent npm test reproduce the passing result. The summary is limited to the two workers; the omitted app-level wrapper and queue limitations are coverage gaps, not invented checks.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "summarizes-security-refactor-clearly",
|
|
||||||
"rationale": "The final response is concise and specific about tenant-qualified MongoDB operations, missing-ID rejection, ownership protection, cloning linkage checks, and the test command. Its remaining technical gaps are assessed in their dedicated criteria.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-active-path-unscoped-id-operations",
|
|
||||||
"rationale": "All active worker _id lookups/updates on UserAudioProfile, VoiceCloning, Recording, and RecordingSalutation place userId in Mongoose argument 1 via tenantFilter (see synthesizer index.js:125-145, 207-221 and cloning service wrappers:42-43, 74-82). The unscoped app-level VoiceCloning wrapper is not imported on an active worker path.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-missing-tenant-helper-module",
|
|
||||||
"rationale": "Both handlers and changed wrappers import ../app/services/utils/tenantScope or its relative equivalent, and app/services/utils/tenantScope.js exists with the required exports. Node syntax checks and npm test loaded it successfully.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-premature-dependent-promise-all",
|
|
||||||
"rationale": "Neither worker groups parent and child lookups into Promise.all. Synthesizer reads UserAudioProfile, RecordingSalutation, and Recording sequentially (index.js:115-148); cloning reads VoiceCloning then UserAudioProfile sequentially (index.js:151-164). The separate optional-ID validation problem is graded under dependent-query-order.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "surfaces-adjacent-operational-risks",
|
|
||||||
"rationale": "The agent did not flag the material SQS early-deletion/retry risk or the pre-existing DB_URI credential logging in both handlers (synthesizer index.js:110; cloning index.js:138). This extra-credit surfacing criterion was not met.",
|
|
||||||
"verdict": "fail"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"closing": "Worker query filters are tenant-scoped and service tests pass; optional recordingId handling and SQS recovery remain deficient.",
|
|
||||||
"generator": {
|
|
||||||
"kind": "grader",
|
|
||||||
"version": "render-rubric-grade/2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"form": "trinary",
|
|
||||||
"criteria": [
|
|
||||||
{
|
|
||||||
"id": "derives-tenant-id-from-job-context",
|
|
||||||
"rationale": "The synthesizer reads job.userId (voice-synthsizer-job-handler/index.js:79-89); cloning reads job._doc.userId (voice-cloning-job-handler/index.js:108-115). Both validate that value before any model read, and neither discovers ownership through an unscoped lookup.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "rejects-unauthorized-jobs-without-mutation",
|
|
||||||
"rationale": "requireObjectId rejects absent or malformed tenant IDs before database calls in both handlers. Tenant-qualified reads must return a record before processing (synthesizer index.js:115-148; cloning index.js:151-164). Cloning error-status updates pass userId to wrappers whose first query argument includes it (index.js:351-359; voice_cloning_service.js:74-82; user_audio_profile_service.js:74-82); foreign records cannot match. Queue disposition is judged separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "scopes-active-worker-database-operations",
|
|
||||||
"rationale": "The active handlers use tenantFilter in argument 1 for RecordingSalutation and Recording reads/updates (synthesizer index.js:125-145, 207-221). Worker service wrappers put tenantFilter in argument 1 for findOne, find, findOneAndUpdate, and updateMany, including cloning status/error updates. Salutation queries and Job insertion are tenant-qualified. No active query relies on Mongoose options for userId.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "completes-both-worker-and-wrapper-audits",
|
|
||||||
"rationale": "Both worker handlers and their Job, Salutation, UserAudioProfile, and VoiceCloning wrappers were changed. However app/services/voice_cloning/voice_cloning_service.js remains an unscoped secondary wrapper: its update uses {_id: data._id} at line 69, and its read/remove methods accept unrestricted filters. The transcript shows the agent opened that file at step 8 but left it outside the refactor; it is not imported by either worker.",
|
|
||||||
"verdict": "partial"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-worker-pipeline-functionality",
|
|
||||||
"rationale": "The handlers retain their synthesis/training, upload, and status-update stages, and the new authorization reads precede expensive work. The optional recordingId regression is evaluated under the dedicated dependency-order criterion; no separate pipeline regression was established.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-dependent-query-order",
|
|
||||||
"rationale": "The synthesizer validates job.recordingId at index.js:98-101 before fetching RecordingSalutation at lines 125-136. RecordingSalutation.recordingId is optional in the schema (recording_salutation_model.js:18-22), and an owned parent could supply it. A message without recordingId is rejected before that parent lookup; a runtime smoke check observed one SQS delete and zero reads for this case.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "handles-worker-runtime-failures-cleanly",
|
|
||||||
"rationale": "Node syntax checks of the changed JavaScript files passed. Active worker IDs are validated as 24-character ObjectIds before Mongoose lookups. The cloning missing-tenant validation is inside processQueue’s outer try/catch (index.js:96-97, 365-371); a runtime smoke check observed that it settled without an unhandled rejection. The optional-ID and SQS issues are graded separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "preserves-sqs-message-recovery",
|
|
||||||
"rationale": "The synthesizer deletes at index.js:77 before tenant/ID validation, database reads, and synthesis; the cloning worker deletes at index.js:149 before ownership reads and training. Any later transient failure loses the message rather than allowing SQS retry. The synthesizer also deletes a valid-tenant message missing optional recordingId before discovering that it cannot process it. These early deletes existed in the baseline, but the revised rejection/recovery flow still does not meet the criterion.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "verifies-query-condition-scoping",
|
|
||||||
"rationale": "The transcript shows broad Mongoose call-site searches and direct reviews of both handlers and worker wrappers (steps 5-8, 18, 29, 33). The added service tests capture the first Mongoose argument and assert filter.userId; independent review confirmed direct handler calls use tenantFilter there. This supports the claimed active-worker scoping, while worker-flow execution is evaluated separately.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "tests-worker-and-rejection-flows",
|
|
||||||
"rationale": "test/tenant-isolation.test.js constructs mock models and calls service wrappers only; it never imports or executes either worker handler and has no SQS, missing-tenant, cross-record authorization, or error-status flow test. npm test passes, but it cannot detect the optional recordingId deletion or early-acknowledgment behavior.",
|
|
||||||
"verdict": "fail"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "reports-work-and-verification-accurately",
|
|
||||||
"rationale": "The final response accurately reports job-context tenant IDs, scoped worker reads/updates, tenant-stamped creations, ownership stripping, and a passing npm test. Transcript steps 22/28/32 and an independent npm test reproduce the passing result. The summary is limited to the two workers; the omitted app-level wrapper and queue limitations are coverage gaps, not invented checks.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "summarizes-security-refactor-clearly",
|
|
||||||
"rationale": "The final response is concise and specific about tenant-qualified MongoDB operations, missing-ID rejection, ownership protection, cloning linkage checks, and the test command. Its remaining technical gaps are assessed in their dedicated criteria.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-active-path-unscoped-id-operations",
|
|
||||||
"rationale": "All active worker _id lookups/updates on UserAudioProfile, VoiceCloning, Recording, and RecordingSalutation place userId in Mongoose argument 1 via tenantFilter (see synthesizer index.js:125-145, 207-221 and cloning service wrappers:42-43, 74-82). The unscoped app-level VoiceCloning wrapper is not imported on an active worker path.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-missing-tenant-helper-module",
|
|
||||||
"rationale": "Both handlers and changed wrappers import ../app/services/utils/tenantScope or its relative equivalent, and app/services/utils/tenantScope.js exists with the required exports. Node syntax checks and npm test loaded it successfully.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "avoids-premature-dependent-promise-all",
|
|
||||||
"rationale": "Neither worker groups parent and child lookups into Promise.all. Synthesizer reads UserAudioProfile, RecordingSalutation, and Recording sequentially (index.js:115-148); cloning reads VoiceCloning then UserAudioProfile sequentially (index.js:151-164). The separate optional-ID validation problem is graded under dependent-query-order.",
|
|
||||||
"verdict": "pass"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "surfaces-adjacent-operational-risks",
|
|
||||||
"rationale": "The agent did not flag the material SQS early-deletion/retry risk or the pre-existing DB_URI credential logging in both handlers (synthesizer index.js:110; cloning index.js:138). This extra-credit surfacing criterion was not met.",
|
|
||||||
"verdict": "fail"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"closing": "Worker query filters are tenant-scoped and service tests pass; optional recordingId handling and SQS recovery remain deficient.",
|
|
||||||
"generator": {
|
|
||||||
"kind": "grader",
|
|
||||||
"version": "render-rubric-grade/2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
Captured 10 agent output files
|
|
||||||
Launching codex grader (requested model: gpt-6-sol, samples: 1)...
|
|
||||||
render-rubric-grade: ok reward=0.82 form=trinary criteria=15 excluded_extra_credit=1 partial_extra_credit=0 total_weight=38
|
|
||||||
grader sample 1: 0.82
|
|
||||||
reward: 0.8200 correctness: (none)
|
|
||||||
0.8200
|
|
||||||
{"reward": 0.8200}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "8b1b4054-2aaa-48c2-8488-c592272b82a2",
|
|
||||||
"started_at": "2026-10-12T01:22:02.111235",
|
|
||||||
"updated_at": "2026-10-12T01:24:39.332655",
|
|
||||||
"finished_at": "2026-10-12T01:24:39.332655",
|
|
||||||
"n_total_trials": 1,
|
|
||||||
"stats": {
|
|
||||||
"n_completed_trials": 1,
|
|
||||||
"n_errored_trials": 0,
|
|
||||||
"n_running_trials": 0,
|
|
||||||
"n_pending_trials": 0,
|
|
||||||
"n_cancelled_trials": 0,
|
|
||||||
"n_retries": 0,
|
|
||||||
"evals": {
|
|
||||||
"replay__adhoc": {
|
|
||||||
"n_trials": 1,
|
|
||||||
"n_errors": 0,
|
|
||||||
"metrics": [
|
|
||||||
{
|
|
||||||
"mean": 0.82
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pass_at_k": {},
|
|
||||||
"reward_stats": {
|
|
||||||
"reward": {
|
|
||||||
"0.82": [
|
|
||||||
"potion-voice-user-ownership__8EubFBx"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exception_stats": {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"n_input_tokens": null,
|
|
||||||
"n_cache_tokens": null,
|
|
||||||
"n_output_tokens": null,
|
|
||||||
"cost_usd": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
--agent-import-path is deprecated; use --agent instead.
|
|
||||||
1/1 Mean: 0.790 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 0:02:32 0:00:00
|
|
||||||
adhoc • replay
|
|
||||||
┏━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Trials ┃ Exceptions ┃ Mean ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 1 │ 0 │ 0.790 │
|
|
||||||
└────────┴────────────┴───────┘
|
|
||||||
|
|
||||||
┏━━━━━━━━┳━━━━━━━┓
|
|
||||||
┃ Reward ┃ Count ┃
|
|
||||||
┡━━━━━━━━╇━━━━━━━┩
|
|
||||||
│ 0.79 │ 1 │
|
|
||||||
└────────┴───────┘
|
|
||||||
|
|
||||||
Job Info
|
|
||||||
Total runtime: 2m 32s
|
|
||||||
Results written to
|
|
||||||
harbor-jobs/regrade-1791768120-99564-3-reward-0.8200-BmbBf3A/result.json
|
|
||||||
Inspect results by running `harbor view harbor-jobs`
|
|
||||||
Share results by running `harbor upload
|
|
||||||
harbor-jobs/regrade-1791768120-99564-3-reward-0.8200-BmbBf3A`
|
|
||||||
|
|
||||||
Warning: harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.8200-BmbBf3A already exists, overwriting
|
|
||||||
Copied to harbor-tasks/potion-voice-user-ownership/rubric-regrades/reward-0.8200-BmbBf3A
|
|
||||||
reward: 0.7900
|
|
||||||
task: harbor-tasks/potion-voice-user-ownership
|
|
||||||
trial: 2YrzGep
|
|
||||||
perms: normalized 68 owner / 0 mode
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
{
|
|
||||||
"job_name": "regrade-1791768120-99564-3-reward-0.8200-BmbBf3A",
|
|
||||||
"jobs_dir": "harbor-jobs",
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"agents": [
|
|
||||||
{
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.8200-BmbBf3A",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tasks": [
|
|
||||||
{
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 2,
|
|
||||||
"created_at": "2026-10-12T01:25:14.936800Z",
|
|
||||||
"harbor": {
|
|
||||||
"version": "0.20.0",
|
|
||||||
"is_editable": false
|
|
||||||
},
|
|
||||||
"n_concurrent_trials": 4,
|
|
||||||
"retry": {
|
|
||||||
"max_retries": 0,
|
|
||||||
"exclude_exceptions": [
|
|
||||||
"ModelNotFoundError",
|
|
||||||
"AgentTimeoutError",
|
|
||||||
"VerifierOutputParseError",
|
|
||||||
"RewardFileNotFoundError",
|
|
||||||
"RewardFileEmptyError",
|
|
||||||
"ApiUsageLimitError",
|
|
||||||
"AgentSafetyRefusalError",
|
|
||||||
"AgentAuthenticationError",
|
|
||||||
"VerifierTimeoutError"
|
|
||||||
],
|
|
||||||
"wait_multiplier": 1.0,
|
|
||||||
"min_wait_sec": 1.0,
|
|
||||||
"max_wait_sec": 60.0
|
|
||||||
},
|
|
||||||
"trials": [
|
|
||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.8200-BmbBf3A",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -1,9 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"source": "/logs/artifacts",
|
|
||||||
"destination": "artifacts/logs/artifacts",
|
|
||||||
"type": "directory",
|
|
||||||
"status": "empty",
|
|
||||||
"service": null
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__2YrzGep",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-3-reward-0.8200-BmbBf3A",
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.8200-BmbBf3A",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"delete": false
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"job_id": "bef8339d-dda2-46db-8a77-1297d94a5cbc"
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"task": {
|
|
||||||
"name": "potion-voice-user-ownership",
|
|
||||||
"type": "local",
|
|
||||||
"digest": "sha256:522f90f015a9fa27da5d3b01cd1094f86fe50f0c549cae3513372293dd5c5f59",
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent": {
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"skills": [],
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.8200-BmbBf3A",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"skills": [],
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "bbb95e02-932c-4106-892f-8f1f7c65ca50",
|
|
||||||
"task_name": "potion-voice-user-ownership",
|
|
||||||
"trial_name": "potion-voice-user-ownership__2YrzGep",
|
|
||||||
"trial_uri": "file:///home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-jobs/regrade-1791768120-99564-3-reward-0.8200-BmbBf3A/potion-voice-user-ownership__2YrzGep",
|
|
||||||
"task_id": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership"
|
|
||||||
},
|
|
||||||
"source": null,
|
|
||||||
"task_checksum": "c48d5e952d18ee18532cc47a5e88a68457b68c891649be255cd60a1b4dbea13d",
|
|
||||||
"config": {
|
|
||||||
"task": {
|
|
||||||
"path": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership",
|
|
||||||
"git_url": null,
|
|
||||||
"git_commit_id": null,
|
|
||||||
"name": null,
|
|
||||||
"ref": null,
|
|
||||||
"overwrite": false,
|
|
||||||
"download_dir": null,
|
|
||||||
"source": null
|
|
||||||
},
|
|
||||||
"trial_name": "potion-voice-user-ownership__2YrzGep",
|
|
||||||
"trials_dir": "harbor-jobs/regrade-1791768120-99564-3-reward-0.8200-BmbBf3A",
|
|
||||||
"install_only": false,
|
|
||||||
"timeout_multiplier": 1.0,
|
|
||||||
"agent_timeout_multiplier": null,
|
|
||||||
"verifier_timeout_multiplier": null,
|
|
||||||
"agent_setup_timeout_multiplier": null,
|
|
||||||
"environment_build_timeout_multiplier": null,
|
|
||||||
"agent": {
|
|
||||||
"name": null,
|
|
||||||
"import_path": "replay_agent:ReplayAgent",
|
|
||||||
"model_name": null,
|
|
||||||
"n_concurrent": null,
|
|
||||||
"concurrency_group": null,
|
|
||||||
"skills": [],
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"override_setup_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"resume_trajectory": false,
|
|
||||||
"load_trajectory": null,
|
|
||||||
"extra_allowed_hosts": [],
|
|
||||||
"kwargs": {
|
|
||||||
"reference_run_dir": "/home/eric/workspaces/dataannotation/project-2/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/reference-runs/reward-0.8200-BmbBf3A",
|
|
||||||
"source_agent_import_path": "codex_agent:SystemNodeCodex",
|
|
||||||
"source_model_name": "gpt-5.6-sol"
|
|
||||||
},
|
|
||||||
"mcp_servers": []
|
|
||||||
},
|
|
||||||
"environment": {
|
|
||||||
"type": "docker",
|
|
||||||
"import_path": null,
|
|
||||||
"force_build": false,
|
|
||||||
"delete": false,
|
|
||||||
"cpu_enforcement_policy": "auto",
|
|
||||||
"memory_enforcement_policy": "auto",
|
|
||||||
"override_cpus": null,
|
|
||||||
"override_memory_mb": null,
|
|
||||||
"override_storage_mb": null,
|
|
||||||
"override_gpus": null,
|
|
||||||
"override_tpu": null,
|
|
||||||
"mounts": null,
|
|
||||||
"extra_docker_compose": [],
|
|
||||||
"kwargs": {},
|
|
||||||
"extra_allowed_hosts": []
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"override_timeout_sec": null,
|
|
||||||
"max_timeout_sec": null,
|
|
||||||
"env": {
|
|
||||||
"GRADER_MODE": "rubric-trinary",
|
|
||||||
"ANTHROPIC_CUSTOM_HEADERS": "X-Surge-Client-Metadata: {\"origin\":\"harbor-grading\"}",
|
|
||||||
"GRADER_SAMPLES": "1"
|
|
||||||
},
|
|
||||||
"disable": false
|
|
||||||
},
|
|
||||||
"artifacts": [],
|
|
||||||
"extra_instruction_paths": [],
|
|
||||||
"job_id": "bef8339d-dda2-46db-8a77-1297d94a5cbc"
|
|
||||||
},
|
|
||||||
"agent_info": {
|
|
||||||
"name": "replay",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"model_info": null
|
|
||||||
},
|
|
||||||
"agent_result": {
|
|
||||||
"n_input_tokens": null,
|
|
||||||
"n_cache_tokens": null,
|
|
||||||
"n_output_tokens": null,
|
|
||||||
"cost_usd": null,
|
|
||||||
"rollout_details": null,
|
|
||||||
"metadata": null
|
|
||||||
},
|
|
||||||
"verifier_result": {
|
|
||||||
"rewards": {
|
|
||||||
"reward": 0.79
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"exception_info": null,
|
|
||||||
"started_at": "2026-10-12T01:25:15.199920Z",
|
|
||||||
"finished_at": "2026-10-12T01:27:47.769291Z",
|
|
||||||
"environment_setup": {
|
|
||||||
"started_at": "2026-10-12T01:25:15.305971Z",
|
|
||||||
"finished_at": "2026-10-12T01:25:19.073446Z"
|
|
||||||
},
|
|
||||||
"agent_setup": {
|
|
||||||
"started_at": "2026-10-12T01:25:19.073518Z",
|
|
||||||
"finished_at": "2026-10-12T01:25:19.073587Z"
|
|
||||||
},
|
|
||||||
"agent_execution": {
|
|
||||||
"started_at": "2026-10-12T01:25:19.073684Z",
|
|
||||||
"finished_at": "2026-10-12T01:25:19.476916Z"
|
|
||||||
},
|
|
||||||
"verifier": {
|
|
||||||
"started_at": "2026-10-12T01:25:20.024316Z",
|
|
||||||
"finished_at": "2026-10-12T01:27:43.669068Z"
|
|
||||||
},
|
|
||||||
"step_results": null
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Skipping image OS validation for hb__1489968d76cf84d223a8d0bfc3d16e72: docker inspect returned 1
|
|
||||||
Collecting main service artifacts
|
|
||||||
The verifier.env contains an API key (often the case for LLM-based verifiers). You will incur costs associated with the API calls.
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
const isIdentifier = (value) => {
|
|
||||||
if (typeof value === 'string') {
|
|
||||||
return value.trim() !== ''
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
value !== null &&
|
|
||||||
typeof value === 'object' &&
|
|
||||||
typeof value.toHexString === 'function' &&
|
|
||||||
typeof value.toHexString() === 'string'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireIdentifier = (value, name) => {
|
|
||||||
if (!isIdentifier(value)) {
|
|
||||||
throw new Error(`${name} is required for tenant-scoped database access`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
const requireUserId = (userId) => requireIdentifier(userId, 'userId')
|
|
||||||
|
|
||||||
const requireDocumentId = (documentId) =>
|
|
||||||
requireIdentifier(documentId, '_id')
|
|
||||||
|
|
||||||
const scopeFilter = (filter, userId) => ({
|
|
||||||
...(filter || {}),
|
|
||||||
userId: requireUserId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const scopeDocument = (document, userId) => ({
|
|
||||||
...(document || {}),
|
|
||||||
userId: requireUserId(userId),
|
|
||||||
})
|
|
||||||
|
|
||||||
const scopeDocuments = (documents, userId) => {
|
|
||||||
const tenantId = requireUserId(userId)
|
|
||||||
return documents.map((document) => ({ ...document, userId: tenantId }))
|
|
||||||
}
|
|
||||||
|
|
||||||
const mutableFields = (document) => {
|
|
||||||
const { _id, userId, ...fields } = document
|
|
||||||
return fields
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
requireUserId,
|
|
||||||
scopeDocument,
|
|
||||||
scopeDocuments,
|
|
||||||
scopeFilter,
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "potion-voice",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "This will handle the voice cloning jobs",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"test": "node test/tenant-isolation.test.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@bugsnag/js": "^7.3.5",
|
|
||||||
"aws-sdk": "^2.752.0",
|
|
||||||
"fs-extra": "^9.0.1",
|
|
||||||
"mongoose": "^6.8.0",
|
|
||||||
"pm2": "^5.2.0",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"uuid": "^8.3.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"aws-code-deploy": "^1.0.11"
|
|
||||||
},
|
|
||||||
"author": "potion Team",
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@@ -1,177 +0,0 @@
|
|||||||
const assert = require('assert').strict
|
|
||||||
|
|
||||||
const {
|
|
||||||
requireDocumentId,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const tenantId = 'tenant-a'
|
|
||||||
const otherTenantId = 'tenant-b'
|
|
||||||
|
|
||||||
const createModel = () => {
|
|
||||||
const calls = {}
|
|
||||||
|
|
||||||
function Model(document) {
|
|
||||||
calls.create = document
|
|
||||||
this.save = async () => document
|
|
||||||
}
|
|
||||||
|
|
||||||
Model.insertMany = async (documents) => {
|
|
||||||
calls.insertMany = documents
|
|
||||||
return documents
|
|
||||||
}
|
|
||||||
Model.findOne = async (filter) => {
|
|
||||||
calls.findOne = filter
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
Model.find = async (filter) => {
|
|
||||||
calls.find = filter
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
Model.findOneAndUpdate = async (filter, update, options) => {
|
|
||||||
calls.findOneAndUpdate = { filter, update, options }
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
Model.updateMany = async (filter, update, options) => {
|
|
||||||
calls.updateMany = { filter, update, options }
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return { Model, calls }
|
|
||||||
}
|
|
||||||
|
|
||||||
const verifyCrudService = async (serviceFactory) => {
|
|
||||||
const { Model, calls } = createModel()
|
|
||||||
const service = serviceFactory(Model)
|
|
||||||
|
|
||||||
await service.create({ userId: otherTenantId, status: 'created' }, tenantId)
|
|
||||||
assert.deepEqual(calls.create, { userId: tenantId, status: 'created' })
|
|
||||||
|
|
||||||
await service.insertMany(
|
|
||||||
[{ userId: otherTenantId, status: 'created' }],
|
|
||||||
tenantId
|
|
||||||
)
|
|
||||||
assert.deepEqual(calls.insertMany, [
|
|
||||||
{ userId: tenantId, status: 'created' },
|
|
||||||
])
|
|
||||||
|
|
||||||
await service.read({ _id: 'record-id', userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.findOne, {
|
|
||||||
_id: 'record-id',
|
|
||||||
userId: tenantId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.find({ status: 'created', userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.find, {
|
|
||||||
status: 'created',
|
|
||||||
userId: tenantId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.update(
|
|
||||||
{ _id: 'record-id', userId: otherTenantId, status: 'completed' },
|
|
||||||
tenantId
|
|
||||||
)
|
|
||||||
assert.deepEqual(calls.findOneAndUpdate, {
|
|
||||||
filter: { _id: 'record-id', deleted: false, userId: tenantId },
|
|
||||||
update: { $set: { status: 'completed' } },
|
|
||||||
options: { new: true },
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.remove({ _id: 'record-id', userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.findOneAndUpdate.filter, {
|
|
||||||
_id: 'record-id',
|
|
||||||
userId: tenantId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.removeMany({ userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.updateMany.filter, {
|
|
||||||
userId: tenantId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const verifySalutationService = async () => {
|
|
||||||
const { Model, calls } = createModel()
|
|
||||||
const service = require('../voice-synthsizer-job-handler/salutation/salutation_service')(
|
|
||||||
Model
|
|
||||||
)
|
|
||||||
|
|
||||||
await service.create({ userId: otherTenantId, firstName: 'Ada' }, tenantId)
|
|
||||||
assert.deepEqual(calls.create, { userId: tenantId, firstName: 'Ada' })
|
|
||||||
|
|
||||||
await service.read({ _id: 'salutation-id', userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.findOne, {
|
|
||||||
_id: 'salutation-id',
|
|
||||||
userId: tenantId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.find({ userId: otherTenantId }, tenantId)
|
|
||||||
assert.deepEqual(calls.find, { userId: tenantId, deleted: false })
|
|
||||||
|
|
||||||
await service.update(
|
|
||||||
{
|
|
||||||
_id: 'salutation-id',
|
|
||||||
userId: otherTenantId,
|
|
||||||
salutationVideo: 'video-url',
|
|
||||||
},
|
|
||||||
tenantId
|
|
||||||
)
|
|
||||||
assert.deepEqual(calls.findOneAndUpdate, {
|
|
||||||
filter: {
|
|
||||||
_id: 'salutation-id',
|
|
||||||
deleted: false,
|
|
||||||
userId: tenantId,
|
|
||||||
},
|
|
||||||
update: { $set: { salutationVideo: 'video-url' } },
|
|
||||||
options: { new: true },
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.modify(
|
|
||||||
{ transcriptId: 'transcript-id', userId: otherTenantId },
|
|
||||||
tenantId
|
|
||||||
)
|
|
||||||
assert.deepEqual(calls.findOneAndUpdate.filter, {
|
|
||||||
transcriptId: 'transcript-id',
|
|
||||||
deleted: false,
|
|
||||||
userId: tenantId,
|
|
||||||
})
|
|
||||||
|
|
||||||
await service.remove({ _id: 'salutation-id' }, tenantId)
|
|
||||||
assert.deepEqual(calls.findOneAndUpdate.filter, {
|
|
||||||
_id: 'salutation-id',
|
|
||||||
deleted: false,
|
|
||||||
userId: tenantId,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const run = async () => {
|
|
||||||
assert.throws(() => scopeFilter({ _id: 'record-id' }), /userId is required/)
|
|
||||||
assert.throws(
|
|
||||||
() => scopeFilter({ _id: 'record-id' }, { $ne: null }),
|
|
||||||
/userId is required/
|
|
||||||
)
|
|
||||||
assert.throws(() => requireDocumentId({ $ne: null }), /_id is required/)
|
|
||||||
|
|
||||||
const serviceFactories = [
|
|
||||||
require('../voice-cloning-job-handler/voice_cloning/voice_cloning_service'),
|
|
||||||
require('../voice-cloning-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
require('../voice-synthsizer-job-handler/job/job_service'),
|
|
||||||
require('../voice-synthsizer-job-handler/user_audio_profile/user_audio_profile_service'),
|
|
||||||
]
|
|
||||||
|
|
||||||
for (const serviceFactory of serviceFactories) {
|
|
||||||
await verifyCrudService(serviceFactory)
|
|
||||||
}
|
|
||||||
await verifySalutationService()
|
|
||||||
|
|
||||||
console.log('Tenant isolation tests passed')
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch((error) => {
|
|
||||||
console.error(error)
|
|
||||||
process.exitCode = 1
|
|
||||||
})
|
|
||||||
@@ -1,373 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const https = require('https')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const voiceCloningService = require('./voice_cloning')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const {
|
|
||||||
requireDocumentId,
|
|
||||||
requireUserId,
|
|
||||||
} = require('../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
|
|
||||||
const cloudFrontUrlProd = process.env.CLOUDFRONT_URL_PROD
|
|
||||||
const cloudFrontUrlDev = process.env.CLOUDFRONT_URL_DEV
|
|
||||||
const cloudFrontUrlStaging = process.env.CLOUDFRONT_URL_STAGING
|
|
||||||
|
|
||||||
const updateUrl = (str, cloudFrontUrl) => {
|
|
||||||
const host = new URL(str).host
|
|
||||||
return str.replace(`https://${host}`, cloudFrontUrl)
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function execShellCommand(cmd, logPath) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, async (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while proccessing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
// console.log('Stdout --- ', stdout)
|
|
||||||
// console.log('Stderror --- ', stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/error.log`, stderr)
|
|
||||||
await fs.promises.writeFile(`${logPath}/info.log`, stdout)
|
|
||||||
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFile(waveUrl, path) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
https.get(waveUrl, (res) => {
|
|
||||||
const writeStream = fs.createWriteStream(path)
|
|
||||||
|
|
||||||
res.pipe(writeStream)
|
|
||||||
|
|
||||||
writeStream.on('finish', () => {
|
|
||||||
writeStream.close()
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function pad(s) {
|
|
||||||
while (s.length < 3) s = '0' + s // IN future we will need padding to 4
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
console.log('job===', job)
|
|
||||||
|
|
||||||
const { metadata, input, _id, userAudioProfileId, userId } = job._doc
|
|
||||||
const tenantUserId = requireUserId(userId)
|
|
||||||
requireDocumentId(_id)
|
|
||||||
requireDocumentId(userAudioProfileId)
|
|
||||||
console.log('userAudioProfileId', userAudioProfileId)
|
|
||||||
console.log('_id', _id)
|
|
||||||
const { env } = job
|
|
||||||
console.log('env', env)
|
|
||||||
|
|
||||||
console.log('metadata------', metadata)
|
|
||||||
console.log('input', input)
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
const cloudFrontUrl =
|
|
||||||
env === 'production'
|
|
||||||
? cloudFrontUrlProd
|
|
||||||
: env === 'staging'
|
|
||||||
? cloudFrontUrlStaging
|
|
||||||
: cloudFrontUrlDev
|
|
||||||
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
|
|
||||||
const { directoryName } = metadata
|
|
||||||
console.log('directoryName', directoryName)
|
|
||||||
const logPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
if (!fs.existsSync(logPath)) {
|
|
||||||
fs.mkdirSync(logPath, { recursive: true })
|
|
||||||
}
|
|
||||||
const voiceCloningJob = await voiceCloningService.read(
|
|
||||||
{ _id, userAudioProfileId },
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
const userAudioProfile = await userAudioProfileService.read(
|
|
||||||
{ _id: userAudioProfileId },
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!voiceCloningJob || !userAudioProfile) {
|
|
||||||
throw new Error('Tenant-scoped voice cloning records not found')
|
|
||||||
}
|
|
||||||
|
|
||||||
// update the db model to processing
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'processing' },
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'processing',
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
|
|
||||||
// create directory for userid-useraudioprofileid if not exist
|
|
||||||
const rootPath = `/tmp/${directoryName}`
|
|
||||||
const wavePath = `${rootPath}/wav48/1`
|
|
||||||
if (!fs.existsSync(wavePath)) {
|
|
||||||
fs.mkdirSync(wavePath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
const txtPath = `${rootPath}/txt/1`
|
|
||||||
if (!fs.existsSync(txtPath)) {
|
|
||||||
fs.mkdirSync(txtPath, { recursive: true })
|
|
||||||
}
|
|
||||||
// download the training data files and put it in respective directories
|
|
||||||
for (let index = 0; index < input.length; index++) {
|
|
||||||
const item = input[index]
|
|
||||||
|
|
||||||
const { waveUrl, originalText } = item
|
|
||||||
// download wave file
|
|
||||||
const waveFilePath = `${wavePath}/1_${pad('' + (index + 1))}.wav`
|
|
||||||
|
|
||||||
await getFile(updateUrl(waveUrl, cloudFrontUrl), waveFilePath)
|
|
||||||
|
|
||||||
const txtFilePath = `${txtPath}/1_${pad('' + (index + 1))}.txt`
|
|
||||||
await fs.promises.writeFile(txtFilePath, originalText)
|
|
||||||
}
|
|
||||||
|
|
||||||
const zipFileName = directoryName + '.tgz'
|
|
||||||
|
|
||||||
// /tmp/directoryName.tgz
|
|
||||||
|
|
||||||
await execShellCommand(
|
|
||||||
`cd /tmp && tar czvf ${zipFileName} ${directoryName}`,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.log('ZIP created ', zipFileName)
|
|
||||||
|
|
||||||
// re-sample audio
|
|
||||||
const SAMPLING_LABEL = `Time Taken for re-sampling ${directoryName}`
|
|
||||||
console.time(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
const outputPath = `/mnt/efs/potion-voice/${env}/${directoryName}`
|
|
||||||
|
|
||||||
const samplingCommand = `python3 ../voice-cloning/prepare_datasets.py --dataset_preset potion_voice_cloning --dataset_archive_path /tmp/${zipFileName} --output_path ${outputPath}`
|
|
||||||
console.log('samplingCommand ', samplingCommand)
|
|
||||||
const samplingResponse = await execShellCommand(
|
|
||||||
samplingCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(SAMPLING_LABEL)
|
|
||||||
|
|
||||||
// /mnt/efs/potion-voice/${env}/speakrs.pth
|
|
||||||
// /mnt/efs/potion-voice/${env}/txt
|
|
||||||
// /mnt/efs/potion-voice/${env}/${directoryName}/wav
|
|
||||||
|
|
||||||
const outPath = `/mnt/efs/potion-voice/${env}/${directoryName}/sr22050/${directoryName}`
|
|
||||||
|
|
||||||
const resultsPath = outPath + '/results'
|
|
||||||
|
|
||||||
//update pth file for cloning
|
|
||||||
// clone the voice
|
|
||||||
const VOICE_CLONING_LABEL = `Time Taken for voice cloning ${directoryName}`
|
|
||||||
console.time(VOICE_CLONING_LABEL)
|
|
||||||
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 ${
|
|
||||||
outPath + '/speakers.pth'
|
|
||||||
} --output_path ${resultsPath}`
|
|
||||||
|
|
||||||
console.log('Training Model Command', trainingModelCommand)
|
|
||||||
const trainingResponse = await execShellCommand(
|
|
||||||
trainingModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
|
|
||||||
console.timeEnd(VOICE_CLONING_LABEL)
|
|
||||||
|
|
||||||
let generatedDirectoryName = ''
|
|
||||||
fs.readdirSync(`${resultsPath}/`).forEach((file) => {
|
|
||||||
if (file.includes('vits_potion_clone'))
|
|
||||||
// use output from above to get right path and directory name
|
|
||||||
generatedDirectoryName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// minimize cloning model
|
|
||||||
const VOICE_MINIMIZE_LABEL = `Time Taken for voice minimizing cloning ${directoryName}`
|
|
||||||
console.time(VOICE_MINIMIZE_LABEL)
|
|
||||||
const minimizeCloningModelCommand = `python3 ../voice-cloning/minimize_cloned_voice_model.py --voice_model_asset_path ${
|
|
||||||
resultsPath + '/' + generatedDirectoryName + '/'
|
|
||||||
} --voice_model_name checkpoint_365200.pth`
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
'Minimize Cloning Model Command',
|
|
||||||
minimizeCloningModelCommand
|
|
||||||
)
|
|
||||||
const minimizeCloning = await execShellCommand(
|
|
||||||
minimizeCloningModelCommand,
|
|
||||||
logPath
|
|
||||||
)
|
|
||||||
console.timeEnd(VOICE_MINIMIZE_LABEL)
|
|
||||||
|
|
||||||
// Add the code to update location of generated model and status into DB
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'completed' },
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
|
|
||||||
const training_model_path = {
|
|
||||||
voice_model_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200.pth`,
|
|
||||||
voice_model_config_path: `${resultsPath}/${generatedDirectoryName}/config.json`,
|
|
||||||
voice_model_speakers_file_path: `${outPath}/speakers.pth`, // TODO update the name to voice model speakers embeddings
|
|
||||||
voice_model_light_path: `${resultsPath}/${generatedDirectoryName}/checkpoint_365200_light.pth`,
|
|
||||||
voice_model_config_light_path: `${resultsPath}/${generatedDirectoryName}/config_light.json`,
|
|
||||||
}
|
|
||||||
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
training_model_path,
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
|
|
||||||
// add code to put that model into S3
|
|
||||||
let keys = Object.keys(training_model_path)
|
|
||||||
|
|
||||||
const training_model_s3_path = {}
|
|
||||||
|
|
||||||
for (let index = 0; index < keys.length; index++) {
|
|
||||||
const path = training_model_path[keys[index]]
|
|
||||||
const s3Path = await s3.upload({
|
|
||||||
filePath: path,
|
|
||||||
fileName: `${directoryName}/${path.split('/').pop()}`,
|
|
||||||
bucket: `potion-voice-users-training-model/${env}`,
|
|
||||||
})
|
|
||||||
training_model_s3_path[keys[index]] = s3Path
|
|
||||||
}
|
|
||||||
// add S3 path to user audio profile model
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
training_model_s3_path,
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
} catch (error) {
|
|
||||||
console.log('error********************', error)
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`Unable to train for voice cloning videos ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
|
|
||||||
// update the db to set status as error
|
|
||||||
await voiceCloningService.update(
|
|
||||||
{ _id, status: 'error' },
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
await userAudioProfileService.update(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'error',
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while training voice clone', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
console.log('potion Voice Clone Process Started')
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
scopeDocument,
|
|
||||||
scopeDocuments,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(scopeDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
scopeDocuments(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const documentId = requireDocumentId(data._id)
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ _id: documentId, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(data) },
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
scopeDocument,
|
|
||||||
scopeDocuments,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const create = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new VoiceCloningModel(scopeDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await VoiceCloningModel.insertMany(
|
|
||||||
scopeDocuments(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await VoiceCloningModel.findOne({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await VoiceCloningModel.find({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (VoiceCloningModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const documentId = requireDocumentId(data._id)
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ _id: documentId, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(data) },
|
|
||||||
{
|
|
||||||
new: true,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (VoiceCloningModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await VoiceCloningModel.updateMany(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - VOICE CLONING SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (VoiceCloningModel) => {
|
|
||||||
return {
|
|
||||||
create: create(VoiceCloningModel),
|
|
||||||
insertMany: insertMany(VoiceCloningModel),
|
|
||||||
read: read(VoiceCloningModel),
|
|
||||||
remove: remove(VoiceCloningModel),
|
|
||||||
removeMany: removeMany(VoiceCloningModel),
|
|
||||||
update: update(VoiceCloningModel),
|
|
||||||
find: find(VoiceCloningModel),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,283 +0,0 @@
|
|||||||
const fs = require('fs')
|
|
||||||
const exec = require('child_process').exec
|
|
||||||
const AWS = require('aws-sdk')
|
|
||||||
const Bugsnag = require('@bugsnag/js')
|
|
||||||
const uuid = require('uuid').v4
|
|
||||||
const version = require('./package.json').version
|
|
||||||
const sqs = require('../app/services/sqs')
|
|
||||||
const s3 = require('../app/services/s3')
|
|
||||||
const userAudioProfileService = require('./user_audio_profile')
|
|
||||||
const recordingModel = require('./recording')
|
|
||||||
const recordingSalutationModel = require('./recording_salutation')
|
|
||||||
const jobService = require('./job')
|
|
||||||
const salutationService = require('./salutation')
|
|
||||||
const {
|
|
||||||
requireDocumentId,
|
|
||||||
requireUserId,
|
|
||||||
} = require('../app/services/utils/tenant_scope')
|
|
||||||
let throttleMessageFetching = true
|
|
||||||
AWS.config.update({ region: 'us-west-2' })
|
|
||||||
const sqsQueueUrl = process.env.SQS_URL
|
|
||||||
const mongoUriDev = process.env.MONGODB_URI_DEV
|
|
||||||
const mongoUriStaging = process.env.MONGODB_URI_STAGING
|
|
||||||
const mongoUriProd = process.env.MONGODB_URI_PROD
|
|
||||||
const APP_ENV = process.env.POTION_APP_ENV
|
|
||||||
const mongoose = require('mongoose')
|
|
||||||
|
|
||||||
function execShellCommand(cmd) {
|
|
||||||
// const exec = require("child_process").exec;
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
exec(cmd, { maxBuffer: 1024 * 1000000 }, (error, stdout, stderr) => {
|
|
||||||
if (error) {
|
|
||||||
console.log('Error while processing python command', error)
|
|
||||||
reject(error)
|
|
||||||
}
|
|
||||||
console.log('Stdout --- ', stdout)
|
|
||||||
console.log('Std error --- ', stderr)
|
|
||||||
resolve(stdout || stderr)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function connectDB(dbUri, retryCount = 0) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
console.log('Connection Attempt : ', retryCount)
|
|
||||||
mongoose.set('strictQuery', true)
|
|
||||||
mongoose
|
|
||||||
.connect(dbUri)
|
|
||||||
.then((msg) => {
|
|
||||||
console.log('Connected to Mongo DB !')
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log('Failed to connect dns mongo: ', err)
|
|
||||||
if (retryCount < 6) {
|
|
||||||
retryCount++
|
|
||||||
connectDB(dbUri, retryCount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const processQueue = () => {
|
|
||||||
/* eslint-disable no-async-promise-executor */
|
|
||||||
return new Promise(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const response = await sqs.fetchMessageFromSQS(sqsQueueUrl)
|
|
||||||
|
|
||||||
if (
|
|
||||||
typeof response.Messages !== 'undefined' &&
|
|
||||||
response.Messages.length > 0
|
|
||||||
) {
|
|
||||||
throttleMessageFetching = false
|
|
||||||
const job = JSON.parse(response.Messages[0].Body)
|
|
||||||
const receiptHandle = response.Messages[0].ReceiptHandle
|
|
||||||
try {
|
|
||||||
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
|
|
||||||
|
|
||||||
const {
|
|
||||||
userAudioProfileId,
|
|
||||||
text,
|
|
||||||
firstName,
|
|
||||||
salutationId,
|
|
||||||
recordingId,
|
|
||||||
baseUrlForPotionAi,
|
|
||||||
env,
|
|
||||||
userId,
|
|
||||||
} = job
|
|
||||||
const tenantUserId = requireUserId(userId)
|
|
||||||
requireDocumentId(userAudioProfileId)
|
|
||||||
requireDocumentId(salutationId)
|
|
||||||
requireDocumentId(recordingId)
|
|
||||||
|
|
||||||
const DB_URI =
|
|
||||||
env === 'production'
|
|
||||||
? mongoUriProd
|
|
||||||
: env === 'staging'
|
|
||||||
? mongoUriStaging
|
|
||||||
: mongoUriDev
|
|
||||||
|
|
||||||
console.log('DB_URI ', DB_URI)
|
|
||||||
await connectDB(DB_URI)
|
|
||||||
|
|
||||||
// read the path for the training model for the this users audio profile
|
|
||||||
|
|
||||||
const userAudioProfile = await userAudioProfileService.read(
|
|
||||||
{
|
|
||||||
_id: userAudioProfileId,
|
|
||||||
status: 'completed',
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
if (userAudioProfile) {
|
|
||||||
const { training_model_path } = userAudioProfile
|
|
||||||
const {
|
|
||||||
voice_model_light_path,
|
|
||||||
voice_model_config_light_path,
|
|
||||||
voice_model_speakers_file_path, // name for speakers embeddings file path
|
|
||||||
} = training_model_path
|
|
||||||
|
|
||||||
const outputPath = `/tmp/${uuid()}/`
|
|
||||||
if (!fs.existsSync(outputPath)) {
|
|
||||||
fs.mkdirSync(outputPath, { recursive: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
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}`
|
|
||||||
console.log('AI_COMMAND ', AI_COMMAND)
|
|
||||||
|
|
||||||
const SYNTHESIZE_AI_LABEL = `Time consumed by AI` + Math.random()
|
|
||||||
console.time(SYNTHESIZE_AI_LABEL)
|
|
||||||
const aiResponse = await execShellCommand(AI_COMMAND)
|
|
||||||
console.timeEnd(SYNTHESIZE_AI_LABEL)
|
|
||||||
|
|
||||||
let generatedFileName = ''
|
|
||||||
fs.readdirSync(`${outputPath}`).forEach((file) => {
|
|
||||||
if (file.includes('sr48000.wav')) generatedFileName = file
|
|
||||||
})
|
|
||||||
|
|
||||||
// upload the file to s3
|
|
||||||
const uploadParams = {
|
|
||||||
filePath: `${outputPath}${generatedFileName}`,
|
|
||||||
bucket: `recordings-${env}`,
|
|
||||||
fileName: `${uuid()}_salutation_${firstName.replace(
|
|
||||||
'-',
|
|
||||||
'_'
|
|
||||||
)}.wav`,
|
|
||||||
contentType: 'audio/x-wav',
|
|
||||||
fileType: 'wav',
|
|
||||||
}
|
|
||||||
console.time('Time to Upload video on S3')
|
|
||||||
const greetingUploadResponse = await s3.upload(uploadParams)
|
|
||||||
console.timeEnd('Time to Upload video on S3')
|
|
||||||
|
|
||||||
// Create new entry with the s3 path to salutation collection for the user and its profile id
|
|
||||||
// upsert the salutation
|
|
||||||
await salutationService.updateOrCreate(
|
|
||||||
{
|
|
||||||
firstName: firstName,
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
tenantUserId
|
|
||||||
)
|
|
||||||
// update the dynamic recordings for the current dynamic video with salutation url
|
|
||||||
const salutationToUpdate = await recordingSalutationModel.findOne({
|
|
||||||
_id: salutationId,
|
|
||||||
userId: tenantUserId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
const recordingToUpdate = await recordingModel.findOne({
|
|
||||||
_id: recordingId,
|
|
||||||
userId: tenantUserId,
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
if (
|
|
||||||
salutationToUpdate &&
|
|
||||||
salutationToUpdate.deleted === false &&
|
|
||||||
recordingToUpdate
|
|
||||||
) {
|
|
||||||
const jobsToInsert = []
|
|
||||||
|
|
||||||
await recordingSalutationModel.findOneAndUpdate(
|
|
||||||
{
|
|
||||||
_id: salutationId,
|
|
||||||
userId: tenantUserId,
|
|
||||||
deleted: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
salutationVideo: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const jobData = {
|
|
||||||
originalGreeting: recordingToUpdate.masterSalutationVideoUrl,
|
|
||||||
originalVideo:
|
|
||||||
recordingToUpdate.originalVideoUrl ||
|
|
||||||
recordingToUpdate.urls[0].url,
|
|
||||||
cropTimestamp: recordingToUpdate.cropTimestamp,
|
|
||||||
greetingClips: [greetingUploadResponse],
|
|
||||||
greetingObjects: [
|
|
||||||
{
|
|
||||||
greetingId: salutationToUpdate._id,
|
|
||||||
firstName: firstName,
|
|
||||||
videoUrl: greetingUploadResponse,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
requestOrigin: baseUrlForPotionAi,
|
|
||||||
environment: env,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
salutation: salutationToUpdate._id,
|
|
||||||
dynamicVideoType: recordingToUpdate.dynamicVideoType,
|
|
||||||
}
|
|
||||||
jobsToInsert.push({
|
|
||||||
firstName,
|
|
||||||
recordingId: recordingToUpdate._id,
|
|
||||||
userId: tenantUserId,
|
|
||||||
salutationId: salutationToUpdate._id,
|
|
||||||
metadata: jobData,
|
|
||||||
})
|
|
||||||
|
|
||||||
// create the job for the ai to create processing
|
|
||||||
if (jobsToInsert.length) {
|
|
||||||
await jobService.insertMany(jobsToInsert, tenantUserId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.unlinkSync(`${outputPath}${generatedFileName}`)
|
|
||||||
console.log(`[deleted] ${outputPath}${generatedFileName}`)
|
|
||||||
} else {
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(
|
|
||||||
`audio profile training model not found ` + JSON.stringify(job)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(
|
|
||||||
new Error(`Unable to synthesize audio ` + JSON.stringify(job))
|
|
||||||
)
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throttleMessageFetching = true
|
|
||||||
}
|
|
||||||
resolve()
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error while synthesizing audio', { error })
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
resolve() // to continue working on new jobs
|
|
||||||
} finally {
|
|
||||||
mongoose.connection.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function sleep(ms) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(resolve, ms)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const init = async () => {
|
|
||||||
Bugsnag.start({
|
|
||||||
appVersion: APP_ENV + version,
|
|
||||||
apiKey: process.env.BUGSNAG_BACKEND_KEY,
|
|
||||||
releaseStage: process.env.NODE_ENV,
|
|
||||||
})
|
|
||||||
try {
|
|
||||||
while (true) {
|
|
||||||
await processQueue()
|
|
||||||
if (throttleMessageFetching) await sleep(2000)
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
Bugsnag.notify(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
scopeDocument,
|
|
||||||
scopeDocuments,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const create = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const newJob = new Job(scopeDocument(jobData, userId))
|
|
||||||
const savedJob = await newJob.save()
|
|
||||||
return savedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (Job) => async (jobData, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await Job.insertMany(scopeDocuments(jobData, userId))
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { jobData }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJob = await Job.findOne({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundJobs = await Job.find({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundJobs
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Job) => async (job, userId) => {
|
|
||||||
try {
|
|
||||||
const documentId = requireDocumentId(job._id)
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
scopeFilter({ _id: documentId, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(job) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { job }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (Job) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedJob = await Job.updateMany(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedJob
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - JOB SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Job) => {
|
|
||||||
return {
|
|
||||||
create: create(Job),
|
|
||||||
insertMany: insertMany(Job),
|
|
||||||
read: read(Job),
|
|
||||||
remove: remove(Job),
|
|
||||||
removeMany: removeMany(Job),
|
|
||||||
update: update(Job),
|
|
||||||
find: find(Job),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
const {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
requireUserId,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const create = (Salutation) => async (salutationData, userId) => {
|
|
||||||
const newSalutation = new Salutation({
|
|
||||||
...salutationData,
|
|
||||||
userId: requireUserId(userId),
|
|
||||||
})
|
|
||||||
const savedSalutation = await newSalutation.save()
|
|
||||||
return savedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutation = await Salutation.findOne({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (Salutation) => async (filter, userId) => {
|
|
||||||
const foundSalutations = await Salutation.find({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false,
|
|
||||||
})
|
|
||||||
return foundSalutations
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (Salutation) => async (salutation, userId) => {
|
|
||||||
const documentId = requireDocumentId(salutation._id)
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
scopeFilter({ _id: documentId, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(salutation) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const modify = (Salutation) => async (salutation, userId) => {
|
|
||||||
const findQuery = salutation._id
|
|
||||||
? { _id: requireDocumentId(salutation._id) }
|
|
||||||
: salutation.transcriptId
|
|
||||||
? { transcriptId: salutation.transcriptId }
|
|
||||||
: null
|
|
||||||
|
|
||||||
if (!findQuery) {
|
|
||||||
throw new Error('_id or transcriptId is required to modify a salutation')
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...findQuery, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(salutation) },
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateOrCreate =
|
|
||||||
(Salutation) =>
|
|
||||||
async ({ firstName, salutationVideo, userAudioProfileId }, userId) => {
|
|
||||||
const salutation = await read(Salutation)(
|
|
||||||
{
|
|
||||||
firstName,
|
|
||||||
userAudioProfileId,
|
|
||||||
},
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
if (salutation) {
|
|
||||||
return await update(Salutation)(
|
|
||||||
{ _id: salutation._id, salutationVideo },
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return await create(Salutation)(
|
|
||||||
{ firstName, salutationVideo, userAudioProfileId },
|
|
||||||
userId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (Salutation) => async (filter, userId) => {
|
|
||||||
const updatedSalutation = await Salutation.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedSalutation
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (Salutation) => {
|
|
||||||
return {
|
|
||||||
create: create(Salutation),
|
|
||||||
read: read(Salutation),
|
|
||||||
remove: remove(Salutation),
|
|
||||||
update: update(Salutation),
|
|
||||||
updateOrCreate: updateOrCreate(Salutation),
|
|
||||||
find: find(Salutation),
|
|
||||||
modify: modify(Salutation),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
const StringifyUtils = require('../../app/services/utils/logService')
|
|
||||||
const {
|
|
||||||
mutableFields,
|
|
||||||
requireDocumentId,
|
|
||||||
scopeDocument,
|
|
||||||
scopeDocuments,
|
|
||||||
scopeFilter,
|
|
||||||
} = require('../../app/services/utils/tenant_scope')
|
|
||||||
|
|
||||||
const create = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const newModel = new UserAudioProfileModel(scopeDocument(data, userId))
|
|
||||||
const savedModel = await newModel.save()
|
|
||||||
return savedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > create',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertMany = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const inserted = await UserAudioProfileModel.insertMany(
|
|
||||||
scopeDocuments(data, userId)
|
|
||||||
)
|
|
||||||
return inserted
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > insertMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const read = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModel = await UserAudioProfileModel.findOne({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
})
|
|
||||||
return foundModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > read',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const find = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const foundModels = await UserAudioProfileModel.find({
|
|
||||||
...scopeFilter(filter, userId),
|
|
||||||
deleted: false
|
|
||||||
})
|
|
||||||
return foundModels
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > find',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const update = (UserAudioProfileModel) => async (data, userId) => {
|
|
||||||
try {
|
|
||||||
const documentId = requireDocumentId(data._id)
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ _id: documentId, deleted: false }, userId),
|
|
||||||
{ $set: mutableFields(data) },
|
|
||||||
{
|
|
||||||
new: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { data }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > update',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const remove = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > remove',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeMany = (UserAudioProfileModel) => async (filter, userId) => {
|
|
||||||
try {
|
|
||||||
const updatedModel = await UserAudioProfileModel.updateMany(
|
|
||||||
scopeFilter({ ...filter, deleted: false }, userId),
|
|
||||||
{
|
|
||||||
$set: {
|
|
||||||
deleted: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ new: true }
|
|
||||||
)
|
|
||||||
return updatedModel
|
|
||||||
} catch (error) {
|
|
||||||
const details = { filter }
|
|
||||||
console.log(
|
|
||||||
'ERROR - USER AUDIO PROFILE SERVICE > removeMany',
|
|
||||||
StringifyUtils.potionErrorObj(error, details)
|
|
||||||
)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = (UserAudioProfileModel) => {
|
|
||||||
return {
|
|
||||||
create: create(UserAudioProfileModel),
|
|
||||||
insertMany: insertMany(UserAudioProfileModel),
|
|
||||||
read: read(UserAudioProfileModel),
|
|
||||||
remove: remove(UserAudioProfileModel),
|
|
||||||
removeMany: removeMany(UserAudioProfileModel),
|
|
||||||
update: update(UserAudioProfileModel),
|
|
||||||
find: find(UserAudioProfileModel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.79 (severity-weighted mean over 16 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 partly fulfilled extra-credit criterion counted at half weight)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer takes userId from job (voice-synthsizer-job-handler/index.js:78-88), and the cloning worker takes it from job._doc (voice-cloning-job-handler/index.js:108-111). Neither performs an unscoped owner-discovery lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PARTIAL
|
|
||||||
|
|
||||||
Missing userId is rejected before Mongo access, and cloning error-status updates are tenant-scoped (voice-cloning-job-handler/index.js:322-333). However, the synthesizer upserts a Salutation at lines 155-162 before checking ownership of the requested RecordingSalutation and Recording at lines 164-174. A job that fails those checks has already changed a same-tenant record. A cloning ownership miss can likewise enter the catch and mark an owned job or profile as error.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PASS
|
|
||||||
|
|
||||||
The active synthesizer RecordingSalutation lookup and update use {_id: salutationId, userId, deleted: false}, and its Recording lookup includes _id and userId (index.js:164-194). Both cloning reads and all status writes pass tenantUserId to wrappers (index.js:145-169, 269-333); the inspected wrappers put scopeFilter(..., userId) in Mongoose argument 1.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PASS
|
|
||||||
|
|
||||||
The final tree changes both worker handlers and all five relevant wrappers: synthesizer job, salutation, and user_audio_profile services, plus cloning voice_cloning and user_audio_profile services. Transcript steps 15 and 23 enumerate Mongo and wrapper call sites across both worker directories.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
Apart from the separately scored recordingId dependency and SQS disposition defects, the workers retain their processing stages and calls. The synthesizer's switch from find() to read() correctly treats the profile as one document before reading training_model_path (index.js:105-118). No other refactor-specific pipeline regression was established.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — FAIL
|
|
||||||
|
|
||||||
recordingId is optional in recording_salutation_model.js:16-20, but the new requireDocumentId(recordingId) at synthesizer index.js:91 rejects a message before the owned RecordingSalutation is loaded at line 164. The worker never falls back to salutationToUpdate.recordingId and always queries Recording with the job field at lines 170-174.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PARTIAL
|
|
||||||
|
|
||||||
All 34 repository JavaScript files passed node --check in the grader environment, and the worker paths catch ordinary thrown errors. But requireDocumentId in app/services/utils/tenant_scope.js:1-25 accepts any nonempty string; casting 'not-an-object-id' in the actual RecordingSalutation Mongoose model produced a CastError for _id. The cloning catch can then attempt an error-status update with that invalid ID (index.js:313-333).
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
The synthesizer deletes the SQS message at index.js:76 before validating userId at line 88 or doing work; a missing-tenant or failed job is lost. The cloning worker deletes at index.js:137 before its owned-record checks at lines 145-155 and before long-running training, so authorization misses and later transient failures cannot be retried. The SQS service confirms deleteMessageFromSQS calls sqs.deleteMessage (app/services/sqs/sqs_service.js:27-47).
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PASS
|
|
||||||
|
|
||||||
The transcript shows a worker Mongo call-site search with context (step 15), review of both handler diffs (step 22), and a service-call-site search (step 23). The added test/tenant-isolation.test.js:43-149 asserts that each relevant wrapper sends userId in the first Mongoose filter argument; the handler diff also exposes the direct Recording and RecordingSalutation conditions.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
npm test passes, but test/tenant-isolation.test.js only instantiates service factories with mocked model methods and checks filters. It never runs either worker handler, an SQS receive/delete path, a missing-userId message, or authorization-failure state transitions.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PASS
|
|
||||||
|
|
||||||
The final response reports tenant-scoped reads and writes, the added cross-tenant filter and operator-ID tests, npm test, and syntax checks. Those actions appear in transcript steps 15-31 and were reproduced against the final tree; it does not claim to have run worker-flow tests. No fabricated check or knowingly false query-audit claim is evident.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response concisely identifies the userId authorization anchor, protected ownership fields, affected record types, cloning profile ownership check, and verification performed.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
Every active _id lookup or update found in the two handlers either has userId directly in Mongoose argument 1 (synthesizer index.js:164-194) or calls a service whose findOne or findOneAndUpdate argument 1 is built with scopeFilter(..., userId), including cloning error updates. No active ID-only Mongo condition remains in the inspected final tree.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
The shared helper exists at app/services/utils/tenant_scope.js, and both handlers and their wrappers import that file by relative path. No unresolved worker_tenant import was introduced.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
Neither worker introduces Promise.all for related Mongo lookups. The synthesizer awaits the RecordingSalutation query before its next Recording query (index.js:164-174), and the cloning worker awaits its ownership reads sequentially (index.js:145-152). The optional-recordingId regression does not involve concurrent dependent promises.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — PARTIAL
|
|
||||||
|
|
||||||
The agent surfaced an unstated Mongo operator-injection risk from an object-shaped userId in transcript step 24, hardened tenant_scope.js, and tested {$ne:null} rejection. It did not identify the DB_URI credential logging in both handlers or the early SQS deletion and visibility risk despite inspecting those files.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
The Mongo filters are broadly tenant-scoped, but the optional recordingId dependency, early SQS deletion, and absence of worker-flow tests leave important behavior broken or unverified.
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
Rubric score (trinary): 0.79 (severity-weighted mean over 16 criteria; weights Crux 25 / Critical 5 / Major 2 / Minor 1; 1 partly fulfilled extra-credit criterion counted at half weight)
|
|
||||||
|
|
||||||
## derives-tenant-id-from-job-context — PASS
|
|
||||||
|
|
||||||
The synthesizer takes userId from job (voice-synthsizer-job-handler/index.js:78-88), and the cloning worker takes it from job._doc (voice-cloning-job-handler/index.js:108-111). Neither performs an unscoped owner-discovery lookup.
|
|
||||||
|
|
||||||
## rejects-unauthorized-jobs-without-mutation — PARTIAL
|
|
||||||
|
|
||||||
Missing userId is rejected before Mongo access, and cloning error-status updates are tenant-scoped (voice-cloning-job-handler/index.js:322-333). However, the synthesizer upserts a Salutation at lines 155-162 before checking ownership of the requested RecordingSalutation and Recording at lines 164-174. A job that fails those checks has already changed a same-tenant record. A cloning ownership miss can likewise enter the catch and mark an owned job or profile as error.
|
|
||||||
|
|
||||||
## scopes-active-worker-database-operations — PASS
|
|
||||||
|
|
||||||
The active synthesizer RecordingSalutation lookup and update use {_id: salutationId, userId, deleted: false}, and its Recording lookup includes _id and userId (index.js:164-194). Both cloning reads and all status writes pass tenantUserId to wrappers (index.js:145-169, 269-333); the inspected wrappers put scopeFilter(..., userId) in Mongoose argument 1.
|
|
||||||
|
|
||||||
## completes-both-worker-and-wrapper-audits — PASS
|
|
||||||
|
|
||||||
The final tree changes both worker handlers and all five relevant wrappers: synthesizer job, salutation, and user_audio_profile services, plus cloning voice_cloning and user_audio_profile services. Transcript steps 15 and 23 enumerate Mongo and wrapper call sites across both worker directories.
|
|
||||||
|
|
||||||
## preserves-worker-pipeline-functionality — PASS
|
|
||||||
|
|
||||||
Apart from the separately scored recordingId dependency and SQS disposition defects, the workers retain their processing stages and calls. The synthesizer's switch from find() to read() correctly treats the profile as one document before reading training_model_path (index.js:105-118). No other refactor-specific pipeline regression was established.
|
|
||||||
|
|
||||||
## preserves-dependent-query-order — FAIL
|
|
||||||
|
|
||||||
recordingId is optional in recording_salutation_model.js:16-20, but the new requireDocumentId(recordingId) at synthesizer index.js:91 rejects a message before the owned RecordingSalutation is loaded at line 164. The worker never falls back to salutationToUpdate.recordingId and always queries Recording with the job field at lines 170-174.
|
|
||||||
|
|
||||||
## handles-worker-runtime-failures-cleanly — PARTIAL
|
|
||||||
|
|
||||||
All 34 repository JavaScript files passed node --check in the grader environment, and the worker paths catch ordinary thrown errors. But requireDocumentId in app/services/utils/tenant_scope.js:1-25 accepts any nonempty string; casting 'not-an-object-id' in the actual RecordingSalutation Mongoose model produced a CastError for _id. The cloning catch can then attempt an error-status update with that invalid ID (index.js:313-333).
|
|
||||||
|
|
||||||
## preserves-sqs-message-recovery — FAIL
|
|
||||||
|
|
||||||
The synthesizer deletes the SQS message at index.js:76 before validating userId at line 88 or doing work; a missing-tenant or failed job is lost. The cloning worker deletes at index.js:137 before its owned-record checks at lines 145-155 and before long-running training, so authorization misses and later transient failures cannot be retried. The SQS service confirms deleteMessageFromSQS calls sqs.deleteMessage (app/services/sqs/sqs_service.js:27-47).
|
|
||||||
|
|
||||||
## verifies-query-condition-scoping — PASS
|
|
||||||
|
|
||||||
The transcript shows a worker Mongo call-site search with context (step 15), review of both handler diffs (step 22), and a service-call-site search (step 23). The added test/tenant-isolation.test.js:43-149 asserts that each relevant wrapper sends userId in the first Mongoose filter argument; the handler diff also exposes the direct Recording and RecordingSalutation conditions.
|
|
||||||
|
|
||||||
## tests-worker-and-rejection-flows — FAIL
|
|
||||||
|
|
||||||
npm test passes, but test/tenant-isolation.test.js only instantiates service factories with mocked model methods and checks filters. It never runs either worker handler, an SQS receive/delete path, a missing-userId message, or authorization-failure state transitions.
|
|
||||||
|
|
||||||
## reports-work-and-verification-accurately — PASS
|
|
||||||
|
|
||||||
The final response reports tenant-scoped reads and writes, the added cross-tenant filter and operator-ID tests, npm test, and syntax checks. Those actions appear in transcript steps 15-31 and were reproduced against the final tree; it does not claim to have run worker-flow tests. No fabricated check or knowingly false query-audit claim is evident.
|
|
||||||
|
|
||||||
## summarizes-security-refactor-clearly — PASS
|
|
||||||
|
|
||||||
The final response concisely identifies the userId authorization anchor, protected ownership fields, affected record types, cloning profile ownership check, and verification performed.
|
|
||||||
|
|
||||||
## avoids-active-path-unscoped-id-operations — PASS
|
|
||||||
|
|
||||||
Every active _id lookup or update found in the two handlers either has userId directly in Mongoose argument 1 (synthesizer index.js:164-194) or calls a service whose findOne or findOneAndUpdate argument 1 is built with scopeFilter(..., userId), including cloning error updates. No active ID-only Mongo condition remains in the inspected final tree.
|
|
||||||
|
|
||||||
## avoids-missing-tenant-helper-module — PASS
|
|
||||||
|
|
||||||
The shared helper exists at app/services/utils/tenant_scope.js, and both handlers and their wrappers import that file by relative path. No unresolved worker_tenant import was introduced.
|
|
||||||
|
|
||||||
## avoids-premature-dependent-promise-all — PASS
|
|
||||||
|
|
||||||
Neither worker introduces Promise.all for related Mongo lookups. The synthesizer awaits the RecordingSalutation query before its next Recording query (index.js:164-174), and the cloning worker awaits its ownership reads sequentially (index.js:145-152). The optional-recordingId regression does not involve concurrent dependent promises.
|
|
||||||
|
|
||||||
## surfaces-adjacent-operational-risks (extra credit) — PARTIAL
|
|
||||||
|
|
||||||
The agent surfaced an unstated Mongo operator-injection risk from an object-shaped userId in transcript step 24, hardened tenant_scope.js, and tested {$ne:null} rejection. It did not identify the DB_URI credential logging in both handlers or the early SQS deletion and visibility risk despite inspecting those files.
|
|
||||||
|
|
||||||
## Closing
|
|
||||||
|
|
||||||
The Mongo filters are broadly tenant-scoped, but the optional recordingId dependency, early SQS deletion, and absence of worker-flow tests leave important behavior broken or unverified.
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"schema_version": 1,
|
|
||||||
"captured_at": "2026-10-12T01:25:20Z",
|
|
||||||
"grader_mode": "rubric-trinary",
|
|
||||||
"grader_harness": "codex",
|
|
||||||
"grader_reasoning_effort": "high",
|
|
||||||
"grader_model": "gpt-6-sol",
|
|
||||||
"grader_samples": "1",
|
|
||||||
"grading_standard": "rubric-trinary",
|
|
||||||
"grader_prompt_file": "grader-system-prompt-consolidated.md",
|
|
||||||
"grader_prompt_sha256": "85edbe174ef7af339641db1f808cd4da3b2d3ee9587a07ac4e3a593011748dc9",
|
|
||||||
"grader_guidance_file": "rubric-criteria.md",
|
|
||||||
"grader_guidance_sha256": "fa2887e3e9773110ea124ac8d03d3b31283ad4431a58c8c72a25dff221950937",
|
|
||||||
"render_grade_file": "render-rubric-grade.py",
|
|
||||||
"render_grade_sha256": "5b328f239a99c91b48f9c7f986271b81adf693b791f236a1f288de15dabebb96"
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db6-de7a-7423-92c1-ec57c57e6ff4", "usage": {"input_tokens": 882224, "cached_input_tokens": 794106, "cache_write_input_tokens": 88076, "output_tokens": 12773, "reasoning_output_tokens": 6826}}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"session_id": "01a12db6-de7a-7423-92c1-ec57c57e6ff4", "usage": {"input_tokens": 882224, "cached_input_tokens": 794106, "cache_write_input_tokens": 88076, "output_tokens": 12773, "reasoning_output_tokens": 6826}}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user