Skip to content

fix(libraryingest): keep audiobook parts out of variant finalisation - #2221

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/libraryingest-audiobook-variant-finalize
Oct 21, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
blurbery:fix/libraryingest-audiobook-variant-finalize

Conversation

@blurbery

@blurbery blurbery commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2220
Related issue: N/A
Validation tasks: changes #1254 C1 and C5 (neither has a recorded result yet)

Every scan of an audiobook library rewrote the part data of its multi-file books. Some books then came back from the Audiobookshelf-compatible API with their parts out of order, and every multi-file book was re-probed and rewritten on the next scan even when nothing on disk had changed. This change stops library ingest from running the filename-based variant pass on audiobook libraries.

The audiobook scanner stores each part with presentation_kind = 'multipart', a part index in natural path order and the part total, and it skips an unchanged book only while those values hold. After matching, ingest ran FinalizeVariantsByPathPrefix over every scanned root. That recomputes the columns from naming.ParseVariantHints, which has no audiobook kind, so it cleared them, or replaced them with multipart_movie indexes taken from Part N and Disc N in the file names. A book with an intro before its numbered parts then listed the intro last, and disc-numbered tracks lost their order within a disc.

Approach

libraryingest now skips the variant pass for audiobook libraries in library, subtree and file ingest. The check lives in the executor rather than in variant_finalize.go, so it doesn't overlap #2218, which rewrites that file. Ebook, manga and video libraries still get the pass: the ebook and manga scanners don't write these columns, and I didn't find anything that reads them there.

Libraries that already have rewritten rows repair themselves. The next scan sees those books as changed, rebuilds each one once with the scanner's values, and skips it on later scans. Multi-file books already failed the skip check once rewritten. A single-file book was rebuilt only when it was marked multipart, so the audiobook scanner's skip check now also rebuilds a single-file book that carries a presentation kind or an edition. The old pass could leave those behind for an {edition-…} tag or a lone Part N file name. No migration is needed.

Only the server changes. The Jellyfin-compatible API hides audiobook libraries, and the apps need nothing new: part order goes back to what the scanner already intended, and no API changes.

Validation

  • Unit test for library, subtree and file ingest across movie, series, mixed, ebook and audiobook libraries: fails on main for audiobooks, passes with the fix.
  • Database check that ingests real audio files with the real scanner and ffprobe against a migrated PostgreSQL 18: on main the parts are rewritten, two books come back out of order and every book is re-probed on the second ingest. With the fix all of that passes, including a library whose rows were rewritten by an earlier build, and a single-file book left with a stale edition and presentation kind. The test was removed from the branch because no CI list selects it and the Linux CI jobs have no ffmpeg; it was run locally against base and head.
  • go test ./internal/libraryingest/, go vet and golangci-lint --new-from-merge-base on the package: clean. I left the full lint and test matrix to CI.
  • Live run on a local dev build against a fresh database: on main the Audiobookshelf-compatible API listed two of the three test books out of order, and a scan of the unchanged library re-indexed all three. After I switched the same database to this branch, the first scan rebuilt the three books once and the next one skipped all three, with every book back in order.

Benchmarks

A scan of the unchanged three-book test library re-probed and rewrote 3 of 3 books on main (skipped=0) and 0 of 3 with this change (skipped=3). The test files are one-second clips, so wall time isn't meaningful at this size, and I haven't measured a large library. On a real library the saving is one ffprobe pass over every part of every multi-file book, on every scan.

Evidence

Surface: the Audiobookshelf-compatible API (GET /api/items/{id}?expanded=1, file names in media.tracks) and the scan log, on a local dev build with three test books. Before is main at bf63b3d, after is this branch at 98f414e on the same database.

Before After
Intro And Parts Part 1, Part 2, Intro Intro, Part 1, Part 2
Two Discs Disc 1 - Track 10, Disc 1 - Track 2, Disc 2 - Track 1 Disc 1 - Track 2, Disc 1 - Track 10, Disc 2 - Track 1
Numbered Tracks 01, 02, 03 01, 02, 03
Scan of the unchanged library processed=3 failed=0 skipped=0 processed=3 failed=0 skipped=3

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2221/

Risks

The first scan after upgrading rebuilds each multi-file audiobook once (one ffprobe pass per part), because its stored rows no longer match. Later scans skip unchanged books. Nothing changes for other library types.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted
  • Adversarial review: A second Claude reviewer went over the investigation and this change. It checked that the tests prove what the description claims (a control before the rows are rewritten, whole-row snapshots, a repair case), and its check of how each scan mode routes libraries found that podcast subtree and file scans go through the video pipeline. So I limited the guard to audiobooks instead of every library type with its own scanner.

AI-assisted with Claude Opus. I directed the task and designed the work.

Note

Fix audiobook ingest to skip variant finalisation

  • Adds finalizesVariants predicate in executor.go so Executor.ingest runs variant finalisation only for non-audiobook folder types. Audiobooks and video files differ in metadata ownership, which the new comment documents.
  • Tightens Scanner.audiobookFolderShouldSkip in audiobook_scan.go: a single-file audiobook is only safe to skip when it has no presentation metadata and no edition key. Otherwise it falls through to reconciliation to clean up stale metadata from earlier filename-based processing.
  • Adds table-driven test TestIngestSkipsVariantFinalizationForAudiobooks in executor_test.go covering library, subtree, and file ingest modes across movie, series, mixed, ebook, audiobook, and whitespace-padded audiobook folder types.
  • Behavioral Change: audiobook ingests no longer run variant finalisation, and unchanged audiobooks with leftover metadata or an edition key are now re-processed instead of skipped.

Macroscope summarized efa4ab1.

Library ingest ran the filename-based variant pass over audiobook
libraries too. It replaced the multipart presentation the audiobook
scanner writes, which changed part order for some books and made every
multi-file book fail the scanner's unchanged-book check, so each scan
re-probed and rewrote it. Skip the pass for audiobook libraries.
@silo-kody

silo-kody Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

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 settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-10T10:27:40.064024Z 98f414e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104 Quick104 added priority: P1 Core-path bug; painful workaround — next after P0 impact: playback Can't play, stalls, or wrong media labels Oct 10, 2026 — with Cursor
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ba85caaf-95f0-43f7-9ae3-001367ff4f4a
📥 Commits

Reviewing files that changed from the base of the PR and between 03486ed and efa4ab1.

📒 Files selected for processing: 1
  • internal/scanner/audiobook_scan.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d0571ce7-9960-417e-b88b-e469fb490a95
📥 Commits

Reviewing files that changed from the base of the PR and between 98f414e and 03486ed.

📒 Files selected for processing (1)
  • internal/libraryingest/executor.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

Ingest skips variant finalization for audiobook library types. Tests cover finalization calls across ingest scopes and audiobook multipart metadata, presentation order, and probe behavior across repeated and repaired ingests.

Changes: Audiobook Ingest

Layer / File(s) Summary
Conditional variant finalization
internal/libraryingest/executor.go, internal/libraryingest/executor_test.go, internal/libraryingest/executor_audiobook_db_test.go
Ingest skips variant finalization for audiobook library types and retains scope-specific errors when finalization fails. Tests cover the condition across ingest scopes and check audiobook multipart metadata, presentation order, and probe behavior across repeated and repaired ingests.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 03486

Audiobook ingest preserves scanner-owned part ordering across library, subtree, and file scans, while other library types retain variant finalization. No merge-blocking risk is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue [#2220] requires audiobook parts to retain scanner natural order and unchanged multi-file books to skip re-indexing. finalizesVariants now excludes audiobook libraries from `FinalizeVariantsBy…
Out of Scope Changes check Passed The production change is limited to the library-ingest guard. The added tests cover the reported audiobook regression, all ingest modes, and repair of rows rewritten by an earlier build. No unrelated …
Title check Passed The title clearly and concisely describes the main change: excluding audiobook parts from variant finalization.
Description check Passed The description directly explains the audiobook ordering and re-probing problem, the implementation, validation, risks, and expected behavior for other library types.
Full details: Linked Issues check

Explanation

Issue [#2220] requires audiobook parts to retain scanner natural order and unchanged multi-file books to skip re-indexing. finalizesVariants now excludes audiobook libraries from FinalizeVariantsByPathPrefix for library, subtree, and file ingest. The unit test covers these modes and library types. The database test verifies multipart kind, indexes, totals, presentation order, unchanged-ingest skips, and repair after earlier variant finalization.

Full details: Out of Scope Changes check

Explanation

The production change is limited to the library-ingest guard. The added tests cover the reported audiobook regression, all ingest modes, and repair of rows rewritten by an earlier build. No unrelated production behavior or API change is demonstrated.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…udiobook-variant-finalize

# Conflicts:
#	internal/libraryingest/executor.go

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 03486ed. Two findings. I'm fixing both in commits on this branch, so there's no need to change anything yourself.

Low: single-file audiobooks keep values from the old variant pass (internal/scanner/audiobook_scan.go, outside this diff)

The description says libraries with rewritten rows repair themselves. That holds for multi-file books, because their rewritten rows fail the skip check. A single-file book is rebuilt only when its presentation_kind is multipart. The old pass could leave multipart_movie or an edition on a single-file book, and those rows still pass the skip check. With the pass gone, nothing clears them.

Trigger: Book {edition-Extended}/Book - Part 1.mp3 scanned on an earlier build. Impact: after upgrading, the file keeps presentation_kind = multipart_movie and edition_key = extended until it changes on disk. The same book scanned fresh has neither. I reproduced this against a migrated PostgreSQL 18 with the real scanner. It's narrow: only {edition-…} tags or a lone Part N file name trigger the parser for audiobooks, and those books behave the same as on main.

Repair: for a single-file book, rebuild when presentation_kind or edition_key is set. The audiobook scanner writes neither for single-file books, so the rebuild runs once and later scans skip the book again.

Quick104 and others added 2 commits October 21, 2026 11:19
Earlier builds ran the filename variant pass over audiobook libraries and
could leave a presentation kind or an edition on a single-file book. The
skip check only rebuilt single-file books marked multipart, so those rows
kept the stale values after the pass stopped running there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
No CI list selects it, and the Linux jobs have no ffmpeg, so it would
skip in the dbpins runner. The unit test already guards the gate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104

Copy link
Copy Markdown
Contributor

Review summary: reviewed 03486ed, fixes pushed as efa4ab1

The fix is correct and sits at the right place. FinalizeVariantsByPathPrefix has one production caller, and the scanner routes audiobooks by the same librarykind.IsAudiobook check in library, subtree and file scans. Audiobooks never share a library with other kinds. The playback v3 multipart resume mapping and the clients' part stitching already expect the values the audiobook scanner writes. With this change those values survive ingest.

Addressed (commits on this branch)

  • d687a6e: a single-file audiobook that the old variant pass left with a presentation kind or an edition is now rebuilt once, so existing libraries fully repair themselves. Before, only multi-file books did.
  • efa4ab1: removed TestIngestKeepsAudiobookPartsDB. No CI list selects it, and the Linux CI jobs have no ffmpeg, which the dbpins runner would need. TestIngestSkipsVariantFinalizationForAudiobooks keeps guarding the gate.

The PR body now describes both.

Verification

  • TestIngestSkipsVariantFinalizationForAudiobooks fails on the base and passes at the head.
  • I ran the removed DB test against a disposable, migrated PostgreSQL 18 with the real scanner and ffprobe. On the base, the parts were cleared or reordered and every book was re-probed on the second ingest. At the head it passed, including the repair case.
  • A local check of the single-file case: before d687a6e, stale multipart_movie/extended values survived every ingest. After it, the next ingest cleared them.
  • internal/scanner and internal/libraryingest pass with a database attached. make lint-changed is clean.
  • A second reviewer from another provider found nothing new.

Remaining for maintainers: nothing blocking.

  • Optional: the guard could move into FinalizeVariantsByPathPrefix so a future caller can't skip it. There is no second caller today, so I left it in the executor.

Validated features: no passed case on the v1.0 board reaches this change. #1254 (Audiobooks, Server) has no recorded results, so its C1 and C5 are unaffected as validated cases. Audiobooks are a labelled beta.

User manual: unaffected. The audiobook libraries page already says files play in natural filename order, and this change makes the server do that.

Apple/Android: no follow-up needed. Both apps order audiobook parts by presentation_part_index under one presentation group, which is what the scanner writes. The Jellyfin-compatible API hides audiobook libraries.

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: a small correctness fix at the ingest boundary. It removes a full ffprobe pass over every multi-file book on every scan and adds no settings or API surface.
  • Readiness: the regression test fails on the base, both review findings are fixed, and the repair path was checked against a real database.

🤖 Reviewed with Claude Code (claude-opus-5-5); second opinion from Codex (gpt-6.1-sol).

@Quick104
Quick104 merged commit daa6a7f into Silo-Server:main Oct 21, 2026
18 checks passed
@blurbery
blurbery deleted the fix/libraryingest-audiobook-variant-finalize branch November 6, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: playback Can't play, stalls, or wrong media priority: P1 Core-path bug; painful workaround — next after P0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Audiobook scans rewrite multipart part order, so every multi-file book is rebuilt on each scan

2 participants