mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-28 01:49:00 +09:00
36b331f3d7411ecf97c05bf15146e83161ab94de
7
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
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> |
||
|
|
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>
|
||
|
|
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> |
||
|
|
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> |
||
|
|
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> |
||
|
|
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> |
||
|
|
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 |