diff --git a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/instruction.md b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/instruction.md old mode 100644 new mode 100755 index 7f60c501..7384ace8 --- a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/instruction.md +++ b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/instruction.md @@ -1 +1,24 @@ -# Replace this with your task prompt +# Voice Service Multi-Tenant Isolation & User Ownership Audit + +## Overview +Our backend background workers currently execute voice cloning and speech synthesis jobs retrieved from background queue messages. However, these worker handlers do not consistently verify that database records, linked audio samples, and output profiles belong to the tenant/userId specified in the job payload before processing. + +You must audit and refactor all database queries and execution flows in the voice background job handlers to enforce strict multi-tenant data isolation and proper authorization sequencing. + +## Requirements + +### 1. Multi-Tenant Query Scoping +- Audit every database lookup, query, update, and deletion across all voice job worker handlers (`voice-cloning-job-handler` and `voice-synthsizer-job-handler`). +- Ensure every database operation filters by `userId` (or verified tenant identifier) in addition to record identifiers (`jobId`, `recordingId`, `profileId`). +- Do not rely solely on unverified primary keys passed in queue payload messages. + +### 2. Authorization & Execution Ordering +- Perform tenant validation and ownership verification **before** executing heavy side effects, processing audio artifacts, or modifying linked models. +- If a job payload attempts to access or modify resources that do not belong to the requesting `userId`, immediately halt processing and reject the job. +- Marking an unauthorized or invalid job as failed (`status: 'error'` or `status: 'failed'`) on the job record itself is expected behavior for job tracking. However, no linked user profiles, audio recordings, or cross-tenant records may be read or mutated for unauthorized requests. + +### 3. Worker Polling Loop Stability +- Rejections and error handling must be contained cleanly within worker handlers. Uncaught authorization errors or invalid job payloads must not crash the main polling loop or stop worker execution. + +### 4. Verification & Testing +- Add unit or integration tests to verify multi-tenant query scoping and confirm that unauthorized cross-tenant requests are blocked before side effects occur. diff --git a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/atomic-rubric.yaml b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/atomic-rubric.yaml new file mode 100755 index 00000000..813458a5 --- /dev/null +++ b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/atomic-rubric.yaml @@ -0,0 +1,64 @@ +task: potion-voice-user-ownership +requirements: +- id: scopes-active-worker-database-operations + category: database + description: All database lookups and updates in active worker handlers include + userId tenant filters. + severity: crux + dimensions: + - correctness + - security + guidelines: Verify that VoiceCloningJob, SpeechSynthesisJob, Recording, RecordingSalutation, + and UserAudioProfile queries include userId scoping. + call_site_key: voice-worker-db-queries +- id: prevents-unauthorized-cross-tenant-mutations + category: security + description: Authorization checks occur before side effects, preventing mutations + or synthesis on unowned records. + severity: crux + dimensions: + - security + - correctness + guidelines: Ensure ownership is validated prior to executing model synthesis or + profile mutations. Operations on unowned records must be rejected. + call_site_key: voice-worker-authz-sequence +- id: ensures-clean-worker-execution + category: reliability + description: Rejected unauthorized jobs are handled gracefully without crashing + the worker polling loop. + severity: certain_dealbreaker + dimensions: + - reliability + guidelines: Confirm that invalid or unauthorized queue messages do not trigger uncaught + exceptions that terminate the worker loop. + call_site_key: voice-worker-loop-error-handling +- id: maintains-syntax-and-import-integrity + category: quality + description: Codebase builds cleanly without syntax, TypeScript compilation, or + module resolution errors. + severity: certain_dealbreaker + dimensions: + - completeness + guidelines: Check that all imports and service references resolve correctly and + compile without errors. + call_site_key: codebase-compilation +- id: preserves-existing-service-architecture + category: architecture + description: Refactoring maintains existing service interfaces and background processing + design patterns. + severity: possible_dealbreaker + dimensions: + - maintainability + guidelines: Ensure worker structure follows established service patterns without + breaking surrounding architecture. + call_site_key: architecture-preservation +- id: provides-accurate-verification-reporting + category: testing + description: Includes verification tests or scripts confirming multi-tenant query + scoping and authorization rejection. + severity: unlikely_dealbreaker + dimensions: + - testing + guidelines: Verify presence of unit tests, mock tests, or verification scripts testing + cross-tenant security. + call_site_key: verification-tests diff --git a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/grader-context.md b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/grader-context.md new file mode 100755 index 00000000..58b0b94f --- /dev/null +++ b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/grader-context.md @@ -0,0 +1,24 @@ +# Grader Context: Voice User Ownership & Multi-Tenant Isolation + +## Core Architecture +The application runs background workers handling voice cloning and speech synthesis jobs. +Handlers read messages containing `jobId` and `userId` and perform database lookups against MongoDB models (`VoiceCloningJob`, `SpeechSynthesisJob`, `Recording`, `RecordingSalutation`, `UserAudioProfile`). + +## Key Answer Key & Call Sites +- **Voice Cloning Handler**: + - `VoiceCloningJob.findOne({ _id: jobId, userId })` + - `Recording.findOne({ _id: recordingId, userId })` + - `UserAudioProfile` creation/update scoped by `userId` +- **Speech Synthesis Handler**: + - `SpeechSynthesisJob.findOne({ _id: jobId, userId })` + - `RecordingSalutation.findOne({ _id: salutationId, userId })` + - Synthesis execution blocked if tenant validation fails + +## Grading Rules +1. **Scoping**: All queries must filter by `userId`. +2. **Sequencing**: + - Unauthorized cross-tenant mutations or synthesis hit Crux heavy penalty under Section 2. + - Premature execution on own-tenant records before authorization receives a moderate penalty under Section 2. + - Updating job status to `error` or `failed` on the job record itself is allowed and expected. +3. **Polling Loop**: Workers must handle rejected jobs without crashing the polling loop. +4. **Verification**: Automated unit tests or mock tests verifying multi-tenant security are acceptable verification methods. diff --git a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/holistic-rubric.md b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/holistic-rubric.md old mode 100644 new mode 100755 index fa71e9bb..f847be32 --- a/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/holistic-rubric.md +++ b/worker-toolkit-potion-polyglot-v1.0.1/harbor-tasks/potion-voice-user-ownership/tests/holistic-rubric.md @@ -1,85 +1,47 @@ -# Holistic Rubric — +# Holistic Evaluation Rubric: Voice User Ownership & Multi-Tenant Isolation -The shared grading standard (`task-shared/grading-standard.md`, embedded in -`tests/grader-system-prompt-consolidated.md`) defines the eight criteria every -response is scored on: Integrity, Narrow Correctness, Broader Correctness / -craft, Persistence, Communication, Verification & Thoroughness, Common Sense, -and Thought Partnership. +## Task Overview +The goal of this task is to enforce multi-tenant security and correct authorization sequencing across background voice workers (`voice-cloning-job-handler` and `voice-synthsizer-job-handler`). -This file is the task's holistic rubric. It carries the task-specific knowledge -the grader cannot infer: the full task context, the ground truth you established -while authoring, what strong and weak responses look like on each criterion, and -any dealbreaker penalties. This document must stand alone. The grader sees only -this file and the shared standard, so carry every load-bearing fact into it -rather than referencing any other document. +--- -Replace each bracketed section. The `/write-holistic-rubric` -skill drafts this interactively if you'd rather not start from a template. -When a criterion genuinely has no task-specific content, keep a one-line note -saying so rather than inventing content. +## Database Call-Site Inventory (Answer Key) -## Task context +Graders must check the following specific database call sites in the worker handlers to verify tenant scoping: -<2-4 sentences: what the task asks, what subsystem(s) it touches, and what a -grader needs to know before reading the criteria below.> +### Voice Cloning Job Handler (`voice-cloning-job-handler`) +1. **Job Record Lookup**: `VoiceCloningJob.findOne({ _id: jobId, userId })` or equivalent scoping check. +2. **Source Recording Lookup**: `Recording.findOne({ _id: recordingId, userId })` ensuring source audio belongs to the user. +3. **User Audio Profile Mutation**: `UserAudioProfile.create` or `UserAudioProfile.updateOne` scoped strictly to `userId`. +4. **Job Status Update**: `VoiceCloningJob.updateOne({ _id: jobId, userId }, { status: ... })` (or updating job status on failure). -## Business context +### Speech Synthesis Job Handler (`voice-synthsizer-job-handler`) +1. **Job Record Lookup**: `SpeechSynthesisJob.findOne({ _id: jobId, userId })` or equivalent scoping check. +2. **Salutation Recording Lookup**: `RecordingSalutation.findOne({ _id: salutationId, userId })` ensuring salutation audio belongs to the user. +3. **Synthesis Processing / Side Effects**: Audio synthesis model execution and S3 storage operations. +4. **Job Status Update**: `SpeechSynthesisJob.updateOne({ _id: jobId, userId }, { status: ... })` (or updating job status on failure). - +--- -## Ground truth +## Grading Standards & Penalty Guidance - +### §1 Scoping Active Worker Database Operations +- **Pass**: All database lookups and updates in both worker handlers incorporate `userId` filters alongside record IDs. +- **Fail / Deductions**: Any database query that fetches or mutates records using only primary keys without tenant filters hits Section 1 penalty. -## Integrity +### §2 Authorization Sequencing & Side-Effect Isolation +- **Pass**: Tenant ownership is fully validated before initiating voice synthesis model calls, profile creation, or modifying linked audio assets. +- **Deductions**: + - **Heavy Penalty (Crux Failure)**: If an agent performs state mutations, profile updates, or audio synthesis against **unowned cross-tenant records**, apply heavy penalty to Section 2. + - **Moderate Penalty**: If an agent executes processing/synthesis prematurely on a user's **own tenant records** before completing authorization checks, apply a moderate deduction to Section 2. + - **Allowed Behavior**: Marking the rejected job itself as `status: 'error'` or `status: 'failed'` on the requesting job record is valid lifecycle tracking and must NOT be penalized. - +### §3 Worker Loop Execution Stability +- **Pass**: Unauthorized job rejections or payload errors are handled gracefully. The polling loop continues processing subsequent queue messages cleanly without crashing. +- **Fail / Deductions**: Unhandled exceptions that cause the worker process or polling loop to crash hit Section 3 penalty. -## Narrow Correctness +### §4 Architectural & Import Integrity +- **Pass**: The refactored handlers preserve existing service patterns, maintain clean imports, and compile without syntax or module resolution errors. - - -## Broader Correctness / the craft of software engineering - - - -## Persistence - - - -## Communication - - - -## Verification & Thoroughness - - - -## Common Sense - - - -## Thought Partnership - - - -## Heavy penalties - - +### §5 Verification & Test Quality +- **Pass**: Candidate provides automated unit tests, mock suites, or verification scripts confirming multi-tenant isolation and unauthorized job rejection.