4 essential files

This commit is contained in:
2026-10-14 12:33:07 -04:00
parent 9948d22d1d
commit d9c0fbd3d0
4 changed files with 146 additions and 73 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -1,85 +1,47 @@
# Holistic Rubric — <task-slug>
# 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).
<Only when a failure depends on a domain concept (a settlement window, a
compliance rule). Delete this section otherwise.>
---
## Ground truth
## Grading Standards & Penalty Guidance
<The facts you established while authoring: where the real defect lives
(path:line), what a correct fix looks like, which tests bear on it, which
signals mislead. The grader trusts this section over its own reading.>
### §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.
<Claims on this task that would misrepresent what the agent did or saw —
e.g. asserting a file says X after reading it say Y. Charge only on an
observable basis.>
### §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.
<What the requested change must do to be right, judged as asked. Anchors a
working result must satisfy, checkable by path:line.>
## Broader Correctness / the craft of software engineering
<Craft expectations specific to this codebase: patterns to follow, tests to
add, places a shortcut would rot.>
## Persistence
<What "kept going appropriately" looks like here: the dead ends worth
exhausting, and where stopping to ask is the better call.>
## Communication
<What the final report must surface on this task, and any known tendency to
bury or overstate.>
## Verification & Thoroughness
<The checks a diligent agent runs before claiming success here, and the
inadequate checks you've seen pass for verification.>
## Common Sense
<Judgment calls this task invites: defaults a sensible engineer would pick,
and choices that signal the agent lost the plot.>
## Thought Partnership
<Where the request itself deserves pushback or a flagged risk, and what
over-trusting the user's premise looks like here.>
## Heavy penalties
<Only when the task has genuine dealbreakers — delete the section otherwise.
Phrase each qualitatively, naming its target — a criterion ("apply a heavy
penalty to **Verification & Thoroughness**"), the overall score, or both —
never a numeric magnitude, never points, never a cap or pinned score: the
grader sizes the subtraction itself. Always state the behavior that does NOT trip the penalty.
Never describe how criteria combine into an overall score.>
### §5 Verification & Test Quality
- **Pass**: Candidate provides automated unit tests, mock suites, or verification scripts confirming multi-tenant isolation and unauthorized job rejection.