fix(music-lab): retry 레이스 가드(retrying 전이) + failed_step 검증 + backoff 빈리스트 가드

- Fix 1: retry_pipeline이 bg.add_task 직전 상태를 'retrying'으로 전이 → 동시 retry 409 방지
- Fix 2: test_retry_failed_pipeline_retriggers에 called[pid/step] assert 추가
- Fix 3: failed_step이 STEPS에 없으면 409 (엉뚱한 prefix 방지)
- Fix 4: STEP_RETRY_BACKOFF_SEC 빈 리스트 시 IndexError → 0으로 폴백

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-12 00:31:19 +09:00
parent 44dbe7c426
commit ef1a7a92fd
3 changed files with 58 additions and 1 deletions

View File

@@ -1130,6 +1130,7 @@ def cancel_pipeline(pid: int):
@app.post("/api/music/pipeline/{pid}/retry", status_code=202)
async def retry_pipeline(pid: int, bg: BackgroundTasks):
from .pipeline.state_machine import STEPS
p = _db_module.get_pipeline(pid)
if not p:
raise HTTPException(404)
@@ -1141,8 +1142,13 @@ async def retry_pipeline(pid: int, bg: BackgroundTasks):
failed_step = reason.split(":", 1)[0].strip() or None
if not failed_step:
raise HTTPException(409, "실패 step을 판별할 수 없음")
# Fix 3: failed_step이 알려진 STEPS에 없으면 409
if failed_step not in STEPS:
raise HTTPException(409, "실패 step 판별 불가")
if failed_step == "publish" and p.get("youtube_video_id"):
raise HTTPException(409, "이미 업로드됨 (중복 방지)")
# Fix 1: bg.add_task 직전에 상태를 'retrying'으로 전이 → 동시 retry 409 방지
_db_module.update_pipeline_state(pid, "retrying")
bg.add_task(orchestrator.run_step, pid, failed_step)
return {"ok": True, "retrying_step": failed_step}