You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(metadata): drop an AI translation of base text that has since changed - #4242
Closes#4237
Related issue: #2472 (fixed by #4234, which changed the same writes)
Validation tasks: #1213 C1, C2 (reached by every AI translation write; outcome changes only when the base text changes while a job runs)
Other clients: Apple, Android, Roku and Jellyfin-compatible clients N/A: they show the stored localized descriptions, and only which translation gets stored changes.
A forced AI re-translation replaces earlier AI text when it writes, and didn't check that the base text it translated was still the item's. When two forced jobs overlapped (the issue's case: the base overview edited and the translation model changed, so the second request got its own job), the slower one wrote its translation of the old text over the newer one, and both reported success.
This PR has no dependencies and can merge in any order. #4234, which it follows, is merged.
Approach
UpsertAITranslation and the season and episode UpsertAIOverview (internal/catalog/localization_repo.go) take the base text each translation was made from. The job passes field.text, the text it sent the model (persistField).
Each write is now INSERT … SELECT … FROM media_items (or seasons, episodes) WHERE the base text still equals it, FOR SHARE OF the base row, then the existing ON CONFLICT rules. A translation of outdated text writes nothing.
The row lock makes a write wait for an edit of the base text in flight, then check the committed text.
A dropped write isn't an error, so the job still reports success for that field; the newer translation stands.
Validation
gofmt, go vet and the changed-lines lint are clean.
New TestAITranslationOfChangedSourceIsDropped (Postgres 18.6, listed in db-contracts.txt):
forced translations of an old overview and tagline, and of an old season overview, leave the current AI translations in place;
a plain translation of old text leaves an empty episode overview empty;
translations of the current text then land, forced or plain.
The two existing AI write tests now seed the base rows the check reads; their assertions are unchanged.
Negative: with the source check disabled (OR true), the new test fails on every write.
go test ./internal/catalog/ ./internal/metadata/translation/ passes.
Not run: two jobs racing against a real model, and a test of the row lock against an edit in flight (the test tables are session-local); the full make test-go.
Evidence
No visible layout change. The evidence is what each write stores, from the DB test on WSL2 (Ubuntu, go1.26.4 linux/amd64), main at 31c9c4e06, this PR at 920430d20.
Base text now
Stored translation
Write
main
This PR
New source.
AI, of the new source
forced, of the old source
replaced
kept
New source.
none
plain, of the old source
filled
left empty
New source.
AI
forced, of the new source
replaced
replaced
$ go test -count=1 -run TestAITranslationOfChangedSourceIsDropped ./internal/catalog/ # source check disabled
localization_ai_upsert_test.go:199: item = &{... Overview:Alte Quelle. Tagline:Alte Quelle. ...}, want the current translations kept
localization_ai_upsert_test.go:206: season overview = "Alte Quelle.", want the current translation kept
localization_ai_upsert_test.go:209: episode = &{... Overview:Alte Quelle. ...}, want nothing written from the outdated text
FAIL
$ go test -count=1 -v -run 'TestAITranslation|TestPlainAITranslation' ./internal/catalog/
--- PASS: TestAITranslationNeverOverwritesProviderOrManualText (0.12s)
--- PASS: TestPlainAITranslationFillsOnlyEmptyFields (0.15s)
--- PASS: TestAITranslationOfChangedSourceIsDropped (0.09s)
ok github.com/Silo-Server/silo-server/internal/catalog 0.425s
Risks
The three repository methods and LocalizationStore change signature; every implementation in the tree is updated.
A translation whose base row is gone writes nothing, where it used to create a localization row.
An AI write briefly holds a share lock on the base row, so a base-text edit waits for it.
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or how I checked a change nobody sees.
AI Disclosure
Harness: Claude Code (Claude desktop app, Code tab)
Drop AI translations in catalog localization repos when base text has changed
AI translation upserts for items, seasons, and episodes now take the source text the translation was made from. The insert in localization_repo.go only proceeds when the current base text still matches that source, and it locks the base row FOR SHARE to keep the check race-free. Existing conflict-update precedence for manual, provider, empty, and AI fields is unchanged.
translation.LocalizationStore interface and its adapters in store.go gain the new source-text parameters; service.go passes f.text through
Adds a database test TestAITranslationOfChangedSourceIsDropped, registered in db-contracts.txt, covering outdated writes being discarded and current-text writes accepted
Behavioral Change: writes made from outdated source text are now silently dropped instead of stored — existing AI translations are retained and empty fields are not filled by stale translations
…nged
A forced AI re-translation replaces earlier AI text when it writes, and
didn't check that the text it translated was still the item's. When two
forced jobs overlapped, for example after the base overview was edited
and the translation model changed, the slower one wrote its translation
of the old text over the newer one.
The item, season and episode AI writes now take the base text each
translation was made from, and land only while media_items, seasons or
episodes still holds that text. The check locks the base row (FOR SHARE),
so an edit in flight is waited for and then seen. It applies to plain
and forced jobs alike: a translation of outdated text never lands, and
one of the current text still replaces earlier AI text when forced.
ClosesSilo-Server#4237
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.
Reviewing changes in Silo
Include the related issue, expected behavior, and validation steps in the PR description.
For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
Follow this repository's AGENTS.md and CONTRIBUTING.md.
Request another review with @kody start-review in a PR comment.
React with 👍 or 👎 to give feedback on individual suggestions.
Review settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
silo-triageBot
added
bug
Something isn't working
priority: P2
Limited scope, workaround exists, or polish
triaged
High-confidence review completed; does not mean fixed, validated, or accepted for release.
labels
Nov 15, 2026
AI localization writes now include the source text used for translation. Repository upserts compare that text with current base content and skip writes when it does not match.
Changes: AI localization source validation
Layer / File(s)
Summary
Pass source text through localization writes internal/metadata/translation/store.go, internal/metadata/translation/service.go, internal/metadata/translation/service_test.go
Write interfaces and adapters accept source text. The translation service passes the original field text to each upsert.
Check current source text before upsert internal/catalog/localization_repo.go
Media-item, season, and episode upserts select and share-lock base rows. They write only when the relevant source text matches.
Verify current and outdated source cases internal/catalog/localization_ai_upsert_test.go, scripts/ci/db-contracts.txt
Tests cover current-source writes and outdated-source translations for forced and plain writes. The new database-contract test is registered.
AI localization writes now check that the base text still matches what was translated, and drop the write otherwise. The supplied code and tests support this behavior. The only open item is a small test improvement at the service layer, which is not merge-blocking.
Security architecture risk: Minimal · up to 92043
The change prevents outdated translations from replacing current text while preserving existing overwrite protections. No introduced material security or failure-containment regression was identified.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — Each changed write targets a specific content ID and language in an item, season, or episode localization table. Source and translated strings remain bound SQL parameters; the change does not turn translation content into executable SQL or broaden the write target.
Trust Boundaries and Controls
inferred — The authoritative source check occurs at the database write boundary. FOR SHARE serializes the check and upsert against a concurrent edit of the same base row. The guarantee is text equality at write time, not newest-job ordering: overlapping forced translations of identical source text may still replace one another under the unchanged AI precedence rule.
Resilience and Maintainability Implications
observed — The examined provider-ID canonicalization paths acquire base-item locks before merging localization rows, consistent with the new AI write's base-before-localization order. Their transactions roll back on error. This resolves the concrete merge lock-inversion candidate without establishing a repository-wide deadlock guarantee.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: AI translations of base text that has since changed are dropped. The changeset adds a source-text check to the AI localization upserts (media item, season, episode) an…
Linked Issues check
Issue #4237 requires that a translation of outdated source text never replace a translation of current source text, for overlapping forced AI re-translations. The PR passes the translated base text (f…
Out of Scope Changes check
Every changed file serves the #4237 fix. localization_repo.go adds the base-text check to the AI upsert methods. service.go passes the source text in persistField. store.go and service_test.go carry t…
Description check
The description is directly related to the changeset. It explains that AI translation writes now take the base text each translation came from, and that writes from outdated base text are dropped. It …
Full details: Title check
Explanation
The title names the main change: AI translations of base text that has since changed are dropped. The changeset adds a source-text check to the AI localization upserts (media item, season, episode) and tests that outdated translations are rejected. The title is specific and matches the changes. It uses the conventional 'fix(metadata):' prefix.
Full details: Linked Issues check
Explanation
Issue #4237 requires that a translation of outdated source text never replace a translation of current source text, for overlapping forced AI re-translations. The PR passes the translated base text (fromOverview, fromTagline, and the season and episode from) from persistField through the LocalizationStore to the catalog repository. In internal/catalog/localization_repo.go, UpsertAITranslation selects from media_items only WHERE COALESCE(mi.overview, '') = $6 and COALESCE(mi.tagline, '') = $7 for each field being written, with FOR SHARE OF mi. A stale translation therefore inserts or updates no row. The same check applies to plain jobs, so an outdated translation does not fill an empty field. Current-text translations keep the existing provenance rules (manual and provider text are not overwritten; AI text is replaced only on force). The season and episode UpsertAIOverview methods use the same base-text pattern per the PR summary. The new test TestAITranslationOfChangedSourceIsDropped covers media-item, season, and episode writes, forced and plain, and the PR reports it fails when the check is disabled. The season and episode SQL bodies were not read in full because the diff read was truncated; that part rests on the PR summary and the test evidence.
Full details: Out of Scope Changes check
Explanation
Every changed file serves the #4237 fix. localization_repo.go adds the base-text check to the AI upsert methods. service.go passes the source text in persistField. store.go and service_test.go carry the signature change through the LocalizationStore interface, its adapter, and the test double. localization_ai_upsert_test.go adds the new test and seeds base rows for the two existing AI write tests, with their assertions unchanged. db-contracts.txt lists the new DB test. The signature change is a necessary consequence of the fix, not unrelated refactoring. The PR does not change the job key, the concurrency default, or client-visible behavior.
Full details: Description check
Explanation
The description is directly related to the changeset. It explains that AI translation writes now take the base text each translation came from, and that writes from outdated base text are dropped. It names the affected functions in localization_repo.go, the persistField change, the new TestAITranslationOfChangedSourceIsDropped test, and the db-contracts.txt registration. It also lists validation steps, a behavior change, and risks. Level of detail is not a factor for this check.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
The reason will be displayed to describe this comment to others. Learn more.
Discarded stale translations are reported as successfully persisted
When the source changes, translateFields counts the discarded translation as persisted and reports a successful job even though nothing was saved. Return an explicit skipped or stale result and exclude it from the persisted count, or retry with the current source.
Prompt for LLM
File internal/catalog/localization_repo.go, lines 152-155:
Discarded stale translations are reported as successfully persisted
When the source changes, this statement affects zero rows but returns nil, so `translateFields` counts the discarded translation as persisted and reports a successful job even when no translation was saved. Return an explicit skipped or stale result and exclude it from the persisted count, or retry with the current source.
The reason will be displayed to describe this comment to others. Learn more.
The job count does include a dropped write, but nothing records the field as done. Library prewarm (LibraryItemsMissing in internal/metadata/translation/pgrepo.go) and the detail page's pending check (internal/catalog/detail.go) both recompute missing fields from the stored localization values. A field a dropped write leaves empty is picked up again on the next view or prewarm, and a field that already holds AI text keeps the newer translation, which is the point of the fix. The PR description says the success result is intended. No change needed.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. The success result is intentional, and missing fields are reevaluated from stored localization values on a later view or prewarm. My suggestion treated the dropped write as an unintended failure, so I withdraw it. No change is needed for this PR.
The reason will be displayed to describe this comment to others. Learn more.
A stale item field suppresses the other valid translation
When only one base field changes, the combined predicates also discard the still-current translation. Compare the source independently for mi.overview and mi.tagline so the unchanged field can still be saved.
Prompt for LLM
File internal/catalog/localization_repo.go, lines 154-155:
A stale item field suppresses the other valid translation
When a caller supplies both translations and only one base field has changed, the combined predicates discard the still-current translation as well. Apply the source comparison independently to each field so the unchanged field can still be saved.
The reason will be displayed to describe this comment to others. Learn more.
This can't happen with the current caller. persistField in internal/metadata/translation/service.go writes the overview and the tagline in separate calls, each with the other value nil, and each predicate is guarded by $3::text IS NULL OR … / $4::text IS NULL OR …. A stale tagline never blocks a current overview. The new test writes the two fields with separate calls too. No change needed.
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Given the current persistField caller, the overview and tagline are written separately, so a stale source for one cannot suppress the other. The suggestion describes a possible behavior if a future caller supplies both fields in one call, but it is not a bug in the current flow. No change is needed for this PR.
Record and assert the source arguments in fakeLocs.
These fake methods discard every new source argument. If persistField passes an empty source or swaps the overview and tagline sources, the recorded writes remain unchanged. The repository tests cannot detect that forwarding error because they call the repositories directly.
Add source fields to aiWrite. Extend the existing service assertions to check provenance for item overview, item tagline, season overview and episode overview.
Also applies to: 234-234, 244-244
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 2e25be38-06ea-42aa-bbda-0c9de2f2f120
Commits
Reviewing files that changed from the base of the PR and between d892d6e and 920430d.
Files selected for processing: 6
internal/catalog/localization_ai_upsert_test.go
internal/catalog/localization_repo.go
internal/metadata/translation/service.go
internal/metadata/translation/service_test.go
internal/metadata/translation/store.go
scripts/ci/db-contracts.txt
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
Reviewed head: 920430d20. No defects found, so this review adds no commits.
The fix is at the right place: the write itself checks that the base text it translated is still current, so it covers forced and plain jobs, every node, and any writer that edits the base text mid-job. The source text the job passes (COALESCE(overview, '') from pgrepo.go) is exactly the expression the new SQL compares, with no trimming on either side.
What I checked
The test detects the fix. With the three source predicates replaced by true, TestAITranslationOfChangedSourceIsDropped fails on every write (item overview and tagline, season, and episode). On the head, it and the two existing AI write tests pass against Postgres. go test ./internal/metadata/translation/, go vet and make lint-changed are clean.
The row lock, live. The PR lists this as untested, so I ran it with two Postgres sessions on the PR's episode statement. Session A updated the base overview and held its transaction open for 3 s. Session B ran the AI write translated from the old text: it waited until A committed (B finished 1 ms after A's commit), then inserted nothing.
Lock order. Both provider-ID merge transactions in internal/metadata/provider_id_integrity.go lock media_items rows FOR UPDATE before they touch localizations, and artwork release locks base rows first as well, so the new FOR SHARE takes locks in the same order and adds no deadlock. One side effect is an improvement: an AI write racing a merge that deletes the item used to fail on the foreign key and fail the job. Now it writes nothing.
Dropped writes. A dropped write still counts toward the job's done total, but no completion marker is stored. Library prewarm and the detail page recompute missing fields from the stored values, so a field left empty is retried later. I answered both Kody threads with the details.
A cross-provider review (gpt-6.1-sol) went through the same paths independently and found no defect.
Validation
The PR body said Validation tasks: none. Every AI translation write goes through the changed statements, so the change reaches #1213 C1 (generate missing fields on demand) and C2 (keep human and provider translations), both passed on build 1804. Their outcome changes only when the base text changes while a job runs. The existing tests for the C2 precedence rules pass unchanged. I updated the PR body's line.
Manual and clients
User manual: unaffected. The manual doesn't describe this race, and nothing it documents changes.
Apple, Android, Roku, web and Jellyfin clients: N/A. They read the stored localizations, and only which translation gets stored changes.
Verdict
Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
Fit: a small correctness fix that makes a stored translation always match the current base text. It adds no setting, endpoint, or new code path.
Readiness: the new test fails without the source check, the lock wait was shown live, and nothing is left open.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workingpriority: P2Limited scope, workaround exists, or polishsize/M50–199 added + deleted lines (all files); change volume, not priority.triagedHigh-confidence review completed; does not mean fixed, validated, or accepted for release.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #4237
Related issue: #2472 (fixed by #4234, which changed the same writes)
Validation tasks: #1213 C1, C2 (reached by every AI translation write; outcome changes only when the base text changes while a job runs)
Other clients: Apple, Android, Roku and Jellyfin-compatible clients N/A: they show the stored localized descriptions, and only which translation gets stored changes.
A forced AI re-translation replaces earlier AI text when it writes, and didn't check that the base text it translated was still the item's. When two forced jobs overlapped (the issue's case: the base overview edited and the translation model changed, so the second request got its own job), the slower one wrote its translation of the old text over the newer one, and both reported success.
This PR has no dependencies and can merge in any order. #4234, which it follows, is merged.
Approach
UpsertAITranslationand the season and episodeUpsertAIOverview(internal/catalog/localization_repo.go) take the base text each translation was made from. The job passesfield.text, the text it sent the model (persistField).INSERT … SELECT … FROM media_items(orseasons,episodes)WHEREthe base text still equals it,FOR SHARE OFthe base row, then the existingON CONFLICTrules. A translation of outdated text writes nothing.Validation
gofmt,go vetand the changed-lines lint are clean.TestAITranslationOfChangedSourceIsDropped(Postgres 18.6, listed indb-contracts.txt):OR true), the new test fails on every write.go test ./internal/catalog/ ./internal/metadata/translation/passes.make test-go.Evidence
No visible layout change. The evidence is what each write stores, from the DB test on WSL2 (Ubuntu,
go1.26.4 linux/amd64),mainat31c9c4e06, this PR at920430d20.mainRisks
LocalizationStorechange signature; every implementation in the tree is updated.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Drop AI translations in
cataloglocalization repos when base text has changedAI translation upserts for items, seasons, and episodes now take the source text the translation was made from. The insert in localization_repo.go only proceeds when the current base text still matches that source, and it locks the base row
FOR SHAREto keep the check race-free. Existing conflict-update precedence for manual, provider, empty, and AI fields is unchanged.translation.LocalizationStoreinterface and its adapters in store.go gain the new source-text parameters; service.go passesf.textthroughTestAITranslationOfChangedSourceIsDropped, registered in db-contracts.txt, covering outdated writes being discarded and current-text writes acceptedMacroscope summarized 920430d.