# AutoShorts Dashboard Quality Gate & Revision Flow

Use this when producing or correcting Dashboard-driven AutoShorts/TrueTraceShorts packages after Sprint 8.8.

## Core rule

Never treat `MP4 exists` as `ready_for_review`.

The required chain is:

```text
Dashboard ProductionQueue item
→ concept proposal
→ explicit creator approval
→ Director Visual Plan
→ premium text-free AI styleframes
→ styleframe QA passed
→ Gianna/voice QA passed
→ hook/retention gate passed
→ metadata/safety/package integrity passed
→ manifest.quality.overall = passed
→ Dashboard review
```

## Dashboard API source of truth

Before production, fetch:

```http
GET /api/agent/production/next
```

Read and follow:

- `quality_profile.version = autoshorts-quality-v1`
- `quality_profile.gates_required`
- `director_skill.doc = docs/director-production-skill.md`
- `production_rules.ready_for_review_requires_quality_passed = true`

Do not rely on memory or old render habits.

## Required package reports

Every real Dashboard prepared package must include:

```text
production_report.json
quality_report.json
voice_qa.json
visual_qa.json
```

Manifest must include:

```json
{
  "quality": {
    "visual_gate": "passed",
    "voice_gate": "passed",
    "hook_gate": "passed",
    "metadata_gate": "passed",
    "safety_gate": "passed",
    "package_integrity_gate": "passed",
    "overall": "passed"
  }
}
```

If `source=prepared_package` and `queue_item_id` are present, the Dashboard importer must not make the video `ready_for_review` unless `quality.overall = passed`.

## Visual gate

Hard reject for review-ready videos:

- PowerPoint/template/test-slide look;
- simple shapes/generic icons/static text cards;
- pure Pillow/deterministic layouts as final look;
- AI-generated readable text in styleframes;
- real logos/URLs/phone/card/bank/IBAN/private data;
- black/empty frames or obvious artefacts.

Use deterministic/Pillow mockups only as rough mechanism blueprints, never as the final premium style.

## Voice gate

For real review candidates:

- generate 2–3 Gianna premium takes;
- normalize audio;
- transcribe with Whisper/forced alignment;
- compare script to transcript;
- target WER <= 2–3%;
- no wrong critical keywords;
- no missing hook/safer move words;
- no clipped syllables, clicks, peaks or glitches.

Package `voice_qa.json` must record selected take and pass/fail notes.

## Reject workflow

Review page has `Reject video`:

- required reason;
- optional categories;
- sets VideoAsset/PostDrafts to `rejected`;
- sets linked ProductionQueueItem to `needs_changes`;
- creates ReviewDecision and ActivityEvent;
- removes from active review;
- keeps artifacts, does not delete.

## Request changes workflow

Review page has `Request changes`:

- required requested change;
- optional categories;
- sets VideoAsset and ProductionQueueItem to `needs_changes`;
- creates RevisionRequest, ReviewDecision and ActivityEvent;
- video is shown as correction work, not normal active review.

## Correcting rejected packages from chat

When the user says e.g. `Korrigiere das abgelehnte Video package_...`:

1. Find the rejected VideoAsset by package/video id.
2. Read `review_decisions` and `revision_requests` from `/api/videos/{id}` or the DB/API payload. Treat stored rejection categories/reason as binding requirements, not optional context.
3. Find linked ProductionQueueItem.
4. Propose revised concept in chat first: working title, hook, script, scene plan, text-free premium styleframe prompts, motion plan, renderer-owned captions, voice QA, quality-gate plan and planned report files.
5. Wait for explicit approval such as `APPROVE_REVISION_PLAN <package_id>_v2`.
6. Create a new revision package id; never overwrite the rejected package. Use e.g. `package_abc_v2`, with manifest fields `revision_of_package_id` and `revision_of_video_asset_id`.
7. Re-run the full Director Quality Workflow.
8. Import only if `quality.overall = passed`; otherwise mark/leave it `needs_internal_fix` and do not put it into active review.
9. After import, verify the old VideoAsset is still `rejected`, the new VideoAsset is `ready_for_review`, the queue points to the new package, and no UploadRequests were created.

No upload, no TikTok API, no website push during correction unless explicitly approved later.

## Revision package implementation notes

For Dashboard prepared-package revisions, write both standalone report files and embed the report payloads into `manifest.json`:

```text
quality_report.json
visual_qa.json
voice_qa.json
production_report.json
manifest.json: quality, quality_report, visual_qa, voice_qa, production_report
```

The current importer reads quality primarily from the manifest, so file-only reports are not enough for `ready_for_review` gating.

After importing a corrected package, check the linked ProductionQueueItem:

```text
status = package_ready
actual_package_id = <new_revision_package>
video_asset_id = <new_video_asset>
error = null
```

If a successful correction still shows the old rejection error on the queue, clear it and patch the importer so passing imports set `queue_item.error = None`. This is a durable UX/logic rule, not a one-off data cleanup.

When using `/api/imports/scan`, remember it scans all folders under `storage/incoming`; duplicates may be reported as imported/skipped depending on existing `candidate_id`/checksum behavior. Verify the exact new package by querying `candidate_id`, `package_id`, queue linkage, quality events, and UploadRequests after the scan.

## Resuming after provider/session interruption

If a provider failure interrupts the response mid-production, do not restart or speculate. Resume from the filesystem and Dashboard state:

1. List/check expected package artifacts.
2. Re-run ffprobe/hash/QA checks.
3. Update the task list from actual artifact state.
4. Continue with missing reports/import/QA only.

Tell the user what survived and what remains. Avoid duplicating renders unless an artifact or QA gate is actually missing/failed.
