Files
project-work/sources/raw-defects.md

66 lines
4.9 KiB
Markdown

Yes, **meaningful failures definitely occurred** in `code-diff.txt`.
While the prompt in `instruction.md` instructed the AI to enforce strict user ownership checks across background worker database queries, the diff generated in `code-diff.txt` introduced several severe runtime, architectural, and security defects.
Here is a breakdown of the specific meaningful failures identified in `code-diff.txt`:
---
### 1. Missing Utility Module (`MODULE_NOT_FOUND` Startup Crash)
* **What the AI did**: Across multiple files—including `voice-cloning-job-handler/index.js`, `voice-synthsizer-job-handler/index.js`, and model service files like `user_audio_profile_service.js` and `voice_cloning_service.js`—the generated diff adds imports for a new tenant utility:
```javascript
const { requireUserId, tenantFilter } = require('../worker_tenant') // or ../../worker_tenant
```
* **The Flaw**: The diff **never creates `worker_tenant.js`** anywhere in the repository.
* **Real-World Consequence**: When Node.js boots either background worker process, it immediately throws `Error: Cannot find module '../worker_tenant'`, causing an **instant 100% startup crash** for all queue workers in production.
---
### 2. Premature SQS Message Deletion (Permanent Silent Data Loss)
* **What the AI did**: In `voice-cloning-job-handler/index.js`, the AI moved the SQS deletion call:
```javascript
await sqs.deleteMessageFromSQS(sqsQueueUrl, receiptHandle)
```
to the very top of `processQueue` inside the `try` block—executing **before** checking `requireUserId(userId)`, before validating tenant records in MongoDB, and before running dataset preparation (`prepare_datasets.py`), voice cloning (`clone_voice.py`), or S3 model artifact uploads.
* **The Flaw**: Violates SQS queue reliability standards. SQS messages must only be deleted after job execution and artifact storage succeed.
* **Real-World Consequence**: If authorization fails, or if Python ML/S3 tasks crash midway, the SQS message has already been deleted. The queue cannot redeliver or retry the job, causing **permanent, silent data loss** without trace or retry capability.
---
### 3. Malformed Mongoose `findOneAndUpdate` Signature (Bypassed User Scoping)
* **What the AI did**: In `user_audio_profile_service.js`, `voice_cloning_service.js`, and `salutation_service.js`, the AI modified `update()` to pass **5 arguments** to Mongoose's `findOneAndUpdate`:
```javascript
const updatedModel = await UserAudioProfileModel.findOneAndUpdate(
{ _id: data._id }, // Arg 1: Query conditions
data, // Arg 2: Update document
{ ...tenantFilter({ _id, userId }), deleted: false },// Arg 3: Options (tenant filter placed here!)
{ $set: changes }, // Arg 4: Ignored by Mongoose
{ new: true } // Arg 5: Ignored by Mongoose
)
```
* **The Flaw**: Mongoose's `findOneAndUpdate(conditions, update, options)` only takes 3 arguments. The AI placed the `tenantFilter` inside the 3rd argument (options) instead of combining it with the query filter (arg 1).
* **Real-World Consequence**:
1. **Security Bypass**: The query filter remains `{ _id: data._id }` (unscoped by `userId`), completely bypassing the user ownership requirement during updates.
2. **Corrupted Updates**: The actual update operation `{ $set: changes }` is pushed to arg 4, which Mongoose ignores entirely.
---
### 4. Orphaned Job States on Authorization Failure
* **What the AI did**: In `voice-cloning-job-handler/index.js`, the AI introduced an `authorized = false` flag. If `requireUserId(userId)` fails or document ownership checks fail, an error is thrown before `authorized = true`. Inside `catch (error)`, database error updates are wrapped in `if (authorized)`:
```javascript
if (authorized) {
await voiceCloningService.update({ _id, userId, status: 'error' })
await userAudioProfileService.update({ _id: userAudioProfileId, userId, status: 'error' })
}
```
* **The Flaw**: When an unauthorized job is rejected, `authorized` remains `false`, so the `catch` block skips updating MongoDB.
* **Real-World Consequence**: Unauthorized or failing jobs are left stuck in their initial pending state in MongoDB indefinitely, providing no feedback to users or system operators.
---
### How This Satisfies the Raccoon Failure Criteria
1. **Broad Agreement**: Senior engineers would universally agree that uncreated imports, premature queue deletions, and invalid Mongoose function signatures are critical code defects.
2. **Feedback Worth Giving**: These mistakes highlight essential lessons in async control flow, SQS queue lifecycle semantics, and Mongoose API usage.
3. **Serious Enough to Block**: Any lead engineer would block a PR containing startup crashes and silent queue message deletions.
4. **Real Consequence**: Production worker pipeline outages, data loss, and security bypasses.