Skip to content

fix(scanner): remove a deleted audiobook folder on the monitor scan - #3172

Merged
Quick104 merged 10 commits into
Silo-Server:mainfrom
Rhainland:fix/1253-audiobook-vanished-folder
Nov 2, 2026
Merged

Quick104 merged 10 commits into
Silo-Server:mainfrom
Rhainland:fix/1253-audiobook-vanished-folder

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1253
Validation tasks: changes #1254 C1; changes #1255 C3; changes #1250 C1; changes #1251 C3; changes #197 scan/rescan criterion (scoped scans of folders with non-UTF-8 names)

With real-time monitoring on, deleting a book's folder doesn't remove the book. The monitor triggers a scan scoped to that folder, and the audiobook scan treated the missing folder as unreadable ("walk incomplete; unreadable paths protected from missing-file reconciliation"). So the book, now unplayable, stayed in the library until the next full scan. Movie and series scans already handle this.

Approach

When a scoped audiobook root no longer exists but its parent is a readable directory inside the library, the scan treats it as an empty scope and reconciles its files. It reuses scopeRootVanished, the check movie and series scans use. A missing library root, a missing parent above the book, and other stat errors keep their protection, so an unmounted drive still can't empty a library.

Before a scoped scan marks any file missing, it now applies the folder-wide sweep's protection for configured roots that are unreachable, or reachable but empty while they still have cataloged files. Without it, a configured root left as an empty mountpoint after its mount dropped would make a queued scoped scan of one of its books mark that book missing. The movie and series pipeline already did this. The protected roots are computed once and reused by the sweep.

The file removal grace (scanner.file_removal_grace, 24 hours by default) now holds an orphaned audiobook as it already held movies and series. With monitoring on, renaming a book folder to a name that sorts later scans the old path first. Without the hold, that scan deleted the book, and the new path's scan re-created it under a new ID, losing its progress, collections, metadata edits, and added date. Now the book leaves the library at once and the new path's scan matches the held item (by author, narrator, year, duration, and title, as on the base). A held book has no library membership, so the Audiobookshelf lists (including the in-progress shelf's hydration and the progress list), the book detail page's related rows, and work pages now require one for every viewer, through catalog.InSomeLibraryWhere from #3114. Reads by ID stay open, as #3114 keeps them. Ebooks and manga are still deleted at once.

scopeRootVanished now stats paths through fspath, which decodes them. Before, it called os.Lstat/os.Stat on the encoded path. For a folder whose name has non-UTF-8 bytes, the encoded name never exists on disk, so the check reported the folder as deleted. That affected the existing movie and series scoped scans too: a scoped scan of such a folder reconciled its files as missing. The fix covers both callers.

Validation

  • Review fix 7d2eaf3d3: the legacy /api/v1/catalog/query excludes audiobooks held without library membership. Existing library-scope tests and make lint-changed pass. A disposable SQL predicate check covers the held, linked and relinked states; no live HTTP or UI check was run for this follow-up.

  • New table test: deleted book folder (now reconciled), deleted author-and-book folders and a missing library root (both still protected). The first row failed before the fix. It now uses a deleted folder beneath a non-UTF-8 parent; temporarily replacing the decoded parent check with os.Stat makes that row fail, and restoring fspath.Stat makes it pass. A further row covers a dangling book symlink with a non-UTF-8 name, which must stay protected; it failed before the fspath change.

  • Database test for a deleted book under a configured root that still has entries (reconciled) and under an empty configured root (kept); the second case failed before the configured-root guard. make test-db-contracts: pass.

  • TestScanSubtreeAudiobookRenameKeepsBookDB: a renamed book folder, old path scanned first, keeps its content ID and added date. It failed at fbce18e4 with a new ID.

  • TestABSListsLeaveOutBooksInNoLibraryDB: a book in no library stays out of Audiobookshelf author, series, search, in-progress hydration, and progress reads for an unrestricted viewer. It failed at fbce18e4 and on the progress case at 4494dc7a. Both tests are in scripts/ci/db-contracts.txt.

  • With main merged in (0e0f1321): go test for internal/scanner/..., internal/audiobooks/..., internal/literaryworks/..., internal/catalog/..., and internal/api/handlers against Postgres 18, including fix(catalog): keep titles in no library out of admin listings #3114's no-library tests; make lint-changed: pass.

  • Full gate on an integration build with the other Audiobooks #1253 fixes: see the summary on Audiobooks #1253.

  • Runtime, twice: moving a book folder out of a monitored library removed the book within seconds (reconciled missing files ... items_deleted=1); moving it back re-added it. On the base build the book stayed until a full scan.

Evidence

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

The visible effect is that a deleted book leaves the library without waiting for a full scan. Server log for the monitor scan after deleting the folder:

Before (e6df1d8ed) After (this branch)
audiobook scan: walk incomplete; unreadable paths protected from missing-file reconciliation audiobook scan: reconciled missing files ... missing=1 memberships_removed=1 items_deleted=1

The runtime capture predates the rename fix. With it, the same scan logs items_deleted=0 (from the database test at 4494dc7a): the book still leaves the library at once, and the first reconcile after the grace deletes its item.

Risks

Full and scoped scans can overlap. Cleanup uses the earlier filesystem walk but reads current file rows, and missing-file updates have no scan-generation check. An older empty observation could therefore undo a concurrent recovery at the same path. This ordering concern is inferred from source and has not been reproduced against a database or live scanner; the underlying reconciliation loop predates this PR.

The book is removed on the monitor event instead of at the next full scan, with the same reconciliation a full scan runs. Storage-loss protection is unchanged.

A deleted book's item now stays, hidden, until the first reconcile after the grace. Like a held movie since #3114, it stays out of listings, but a read by ID still opens it for a viewer with unrestricted library access. A second rename before the trash sweep can still give the book a new ID, as on the base, because the duplicate match also counts the old, missing files' duration.

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 says there is none.

AI Disclosure

  • Legacy catalog query follow-up: Codex in T3 Code (gpt-6-astra), prompted by CodeRabbit.

  • Harness: Claude Code (T3 Code)

  • Tool(s): Claude Code, Codex CLI, GitHub CLI, Playwright, Docker, ffmpeg

  • Model(s): claude-opus-5-5; gpt-6.1-sol (review)

  • Involvement: Fully AI-generated, human verified

  • Adversarial review: Independent Claude Opus 5.5 and GPT 6.1 Sol reviews of the branch diff (correctness, repo standards, the bug as described). Neither found anything.

  • Maintainer review follow-up (Quick104): the rename fix in 4494dc7a, 71dca6e2, and 9706ce43 (plus merge 0e0f1321 of main) was written with Claude Code in T3 Code (claude-opus-5-5). Two GPT 6.1 Sol rounds (gpt-6.1-sol, Codex) reviewed it: one on the plan at fbce18e4, one on 4494dc7a. Their in-progress hydration and progress-limit findings are fixed. Native v2 unscoped reads were already covered on main by fix(catalog): keep titles in no library out of admin listings #3114, now merged into this branch. The legacy v1 JSON catalog query receives an audiobook membership guard in the subsequent review fix. Reads by ID stay open, so progress sync between the two rename scans keeps working. Repeated renames are left for maintainers.

Note

Treat deleted audiobook folders as empty scan scopes and hide library-less audiobooks

  • A vanished audiobook folder under a reachable library root is now scanned as an empty scope instead of a failed root, so its files get marked missing and reconciled in audiobook_scan.go
  • Audiobooks with no library membership are excluded from listings, search, detail queries, batch lookups, and progress lists via the access-filter builders in media_store.go and catalog/detail.go
  • Audiobook items now fall under the removal grace period, so a monitored folder rename keeps the content ID and first-seen date
  • Scanner sweep is refactored into protected-root helpers (sweepProtectedRoots, sweepMissingWithProtectedRoots) in scanner.go
  • Adds database contract tests for visibility, deleted-folder reconciliation, and rename identity in audiobook_test.go and dead_root_test.go
  • Behavioral Change: appendAudiobookAccessConditions in media_store.go and appendWorkItemsAccessFilters in repository.go now require library membership even when no allowed-library list is set, hiding previously visible library-less items

Macroscope summarized 6b7ce37.

When real-time monitoring scanned a book folder that had just been deleted,
the audiobook scan treated the missing folder as unreadable and protected its
files, so the book stayed in the library until the next full scan. Treat a
vanished folder under a readable parent as an empty scope, as movie and series
scans already do.
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Recent 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: 4aea903b-75bc-4ad8-9eb5-34545fabce1e
Commits

Reviewing files that changed from the base of the PR and between 7d2eaf3 and 10e81b9.

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

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

Walkthrough

Audiobook scans treat certain vanished book folders as empty scopes and calculate protected roots for missing-file reconciliation. Missing audiobooks are retained during the removal grace period. Audiobook-related queries filter out items without library membership when no allowed-library list is supplied.

Changes: Audiobook reconciliation and catalog visibility

Layer / File(s) Summary
Handle vanished audiobook scopes
internal/scanner/scanner.go, internal/scanner/audiobook_scan.go, internal/scanner/audiobook_test.go
Path checks identify vanished audiobook scopes under existing library roots. Scans treat those scopes as empty. Tests cover missing parents and library roots, and dangling symlinks.
Calculate protected roots and reconcile missing files
internal/scanner/scanner.go, internal/scanner/audiobook_scan.go, internal/scanner/dead_root_test.go, scripts/ci/db-contracts.txt
Audiobook cleanup calculates protected roots and passes them to missing-file reconciliation. Database tests cover vanished folders and monitored folder renames.
Retain missing audiobooks and filter unlinked items
internal/catalog/library_repo.go, internal/catalog/detail.go, internal/audiobooks/*, internal/literaryworks/repository.go, internal/api/handlers/catalog.go, docs/architecture/missing-files.md, scripts/ci/db-contracts.txt
The grace-period query retains missing audiobooks. Audiobook, catalog, literary-work, progress, and legacy catalog queries require library membership in the applicable unrestricted cases. A database test checks audiobook visibility and progress results.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: Minimal · previous review 10e81

The reviewed change adds focused regression coverage for vanished audiobook scopes, with no concrete merge-blocking risk identified.

Security architecture risk: Low · up to 10e81

The change adds storage-loss protections and preserves removed books for recovery while hiding them from listings. A remaining concern is whether overlapping full and scoped scans can let stale cleanup undo a recovery. No new unauthorized-access path was established.

Retained concerns

  • Medium · reliability · inferred: Vanished-scope cleanup now acts on an earlier empty filesystem observation while reading current database rows. A concurrent full scan may restore files at the same path before that cleanup marks them missing and removes library membership, potentially undoing recovery. Scope claims serialize overlapping scoped scans but explicitly allow full/scoped overlap. Moved-path guards and removal grace reduce consequences without establishing same-path recovery ordering. The overlap policy predates this PR; activating cleanup for vanished audiobook scopes newly exposes this transition. The interleaving is inferred, not runtime-reproduced.
Security review details

Security Blast Radius

  • observed — Missing-file marking selects files within the scanned folder and path scope, while the subsequent sweep reconciles that folder. Membership deletion is folder-scoped, and final item deletion requires absence of every surviving library membership. A surviving link in another library therefore constrains destructive cleanup.

Trust Boundaries and Controls

  • observed — The specifically routed public-entrypoint symbol is a Go test using temporary directories and direct scanner calls. It does not itself introduce remote reachability or authority. The exercised production control distinguishes a genuinely absent child scope from a missing library root, missing parent, or dangling child symlink.

Resilience and Maintainability Implications

  • observed — Existing concurrency controls provide partial containment: overlapping scoped ingests wait in arrival order, and missing-file updates reject rows moved to another path. Full and scoped scans are explicitly permitted to overlap, leaving the same-path recovery ordering concern unresolved.

Hardening Proposals

  • proposed — Consider coordinating overlapping full-scan recovery and scoped cleanup, or making missing-file mutation conditional on an observation generation, so an older empty observation cannot override a newer successful recovery.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary scanner change: removing a deleted audiobook folder during a monitor scan.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The pull request description directly explains the audiobook scanner fixes, protected-root handling, removal grace behavior, library visibility changes, rename preservation, and validation results cov…
Full details: Description check

Explanation

The pull request description directly explains the audiobook scanner fixes, protected-root handling, removal grace behavior, library visibility changes, rename preservation, and validation results covered by the changeset.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 12 functions across 11 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

@silo-kody

silo-kody Bot commented Oct 27, 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 ❌

@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Oct 27, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

The audiobook’s presence in library browsing changes: after its monitored folder is deleted, it disappears without waiting for a full scan. The before-and-after server logs do not show what a client displays; please add before-and-after captures of the same library screen or query and name the client surface and build or commit for each.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

Comment thread internal/scanner/audiobook_scan.go Resolved
@silo-triage silo-triage Bot added bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 27, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

#1254 C1 is currently Not run and has no linked failure or blocker, so this PR does not unblock a recorded case. The diff changes the removed-folder scenario in C1: a monitor-triggered scoped audiobook scan now reconciles a vanished book folder. Please replace the line with Validation tasks: changes #1254 C1; C1 still needs human validation after merge.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

scopeRootVanished received encoded walk roots but called os.Lstat and
os.Stat on them directly. For a folder or symlink whose name holds
non-UTF-8 bytes, the encoded name never exists on disk, so a scope that
is still present (or a dangling symlink that should stay protected)
looked deleted, and its cataloged files were reconciled as missing.
Use fspath.Lstat and fspath.Stat so both the video and the audiobook
callers check the real path.
@silo-triage silo-triage Bot added size/M 50–199 added + deleted lines (all files); change volume, not priority. and removed size/S 0–49 added + deleted lines (all files); change volume, not priority. labels Oct 28, 2026
@silo-kody

silo-kody Bot commented Oct 28, 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 ❌
⚠️ 2 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime

@Rhainland

Copy link
Copy Markdown
Contributor Author

Not adding client captures. The change is server-side: the book's catalog row is removed on the monitor event. Every client lists library items from that catalog, so each one stops showing the book. The server log shows the removal; on the base build the book stayed listed until a full scan.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


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: 978a995c-d45a-4f19-ac59-6953073ac087
Commits

Reviewing files that changed from the base of the PR and between 62b1a6e and ada8995.

Files selected for processing: 3
  • internal/scanner/audiobook_scan.go
  • internal/scanner/audiobook_test.go
  • internal/scanner/scanner.go

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

Comment thread internal/scanner/audiobook_scan.go Resolved

@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.

Note

AI-generated review posted on behalf of Quick104. Primary review: Codex in T3 Code (gpt-6.1-sol); independent review: Claude Opus 5.5 (claude-opus-5-5). Tools: GitHub CLI and Go.

Reviewed ada8995eb69f14f167defddfe632f571e0023695 against merge base 62b1a6e82408eb4be3409255583bf8b0a192a69f. One verified finding.

Comment thread internal/scanner/audiobook_scan.go Resolved
@Quick104

Quick104 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Re-reviewed at 9706ce43e0a6b37ec93e972c5049727507916522. Current main (81ae2ce1c) is merged in as 0e0f13216, which resolves a scripts/ci/db-contracts.txt conflict my first fix commit caused. The rename regression from the earlier review is fixed on this branch in 4494dc7a3, 71dca6e2d, and 9706ce43e, on top of the author's fbce18e4. A monitored rename of a tagged book folder now keeps the book's ID, progress, collections, metadata edits, and added date (thread).

Current head: 10e81b969ec8d9613a82b132c850cdab6666464f. CodeRabbit found the remaining legacy v1 JSON query path; the follow-up excludes held audiobooks there. Existing scope tests and changed-line lint pass, plus a disposable SQL predicate check. The full database/package results below belong to 9706ce43e; no live HTTP/UI check was added. CI on 10e81b969 is green after one retry of the known #3361 playback race.

Fit: 9/10 · Readiness: 9/10 — CI green; documented follow-ups remain

Removing a deleted book on the monitor event matches what movie and series libraries already do. The fix reuses the existing file removal grace and #3114's no-library rule instead of adding a setting or a new cleanup path. It was proven with database tests that failed on the author's head, not on a live deployment. The remaining limitations and investigations are described below.

What changed on the branch

Left for maintainers

  • Overlapping scans. Full and scoped scans can overlap. An older empty filesystem observation could mark current rows missing after a concurrent scan restores the same path. The underlying reconciliation loop predates this PR, which adds vanished child scopes as another trigger. This is inferred from source, not reproduced against a database or live scanner; it is also recorded in the PR Risks.

  • Repeated renames. Renaming a book twice before the trash sweep can still give it a new ID, because the duplicate match sums the duration of the old, missing files too. The merge base has the same limit; I confirmed it from the source only.

  • [bug] A full audiobook scan removes books under an empty library folder while warning that cleanup was skipped #3370 (full scan of a multi-folder audiobook library, reachable but empty folder) is still a separate follow-up to this PR.

Verification

  • TestScanSubtreeAudiobookRenameKeepsBookDB failed at fbce18e4 (new content ID) and passes now. TestABSListsLeaveOutBooksInNoLibraryDB failed at fbce18e4, and on its progress case at 4494dc7a3, and passes now. The author's two tests and fix(catalog): keep titles in no library out of admin listings #3114's no-library tests pass with main merged in.
  • The scanner, audiobooks, literaryworks, catalog, and API handler packages pass against a fresh Postgres 18 migrated from the merged tree. make lint-changed is clean.
  • No live deployment, device, or client check was run. The author's runtime capture predates the fix. The follow-up's test results are on a separate evidence page:

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3172-rename-hold/

Independent review

Two GPT-6.1 Sol rounds (Codex) reviewed the fix: one on the plan at fbce18e4, one on 4494dc7a3.

Earlier feedback

Unchanged from the previous summary. Kody's encoded-path finding is fixed in ada8995e. CodeRabbit withdrew its nested-mount finding. The re-probe-before-sweep point is answered in its thread. CodeRabbit's membership note describes intended behavior.

Validated features

The validation board couldn't be read (the CLI token lacks read:project), so this comes from the task issues' comments. #1254 C1 is recorded as failing on the base and passing with this PR, so this PR unblocks it. #1255 C3 still removes a deleted book on the monitor event; the book leaves the library at once, and its item is now deleted after the grace. Full scans keep their behavior apart from the same hold, so #1255 C1 is unaffected.

Suggested line: Validation tasks: unblocks #1254 C1; changes #1255 C3

User manual

Silo-Server/siloserver.org#331 tracks the stale "If old titles stay after a folder rename" section of the Autoscan guide.

Clients

Server-only. Audiobookshelf clients read the same endpoints and need no change. Jellyfin clients don't see audiobooks.

Note

AI-generated review posted on behalf of Quick104. Review and fix: Claude Code in T3 Code (claude-opus-5-5); independent rounds: Codex (gpt-6.1-sol). Tools: GitHub CLI, Go, Docker (a throwaway local Postgres).

Legacy query follow-up implemented with Codex in T3 Code (gpt-6-astra).

CodeRabbit’s encoded-parent coverage suggestion is addressed in 10e81b969: the existing deleted-folder row now uses a non-UTF-8 parent. It fails when the parent check is temporarily changed to os.Stat, and passes with fspath.Stat; changed-line lint is clean. Production code is unchanged by this commit. CI on 7d2eaf3d3 failed only on the known #3361 playback race (cleanup=0); CI on the resulting head is now green.

Final coordinator check: 10e81b969 is the current head, required CI passed, and GitHub reports it mergeable. The repeated-rename follow-up thread remains open; all fix threads are resolved. Fetched main 7e0765b42 adds only the unrelated #3388 admin leaderboard change and its test selection, so it needs no branch update here. No approval or merge performed.

🤖 Codex in T3 Code (gpt-6-astra).

…k scan marks files missing

A scoped scan of a deleted book folder treats the folder as an empty scope. When the configured library root has lost its mount and is left as an empty directory, the empty-cleanup decision only probes the scope, so the book's files were marked missing before the folder-wide sweep applied its configured-root protection. Compute the sweep's protected roots once, before marking, and skip them when a scoped scan marks files missing, as the movie and series pipeline does.
@silo-kody

silo-kody Bot commented Oct 28, 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 ❌

@coderabbitai coderabbitai Bot 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.

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)

Minor · Keep memberships for files under protected roots. · audiobook_scan.go:337-341

internal/scanner/audiobook_scan.go:337-341
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Keep memberships for files under protected roots.

A scoped audiobook scan of a deleted book under an empty configured root can reach reconcileMembershipsOnce. The fresh protected-root list prevents orphan-item deletion, but the membership DELETE ignores that list. The book therefore remains in the database but disappears from the library until its files return.

Apply the protected-prefix predicate to membership deletion as well as orphan-item deletion.

Suggested fix
@@
 	args := []any{folderID}
 	itemPredicate := ""
 	if contentIDs != nil {
 		args = append(args, contentIDs)
 		itemPredicate = " AND mil.content_id = ANY($2::text[])"
 	}
+	protectedPredicate := ""
+	if len(protectedPathPrefixes) > 0 {
+		clauses, protectedArgs := pathscope.CoverageClauses("protected_mf.file_path", protectedPathPrefixes, len(args)+1)
+		args = append(args, protectedArgs...)
+		protectedPredicate = `
+		  AND NOT EXISTS (
+			SELECT 1
+			FROM media_files protected_mf
+			WHERE protected_mf.media_folder_id = mil.media_folder_id
+			  AND protected_mf.content_id = mil.content_id
+			  AND (` + strings.Join(clauses, " OR ") + `)
+		  )`
+	}
 	tx, err := r.pool.Begin(ctx)
@@
-		WHERE mil.media_folder_id = $1`+itemPredicate+`
+		WHERE mil.media_folder_id = $1`+itemPredicate+protectedPredicate+`
Nitpick comments: 1
internal/scanner/audiobook_test.go: 1

744-789: Trivial · Functional Correctness · Quick win

Add coverage for a missing book below a legacy-byte parent.

The current non-UTF-8 case uses a dangling symlink. fspath.Lstat(scope) finds that symlink, so the test does not reach the parent-directory check. A regression to an undecoded parent Stat could therefore protect a deleted book under a legacy-byte parent while all current tests pass.

Suggested fix
 	if err := os.MkdirAll(author, 0o755); err != nil {
 		t.Fatal(err)
 	}
+	legacyAuthor := filepath.Join(library, "Author\xe5")
+	if err := os.MkdirAll(legacyAuthor, 0o755); err != nil {
+		t.Fatal(err)
+	}
+	legacyGoneBook := filepath.Join(legacyAuthor, "Gone Book")
 	missingLibrary := filepath.Join(t.TempDir(), "unmounted")
@@
 		{"deleted book folder", filepath.Join(author, "Gone Book"), library, false},
+		{"deleted book below legacy-byte parent", fspath.Encode(legacyGoneBook), library, false},
 		{"deleted author and book folders", filepath.Join(library, "Gone Author", "Gone Book"), library, true},

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: e386a90f-7889-4ece-af09-40f659f4836f
Commits

Reviewing files that changed from the base of the PR and between ada8995 and fbce18e.

Files selected for processing: 4
  • internal/scanner/audiobook_scan.go
  • internal/scanner/dead_root_test.go
  • internal/scanner/scanner.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; 2 remain after this review.

Comment thread internal/scanner/audiobook_scan.go Resolved
@macroscopeapp

macroscopeapp Bot commented Oct 28, 2026

Copy link
Copy Markdown

3 relevant case results examined; most severe classification: major change.

Task Case Surface Validated build Classification Reason
silo-server#1254 — Audiobooks C1 Server e6df1d8ed → integration 62b1a6e82 + #3165–#3173 major change The monitor-removal outcome changes; #3166 remains open, so re-test the full case after both changes land.
silo-server#1255 — Audiobooks C3 Web admin e6df1d8ed → integration 62b1a6e82 + #3165–#3173 unblocks The #3172 monitor-removal finding is addressed; re-test the removed-book admin scenario after merge.
silo-server#1251 — Series C3 Web admin 1555e5214 + #1954/#1955 no behavior change Recorded C3 used Admin “Scan Library”; that full-root scan does not exercise the changed vanished-descendant branch.

The task ## Results tables remain Not run; the 27 October comments are rehearsal records on an integration build preceding fbce18e, with human acceptance pending. #1250 C1 remains Not run and #197 has no Results record; keep them as first-run targets for the scoped non-UTF-8 scan behavior. Remove #1251 C3 from the line because its recorded full-library scan does not exercise the changed path.

Suggested line: Validation tasks: changes #1254 C1; unblocks #1255 C3; changes #1250 C1; changes #197 scan/rescan criterion (scoped scans of folders with non-UTF-8 names)

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@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.

Note

AI-generated review posted on behalf of Quick104. Review: Claude Code in T3 Code (claude-opus-5-5); independent round: Codex (gpt-6.1-sol). Tools: GitHub CLI, Go, Docker (a throwaway local Postgres).

Reviewed fbce18e4d0d3050f55d0a93dceb4a806424ba904 against merge base 62b1a6e82408eb4be3409255583bf8b0a192a69f. One verified finding. It needs a maintainer decision, so no commits were pushed.

Comment thread internal/scanner/audiobook_scan.go Resolved
With monitoring on, renaming a book folder to a name that sorts later scans
the old path first. That scan now reconciles the vanished folder, and the
orphaned audiobook was deleted at once because the removal grace held only
movies and series. The new path's scan then created the book under a new ID,
losing its progress, collections, metadata edits, and added date.

Hold audiobooks through the grace as well, so the new path's scan matches the
held item and keeps its ID. A held book has no library membership, so the
Audiobookshelf reads (listings and by-ID hydration), the book detail page's
related rows, and work pages now require one for every viewer, not only for
viewers with disabled libraries. Ebooks and manga are still deleted at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels Nov 1, 2026
@silo-kody

silo-kody Bot commented Nov 1, 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 ❌

JOIN media_files mf ON mf.content_id = mi.content_id
WHERE mi.content_id = cid
AND mi.type IN ('movie', 'series')
AND mi.type IN ('movie', 'series', 'audiobook')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug critical

Duplicate detection failure in internal/catalog/library_repo.go occurs because holding audiobook orphans retains historical file rows that findAudiobookDuplicate includes in its unconditional SUM(mf.duration), counting both old missing files and new live files after a successful folder rename. Renaming the book again within the removal grace makes its stored duration approximately twice the probed duration, causing the lookup to reject it and create a new content ID that loses the original progress, collection links, and added date; calculate duplicate duration from one recording's file set rather than every historical path.

Prompt for LLM

File internal/catalog/library_repo.go:

Line 727:

Duplicate detection failure in `internal/catalog/library_repo.go` occurs because holding audiobook orphans retains historical file rows that `findAudiobookDuplicate` includes in its unconditional `SUM(mf.duration)`, counting both old missing files and new live files after a successful folder rename. Renaming the book again within the removal grace makes its stored duration approximately twice the probed duration, causing the lookup to reject it and create a new content ID that loses the original progress, collection links, and added date; calculate duplicate duration from one recording's file set rather than every historical path.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

This is the repeated-rename limitation already recorded in the PR Risks section and review summary. audiobookDuplicateCandidateSQL sums every file row on both the original merge base 62b1a6e82 and current head 7d2eaf3d3; neither query excludes historical missing rows. The removal hold repairs the first old-path-first rename, but does not repair duplicate matching after multiple renames.

The source supports the duration concern. I have not reproduced A → B → C against a database or a running server, so this thread stays open as a follow-up; the earlier rename test proves only the first rename.

Checked with Codex in T3 Code (gpt-6-astra).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agreed. The unconditional duration sum predates this PR; the removal hold fixes the first old-path-first rename but leaves the repeated-rename limitation unresolved.

The source supports the concern, but A → B → C remains unverified at runtime or against a database. The existing rename test establishes only that the first rename preserves identity.

This should remain an open follow-up rather than be presented as a newly introduced, reproduced critical regression. A focused database test covering two renames within the grace period would establish the failure and validate a fix. Simply excluding missing rows may not suffice, since old-path-first matching needs those rows when no live files remain.

No code, issue, or thread status has been changed.

ListProgressForAudiobooks applied its limit before the by-ID hydration
dropped books in no library, so a few recently played books held through the
file removal grace could empty the in-progress shelf. Require a library
membership in the query itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/XL 500–999 added + deleted lines (all files); change volume, not priority. and removed size/L 200–499 added + deleted lines (all files); change volume, not priority. labels Nov 1, 2026
@silo-kody

silo-kody Bot commented Nov 1, 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 ❌

Quick104 and others added 2 commits November 1, 2026 23:31
…retention

# Conflicts:
#	scripts/ci/db-contracts.txt
Main's Silo-Server#3114 added catalog.InSomeLibraryWhere for listings that name no
library, and keeps reads by ID open for an unrestricted viewer. Use it for the
audiobook listing predicates, and drop the membership check from the single
GetAudiobookByID read, so progress sync for a book between a rename's two scans
isn't rejected. Batch hydration for the in-progress shelf and the progress list
still leave out books in no library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/XL 500–999 added + deleted lines (all files); change volume, not priority. labels Nov 1, 2026
@silo-kody

silo-kody Bot commented Nov 1, 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 ❌
⚠️ 4 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


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: ef46fb42-f35f-4400-a6e5-8a588f0f2233
Commits

Reviewing files that changed from the base of the PR and between fbce18e and 71dca6e.

Files selected for processing: 9
  • docs/architecture/missing-files.md
  • internal/audiobooks/abs_progress_store.go
  • internal/audiobooks/media_store.go
  • internal/audiobooks/media_store_db_test.go
  • internal/catalog/detail.go
  • internal/catalog/library_repo.go
  • internal/literaryworks/repository.go
  • internal/scanner/dead_root_test.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; 1 remain after this review.

Comment thread internal/catalog/library_repo.go Resolved
@silo-kody

silo-kody Bot commented Nov 1, 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 ❌

@coderabbitai coderabbitai Bot 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.

Nitpick comments: 1
internal/scanner/audiobook_test.go: 1

811-856: Trivial · Functional Correctness · Quick win

Cover a deleted scope below an encoded parent directory.

The current test does not exercise the decoded-parent behavior. Its deleted-folder case uses the UTF-8 parent Author, and its non-UTF-8 case uses an existing dangling symlink. A regression from fspath.Stat to os.Stat for the parent check could therefore pass this test.

Suggested fix
 	library := t.TempDir()
 	author := filepath.Join(library, "Author")
 	if err := os.MkdirAll(author, 0o755); err != nil {
 		t.Fatal(err)
 	}
+	legacyAuthor := filepath.Join(library, "A\xe5thor")
+	if err := os.MkdirAll(legacyAuthor, 0o755); err != nil {
+		t.Skipf("file system rejects non-UTF-8 names: %v", err)
+	}
 	missingLibrary := filepath.Join(t.TempDir(), "unmounted")
@@
 		{"deleted book folder", filepath.Join(author, "Gone Book"), library, false},
+		{"deleted book folder below encoded parent", fspath.Encode(filepath.Join(legacyAuthor, "Gone Book")), library, false},
 		{"deleted author and book folders", filepath.Join(library, "Gone Author", "Gone Book"), library, true},

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: 96b4c546-e2b4-4926-8227-b6be5010dce9
Commits

Reviewing files that changed from the base of the PR and between 71dca6e and 7d2eaf3.

Files selected for processing: 11
  • docs/architecture/missing-files.md
  • internal/api/handlers/catalog.go
  • internal/audiobooks/abs_progress_store.go
  • internal/audiobooks/media_store.go
  • internal/audiobooks/media_store_db_test.go
  • internal/catalog/detail.go
  • internal/literaryworks/repository.go
  • internal/scanner/audiobook_scan.go
  • internal/scanner/audiobook_test.go
  • internal/scanner/scanner.go
  • scripts/ci/db-contracts.txt
Files skipped from review as they are similar to previous changes: 1
  • docs/architecture/missing-files.md

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

@silo-kody

silo-kody Bot commented Nov 2, 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 ❌

@Quick104

Quick104 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit completed its review of 10e81b969 with no actionable inline findings and confirmed the legacy catalog membership fix. Kody also completed its review.

I checked the inferred scan-overlap concern in the summary. libraryingest.conflicts permits a library scan alongside a scoped scan. reconcileAudiobookMissingFiles uses the earlier walk’s seenPaths but reads current file rows, and MarkMissing checks ID/path without a scan generation. The same reconciliation loop and missing-file update exist on base 62b1a6e82; this PR also lets a vanished child scope reach them. A same-path recovery could therefore be overwritten in the proposed interleaving. I have not reproduced that interleaving against a database or live scanner, so it remains an open reliability concern, not a reproduced regression. It is now recorded in Risks.

CI on this head failed only in TestRelayMovePreservesMandatoryAudio/legacy=true with unconfirmed rehome status=502, cleanup=0 (#3361). I requested one failed-jobs retry of run 41364971006; its result is pending.

🤖 Codex (gpt-6-astra)

@Quick104
Quick104 merged commit 08d1f4d into Silo-Server:main Nov 2, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants