Commit Graph
16 Commits
Author SHA1 Message Date
Andrew Beveridge ☄️andClaude Opus 5.5 60687d6cd6 feat(theme): editable + previewed end screen; optional title/end screens (v0.268.0) (#1134)
## Summary
Randy Vild (tenant `randy-vild`) emailed: *"I have completed 3 songs but
all three songs produce the large text at the end even though I have in
my settings smaller text like in my beginning."*

Root cause: the theme editor's size/position sliders only edit
`intro.*`. The end screen has its own `end.*` layout (title 350 /
closing message 400 / yellow capitals artist in Randy's theme). The
editor neither exposed it nor previewed it ("The end screen isn't
previewed").

## Changes
- **End screen tab**: own title/artist colours, size + position sliders
(closing message, song title, artist), show/hide song title / artist
name, capitals toggles, and **Copy title card layout**. That copies the
title card's regions/colours/capitals and moves the closing message just
above the title, or below the artist if there's no room, so they never
overlap.
- **End screen preview**: `theme_preview_service.render_end_screen` uses
the same `VideoGenerator.create_end_video` as `screens_worker`. The
preview column shows the screen for the active tab plus the lyrics
frame; Advanced shows all three.
- **Leave out the title card / end screen**: optional `intro.enabled` /
`end.enabled` (absent = included; not added to the DEFAULT_*
required-field lists). The setting is honoured end to end:
- The screens worker skips the omitted screen and records
`state_data.screens_included`.
- The video worker's prerequisite check and the `/retry` ladder
(`_has_title_screen`, which also requires `screens_progress: complete`)
treat an omitted screen as done.
- The orchestrator sets the omitted screen's path to `None` and gives
the original-vocals guide an intro offset of 0.
- Encoding passes explicit `include_title_screen` /
`include_end_screen=false` to the GCE worker. Without them, its loose
`*title*.png` / `*end*.png` globs would rebuild the screen from
`style/*_background.png`.
- `LocalEncodingService.encode_lossless_mp4` builds the concat from
whichever segments exist (1–3).
  - The portrait renderer drops omitted cards.
- 11 new strings × 33 locales (`endScreenHint` removed). Docs: API.md,
README.md.

## Verification
- `make test` all green: frontend 1665 tests; backend unit, integration
and emulator suites.
- New `backend/tests/test_theme_screen_omission.py`, 28 tests:
  - screens worker for all 4 include combinations;
  - prerequisites and the retry helper;
  - orchestrator config and encoder options;
  - GCE `run_encoding` with decoy theme PNGs present;
  - concat for n = 1/2/3.
- Real-ffmpeg renders:
- end-screen preview (its own background; text size changes only the end
screen);
  - portrait durations with screens omitted.
- Frontend: editor tests for the end tab, copy layout, region toggles
and enable switches, plus unit tests for the `copyTitleCardLayoutToEnd`
util.
- Rendered Randy's real theme locally:
  - as saved, the end screen reproduces the large text;
  - after Copy title card layout, it matches his title card.
- Local CodeRabbit review: 0 findings.

## Deploy notes
- The worker paths changed (`gce_encoding/`,
`local_encoding_service.py`, `karaoke_gen/`), so CI blue-green redeploys
the encoding worker.
- Existing themes are unaffected: they have no `enabled` key.

@coderabbitai ignore

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

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 15:09:25 -04:00
Andrew Beveridge ☄️andClaude Opus 5.5 a2e8e98eaf fix: user-instrumental renders for any audio format + crash-report diagnostics (v0.243.1) (#1060)
## Summary
**1. User-instrumental renders failed for WAV/M4A/OGG/AAC** (job
3ea34552: "Encoding failed on retry: No instrumental audio found")
- The orchestrator render path sent only
`instrumental_selection="custom"` to the GCE encoder.
- The encoder's custom lookup accepted just
`*custom_instrumental*.{flac,mp3}`, and the staged copy kept its
original extension. Tenant MP3s worked; a `.wav` didn't.
- Fix: the orchestrator now passes `existing_instrumental`, so the
encoder downloads the file and matches any extension. The custom lookup
(extracted as `resolve_instrumental`, now tested directly rather than
via copied globs) also accepts any audio extension.

**2. Crash reports now carry enough to diagnose.** A Firefox "Uncaught
out of memory" froze a tab and the alert was useless:
- There was no Error object, so the reporter's own stack became the
pattern.
- The stack pushed URL/UA/build out of Discord's view.
- `extra` was never kept.

Changes:
- **Frontend:** `lib/diagnostics.ts` keeps a 30-entry breadcrumb trail
(nav, clicks, upload phases, errors) and snapshots page age,
DOM/canvas/audio counts, live blob URLs and the JS heap (Chromium).
Errors without an Error object are flagged `synthetic` (reporter stack
dropped, location kept). Each page load can send at most 20 reports.
Benign media `AbortError` rejections are still filtered.
- **Backend:**
- Sample order is now message → location → URL/UA/build → `Diag:` →
`Trail:` → trimmed stack.
  - Stackless errors group by message.
- The full `extra` is logged as `client_extra` on
`frontend_crash_reported`.
  - `TROUBLESHOOTING.md` has a runbook entry.

## Testing
- New backend tests: `resolve_instrumental` across extensions,
orchestrator config, GCE backend config forwarding, and ingestion
sample/grouping.
- New Jest tests: diagnostics, reporter, global handlers, upload
breadcrumbs.
- Targeted backend suites pass. The frontend Jest suite passes in full.
- The full local backend run hit 93 failures from the shared dev env's
`idna` being upgraded mid-run by another process (`ImportError:
uts46data`). These are unrelated to this diff; CI is the gate.

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

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Custom instrumentals can now be used in renders from WAV, M4A, OGG,
AAC, MP3, and FLAC files. When multiple supported versions are
available, FLAC is preferred.
* Crash reports now include additional browser diagnostics and recent
activity, helping provide more context when an error occurs.
* **Bug Fixes**
* Added a clearer message when an uploaded instrumental exceeds the size
limit, including the maximum size and supported format suggestions.
* Improved grouping of frontend errors when a stack trace is
unavailable.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 21:36:09 -04:00
Andrew Beveridge ☄️andClaude Opus 4.8 ed7c6006be Incident hardening: encode→publish seam test + typed contract + guard discipline (T1/P3/P1/P2) (#986)
Part 2 of 3 of the **Incident hardening (post-NOMAD-1632)** initiative
(plan: `docs/archive/2026-09-12-incident-hardening-plan.md`). Both
incident bugs lived in the **encode→publish seam**, yet no test composed
the *real* `GCEEncodingBackend.encode()` with the *real* orchestrator —
so green mocked unit tests gave false confidence in both directions.

## T1 — composed encode→publish seam integration test
New `TestEncodePublishSeam` in
`backend/tests/test_video_worker_orchestrator.py` runs the **real**
backend through the **real** orchestrator `_run_encoding`, patching only
the network boundary (`encode_videos`) and storage. Asserts all four
shapes:
- **empty** `output_files` → completeness guard does **NOT** trip →
orchestrator downloads 0 → raises "stale" → **re-encodes** and recovers
(the Failure-B path the original fix broke);
- **partial** (720p missing) → guard trips → job fails loud (the
Failure-A defense);
- **complete** → success, all result attrs populated (uses the
NOMAD-1632 "Portrait of Jennie" title so the 720p classifies correctly);
- **malformed** (stray/wrong-extension names) → classified out, treated
as empty (no mis-slotting, no crash).

## P3 — kill mock drift: fixtures + typed contract
- Golden fixtures under `backend/tests/fixtures/encoding/`
(`success`/`cached`/`empty`/`partial`/`malformed`) + README.
- Typed `GceEncodeResponse` (TypedDict) in `encoding_interface.py`,
shared by producer (`EncodingService.encode_videos`) and consumer
(`GCEEncodingBackend.encode`) — type-only import, no runtime cost/cycle.
- `backend/tests/test_encoding_contract.py` replays every fixture
through `classify_encoded_output` / `encode()` and validates the schema.
The "empty" shape that hid Failure B is now in the corpus.

## P1/P2 — process docs
`docs/TESTING.md`: **"New Guard / New Enforcement Checklist"**
(recoverable ≠ wrong, fail-open on uncertainty, test
empty/partial/malformed/complete, shadow-first, composed integration
test) and a **"Critical-Path Change Tier"** note + blameless post-mortem
template.

## Tests
`138 passed` locally — new seam tests + contract tests + existing
orchestrator/interface regression. No behavior change to app code (typed
annotation only).

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-12 21:48:55 +00:00
Andrew Beveridge ☄️andClaude Opus 4.8 939f10f12c fix(encoding): completeness guard must not fire on empty result (prod hotfix) (#983)
## Production hotfix

v0.222.2 (#982) added a completeness guard to
`GCEEncodingBackend.encode()` that fails the job when the worker returns
fewer formats than requested. It fired too broadly — including when
`output_files` was **empty** — which hard-failed real user jobs:

> Video generation failed: Encoding failed: Encoder returned an
incomplete result: missing ['mp4_4k_lossless', 'mp4_4k_lossy', 'mkv_4k',
'mp4_720p'] (requested [...], got []). Refusing to publish a partial
release.

### Root cause

An **empty** result is a normal, recoverable condition, distinct from
the partial result the guard was built for. A stale GCE job cache
(finals deleted from GCS on an admin reset / re-run) returns
`output_files=[]`; the orchestrator already recovers by downloading zero
files, raising a `"stale"` `RuntimeError` from
`_download_gce_encoded_files`, and re-encoding under a fresh job id. The
guard sits **inside** `encode()` and raised before that recovery could
run.

### Fix

Fire the guard **only on a partial result** (`if output_files and
missing_formats`) — the actual NOMAD-1632 case (some formats present,
720p missing). Empty results fall through to the existing stale-cache
re-encode path, exactly as before v0.222.2. Partial results never hit
the stale-retry anyway (they download >0 files), so no recovery path is
short-circuited.

Adds a regression test asserting an empty result returns `success=True`
(not blocked by the guard). Version → 0.222.3.

### Impact

Jobs failing since the v0.222.2 deploy (e.g. `252ab966`, `0e21062d`) can
be retried once this deploys. No data loss — the jobs failed loud before
publishing.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of empty cached encoding results so stale jobs can
be detected and retried correctly.
- Prevented empty results from being incorrectly treated as partial
encoding failures.

- **Tests**
- Added regression coverage for stale-cache recovery with no output
files.

- **Chores**
  - Updated the package version to 0.222.3.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-12 14:20:52 -04:00
Andrew Beveridge ☄️andClaude Opus 4.8 7c03834aaf fix(encoding): map GCE finals by format tag, not whole filename (NOMAD-1632 720p gap) (#982)
## Problem

Validator alert: `MP4-720p: missing 1632`. This was **NOMAD-1632 — Nat
King Cole – "Portrait of Jennie"** (job `21150e73`). Only the **720p**
variant was missing; MP4 and CDG were present and correct (so recycling
the brand code would have been *wrong*).

## Root cause — filename/title substring collision

The encoder produced and uploaded the 720p to GCS correctly (`… (Final
Karaoke Lossy 720p).mp4`), but `GCEEncodingBackend.encode()` mapped the
worker's returned file list to format keys by scanning the **whole
filename**, checking `"portrait"` (to detect the 9:16 portrait video)
**before** `"720p"`. The title contains "Portrait", so the 720p matched
the portrait branch → `mp4_720p` never set → `final_video_720p=None` →
`upload_to_public_share` **silently skips** a `None` path → published to
MP4/ + CDG/ with no MP4-720p/ entry. Deterministic for **any** song
whose artist/title contains a format word ("portrait", "720p", "4k",
"lossless", "vocals", …). Only the daily validator caught it, ~24h
later.

## Fix

- **`classify_encoded_output()`** — a shared, title-collision-proof
classifier that matches the trailing **format parenthetical only** (plus
system short-names), never artist/title text. Used by both
`GCEEncodingBackend.encode()` and `redistribute_video` (same latent
bug).
- **Completeness guard** (defense-in-depth) — `encode()` now returns
`success=False` (orchestrator raises → retry + immediate alert) if the
worker returns fewer formats than requested, so *any* partial-encode
cause fails loud instead of publishing an incomplete release.
- **Portrait Video download button** in `OutputLinks` (shown when the
job has `finals.portrait_1080x1920`) — the feature shipped but had no UI
download. Added the backend download filename suffix and the
`outputLinks.portrait` string translated to all 33 locales.
- Docs: `GDRIVE-VALIDATOR.md` History entry; version bump 0.222.1 →
0.222.2.

## Live gap remediation (already done, outside this PR)

The correct 720p already existed in GCS, so it was uploaded directly to
the `MP4-720p/` public-share folder as `NOMAD-1632 - Nat King Cole -
Portrait of Jennie.mp4` (verified present; mirror backfills nightly). No
re-render, no YouTube disruption. 1632 was **not** recycled.

## Testing

- `test_encoding_interface.py` — 37 pass, incl. a NOMAD-1632
reproduction (`Portrait of Jennie` 720p → `mp4_720p`),
title-with-"720p"/"4k" leakage cases, short-name coverage, and a
completeness-guard failure test.
- `OutputLinks.test.tsx` — portrait button show/hide (frontend unit
suite: 1252 pass).
- Orchestrator (82) + change-visibility (25) suites pass.
- Full backend unit run: 4373 pass (8 failures are pre-existing
`test_emulator_integration` env failures — emulator not running locally;
unrelated to this change).

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Added downloadable portrait-format video output at 1080×1920.
  - Added localized “Portrait Video” labels across supported languages.

- **Bug Fixes**
- Improved output recognition so video titles containing format terms
are classified correctly.
- Prevented incomplete encoding results from being published when a
requested format is missing.
  - Corrected portrait-format filenames for clearer downloads.

- **Chores**
  - Updated the application version to 0.222.2.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-09-12 05:58:23 -04:00
Andrew Beveridge ☄️andClaude Opus 4.8 51dbf1cbfd fix(encoding): serialize heavy encodes (OOM-proof) + auto-resubmit lost renders (#908)
## Problem

Three Arctic Monkeys renders (`a3f340a2`, `374dec26`, `590630c0`) failed
within ~2 min on 2026-08-15 with `lost contact with worker after 5
consecutive poll failures: Encoding job … not found`.

**Root cause (confirmed from live forensics):** Both 60 GB c4d primary
encoding workers were down (Spot stockout), so all render traffic
funneled onto the single 32 GB `n2-highcpu-32` fallback. The worker ran
`ThreadPoolExecutor(max_workers=4)`, so the batch put **3 concurrent 4K
ffmpeg encodes** (~30 GB) on it → **kernel OOM-killer fired** →
`encoding-worker` service restarted → in-memory `jobs` registry wiped →
every poll `404`'d → all three failed. ffmpeg already saturates all
cores for one job, so the parallelism bought **no throughput**, only
multiplied peak RAM.

## Fix

**Worker — serialize the heavy lane**
(`backend/services/gce_encoding/main.py`)
- Split the single pool into `heavy_executor`
(`max_workers=ENCODING_HEAVY_CONCURRENCY`, default **1**, clamped to
`[1,4]`) for renders/encodes and `light_executor` (previews + wheel
installs). One heavy ffmpeg at a time = OOM-proof on any machine type;
extras queue as `pending`.
- `/status` now exposes `queue_position` (+ `restart_failure_code`);
jobs tagged by `kind`.

**Client + workers — auto-resubmit a lost job**
- `wait_for_completion` raises the typed `EncodingJobLostError` on a
**404-after-the-job-was-seen** (a pinned poll can only 404 if the worker
lost it) or a terminal failure carrying `restart_failure_code`. 404 is
now a typed `EncodingJobNotFoundError` (no message parsing).
- Time spent `pending` counts against a generous `queue_timeout`, not
the per-run `timeout`.
- `run_with_lost_job_resubmit` resubmits a lost job as
`<id>_retry_<hex8>` (bounded, `ENCODING_RESUBMIT_MAX=2`), wired into
`render_video_worker`, `video_worker`, and `video_worker_orchestrator`
(incl. the stale-cache path). Idempotent by deterministic output paths
(overwrite, no dupes).
- `GCEEncodingBackend.encode` re-raises the lost error instead of
flattening it to `success=False`, so the resubmit actually fires.

## Testing
- New tests: worker lane serialization + `queue_position`;
concurrency-clamp matrix; client lost-job detection (404-after-seen,
restart code, pending-not-timeout); resubmit wrapper (fresh id, bounded,
non-retry of other errors); backend re-raise; preview queue-timeout cap.
- Full backend suite: **3766 passed, 139 skipped**.
- Local CodeRabbit review completed; feedback addressed (typed 404,
bounded env parsing, preview queue cap, idempotency doc).

## Deploy note
`main.py` ships in the wheel, but the running uvicorn process only picks
up worker-side changes on a **service restart** — the CI deploy /
blue-green swap handles this. Post-deploy verification: re-render the 3
failed jobs **concurrently** (the exact OOM trigger) and confirm no OOM
(`journalctl -k`), `NRestarts` doesn't increase, and all three complete.

@coderabbitai ignore

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-15 15:26:25 -04:00
Andrew Beveridge ☄️andClaude Opus 4.8 3f4b7550ab feat(portrait): 9:16 karaoke video output (GCS + Dropbox) (#890)
## Summary

Adds a **portrait 1080×1920 karaoke video** as an additional output of
every finalised job — for phone viewing / social sharing — distributed
to **GCS + the Dropbox brand-code folder only** (never Google Drive or
YouTube). Default-on, gated by `PORTRAIT_RENDER_ENABLED`, and fully
**non-fatal**.

It is a genuine **re-render** at portrait resolution with re-wrapped
lyrics — *not* a transform of the finished landscape video. The design
experiments proved transforms are unusable: letterboxing leaves the
lyrics tiny (~32% of the frame); centre-cropping slices the start/end
off **every** line. See the comparison in
`docs/archive/2026-06-14-portrait-video-experiments/comparison.png`.

## What's included

**New `karaoke_gen/portrait/` module** (reuses the existing
`SubtitlesGenerator` engine + the job's corrected-lyrics data, so
word-by-word timing is identical to the landscape video):
- `wrap.py` — orphan-merging balanced wrapper (no stranded "No," lines),
timing-preserving
- `background.py` — branded portrait background (wordmark/header +
song/artist + footer) + "thank you" end card
- `renderer.py` — portrait ASS + title/end cards + single-pass ffmpeg
assembly (title + lyrics body + end)

**Backend integration** (minimal, low-risk):
- `gce_encoding/main.py::render_portrait_into_outputs` — renders on the
GCE encoder inside `run_encoding`, using the un-padded instrumental +
un-countdown-processed segments (inherently in sync). Writes into
`output_dir`, so it rides the existing `finals/` GCS upload + Dropbox
folder upload.
- `EncodingOutput.portrait_mp4_path` + filename classification +
orchestrator download-allowlist mapping + admin files-manifest entry.
YouTube/Drive use their own allowlists, so the portrait is naturally
excluded from them.

## Testing

- 17 new tests in `tests/unit/portrait/` (balanced wrapping,
background/layout, guard + non-fatal wiring, and a real end-to-end
ffmpeg render on a synthetic fixture).
- Existing GCE/encoding/orchestration/lyrics-output suites green (116
tests total across touched areas).
- **Verified end-to-end on real prod job piri – dog (`052b94ab`)** via
the backend integration function: produced a valid, on-brand 1080×1920
portrait with live word-highlighting, correct title/end cards, correct
duration.

## Safety / rollout

- Additive + `PORTRAIT_RENDER_ENABLED` (default on) + wrapped in
try/except: a portrait failure logs and returns `None` — it never fails
the job or blocks landscape outputs/distribution.
- Subprocess timeouts on ffprobe/ffmpeg so a stalled render can't hang
the worker.
- ~15–30s + ~10 MB per job.

Design: `docs/archive/2026-06-14-portrait-video-design.md` · Plan:
`docs/archive/2026-07-13-portrait-video-plan.md`

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

@coderabbitai ignore

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-14 21:01:08 -04:00
Andrew Beveridge ☄️andClaude Opus 4.8 113197293b fix: restore missing (Title/End).mov + original audio in Dropbox folders (#842)
## Summary
- Organised Dropbox track folders stopped containing the 5-second screen
videos (`(Title).mov`/`(End).mov`) and the original input audio
(`(flacfetch).flac` / `(uploaded).mp3`). Root cause:
`_upload_to_dropbox` uploads the whole `output_dir`, and the
monolith→distributed-GCE migration quietly narrowed what lands there.
- Restores both file types for new jobs, adds an audio-only backfill for
past jobs, and adds a daily-E2E guard so this regression class is caught
automatically.
- Bundles a CLI fix for an ffmpeg interactive-prompt hang in
`--finalise-only` (found while regenerating the missing files locally).

## Changes
**Screen `.mov`s (forward):** GCE encoder copies its generated
`title/end.mov` into `outputs/` with canonical names → plumbed via
`EncodingOutput.title_mov_path`/`end_mov_path`, the `GCEEncodingBackend`
filename mapping, and `_download_gce_encoded_files` back into
`output_dir`.

**Original audio (forward):** new `backend/services/original_audio.py`
(source tag `(uploaded)`/`(flacfetch)`/`(YouTube)` + GCS path +
filename); orchestrator `_stage_original_audio_for_upload()` fetches it
into `output_dir` before folder uploads (non-fatal, only when a folder
upload will occur).

**Backfill (audio only):** `backend/scripts/backfill_original_audio.py`
— dry-run by default, `--live` to upload, skips when audio is gone from
GCS or already present. `.mov` can't be backfilled (needs re-encode).
Adds `DropboxService.file_exists` (re-raises non-not-found `ApiError`).

**Daily E2E guard:** `audio_download_worker` records original audio in
`file_urls['input']['audio']`; `_upload_results` registers
`title_mov`/`end_mov` under `file_urls['finals']`;
`happy-path-real-user.spec.ts` STEP 10.5 asserts the admin files
manifest contains `finals/title_mov`, `finals/end_mov`, `input/audio`,
`finals/lossless_4k_mp4`.

**CLI ffmpeg-hang fix:** `karaoke_finalise` only added `-y` in
non-interactive mode, so a pre-existing output made ffmpeg block on an
invisible `Overwrite? [y/N]` prompt until the 600s timeout (silently
aborting at step 2/6). `-y` is now unconditional +
`stdin=subprocess.DEVNULL` on all ffmpeg `subprocess.run` calls.

## Testing
- [x] 38 new/updated unit tests; all affected suites green
(`encoding_interface`, `video_worker_orchestrator`,
`gce_encoding_worker`, `original_audio`, `backfill_original_audio`,
`dropbox_service`, `upload_results_screen_movs`,
`audio_download_worker`, full `karaoke_finalise` suite)
- [x] Full backend suite: +38 passing vs main, 0 new failures (12
pre-existing `asyncio.get_event_loop()` ordering failures on main,
unrelated)
- [x] Output-file completeness now verified by the daily GHA E2E (STEP
10.5)

## Review
- [x] Local CodeRabbit review completed (scoped to this branch) — 1
major finding fixed (`file_exists` masking non-not-found errors),
re-review clean (0 findings)

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 17:11:24 -04:00
Andrew Beveridge ☄️andClaude Opus 4.6 fe7fdc8ed5 fix: map with_vocals_mp4 in GCE encoding output (#548)
## Summary

- **Fix GCE encoding backend** dropping the `(With Vocals).mp4` file
from output results — the list-to-dict mapper didn't recognize the "with
vocals" filename pattern, so `finals/with_vocals_mp4` was never set in
Firestore
- **Set `with_vocals_mp4_path`** in the `EncodingOutput` returned by
`GCEEncodingBackend.encode()` so the orchestrator can thread it through
to upload
- **Fix local encoding edge case** where input already being MP4 caused
the with-vocals output to be silently skipped instead of copied

PR #535 threaded `with_vocals_mp4` through the pipeline but missed these
two spots in the GCE backend path, which is what production uses.

## Test plan

- [x] 27 encoding interface tests pass (including new regression test)
- [x] 38 local encoding service tests pass
- [x] Full backend suite: 2323+ tests pass
- [x] Full frontend suite: 707 tests pass (38 suites)
- [x] CodeRabbit: no findings
- [x] Manual: fixed job `fa1e2eab` in Firestore — download now serves
39.6 MB MP4 instead of 120.4 MB MKV

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 17:23:03 -04:00
Andrew Beveridge ☄️andClaude Opus 4.5 9a927972a8 fix: propagate countdown padding through orchestrator encoding path (#338)
## Summary

- Fixes 3-second audio desync in countdown-padded videos when using GCE
encoding (orchestrator path)
- PR #328 only fixed the writer side (render_video_worker), this fixes
the reader side (video_worker_orchestrator)
- Follows "Fix Both Sides of Dual Code Paths" pattern from
LESSONS-LEARNED.md

## Root Cause

Job c6a6e31d had correct state (`has_countdown_padding: True`,
`countdown_padding_seconds: 3.0`) written by render_video_worker, but
the orchestrator path had zero countdown handling:

1. `OrchestratorConfig` had no countdown field
2. `create_orchestrator_config_from_job` didn't read
`lyrics_metadata.has_countdown_padding`
3. `EncodingInput.options` didn't include countdown padding
4. GCE encoding worker didn't pad instrumental audio

## Changes

| File | Change |
|------|--------|
| `video_worker_orchestrator.py` | Added `countdown_padding_seconds`
field, read from lyrics_metadata |
| `encoding_interface.py` | Extract countdown from options, add to GCE
encoding config |
| `gce_encoding/main.py` | Added `pad_audio_file()` function, pad
instrumental before encoding |
| `test_video_worker_orchestrator.py` | Added 6 regression tests for
orchestrator countdown flow |
| `pyproject.toml` | Version bump 0.110.0 → 0.110.1 |

## Test plan

- [x] All 67 countdown tests pass
- [x] All 17 encoding interface contract tests pass  
- [x] All 6 new orchestrator countdown tests pass
- [ ] Deploy and verify with a new job that has early vocals

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

<!-- @coderabbitai ignore -->

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 01:25:40 -08:00
Andrew Beveridge ☄️andClaude Opus 4.5 40f11c3f19 fix(gce): Pass instrumental_selection through orchestrator to GCE encoder (#285)
## Summary
- Fix bug where orchestrator path did not pass `instrumental_selection`
to GCE encoder, causing it to default to `clean` even when user selected
`with_backing`
- Add `instrumental_selection` field to `OrchestratorConfig` and
`EncodingInput` dataclasses
- Add 6 regression tests to prevent recurrence
- Document lesson learned about fixing both sides of dual code paths

## Problem
PR #271 fixed the GCE worker to READ `instrumental_selection` from
config, but only verified the legacy path (`video_worker.py`
`_encode_via_gce`) which was already SENDING it. The orchestrator path
(`encoding_interface.py`) was never updated to send it. Since
`USE_NEW_ORCHESTRATOR=true` is the production default, the bug
persisted.

## Root Cause Analysis
Two code paths exist for GCE encoding:

| Path | File | `instrumental_selection` sent? |
|------|------|-------------------------------|
| Legacy | `video_worker.py` → `_encode_via_gce()` | ✅ Yes |
| Orchestrator | `video_worker_orchestrator.py` →
`encoding_interface.py` | ❌ No (bug!) |

PR #271 only fixed the **receiving side** (GCE worker reads selection)
but missed the **sending side** (orchestrator doesn't send it).

## Solution
1. Add `instrumental_selection` field to `OrchestratorConfig` dataclass
2. Add `instrumental_selection` field to `EncodingInput` dataclass
3. Pass `instrumental_selection` in
`create_orchestrator_config_from_job()`
4. Pass `instrumental_selection` in orchestrator's `_run_encoding()`
5. Include `instrumental_selection` in `GCEEncodingBackend.encode()`
config

## Test plan
- [x] Added `test_create_config_passes_instrumental_selection`
regression test
- [x] Added `TestInstrumentalSelectionEndToEnd` test class with 5
integration tests
- [x] All new tests pass locally
- [ ] Deploy and verify affected job (a16c96f2) would use correct
instrumental

## Lesson Learned
Added to `LESSONS-LEARNED.md`:
> **Fix Both Sides of Dual Code Paths**: When fixing a bug in a system
with multiple code paths (e.g., legacy vs orchestrator), verify ALL
paths are fixed. Write integration tests that cover each path.

@coderabbitai ignore

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

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 16:10:47 -05:00
Andrew Beveridge ☄️andClaude Opus 4.5 b345135be1 feat: Unify GCE encoding with LocalEncodingService (single code path) (#214)
## Summary
- Unifies GCE encoding worker with LocalEncodingService (same code as
local CLI)
- Removes all fallback/simplified encoding logic
- Produces proper filenames: `Artist - Title (Final Karaoke Lossless
4k).mp4`
- Includes concatenated title + karaoke + end screens
- CI uploads wheel to GCS for hot code updates without restart

## Problem
Cloud/remote karaoke generation was using simplified, duplicated
encoding logic that:
- Used generic filenames like `output_4k_lossless.mp4`
- Did NOT concatenate title + karaoke + end screens
- Was missing MKV format for YouTube uploads

## Solution
GCE worker now:
1. Downloads latest karaoke-gen wheel from GCS at job start
2. Imports and uses `LocalEncodingService` (same as local CLI)
3. Produces identical output to local karaoke-gen

## Test plan
- [ ] Run a cloud generation job after merging
- [ ] Verify output files have proper names
- [ ] Verify videos include title/end screens
- [ ] Verify Dropbox/GDrive uploads work correctly

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-06 01:25:45 -05:00
Andrew Beveridge ☄️andClaude Opus 4.5 44c44da95e fix: Handle GCE worker output_files as list of paths (#193)
## Summary
Fix the actual root cause of `'list' object has no attribute 'get'`
error in GCE encoding.

## Problem
The GCE encoding worker returns `output_files` as a **list of paths**:
```json
"output_files": [
    "jobs/501258e1/finals/output_4k_lossless.mp4",
    "jobs/501258e1/finals/output_4k_lossy.mp4",
    "jobs/501258e1/finals/output_720p.mp4"
]
```

But the code expected a **dict** with format keys:
```json
{"mp4_4k_lossless": "path/...", "mp4_4k_lossy": "path/...", ...}
```

This caused the error when calling `.get()` on the list.

## Solution
Added conversion logic to map the list of paths to the expected dict
format by matching filename patterns (e.g., `output_4k_lossless.mp4` ->
`mp4_4k_lossless`).

## Testing
- [x] Verified GCE worker response format
- [ ] Deploy and test with job 501258e1

## Notes
PR #191 fixed a similar issue in `wait_for_completion` where the entire
`status` response could be a list. This PR fixes a different issue where
`output_files` within the response is a list.

@coderabbitai ignore

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

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 23:23:21 +00:00
Andrew Beveridge ☄️andClaude Opus 4.5 27495fb4fe fix: Handle list response from GCE encoding worker (#186)
## Summary
- Fix "'list' object has no attribute 'get'" error when GCE worker
returns a list instead of dict
- Add defensive handling in `GCEEncodingBackend.encode()` to extract
first dict from list responses
- Add local tests to catch encoding integration issues earlier

## Changes
- `backend/services/encoding_interface.py` - Handle list/non-dict
responses from GCE worker
- `backend/tests/test_encoding_interface.py` - Add tests for list
response handling and backend options
- `backend/tests/test_video_worker_orchestrator.py` - Add test for GCS
paths structure
- `backend/tests/conftest.py` - Move env var setup to top before imports

## Testing
- [x] All 57 tests pass locally (`make test`)
- [x] `test_encode_handles_list_result` validates fix
- [ ] Deploy and test with existing job at
`awaiting_instrumental_selection`

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 18:48:22 +00:00
Andrew Beveridge ☄️andClaude Opus 4.5 bb19a6e1fc fix: Add dry_run parameter to GCEEncodingBackend (#184)
## Summary
- Fixed `GCEEncodingBackend.__init__() got an unexpected keyword
argument 'dry_run'` error
- Jobs were failing during video generation when using GCE encoding

## Changes
- Added `dry_run` parameter to `GCEEncodingBackend.__init__()` for
interface consistency with `LocalEncodingBackend`
- Parameter is stored but not used since GCE is a remote service that
doesn't support dry run mode

## Testing
- [x] All 23 encoding interface tests pass
- [x] No breaking changes to existing functionality

@coderabbitai ignore

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

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 11:54:27 -05:00
Andrew Beveridge ☄️ c1588992ce refactor: Unify video worker pipeline with new orchestrator (#182)
Resolves GCE vs KaraokeFinalise code path divergence that caused features like YouTube upload, Discord notifications, and CDG/TXT packaging to be missing from the GCE encoding path.

- New services: youtube_upload_service, discord_service, packaging_service, local_encoding_service, encoding_interface
- New VideoWorkerOrchestrator coordinates all stages (packaging, encoding, distribution, notifications)
- Works with any encoding backend (GCE or local)
- 139 new tests, 976 total tests passing
- Feature flag USE_NEW_ORCHESTRATOR (default: true) with rollback capability
2026-01-04 00:25:23 -05:00