Files
karaoke-gen/backend/models
Andrew Beveridge ☄️andClaude Opus 4.8 156d4369f9 Tenant bulk upload: folder pick + LLM pairing + review table + resumable uploads (v0.200.0) (#943)
## Summary

Adds a **Bulk** mode to tenant portals (frog #3, Vocal Star ask): drop a
folder of tracks, automation pairs Mixed vs Instrumental audio and
extracts Artist/Title from filenames, the operator reviews/fixes an
editable table, then submits all as jobs — with uploads that survive
slow/flaky connections.

### Bulk mode
- `POST /api/tenant/bulk/analyze` — authed, gated on new
`TenantFeatures.bulk_upload` (default on), cap 100 audio files. Regex
fast path for the `S####-1/-2 … Guide/BV/Instru` convention +
Vertex-Gemini pass for leftovers
(`backend/services/tenant_bulk/analyze.py`), regex-only fallback if the
model errors. Pure analysis — filenames only, no state written.
- Label parsing: STRONG labels (guide/instru/bv/backing vocals) override
the `-1`/`-2` slot (surfaces the real-world `S1102-2 … Guide` anomaly as
mixed-only unpaired); WEAK words (Off/Lead/Vocals/Karaoke) stay in the
title unless bracketed.
- `TenantBulkFlow.tsx`: folder/file pick → editable review table
(reassignable Mixed/Instrumental dropdowns, warnings strip,
low-confidence cautions) → bounded-concurrency submit reusing the tenant
single-submit sequence. Mixed-only rows blocked + flagged. Jobs stamped
`state_data.batch_id` + `created_from='tenant-bulk'`.

### Resilient uploads (opt-in `upload_mode: "resumable"`)
- Backend returns **GCS resumable session URIs** (created server-side
with the caller's Origin → GCS answers session CORS itself; **no bucket
CORS changes**). Signed PUT stays the default for all existing clients.
- `frontend/lib/resumable-upload.ts` (dependency-free): 256KiB-aligned
adaptive chunks, always-query-offset resume (no persisted byte ever
re-sent), stall detection instead of hard timeouts, backoff+jitter cut
short by online/visibility events, waiting-offline pause, EWMA
throughput + per-row ETA, non-advancing-308 loop guard.
- `frontend/lib/upload-recovery.ts`: IndexedDB persistence → after a
reload/crash a "Resume unfinished batch?" banner lets the operator
re-pick the folder and every upload resumes from its server-side offset
against the same jobs (never duplicates).

### Tests
- Backend: 26 new (real Bulk-Batch-1 fixture incl. S1102 anomaly,
label-in-title regressions, endpoint auth/feature/cap gates, upload_mode
contract)
- Frontend: 22 new (engine chunk choreography/offset recovery/permanent
errors/retry caps; component resumable routing, re-pick recovery,
retry-no-duplicate)
- Full suite green: backend (incl. emulator) + 1194 frontend
- Prod E2E extension of `tenant-happy-path` is a documented follow-up
(needs this deployed first)

### Docs
- `docs/API.md`: new endpoint + `upload_mode`/`batch_id` fields
- Design + decision record: workspace
`docs/archive/2026-08-25-tenant-bulk-upload-plan.md`

Local CodeRabbit review: 3 completed rounds on this branch, all 9
findings fixed.

@coderabbitai ignore

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-25 17:10:07 -04:00
..