fix(i18n): stop two runs from spending one translation twice

apply() already refuses a translation another entry holds, on the same floor the release gate reads, so within one process the second sharer is discarded. Four entries of docs/vi nevertheless shared one msgstr: one_catalog reads the catalog once, keeps what it has spent in memory and writes the whole file back after every chunk, so two concurrent runs each hold a private view and overwrite each other.

exclusive() takes an flock on build/i18n/<domain>-<code>.lock around the whole read-modify-write. It tries the lock non-blocking first so a second run can say it is waiting instead of looking hung. The lock files sit under build/, which .gitignore already excludes.

The damage could not be repaired either: prune ran damaged(), which reads one entry at a time, and a collapse is only visible across entries - each one is individually sound. over_shared() groups the machine translations by what they say and returns every sharer beyond MAX_SHARING_SOURCES. prune clears those first, so damaged() no longer sees them and the printed counts cannot overlap. Measured on the corpus: 10 in docs/vi, 132 overall.

MAX_SHARING_SOURCES lands in damage.py next to COLLAPSE_FLOOR and the gate imports both from there. fe80a23725 split a criterion across the two ends once already and the run never converged: every pass wrote what the gate condemned and prune emptied it again.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kevinveenbirkenbachandClaude Opus 5 committed 2026-09-29 12:45:36 +02:00
1 parent 156ed543fe
commit 9d0bc06cc3
6 files changed
+143 -24

No files matched your search

@@ -24,6 +24,7 @@ from utils.i18n.translate import (
URL_SUPPRESSION,
apply,
damaged,
over_shared,
pending,
retry,
taken_translations,
@@ -370,5 +371,55 @@ class TestDuplicateTranslation(unittest.TestCase):
self.assertEqual(taken_translations(catalog), {"Schon vergeben"})
class TestOverSharedTranslation(unittest.TestCase):
LONG_A = "Central identity provider issuing tokens for every service"
LONG_B = "Issue and project tracking platform for software teams today"
LONG_C = "Reverse proxy routing and balancing traffic to the backends"
SHORT_A = "Save the file"
SHORT_B = "Open the file"
SHORT_C = "Close the file"
SHARED = "Beschreibung eines Dienstes"
def _catalog(self, sources: list, translation: str, *, machine: bool = True):
catalog = Catalog(locale="de")
for source in sources:
catalog.add(source, translation)
for message in catalog:
if message.id and machine:
message.user_comments = [MACHINE_TRANSLATION]
return catalog
def _ids(self, catalog) -> list:
return sorted(str(message.id) for message in over_shared(catalog))
def test_every_sharer_beyond_the_limit_is_returned(self) -> None:
catalog = self._catalog(
[self.LONG_A, self.LONG_B, self.LONG_C], self.SHARED
)
self.assertEqual(
self._ids(catalog), sorted([self.LONG_A, self.LONG_B, self.LONG_C])
)
def test_two_sharers_stay(self) -> None:
catalog = self._catalog([self.LONG_A, self.LONG_B], self.SHARED)
self.assertEqual(over_shared(catalog), [])
def test_short_sources_may_share_one(self) -> None:
catalog = self._catalog(
[self.SHORT_A, self.SHORT_B, self.SHORT_C], "Datei"
)
self.assertEqual(over_shared(catalog), [])
def test_a_hand_translation_is_left_alone(self) -> None:
catalog = self._catalog(
[self.LONG_A, self.LONG_B, self.LONG_C], self.SHARED, machine=False
)
self.assertEqual(over_shared(catalog), [])
if __name__ == "__main__":
unittest.main()