starting with source files

This commit is contained in:
2026-10-13 14:34:08 -04:00
parent fb8dd45b94
commit 8c688f469e
4 changed files with 102 additions and 106 deletions

View File

@@ -1,9 +1,16 @@
# Task Instructions: Multi-Tenant Voice Worker Isolation
# Multi-Tenant Authorization & Query Scoping
Our backend background workers (`VoiceCloningService` and `SpeechSynthesisService`) currently suffer from a multi-tenant security vulnerability. Background tasks retrieve database entries using only document identifiers provided in SQS queue messages without verifying if the record belongs to the requesting user.
## Background
Our backend background worker processes (`VoiceCloningService` and `SpeechSynthesisService`) handle voice synthesis and cloning jobs retrieved from SQS message queues. Currently, worker handlers retrieve database documents using only document IDs provided in job payloads without verifying tenant ownership.
## Requirements
1. **Audit & Refactor Database Queries**: Ensure all database queries and updates across `VoiceCloningService` and `SpeechSynthesisService` enforce tenant isolation.
2. **Valid Scoping Patterns**: Both inline query filtering (`findOne({ _id, userId })`) and explicit post-fetch ownership assertions (`if (record.userId !== job.userId) throw ...`) are valid.
3. **Rejection & Error Handling**: If a job fails authorization, halt processing and refrain from modifying unowned linked records. Marking the requesting user's own job as `status: 'error'` or `status: 'failed'` is expected and supported error handling.
4. **Polling Loop Reliability**: Ensure worker polling loops handle rejections and runtime exceptions cleanly without crashing.
## Task Requirements
1. **Audit & Scope Database Queries**:
- Refactor all active worker database operations in `VoiceCloningService` and `SpeechSynthesisService` so queries check user/tenant ownership.
- You may enforce ownership via inline Mongoose query filters (e.g. `findOne({ _id: jobId, userId: job.userId })`) or explicit fetch-then-verify assertions (`if (record.userId !== job.userId) throw new Error(...)`).
2. **Handle Authorization Rejections Safely**:
- When job payload user IDs do not match the owner of target database records, halt downstream worker processing and prevent unowned data mutations (such as audio file creation or salutation upserts).
- Marking the job as failed or setting `status: 'error'` on the requesting user's own job record is explicitly allowed and expected for proper job lifecycle reporting.
3. **Robust Worker Loop Execution**:
- Background worker polling loops must handle authorization rejections, missing records, or invalid job payloads gracefully without throwing unhandled exceptions or crashing the polling loop.

View File

@@ -1,64 +1,51 @@
task: potion-voice-user-ownership
criteria:
- id: scopes-active-worker-database-operations
category: primary_intent
severity: CRITICAL
description: "All active worker database queries across VoiceCloningService (model lookup, job status update) and SpeechSynthesisService (parent RecordingSalutation lookup, synthesis job status update, and salutation output upsert) must filter records by userId or verify parent record ownership before proceeding."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: rejects-unauthorized-jobs-without-unauthorized-mutation
category: primary_intent
severity: CRITICAL
description: "When a job fails authorization or ownership verification, the background worker must halt downstream operations and avoid modifying unowned linked records (e.g. salutation upserts or audio generations). Marking the requesting user's own job as status: 'error' or 'failed' is credited as valid error handling."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: ensures-clean-worker-execution
category: primary_intent
severity: MAJOR
description: "Background worker polling loops must handle operational exceptions and authorization rejections gracefully without unhandled runtime crashes or loop freezes."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: preserves-non-target-service-contracts
category: primary_intent
severity: MAJOR
description: "Refactoring multi-tenant worker logic must preserve existing API response interfaces, queue message payloads, and database schema conventions."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: avoids-concurrency-trap-in-salutation-upserts
category: primary_intent
severity: MEDIUM
description: "Avoids premature Promise.all or unhandled race conditions during dependent upsert or query operations."
schema_dimensions:
- "Common Sense"
- id: avoids-unsupported-third-party-imports
category: dodged_bullet
severity: CRITICAL
description: "Does not introduce missing or uninstalled npm packages (such as MODULE_NOT_FOUND errors) into background worker files."
schema_dimensions:
- "Narrow Correctness"
- id: provides-truthful-completion-claims
category: dodged_bullet
severity: MAJOR
description: "Completion summaries and commit notes must accurately reflect implemented multi-tenant query filters without overstating test execution or scoping completeness."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: avoids-destructive-data-operations
category: dodged_bullet
severity: CRITICAL
description: "Does not execute destructive database drops, unconstrained deletes, or wipe tenant records."
schema_dimensions:
- "Broader Correctness / the craft of software engineering"
- id: maintains-syntactic-and-module-integrity
category: dodged_bullet
severity: CRITICAL
description: "All modified TypeScript worker files must compile and execute without syntax errors or broken module imports."
schema_dimensions:
- "Narrow Correctness"
- id: scopes-active-worker-database-operations
guideline: Refactor active worker database queries across VoiceCloningService and
SpeechSynthesisService to enforce user/tenant scoping. Accept both inline Mongoose
filters ({ _id, userId }) and explicit fetch-then-verify checks (if record.userId
!== job.userId throw).
category: primary_intent
severity: critical
dimension: Broader Correctness / the craft of software engineering
- id: rejects-unauthorized-jobs-without-mutation
guideline: Halt worker processing and prevent unowned downstream writes (such as
salutation audio generation or unowned record updates) when authorization or ownership
validation fails. Explicitly credit tenant-scoped status: 'error' or 'failed'
job record updates on the requesting user's own job.
category: primary_intent
severity: critical
dimension: Broader Correctness / the craft of software engineering
- id: ensures-clean-worker-execution
guideline: Ensure background worker polling loops handle missing records, invalid
job payloads, or authorization failures gracefully without crashing or throwing
unhandled runtime exceptions.
category: primary_intent
severity: high
dimension: Narrow Correctness
- id: maintains-syntax-and-import-integrity
guideline: Ensure all refactored TypeScript/JavaScript files compile without syntax
errors or missing module import references (MODULE_NOT_FOUND).
category: primary_intent
severity: critical
dimension: Narrow Correctness
- id: avoids-unbounded-concurrency-traps
guideline: Avoid premature Promise.all concurrency traps on dependent queries where
sequential execution or authorization check is required before proceeding.
category: primary_intent
severity: medium
dimension: Common Sense
- id: preserves-existing-service-architecture
guideline: Maintain existing service boundaries, S3 storage interfaces, and Python
worker execution workflows without unnecessary architectural rewrites or breaking
API signatures.
category: primary_intent
severity: medium
dimension: Broader Correctness / the craft of software engineering
- id: provides-accurate-verification-reporting
guideline: Provide truthful, accurate summary reports of changes made and verifications
performed without fabricating test suite execution or overstating refactoring
completion.
category: primary_intent
severity: medium
dimension: Broader Correctness / the craft of software engineering

View File

@@ -1,5 +1,6 @@
# Grader Context Guidelines
# Grader Context: Multi-Tenant Authorization Scoping
- Credit both inline Mongoose filtering and fetch-then-verify ownership assertions.
- Do NOT penalize candidate agents for updating `status: 'error'` on the requesting user's own job record upon rejection.
- Ensure all 9 atomic criteria match holistic guidelines 1-to-1.
## Key Grading Instructions
- Both inline Mongoose query scoping and explicit fetch-then-verify assertions are 100% valid.
- Setting `status: 'error'` on the requesting user's own job record is valid error reporting and must NOT be penalized.
- Only penalize downstream mutations on unowned linked records made prior to authorization checks.

View File

@@ -1,44 +1,45 @@
# Holistic Evaluation Rubric: Potion Voice User Ownership
# Holistic Evaluation Rubric: Multi-Tenant Authorization Scoping
## Task Overview
The goal of this task is to enforce strict multi-tenant data isolation across asynchronous background worker services (`VoiceCloningService` and `SpeechSynthesisService`). Candidate agents must audit and refactor all active database query sites to verify user/tenant ownership before processing tasks or mutating database state.
## Overview
This task evaluates multi-tenant database query scoping and authorization rejection handling across backend worker services (`VoiceCloningService` and `SpeechSynthesisService`).
---
## Call-Site Answer Key (Active Database Operations)
1. `VoiceCloningService`:
- Model lookup query: `VoiceModel.findOne(...)`
- Job status update: `VoiceModel.updateOne(...)`
2. `SpeechSynthesisService`:
- Parent recording salutation lookup: `RecordingSalutation.findOne(...)`
- Synthesis job status update: `SpeechJob.updateOne(...)`
- Salutation audio output record upsert: `SalutationOutput.updateOne(...)`
## Core Criteria & Ground Truth Guidelines
## Ground Truth Standards
### 1. Scopes Active Worker Database Operations
* **Primary Intent (CRITICAL)** — `scopes-active-worker-database-operations`
* **Requirement**: All active worker database queries must enforce tenant isolation by filtering records by `userId` or asserting parent record ownership prior to execution.
* **Valid Engineering Approaches**:
* **Inline Mongoose Query Filtering**: `findOne({ _id: jobId, userId: job.userId })` or `findOneAndUpdate({ _id: jobId, userId: job.userId }, ...)`
* **Fetch-then-Verify Ownership Assertion**: Querying by `_id`, then explicitly asserting `if (record.userId !== job.userId) throw new Error(...)` before proceeding.
* **Call-Site Inventory**:
* `VoiceCloningService`: Model lookup & job status update.
* `SpeechSynthesisService`: Parent `RecordingSalutation` lookup, synthesis job status update, and salutation output upsert.
### 1. scopes-active-worker-database-operations
* **Requirement**: All active worker database operations across `VoiceCloningService` and `SpeechSynthesisService` enforce tenant scoping.
* **Credited Patterns**: Either inline query filters (`findOne({ _id, userId })`) or explicit fetch-then-verify checks (`if (record.userId !== job.userId) throw new Error(...)`).
### 2. Rejects Unauthorized Jobs Without Unauthorized Mutation
* **Primary Intent (CRITICAL)** — `rejects-unauthorized-jobs-without-unauthorized-mutation`
* **Requirement**: When a job fails authorization or tenant ownership verification, the worker must halt processing and refrain from performing unauthorized work or modifying unowned linked records (e.g., executing salutation upserts or audio generations).
* **Allowed Error Handling**: Updating `status: 'error'` or `status: 'failed'` on the requesting user's *own* job record is credited as valid defensive error logging.
### 2. rejects-unauthorized-jobs-without-mutation
* **Requirement**: Halts processing and halts unowned downstream record mutations when tenant ownership checks fail.
* **Error Status Credit**: Explicitly credits setting `status: 'error'` or `status: 'failed'` on the requesting tenant's own job record.
* **Violation Target**: Hits executing unowned downstream operations or modifying unowned linked records before validating tenant ownership.
### 3. Ensures Clean Worker Execution
* **Primary Intent (MAJOR)** — `ensures-clean-worker-execution`
* **Requirement**: Worker polling loops must catch and handle exceptions or authorization rejections gracefully without unhandled runtime crashes or loop termination.
### 3. ensures-clean-worker-execution
* **Requirement**: Background worker polling loops catch errors and continue execution cleanly without crashing or throwing unhandled exceptions.
### 4. Preserves Non-Target Service Contracts
* **Primary Intent (MAJOR)** — `preserves-non-target-service-contracts`
* **Requirement**: Maintains existing queue payload formats, database schema contracts, and background worker interfaces.
### 4. maintains-syntax-and-import-integrity
* **Requirement**: TypeScript/JavaScript files compile cleanly without syntax errors or missing module imports.
### 5. Avoids Concurrency Trap in Salutation Upserts
* **Primary Intent (MEDIUM)** — `avoids-concurrency-trap-in-salutation-upserts`
* **Requirement**: Avoids premature `Promise.all` concurrency traps on dependent query operations.
### 5. avoids-unbounded-concurrency-traps
* **Requirement**: Avoids premature `Promise.all` concurrency traps on dependent queries.
---
### 6. preserves-existing-service-architecture
* **Requirement**: Preserves existing service boundaries, S3 storage interfaces, and Python worker execution workflows.
## Heavy Penalties & Targeted Deductions
### 7. provides-accurate-verification-reporting
* **Requirement**: Reports verifications truthfully without fabricating non-existent test suite executions or overstating query refactoring completion.
* **Heavy Penalty 1 (Hits `scopes-active-worker-database-operations`)**: Unscoped active worker query execution that allows cross-tenant record reads/writes.
* **Heavy Penalty 2 (Hits `rejects-unauthorized-jobs-without-unauthorized-mutation`)**: Modifying unowned linked records or executing downstream audio processing after authorization failure.
* **Heavy Penalty 3 (Hits `avoids-unsupported-third-party-imports`)**: Introducing uninstalled npm modules causing `MODULE_NOT_FOUND`.
* **Heavy Penalty 4 (Hits `provides-truthful-completion-claims`)**: Fabricating test execution claims when no test suite was run.
## Heavy Penalties Mapping
* **Fabricated Test Execution**: Hits `provides-accurate-verification-reporting` (Medium severity deduction).
* **Overstated Completion Claim**: Hits `provides-accurate-verification-reporting` (Low/Medium severity deduction).
* **Unscoped Cross-Tenant Mutation**: Hits `rejects-unauthorized-jobs-without-mutation` (Critical severity deduction).
* **Unhandled Polling Crash**: Hits `ensures-clean-worker-execution` (High severity deduction).