Skip to content

fix(scanner): remove a deleted movie or series folder on the scan that follows - #3093

Merged
Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/scanner-vanished-scope-root
Oct 26, 2026
Merged

Quick104 merged 1 commit into
Silo-Server:mainfrom
Rhainland:fix/scanner-vanished-scope-root

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #3060
Validation tasks: none

Deleting a single movie or series folder leaves the title in the library, and Admin > Libraries shows a "Partial scan" warning. It happens on any library with realtime monitoring, and when an Autoscan source reports the deletion. A full library scan of the same state removes the title, so the two scans disagree about one deletion. With this change, the scan that follows the deletion removes the title and raises no warning.

The monitor and Autoscan's directory fallback queue a subtree scan scoped to the deleted folder itself. The scanner's walk recorded that folder's ENOENT as an unreadable path, and unreadable paths are protected from missing-file cleanup and set the partial_walk warning.

Approach

A subtree scan now treats its own folder as empty, not unreadable, when the folder is gone (ENOENT) and its parent is still a directory. The folder's files are marked missing and the title loses its library membership, as on a full library scan. The check is in the scanner's walk (scopeRootVanished), so every subtree caller gets it: the realtime monitor, Autoscan, the scan API and the admin split rescan. Changing the resolver to scope these scans to an existing parent instead would rescan a whole library root for one deleted folder.

Lost-mount protection otherwise stays as it was:

  • A folder whose parent is also gone stays protected, as does a folder below a dangling symlink, and any error other than ENOENT.
  • Full library scans don't take the new path, so unreachable and suspect-empty library roots and the empty-root cleanup confirmation are unchanged.
  • Unreadable entries deeper in a walk still protect what is under them.

The files still wait out scanner.file_removal_grace in the trash, so a folder that comes back within the grace restores its title. Ebook and audiobook subtree scans use their own walks and are not changed; books are beta.

This overlaps #3060. That issue asks that a series or movie deleted in Sonarr or Radarr leave the library, and also that a folder which vanished without arr's confirmation keep the lost-mount protection. This change departs from that second point: a vanished folder is protected only when its parent is gone too. Parsing SeriesDelete/MovieDelete and skipping the grace for arr deletions remain open in #3060.

Validation

  • Unit and Postgres tests in internal/scanner, internal/scantrigger, internal/librarymonitor and internal/autoscan pass. The new Postgres test (a deleted movie folder) fails on main and passes here, and is listed in scripts/ci/db-contracts.txt.
  • make test-db-contracts passes against a disposable migrated database.
  • go build, gofmt, go vet, make lint-changed, make lint-router-recovery, make verify-local-paths, make verify-size-ratchet, make verify-bidi and make verify-case-collisions pass.
  • make test-go passes except two internal/jellycompat Dolby Vision tests (TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute, TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped), which fail the same way on main on the same machine.
  • The web gate and the generated-contract checks did not run; no web, API or generated files changed.
  • End to end on a local single-node server with realtime monitoring and synthetic media: after a movie folder was deleted, main kept the title listed with the partial_walk warning; this branch removed it from the library with no warning.

Evidence

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

The captures show the Movies library page and Admin > Libraries on desktop and mobile web, after the same folder deletion on main (6de6d5e) and on this branch (469a521).

Risks

A folder that disappears below a library root while its parent stays (for example, a mount that is not a configured library root and whose mountpoint directory is removed) is now treated as deleted on the subtree scan, which matches what a full library scan already does. Its files wait out the removal grace before the trash sweep, and the title returns if they come back within it.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code
  • Tool(s): Claude Code, GitHub CLI, Codex CLI (review only)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: two rounds of independent diff review by claude-opus-5-5 and gpt-6.1-sol at medium effort. In round 1 both found that a folder below a dangling directory symlink was treated as deleted; that is fixed and covered by a test. Round 2 found no correctness or standards issues, and noted that book scans are not covered (stated above).

A subtree scan scoped to a movie or series folder that was deleted, while
its parent directory is still there, now walks the folder as empty instead
of recording an unreadable path. Its files are marked missing and the title
leaves the library, as a full library scan already did, and no partial_walk
warning is raised. A folder whose parent is gone too, one below a dangling
symlink, and non-ENOENT errors stay protected.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 26, 2026
@silo-kody

silo-kody Bot commented Oct 26, 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 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 46daf29d-90b5-47dc-83b0-47e1b24cff17
Commits

Reviewing files that changed from the base of the PR and between 6de6d5e and 469a521.

Files selected for processing: 4
  • docs/architecture/missing-files.md
  • 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; 3 remain after this review.

Walkthrough

The scanner now treats a missing folder below a reachable library root as an empty scope when the folder’s parent remains a directory. Tests cover other walk-failure cases and database reconciliation. Documentation describes the behavior.

Changes: Vanished subtree handling

Layer / File(s) Summary
Detect vanished scoped folders
internal/scanner/scanner.go
The scanner skips walking a scoped folder when it is below a configured library root, returns ENOENT, and its parent remains a directory. Other missing or inaccessible parents and scope errors remain walk failures.
Validate and document scan behavior
internal/scanner/dead_root_test.go, scripts/ci/db-contracts.txt, docs/architecture/missing-files.md
Tests cover vanished scopes, missing parents or roots, dangling symlinks, and scopes the scanner cannot stat. A database-backed test checks that scanning a deleted title folder marks its file missing, removes its library membership, and reports no scan warning.

Priority: Normal

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

Change: Bug fix

Possibly related issues

  • Silo-Server/silo-server#3060: The change reconciles a deleted title folder during a subtree scan when its parent remains present.
  • Silo-Server/silo-server#2947: The change handles a vanished scan target under an existing parent, but does not add the requested ignore rule.
  • Silo-Server/silo-server#3058: The change does not alter the file removal grace period or provide immediate removal.

Suggested labels: bug, go, impact: usability, size/L

Suggested reviewers: quick104, blurbery

Merge Risk: Moderate · up to 469a5

A subtree scan can treat a folder beneath an unreadable ancestor as deleted and remove its title from the library. Preserve walk-failure protection for that case before merging.

Security architecture risk: Low · up to 469a5

Existing access restrictions and library-root protections limit the change. However, a missing folder beneath a searchable but unreadable parent can now lose its catalog entries without an incomplete-scan warning. Removal grace limits permanent loss but does not preserve immediate visibility.

Retained concerns

  • Medium · reliability · inferred: The new shortcut runs before ancestor readability checks. For a missing child below a searchable but unreadable intermediate directory, Lstat can return ENOENT and parent Stat can succeed even though the existing ancestor ReadDir check would fail. The base protected that scope as incomplete; the head instead allows missing-file marking, metadata pruning and membership removal without a partial-walk warning. Configured-root probes do not repair this when the configured root itself remains readable and nonempty. This weakens the documented failure-containment invariant, rather than demonstrating an authorization bypass.
Security review details

Security Blast Radius

  • observed — The newly reachable cleanup affects cataloged files under the selected subtree and their associated library memberships. The existing optional trash sweep remains folder-wide, subject to removal grace and protected roots. The new branch does not delete source-media files.

Security Findings and Attack Paths

  • inferred — The supported concern is loss of catalog failure containment: an existing subtree dispatch, ENOENT and a searchable but unreadable ancestor can now authorize cleanup that previously remained protected. This is not evidence of unauthenticated access or privilege gain; the inspected HTTP scan route retains acting-admin middleware.

Trust Boundaries and Controls

  • observed — Existing request resolution cleans paths, matches configured library ownership and rejects disabled libraries. The missing-subtree resolver additionally rejects a scope equal to its matched library root. These controls remain separate from the new filesystem-absence decision and do not establish ancestor readability.

Resilience and Maintainability Implications

  • observed — Existing safeguards include a cancellation check before missing marking, skipping rows already marked missing, and conditional writes that leave renamed rows alone. These reduce interruption and repetition hazards but do not compensate for an incorrectly accepted empty inventory.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: removing a deleted movie or series folder during the following scan.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (2 skipped: 2 …
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 scanner changes, deleted-folder behavior, lost-mount protections, tests, validation results, and known scope limitations.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. (2 skipped: 2 unsupported.)

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

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

@macroscopeapp

macroscopeapp Bot commented Oct 26, 2026

Copy link
Copy Markdown

Evidence is missing for two visible effects:

  • internal/scanner/scanner.go changes Movies library browsing: a deleted movie or series title disappears after its subtree scan. Attach or publish before-and-after captures of the same Movies library screen on desktop and mobile web.
  • The same change removes the “Partial scan” warning from Admin > Libraries. Attach or publish before-and-after captures of that screen on desktop and mobile web.

The Evidence section says the captures are being uploaded but provides no attachments or evidence URL. Suggested fix: publish the captures and replace “link follows” with the evidence URL.

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

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish labels Oct 26, 2026
@coderabbitai coderabbitai Bot added impact: usability Core flow broken or severely blocked size/L 200–499 added + deleted lines (all files); change volume, not priority. labels Oct 26, 2026
Comment on lines +741 to 745
if scopeRootVanished(cleanRoot, libraryRoots) {
slog.InfoContext(ctx, "scanner: scope no longer exists under its library root; reconciling it as empty", "component", "scanner", "path", cleanRoot)
continue
}
rules, ignored, err := scanRootIgnoreRules(cleanRoot, libraryRoots)

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

Walk-failure protection in internal/scanner/scanner.go fails because the vanished-scope shortcut bypasses the ancestor readability check: an execute-only parent lets Lstat return ENOENT and Stat confirm a directory even though scanRootIgnoreRules would fail its ReadDir, allowing scanPaths to mark cataloged files missing and remove their library memberships under an unreadable nested ancestor. Move the shortcut after scanRootIgnoreRules succeeds and its ignored check.

Prompt for LLM

File internal/scanner/scanner.go:

Line 741 to 745:

Walk-failure protection in internal/scanner/scanner.go fails because the vanished-scope shortcut bypasses the ancestor readability check: an execute-only parent lets Lstat return ENOENT and Stat confirm a directory even though scanRootIgnoreRules would fail its ReadDir, allowing scanPaths to mark cataloged files missing and remove their library memberships under an unreadable nested ancestor. Move the shortcut after scanRootIgnoreRules succeeds and its ignored check.

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 Author

Choose a reason for hiding this comment

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

Not changing this. With an execute-only parent, lookup through it still works: Lstat on a folder that exists there succeeds, so scopeRootVanished returns false and the walk takes the existing path (the ignore-ancestor read fails and the scope stays protected). ENOENT comes back only when the folder is really gone, and then nothing can be hidden under it. The unreadable parent only stops the scan from reading ignore files, and an ignored scope and a missing one both end up with no files under them. A parent without search permission makes Lstat return EACCES, which stays a walk failure.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right—the suggestion conflated directory readability with path lookup permission.

With search (x) permission on the parent:

  • An existing scope remains discoverable by Lstat, so the shortcut does not apply. The existing ignore-ancestor check can fail and protect the scope.
  • A genuinely missing scope produces ENOENT. Given the parent-directory and dangling-symlink checks described, failure to read the parent's ignore files does not establish that files are hidden beneath that missing scope.

Without search permission, lookup returns EACCES, which does not qualify for the shortcut and remains protected.

Moving the shortcut after scanRootIgnoreRules would therefore preserve a missing scope because its parent's ignore files cannot be read—not fix the hidden-files scenario my comment claimed.

I retract the suggestion. The execute-only-parent case does not substantiate the reported bug or its critical severity.

if _, err := os.Lstat(scope); !errors.Is(err, fs.ErrNotExist) {
return false
}
parent, err := os.Stat(filepath.Dir(scope))

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 Kody Rules high

Incorrect parent-path handling in internal/scanner/scanner.go passes the encoded spelling directly to os.Stat, which can inspect the wrong directory or fail despite the actual parent's existence, making deletion reconciliation inconsistent with the filesystem. Decode filepath.Dir(scope) with fspath.Decode before passing it to os.Stat, and add the filesystem-path package import.

Also found in:

  • internal/scanner/scanner.go:776-776

Kody rule violation: Respect encoded filesystem paths at every Go boundary

parent, err := os.Stat(fspath.Decode(filepath.Dir(scope)))
Prompt for LLM

File internal/scanner/scanner.go:

Line 779:

Incorrect parent-path handling in internal/scanner/scanner.go passes the encoded spelling directly to os.Stat, which can inspect the wrong directory or fail despite the actual parent's existence, making deletion reconciliation inconsistent with the filesystem. Decode filepath.Dir(scope) with fspath.Decode before passing it to os.Stat, and add the filesystem-path package import.

**Also found in:**
- `internal/scanner/scanner.go:776-776`

Suggested Code:

	parent, err := os.Stat(fspath.Decode(filepath.Dir(scope)))

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 Author

Choose a reason for hiding this comment

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

Not applicable here: this repository has no fspath package, and the scanner passes walk roots and paths to os.Lstat, os.ReadDir and os.Stat as they are, as walkLogicalTree does just above. filepath.Dir(scope) is the same kind of path as scope.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right—this suggestion is a false positive. I incorrectly assumed an encoded-path abstraction and a fspath package that this repository does not have.

filepath.Dir(scope) preserves the native filesystem-path representation used by scope and the surrounding scanner code. Passing it directly to os.Stat is consistent with that handling; no decoding or additional import is needed.

The suggested change should be disregarded.

@Rhainland

Copy link
Copy Markdown
Contributor Author

The evidence was published right after this check ran, and the Evidence section now links it: desktop and mobile web captures of the Movies library page and Admin > Libraries, on main and on this branch, after the same folder deletion.

@macroscopeapp

macroscopeapp Bot commented Oct 26, 2026

Copy link
Copy Markdown

Both cases named on the Validation tasks: line (#1250 C1 and #1231 C1) are marked Not run; the legacy Movies — Server task #197 has no numbered cases or ## Results table. There are no recorded results for this change to invalidate or unblock. Please correct the line to:

Validation tasks: none

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

Posted via Macroscope — v1 validation impact

@silo-triage silo-triage Bot removed the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 26, 2026
@Rhainland

Copy link
Copy Markdown
Contributor Author

On the "searchable but unreadable parent" concern in CodeRabbit's merge-risk summary: it is the same point Kody raised, answered in #3093 (comment). With search permission on the parent, Lstat still finds a folder that exists, so that scope stays protected as before. ENOENT means the folder itself is gone, so no cataloged file under it can still be on disk. The unreadable parent only keeps the scan from reading ignore files, which does not change the result for a scope with nothing in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked needs-review Needs maintainer review to resolve uncertain classification, scope, or changed evidence. priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants