fix(translation): use per-language dot-notation to prevent race condition

concurrent retranslation tasks (concurrency:2) were each replacing the
entire outputs doc, so the last writer silently overwrote the others.
Now each task only writes outputs.<lang> for the languages it processed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-05-07 16:45:28 +01:00
parent 865473937f
commit b873f0af6d

View file

@ -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": {