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(audiobooks): keep a provider match intact across rescans - #4220
Related issue: N/A
Validation tasks: changes #1254 C2, #1255 C1 and C2 (none has a recorded pass yet)
Other clients: Apple N/A (shows the stored metadata; no client change); Android N/A (same); Roku N/A (same); Web included (the admin unmatched list already shows Match, and hides Ignore, for books)
A matched audiobook does not stay matched. Once a file in its folder changes, even
just its modification time, the next scan writes the tag year over the provider's
year (or 0 when the file has no year tag), replaces the provider's authors and
narrators with the tag credits, and merges tag genres back in. The provider's
overview and cover stay, so the book permanently describes two editions; a matched
book is never enriched again. The match itself also overreaches: a provider with no
narrators deletes the narrator read from the file, the credits are written after the
match commits (a failure there still leaves the book marked matched), and the
provider poster replaces the book's own folder or embedded cover while the old
thumbhash stays. Finally, media_items.status is empty for every audiobook, so
Admin → Libraries → Unmatched Items can never list a book that found no match.
This gives each field one owner and lists unmatched audiobooks.
Approach
A book counts as matched when it has a provider ID other than the asin the
scanner reads from tags, when its last enrichment outcome is success (an
automatic match that stored only the ASIN), or when its status is matched,
which Match Item and Refresh Metadata write with the match whatever IDs it
carries. The scanner and the unmatched list use this one predicate.
Scanner: for a matched book, year, genres and studios are only filled when empty,
and tagged credits (split per person since fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203) are only added for a kind
(author or narrator) the book has no credit for. An unmatched book keeps today's
behavior: its tagged authors and narrators replace the stored credits. Title and series stay
scanner-owned. Admin locks still win over both writers.
Enricher: credits are replaced per kind, only for the kinds the provider returns,
inside the match transaction. If any part of that write fails, the transaction
rolls back and the failure goes through fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204's failure recording, so the book
stays unmatched and is retried under its backoff. A provider poster only fills a missing cover, and a written poster
always carries its own thumbhash (empty for an uncached URL).
The scanner's check for a renamed or moved folder compares the tag year stored
on the files (media_files.base_year) instead of media_items.year, which a
match now owns, so a matched book whose provider year differs from its tag
keeps its item and listening progress. Files indexed before base_year
existed (migration 078 left them at 0) fall back to media_items.year. This
sits beside fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203's rule that the candidate's credits contain the tagged credits
and its files are gone from disk.
Both writers decide under the item's row lock, so a rescan running during a match
cannot write tag values over it.
Unmatched list: audiobooks keep an empty status. Setting 'unmatched' there would
make the scanner re-probe the book on every scan, let orphan cleanup delete it as
provisional, and send it to the movie and series matcher. The list instead adds
audiobooks that are not matched by that predicate and whose enrichment outcome is no_match or failed (fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204: providers kept failing), or that were enriched before audiobook_enrichment_state existed. No backfill is needed.
Books in a library with no provider chain, or not yet tried, are not listed.
docs/architecture/audiobook-metadata.md records the ownership rule; docs/libraries-api.md and the status field description mention audiobooks.
Books already mixed by the old rescan are not repaired automatically. An admin can
run Refresh Metadata or Match Item on the book to restore the provider's values.
Image caching (found while checking the poster path): the image-cache job rewrites
a remote poster_path to the cached copy only while metadata.cache_images is on.
If enqueueing the job fails, the error is logged and the remote URL stays. This PR
does not change that.
Validation
Go: build, gofmt, go mod tidy -diff, go vet ./..., make lint-changed, make lint-router-recovery: pass.
Tests on the rebased head, against a freshly migrated PostgreSQL 17 + pgvector database: the internal/scanner, internal/audiobooks, internal/catalog package tests and this PR's DB tests pass, as do fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203's and fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204's audiobook contract tests (rename, second copy, enrichment retry state, sweep rate limit). Before the rebase, make test-go passed except two real-ffmpeg tests that fail the same way on main with this machine's ffmpeg, and make test-db-contracts passed except three internal/recommendations tests that pass when run on their own on this branch and on main (backup tests skipped: no pg_dump here).
New DB tests: a matched book (by provider ID, by an ASIN-only success, or by Match Item) keeps its year, genres and credits through a rescan, while an unmatched or failed one takes its tags; a renamed folder of a matched book keeps its item, including legacy files without base_year; a match keeps the tag narrator and the local cover and fills a missing cover; the unmatched list includes no-match and failed audiobooks and drops them once matched.
Contracts and hygiene on the rebased head: make lint-changed, verify-size-ratchet, verify-apiv2-openapi, verify-apiv2-web-types, verify-apiv2-contract (0 changes), verify-apiv2-fixtures, verify-route-inventory, verify-local-paths: pass. Before the rebase also TestCommittedArtifactMatchesRouter, verify-case-collisions, verify-bidi, verify-migrations and web format:check. Web lint, build and make test-web were not run; the only web change is a regenerated doc comment in schema.ts.
Live, after the rebase: an isolated sandbox with the Audiobook Metadata plugin 0.1.7 and seven synthetic books (six real titles, one unmatchable), run on main (c7f2c0a) and then on this branch, each from new item rows. Each run: scan, let enrichment match, touch every file, rescan.
Year and credits after touch + rescan (same books, provider matched first):
Book
Provider value
main after rescan
This branch after rescan
Dungeon Crawler Carl 2
2021
0
2021
Rebecca
2014
0
2014
Guards! Guards!
2007; Tony Robinson (N), introduction author
1989; Nigel Planer (N), intro author gone
unchanged
The Hunger Games
2018
2008
2018
The Martian
2020; Wil Wheaton (N)
2013; R. C. Bray (N)
unchanged
The Way of Kings has embedded art and two tagged narrators. On main the provider
matched an edition with no narrators, and the match deleted both narrators, replaced
the cover with the provider's remote URL and kept the embedded art's thumbhash. On
this branch the cover, its thumbhash and both narrators stay. On this run the branch
matched an edition that lists the same narrators, so the provider-without-narrators
case is covered by a DB test rather than the live comparison. Unmatched Items: on main it lists only a movie;
on this branch it also lists the unmatchable audiobook.
Surface and build: web detail page and Admin → Libraries, desktop; main at c7f2c0a, this branch at 5fe0bc9. Mobile web shows the same data through the same endpoints; no layout changed.
Risks
Behavior change for matched audiobooks: after a provider match, editing tags no
longer changes year, genres, studios or credits on rescan. Refresh Metadata, Match
Item or a manual edit is the way to change them. The user manual's audiobook page
needs a matching update.
The unmatched-items count and list run one extra EXISTS per audiobook row.
Rename detection still depends on the stored author and narrator matching the
tags, so a matched book whose provider spells them differently gets a new item
when its folder is renamed. On main this already happens until a file of the
book changes; recognising a moved folder independently of provider-owned fields
is a separate change.
No migration.
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 in T3 Code
Tool(s): Claude Code, GitHub CLI, Playwright (screenshots)
Model(s): claude-opus-5-5
Involvement: Fully AI-generated (not yet human verified)
Adversarial review: one independent review of the diff (Claude Code code-review skill, medium). It found two races between a rescan and a match, where a stale scanner write could overwrite provider values or credits; both writers now decide under the item's row lock. It also found a doc statement that contradicted the legacy-row behavior, now corrected. Remaining findings (a shared predicate in the claim query, a tag release date filling an empty one, an extra query per book, unit-only coverage of credits) were judged not to need changes.
Audiobook scanning now preserves provider-owned metadata after a provider match. Enrichment writes provider metadata and credits transactionally while retaining local cover data. The unmatched-items API now lists audiobooks without provider matches as unmatched, with updated API descriptions and database-backed tests.
Changes: Audiobook metadata ownership and unmatched listing
The scanner checks provider-match state before applying audiobook tags and credits. Matched books retain provider-owned values, while unmatched books continue to use tag metadata. Tests cover provider-ID matches, successful enrichment outcomes, and unmatched books.
Enrichment resolves provider people and writes metadata and supplied credit kinds within a transaction. Existing local covers and unrelated credit kinds are preserved.
The API includes audiobooks without provider matches in the unmatched list and reports their normalized status as unmatched. API descriptions, documentation, and database-contract test registration reflect the behavior.
sequenceDiagram
participant updateAudiobookMediaItemTx
participant audiobookProviderMatched
participant PostgreSQL
participant applyBookToMediaItem
updateAudiobookMediaItemTx->>PostgreSQL: Lock audiobook item row
updateAudiobookMediaItemTx->>audiobookProviderMatched: Check provider-match state
audiobookProviderMatched->>PostgreSQL: Query provider-match predicate
PostgreSQL-->>audiobookProviderMatched: Return match status
updateAudiobookMediaItemTx->>applyBookToMediaItem: Pass provider-match status
Loading
Suggested reviewers:rhainland, blurbery
Merge Risk: Moderate · up to 10b17
Audiobook copies at new paths can be catalogued as duplicates after a provider match whose year differs from the tag year. A match applied in the admin UI with only an ASIN may not be recognized as a match, so the book stays in the unmatched list and rescans can overwrite its provider metadata. Resolve or explicitly accept both before merging.
Security architecture risk: Minimal · up to 10b17
The inspected changes strengthen metadata ownership and match-write consistency while adding audiobooks to an existing admin-only list. No introduced security, failure-containment, or ownership regression was established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
observed — The background enrichment path selects audiobook records across library memberships, while each match write targets one content ID. The listing expansion exposes eligible audiobook catalog fields through the existing administrative endpoint.
Trust Boundaries and Controls
observed — The unmatched-list route retains its admin wrapper. The new audiobook branch remains inside the existing library-membership and ignored-item guards. Search remains bound as a SQL parameter; the new predicate and status expression use server-controlled SQL fragments.
observed — Provider-result persistence rechecks administrative field locks after provider calls. A crew lock suppresses credit writes, and any existing poster suppresses provider-poster replacement and subsequent poster queuing from that result.
Resilience and Maintainability Implications
inferred — The shared item-row lock serializes the inspected scanner and enrichment ownership decisions. Claim-token fencing prevents a replaced worker from committing a terminal match, and transaction failure rolls back credited match data together. Person records created before the transaction can remain unreferenced after failure, but do not themselves establish an item credit.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix(audiobooks): keep a provider match intact across rescans" matches the main change in the changeset. The scanner now preserves provider-matched year, genres, studios, and credits during …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description states the problem, approach, validation, evidence, and risks for PR #4220. It covers the audiobook scanner, enricher, unmatched-items list, and docs, which match the changeset. It is …
Full details: Title check
Explanation
The title "fix(audiobooks): keep a provider match intact across rescans" matches the main change in the changeset. The scanner now preserves provider-matched year, genres, studios, and credits during rescans, and the enricher and unmatched list changes support the same ownership model. The title is specific, concise, and follows a conventional commit style.
Full details: Description check
Explanation
The description states the problem, approach, validation, evidence, and risks for PR #4220. It covers the audiobook scanner, enricher, unmatched-items list, and docs, which match the changeset. It is specific and on topic.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Please add phone-width before-and-after captures of the audiobook detail page and Admin → Libraries → Unmatched Items, using the same data and identifying each build. These metadata and list changes are visible on mobile web too; unchanged layout does not make them desktop-only under the repository’s Evidence policy.
The reason will be displayed to describe this comment to others. Learn more.
Successful provider results without durable IDs lose match protection
Metadata without a durable non-ASIN ID is treated as unmatched by the scanner but excluded from the admin unmatched list because its outcome is success. Record and use an explicit successful-match marker, or require a durable provider identity before recording success.
Prompt for LLM
File internal/catalog/audiobook_match.go, lines 9-13:
Successful provider results without durable IDs lose match protection
A provider can return metadata without a durable non-ASIN ID, but the successful enrichment is then treated as unmatched by the scanner and excluded from the admin unmatched list because its outcome is `success`. Record and use an explicit successful-match marker, or require a durable provider identity before recording success.
The state can occur on main today. The enricher records success whenever a provider returns metadata, and it stores only the provider IDs that pass identity admission. When a provider's own ID is already owned by another item (a second copy of the same book in another library, for example), admission drops it, and the book is success with nothing but its asin row. The scanner then treated it as unmatched and let the tags overwrite year, genres and credits, while the unmatched list hid it because its outcome was success.
There is now one definition. catalog.AudiobookProviderMatchedWhere is true for a provider ID other than asinor an audiobook_enrichment_state outcome of success. The scanner's ownership check and the admin unmatched list both use it, so a book is either matched (provider owns the fields, not listed) or not matched (tags own the fields, listed after a no_match). I kept the stored IDs as they are rather than refusing success without a durable non-ASIN ID: that would throw away metadata a provider really returned.
How this meets #4214: its tagged-ASIN lookup admits whatever IDs the provider's record carries. When that record includes the provider's own ID, the book is matched through the ID. When admission leaves only the ASIN, the book is still matched through the success outcome. Either way it is "matched" here, whichever PR merges first, and neither PR needs to change for the other.
Tests: the scanner rescan test gains a case seeded with only an asin row and a success outcome; it fails on the previous predicate (year 0, tag credits) and passes now. The unmatched-list test checks that an ASIN-only success leaves the list.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. The shared predicate addresses the reported mismatch: an ASIN-only audiobook with a successful enrichment retains provider ownership and stays out of the unmatched list.
The two regression cases cover the scanner and list behavior. I haven’t independently verified the commit or run the tests.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Match duplicate candidates on the tag year, not the provider-owned… · audiobook_scan.go:64
internal/scanner/audiobook_scan.go:64 Major · Data Integrity & Integration · Heavy lift
Match duplicate candidates on the tag year, not the provider-owned mi.year.
applyBookToMediaItem keeps the provider year once a book is matched. A copy of that book under a new folder then calls findAudiobookDuplicate with the tag year as $3. When the two years differ, line 64 excludes the existing item. claimAudiobookIdentity then creates a second catalog item for the same recording.
Rescans at an unchanged path are not affected. They return the existing ID before this lookup runs.
Compare the candidate year against the tag-derived year instead. audiobook_scan.go:1380 stores that value as media_files.base_year. Before using it as the key, confirm that it holds the raw tag year for audiobooks. scanner.go:3408 also assigns BaseYear from group assignments.
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: c5a52c95-6125-43c0-af7d-33565bfff1c3
Commits
Reviewing files that changed from the base of the PR and between e444af6 and 10b17f4.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
Re the CodeRabbit outside-diff finding on the duplicate-candidate SQL (internal/scanner/audiobook_scan.go, audiobookDuplicateCandidateSQL): confirmed and fixed in 6919ab0.
The rule compared the parsed tag year with mi.year. With this PR mi.year belongs to the provider once a book is matched, so a renamed or moved folder of a matched book whose provider year differs from its tag got a new content ID and lost its progress. It now compares against media_files.base_year. For audiobooks, only upsertAudiobookPresentationTx writes that column, from book.Year (the parsed tag), and has done so since audiobook libraries were added; the UpdateIdentity writers are on the video scan path.
The change only touches the year line of the SQL. It sits beside #4203, which changes the Go side of the same function so the candidate's credits must contain the tagged credits; the credits comparison is untouched here.
New Postgres test TestAudiobookRenamedFolderFindsMatchedItemDB: a matched book with provider year 2008 and tag year 2005, folder renamed, keeps its content ID. It fails on the previous SQL (new content ID) and passes now.
The reason will be displayed to describe this comment to others. Learn more.
Renamed legacy audiobooks lose their identity when base year is unset
Migration 078 sets base_year to 0 for existing files, so a tagged book renamed before its next full rescan no longer matches its existing item even when media_items.year matches. Fall back to the previous year comparison for legacy files, or backfill their tag years before relying on base_year.
Prompt for LLM
File internal/scanner/audiobook_scan.go, lines 67-70:
Renamed legacy audiobooks lose their identity when base year is unset
Existing files receive `base_year = 0` when migration 078 adds the column, so a tagged book renamed before its next full rescan no longer matches its existing item even when `media_items.year` matches. Preserve the previous year comparison as a fallback for legacy files without a stored tag year, or backfill their years before relying on this predicate.
Migration 078 added media_files.base_year as NOT NULL DEFAULT 0, so audiobook files that existed then hold 0. An unchanged audiobook folder is skipped on rescan, so those rows keep 0 until the folder is rewritten. The candidate SQL now matches when any of the item's files has base_year equal to the tag year, or, when none of its files has a base_year set, when mi.year equals the tag year (the previous rule, for legacy rows only).
TestAudiobookRenamedFolderFindsMatchedItemDB now has two cases: a matched book whose provider year differs from the tag year, and a book whose files have base_year 0 with mi.year equal to the tag year. The legacy case fails on the previous commit and passes now.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming. The fallback addresses the legacy base_year = 0 case while preserving the stored tag-year comparison for newer records. The added regression case also verifies that the legacy scenario failed before the fix.
The reason will be displayed to describe this comment to others. Learn more.
Keep rename detection independent of provider-owned credits
When a provider spells an author or narrator differently from the tags (for example, Stephen King versus King, Stephen), this now permanently preserves only the provider spelling. However, audiobookDuplicateCandidateSQL still requires case-insensitive exact equality between those stored credits and the tag names. After a rescan followed by a folder rename, the root and file-path lookups miss, duplicate detection rejects the existing recording, and claimAudiobookIdentity allocates a new content ID, leaving listening progress attached to the old item. Previously, the rescan restored the tag credits used by that lookup. Preserve scanner identity facts separately or update duplicate detection to accommodate provider-owned credits, as this change already does for the year.
The reason will be displayed to describe this comment to others. Learn more.
Agreed that the gap exists. I'm not widening this PR for it, for three reasons.
This PR doesn't introduce it. On main a match already replaces the credits with the provider's, and they stay until a file of the book changes and the scanner rewrites them from tags. Rename detection runs before that rewrite, so a renamed but otherwise unchanged matched book already misses this lookup on main when the spellings differ. This PR makes that state last instead of being temporary.
The trigger is rarer than the year case. Years differ between tag and provider routinely, which is why the year comparison moved to the tag year stored on the files. Differently spelled names and a missing tagged narrator are much rarer. A provider with no narrators now leaves the tag narrator in place, because a match replaces only the credit kinds the provider supplies. fix(audiobooks): match the tagged volume, edition and narrator #4214 rejects a match whose narrators contradict the tags.
A rescan of a matched audiobook replaced the provider's year with the tag
year (or 0), replaced its credits with the tag credits, and merged tag
genres back in, while the provider's overview and cover stayed. A match
deleted a narrator read from tags when the provider had none, wrote
credits outside its transaction, and replaced the book's own cover with
the provider poster while keeping the old thumbhash.
Give each field one owner. Once a provider matched a book (it has a
provider ID other than the scanner's ASIN), the provider owns year,
genres, studios and credits, and the tags only fill what is empty. Tags
keep the title and series. A match replaces credits only for the kinds
the provider names, inside the match transaction, and fills a cover
only when the book has none. Both writers decide under the item's row
lock.
The admin unmatched-items list now includes audiobooks whose enrichment
found no provider match, derived from the enrichment state so no
backfill is needed and media_items.status stays empty for books.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A successful enrichment stores the provider IDs that survive identity
admission. When those are only the tagged ASIN, the scanner treated the
book as unmatched and let tags overwrite the provider's values, while
the unmatched list hid it as a success. Count the enrichment success
outcome as a match too, in the one predicate both use.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ched books
Match Item can apply only the ASIN. It writes status 'matched' through
the metadata pipeline but no enrichment outcome, so the book stayed in
the unmatched list and a rescan let tags overwrite the match. Count that
status in the matched predicate.
The duplicate check for a renamed or moved folder compared the tag year
with media_items.year, which a match now owns. Compare it with the tag
year stored on the files, so a matched book whose provider year differs
keeps its content ID and progress.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…base_year
Migration 078 left media_files.base_year at 0 for files that existed
then, and an unchanged audiobook folder is never rewritten. The renamed
folder check now compares the files' tag year when it is set and the
item year when none of the item's files has one.
Document that rename detection still needs the stored author and
narrator to match the tags.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tched
#4204 added the terminal enrichment outcome 'failed'. List those books
in the admin unmatched list beside 'no_match', so an admin can find and
match them; the matched predicate and the scanner already treat them as
unmatched. Describe split credits and the failure path in the ownership
doc.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 workingevidence-requiredNeeds before-and-after evidence before the Evidence check passesgoPull requests that update go codeimpact: usabilityCore flow broken or severely blockedpriority: P2Limited scope, workaround exists, or polishsize/XL500–999 added + deleted lines (all files); change volume, not priority.
1 participant
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
Related issue: N/A
Validation tasks: changes #1254 C2, #1255 C1 and C2 (none has a recorded pass yet)
Other clients: Apple N/A (shows the stored metadata; no client change); Android N/A (same); Roku N/A (same); Web included (the admin unmatched list already shows Match, and hides Ignore, for books)
A matched audiobook does not stay matched. Once a file in its folder changes, even
just its modification time, the next scan writes the tag year over the provider's
year (or 0 when the file has no year tag), replaces the provider's authors and
narrators with the tag credits, and merges tag genres back in. The provider's
overview and cover stay, so the book permanently describes two editions; a matched
book is never enriched again. The match itself also overreaches: a provider with no
narrators deletes the narrator read from the file, the credits are written after the
match commits (a failure there still leaves the book marked matched), and the
provider poster replaces the book's own folder or embedded cover while the old
thumbhash stays. Finally,
media_items.statusis empty for every audiobook, soAdmin → Libraries → Unmatched Items can never list a book that found no match.
This gives each field one owner and lists unmatched audiobooks.
Approach
asinthescanner reads from tags, when its last enrichment outcome is
success(anautomatic match that stored only the ASIN), or when its
statusismatched,which Match Item and Refresh Metadata write with the match whatever IDs it
carries. The scanner and the unmatched list use this one predicate.
and tagged credits (split per person since fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203) are only added for a kind
(author or narrator) the book has no credit for. An unmatched book keeps today's
behavior: its tagged authors and narrators replace the stored credits. Title and series stay
scanner-owned. Admin locks still win over both writers.
inside the match transaction. If any part of that write fails, the transaction
rolls back and the failure goes through fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204's failure recording, so the book
stays unmatched and is retried under its backoff. A provider poster only fills a missing cover, and a written poster
always carries its own thumbhash (empty for an uncached URL).
on the files (
media_files.base_year) instead ofmedia_items.year, which amatch now owns, so a matched book whose provider year differs from its tag
keeps its item and listening progress. Files indexed before
base_yearexisted (migration 078 left them at 0) fall back to
media_items.year. Thissits beside fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203's rule that the candidate's credits contain the tagged credits
and its files are gone from disk.
cannot write tag values over it.
status. Setting'unmatched'there wouldmake the scanner re-probe the book on every scan, let orphan cleanup delete it as
provisional, and send it to the movie and series matcher. The list instead adds
audiobooks that are not matched by that predicate and whose enrichment outcome is
no_matchorfailed(fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204: providers kept failing), or that were enriched beforeaudiobook_enrichment_stateexisted. No backfill is needed.Books in a library with no provider chain, or not yet tried, are not listed.
docs/architecture/audiobook-metadata.mdrecords the ownership rule;docs/libraries-api.mdand thestatusfield description mention audiobooks.Books already mixed by the old rescan are not repaired automatically. An admin can
run Refresh Metadata or Match Item on the book to restore the provider's values.
Image caching (found while checking the poster path): the image-cache job rewrites
a remote
poster_pathto the cached copy only whilemetadata.cache_imagesis on.If enqueueing the job fails, the error is logged and the remote URL stays. This PR
does not change that.
Validation
go mod tidy -diff,go vet ./...,make lint-changed,make lint-router-recovery: pass.internal/scanner,internal/audiobooks,internal/catalogpackage tests and this PR's DB tests pass, as do fix(scanner): read audiobook titles, part order, chapters, credits, and series correctly from tags #4203's and fix(audiobooks): back off on provider throttling and stop retrying failures forever #4204's audiobook contract tests (rename, second copy, enrichment retry state, sweep rate limit). Before the rebase,make test-gopassed except two real-ffmpeg tests that fail the same way onmainwith this machine's ffmpeg, andmake test-db-contractspassed except threeinternal/recommendationstests that pass when run on their own on this branch and onmain(backup tests skipped: nopg_dumphere).base_year; a match keeps the tag narrator and the local cover and fills a missing cover; the unmatched list includes no-match and failed audiobooks and drops them once matched.make lint-changed,verify-size-ratchet,verify-apiv2-openapi,verify-apiv2-web-types,verify-apiv2-contract(0 changes),verify-apiv2-fixtures,verify-route-inventory,verify-local-paths: pass. Before the rebase alsoTestCommittedArtifactMatchesRouter,verify-case-collisions,verify-bidi,verify-migrationsand webformat:check. Web lint, build andmake test-webwere not run; the only web change is a regenerated doc comment inschema.ts.main(c7f2c0a) and then on this branch, each from new item rows. Each run: scan, let enrichment match, touch every file, rescan.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-4220/
Year and credits after touch + rescan (same books, provider matched first):
mainafter rescanThe Way of Kings has embedded art and two tagged narrators. On
mainthe providermatched an edition with no narrators, and the match deleted both narrators, replaced
the cover with the provider's remote URL and kept the embedded art's thumbhash. On
this branch the cover, its thumbhash and both narrators stay. On this run the branch
matched an edition that lists the same narrators, so the provider-without-narrators
case is covered by a DB test rather than the live comparison. Unmatched Items: on
mainit lists only a movie;on this branch it also lists the unmatchable audiobook.
Surface and build: web detail page and Admin → Libraries, desktop;
mainat c7f2c0a, this branch at 5fe0bc9. Mobile web shows the same data through the same endpoints; no layout changed.Risks
longer changes year, genres, studios or credits on rescan. Refresh Metadata, Match
Item or a manual edit is the way to change them. The user manual's audiobook page
needs a matching update.
EXISTSper audiobook row.tags, so a matched book whose provider spells them differently gets a new item
when its folder is renamed. On
mainthis already happens until a file of thebook changes; recognising a moved folder independently of provider-owned fields
is a separate change.
Checklist
AI Disclosure
code-reviewskill, medium). It found two races between a rescan and a match, where a stale scanner write could overwrite provider values or credits; both writers now decide under the item's row lock. It also found a doc statement that contradicted the legacy-row behavior, now corrected. Remaining findings (a shared predicate in the claim query, a tag release date filling an empty one, an extra query per book, unit-only coverage of credits) were judged not to need changes.🤖 Generated with Claude Code