diff --git a/backend/app/tasks/translate_and_synthesize.py b/backend/app/tasks/translate_and_synthesize.py index 98c083d..5d2ab7a 100644 --- a/backend/app/tasks/translate_and_synthesize.py +++ b/backend/app/tasks/translate_and_synthesize.py @@ -280,14 +280,21 @@ async def _async_translate_and_synthesize(job_id: str, languages: list[str] | No finally: pass - # Update status to TTS generating + # Update status to TTS generating. + # Use per-language dot-notation so concurrent single-language retranslation tasks + # don't overwrite each other's results (concurrency:2 race condition). + per_lang_updates = { + f"outputs.{lang}": updated_outputs[lang] + for lang in target_languages + if lang in updated_outputs + } await db.jobs.update_one( {"_id": job_id}, { "$set": { "status": JobStatus.TTS_GENERATING.value, - "outputs": updated_outputs, - "updated_at": datetime.utcnow() + "updated_at": datetime.utcnow(), + **per_lang_updates, }, "$push": { "review.history": {