Repository navigation
fix(autoscan): drop titles Sonarr or Radarr deleted with their files - #3335
Conversation
Sonarr's SeriesDelete and Radarr's MovieDelete parsed as no-ops, so a series or movie deleted in arr with its files stayed in the library until the next scheduled scan on libraries without filesystem monitoring. With deletedFiles true, the webhook parser now emits a subtree change for the series or movie folder, marked Removed. Arr sends the notification before it deletes the folder, so webhook ingestion keeps the delivery queued and rechecks it every 10 seconds, without recording an error, until the folder is gone (ENOENT) while its parent is still a directory, and then scans it. Each check is a bounded stat, so a stalled mount keeps the delivery waiting. A folder not confirmed gone after an hour is scanned as it stands. deletedFiles false, or a delete that names no folder, stays a no-op. The webhook setup hint lists On Series Delete and On Movie Delete, and the custom-script examples in docs/scan-api.md no longer scan on these events. Closes #3266 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Parse and expose folder-delete events internal/autoscan/types.go, internal/autoscan/arrwebhook/parse.go, internal/autoscan/arrwebhook/parse_test.go, web/src/pages/admin/autoscan/webhookSetup.ts, docs/scan-api.md |
The parser marks qualifying series and movie subtree changes as removed. Setup instructions add the corresponding triggers. The custom-script documentation distinguishes file-delete events from folder-delete events. |
Wait for removal and enqueue the scan internal/autoscan/service.go, internal/autoscan/service_ingest_test.go, internal/autoscan/service_test.go, internal/api/handlers/autoscan_webhook.go, docs/architecture/missing-files.md |
Eligible deliveries retry while the folder remains present. The service confirms removal by checking that the path is absent and its parent exists, then scans the subtree. After one hour, it proceeds without confirmation. The result and debug log report when a delivery is awaiting removal. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- [bug] Series or movie deleted in Sonarr/Radarr with its files stays in the library until the removal grace ends #3060: The change waits for the deleted folder to disappear before reconciling its subtree, matching the issue’s whole-series and whole-movie deletion scenario.
Possibly related PRs
- Silo-Server/silo-server#3093: This change queues a vanished-subtree scan after confirming folder removal, relying on the scan behavior changed in PR
#3093. - Silo-Server/silo-server#3172: This change queues a vanished-folder scan and relies on the protected-root behavior changed in PR
#3172.
Suggested labels: go, javascript, documentation, needs-review, impact: usability, evidence-required
Suggested reviewers: rhainland
Merge Risk: 
Minimal · up to 205d3
-
The folder-delete scan change has no identified issue requiring a fix before merge. Normal checks remain appropriate.
Architecture risk: 
Medium · up to 205d3
-
The change affects 3 systems.
Changed systems:
internal,docs,webArchitecture concerns
No architecture-level concerns identified.Review details
-
Systems and components
- observed — internal (service) was modified; 7 changed files map to changed impact.
- observed — docs (service) was modified; 2 changed files map to changed impact.
- observed — web (ui) was modified; 1 changed file maps to changed impact.
Before / after behavior
- observed — Modified behavior in docs/scan-api.md: The Sonarr deletion case no longer includes
SeriesDelete; onlyEpisodeFileDeletereaches the existing deletion scan branch. - observed — Modified behavior in docs/scan-api.md: The Radarr deletion case no longer includes
MovieDelete; onlyMovieFileDeletereaches the existing deletion scan branch. - observed — Modified behavior in docs/scan-api.md: A note states that the custom scripts do not handle whole-series or whole-movie deletion because they run before the folder is removed; the built-in receiver waits for the folder to disappear before scanning.
- observed — Modified behavior in internal/api/handlers/autoscan_webhook.go: The webhook-ingest debug log now records
result.AwaitingRemoval.
Reliability and maintainability
- inferred — Risk-relevant change factors for internal: blast_radius_1; direct_dependents_1
-
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#3266requiresSeriesDeleteandMovieDeletewithdeletedFiles: trueto enqueue a subtree change for the series or movie folder. The parser emits aRemovedchange forseries.pathormovie.folderPath, withmovie.pathas fallback. Events with files kept, absentdeletedFiles, or no usable folder path remain no-ops. Ingestion waits for folder removal, then scans, and the change includes parser and ingestion tests.
Full details: Out of Scope Changes check
-
Explanation
The changes remain within issue
#3266. The removal wait, bounded filesystem checks, retry handling, tests, setup hint, architecture documentation, and scan API documentation support whole-folder delete webhook handling. The PR explicitly excludes the separate file-removal-grace change. No unrelated functional change is demonstrated.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 90.91% which is sufficient. 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 11 functions across 8 files.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
| if !change.Removed || removalConfirmed(ctx, change.SourcePath) { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Webhook retry worker starvation in internal/autoscan/service.go occurs when serial removalConfirmed calls each wait up to five seconds for distinct paths on a stalled NFS mount, occupying a 100-delivery batch for roughly 500 seconds, delaying unrelated deliveries, and exceeding the batch’s five-minute leases so another node can reclaim still-unprocessed deliveries. Bound batch-wide filesystem-check time or use bounded parallel processing with lease-aware claiming.
Prompt for LLM
File internal/autoscan/service.go:
Line 751 to 753:
Webhook retry worker starvation in internal/autoscan/service.go occurs when serial removalConfirmed calls each wait up to five seconds for distinct paths on a stalled NFS mount, occupying a 100-delivery batch for roughly 500 seconds, delaying unrelated deliveries, and exceeding the batch’s five-minute leases so another node can reclaim still-unprocessed deliveries. Bound batch-wide filesystem-check time or use bounded parallel processing with lease-aware claiming.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Fixed in 107224d. Each removal check is now bounded to 2 seconds, so a full 100-delivery batch on a stalled mount takes at most about 200 seconds, inside the 5-minute delivery lease. Deliveries still waiting after two minutes are rechecked once a minute, which also shrinks how many of them share a batch. Before this PR the same path had no bound at all: the vanished-file resolver calls an unbounded Lstat.
There was a problem hiding this comment.
Thanks—that addresses the lease-overrun scenario I flagged, provided the 2-second timeout covers the whole removal check per delivery, including the folder and parent checks. A 100-delivery batch would then spend roughly 200 seconds on those checks, leaving about 100 seconds of the five-minute lease for other processing.
Unrelated deliveries can still be delayed behind stalled checks, so the change mitigates rather than eliminates worker starvation. The once-per-minute rechecks after two minutes also reduce retry pressure.
The pre-existing unbounded Lstat is relevant context. Based on your description of 107224d5b, I would no longer treat the original ~500-second lease-overrun concern as outstanding; the remaining batch latency is a separate trade-off.
There was a problem hiding this comment.
It does: removalConfirmed sets one 2-second context per delivery, and both the folder stat and the parent stat use it, so the whole check for a delivery is bounded to 2 seconds.
There was a problem hiding this comment.
Thanks for confirming. The shared 2-second deadline covers both stats, satisfying the condition I raised. That bounds removal-check time for a 100-delivery batch to roughly 200 seconds, below the five-minute lease.
I consider the original lease-overrun finding addressed by 107224d5b. Unrelated deliveries may still wait behind those checks, but that is a remaining latency trade-off, not the original ~500-second overrun.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 20eaec4ac6
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| // Expected for every arr folder delete: check again shortly, without | ||
| // the failure backoff and without recording an error on the source. | ||
| result.AwaitingRemoval = true | ||
| if err := s.store.RetryWebhookDelivery(ctx, delivery.ID, delivery.LockedBy, removalRecheckDelay, ""); err != nil { |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Deduplicate pending folder-removal retries
An attacker who has an enabled autoscan webhook token and knows any existing in-library folder can repeatedly submit MovieDelete/SeriesDelete with deletedFiles:true. Every request creates a distinct durable row, and this branch reschedules each row every 10 seconds for up to an hour without deduplication or backoff. The default 60/min/IP limit can keep the 100-row/15-second retry worker occupied, delaying legitimate retries; distributed IPs can grow the queue faster. Coalesce waits by source and normalized path, cap them per source, and back off rechecks. The 256-bit token and per-IP limiter mitigate but do not stop a stolen-token sender.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Partly addressed in 107224d. A delivery still waiting after two minutes is now rechecked once a minute instead of every 10 seconds, so a repeated or never-completed delete costs the retry batch about a sixth as much over its hour. Checks stay in next_attempt_at order, so failed deliveries from other sources are delayed, not starved. I did not add per-path coalescing. The sender needs the 256-bit source token and is rate-limited per IP, and that same sender can already send import events that queue real scans, which costs more than a recheck. Coalescing would need a new repository query keyed on source and path. If a maintainer wants it, I can file it as a follow-up.
|
Minor change: #1232 C1 (Web admin, build 1804 · Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Arr can send a series or movie folder with a trailing separator, which path rewrites keep. filepath.Dir then returned the folder itself instead of its parent, so the removal was never confirmed and the delivery waited the full hour. Clean the path before checking it and its parent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Minor change: #1231 C1 (Server, build 1804 · Suggested fix: No diff — re-check C1 on the merged build with Validation tasks: changes #1231 C1; changes #1232 C1 Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
A delivery still waiting for a deleted folder after two minutes is rechecked once a minute instead of every 10 seconds, so slow recycle-bin copies and repeated folder-delete deliveries cost the shared retry batch little. Each filesystem check is bounded to 2 seconds, so a full batch on a stalled mount finishes well inside the delivery lease and another node does not reclaim rows still in progress. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
The folder-delete behavior is visible because library titles disappear only after Arr removes their folders. The Evidence section reports live before-and-after results, but does not identify a recording of this timing; please ensure the evidence page shows a recording of the title remaining while the folder exists and disappearing after removal. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
There was a problem hiding this comment.
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:
5a8f3a8c-7c50-4a64-ba8a-a4c6b79e98fc
Files selected for processing: 3-
docs/architecture/missing-files.mdinternal/autoscan/service.gointernal/autoscan/service_ingest_test.go
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 10 included reviews per hour; 1 remain after this review.
-
A timed-out stat keeps its goroutine blocked until the kernel returns, so distinct deleted paths on a stalled mount could pile up blocked goroutines. Removal checks now hold one of 16 slots until their stat actually returns; with none free, the check does not start and the path reads as unconfirmed, so the delivery keeps waiting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #3266
Related issue: #3060
Validation tasks: changes #1231 C1; changes #1232 C1
Deleting a whole series in Sonarr, or a movie in Radarr, with its files leaves the title in Silo's library until the next scheduled library scan. This affects libraries that rely on a Sonarr/Radarr Webhook autoscan source instead of filesystem monitoring, such as media on NFS. Tools that delete through the arrs, such as Maintainerr, hit it too. With this change, the title leaves the library shortly after arr finishes deleting the folder.
Sonarr's
SeriesDeleteand Radarr'sMovieDeleteparse as "valid delivery, nothing to do", so no scan is queued.Approach
When
deletedFilesistrue, the webhook parser now turns the delivery into a scan of the series folder (series.path) or movie folder (movie.folderPath, falling back tomovie.path). Since #3093, such a scan marks a vanished folder's files missing and removes the title from the library. WithdeletedFiles: falsethe delivery stays a no-op.Arr sends the notification before it deletes the folder: the webhook goes out from a synchronous handler, and the folder is deleted afterwards in an async one, as a recursive delete or a move to the recycle bin. Silo queues its scan while handling the request, so a scan queued straight away would usually find the files still there, and nothing would scan again afterwards. So the parser flags the change as
Removed, and webhook ingestion keeps the delivery in its durable queue until the folder is gone (ENOENT) while its parent is still a directory, the same evidence the scanner requires before it treats a vanished folder as deleted. Then it scans:The webhook setup hint in Admin > Autoscan > Sources lists On Series Delete (Sonarr) and On Movie Delete (Radarr) as optional triggers.
docs/architecture/missing-files.mdrecords the rule. The Sonarr and Radarr custom-script examples indocs/scan-api.mdno longer scan on these events, since a script runs before arr deletes the folder too.The files still wait out
scanner.file_removal_gracein the trash, like any other vanished file. Skipping that grace for arr deletes, which #3060 also asks for, is out of scope.Validation
go build,gofmt,go vet,make lint-changed,make lint-router-recovery,make test-go), the web lint, format, build and budget checks, and everyverify-*target pass.make test-webfailed 8 tests in 5 files this PR doesn't touch (global search, access groups, shuffle playback, ChatGPT connection, PGS subtitles) while sandbox builds ran on the same machine. All 104 tests in those files pass when rerun on their own.deletedFilesabsent, a movie withoutfolderPath, and a delete that names no folder. The ingest tests cover a delivery whose folder is still on disk (rechecked at an even interval, no error recorded, no scan), the scan once the folder is gone, the expired wait, a path outside every library, a folder whose parent is gone too (keeps waiting), and a deleted folder named with a trailing separator. They call code this change adds, so they can't build onmain. Instead, removing each part of the fix in turn makes the matching test fail for that reason. The parts removed were: the parser case, the wait, the fixed recheck interval, the expiry, the parent check, the no-folder no-op, and the path cleaning. Without the wait, the code behaves like a scan on arrival.MovieDeleteorSeriesDeletepayload and removes the folder only after Silo answers, the order arr uses.main: both deliveries got 202, no scan was queued, and both titles were still listed after their folders were gone.MovieDeletewith files kept changed nothing. No source recorded an error.Evidence
Before-and-after recordings of the Movies library's Library tab while a Radarr
MovieDeletearrives and the folder is removed 15 seconds later: onmainthe title stays listed, with this change it leaves once the folder is gone. The setup hint in a webhook source's edit dialog now lists On Series Delete for Sonarr and On Movie Delete for Radarr, at desktop and phone widths.Evidence: https://evidence.siloserver.org/r/silo-server/issue-3266/
Risks
removedflag and scans straight away. The title then stays until the scheduled scan, which is today's behavior.removedflag is stored only inside the queued delivery's JSON. Older rows lack it and read asfalse.Checklist
Follow-ups
AI Disclosure
ENOENTends it early, and rechecks use a fixed interval. Its fourth finding, that the last title under a library root stays protected, is the existing empty-root rule, listed under Risks. A multi-agent code review of the diff (claude-opus-5-5 and claude-sonnet-5-5 subagents) then found an unbounded stat on network mounts, a transient resolver error ending the wait, a delete naming no folder returning 400, and the custom-script docs describing the same race. All four were fixed, and the wait also requires the folder's parent to exist. The retry-count and mixed-version effects are listed under Risks. A background review of this PR (gpt-6.1-sol, xhigh, reviewed 20eaec4) found that a folder named with a trailing separator was never confirmed gone, so it waited the full hour. That is fixed in 259d7d3 with a test. Kody and the Codex security review then pointed out that stalled-mount checks could outlast a batch's delivery lease, and that repeated delete deliveries could crowd the retry batch. 107224d bounds each check to 2 seconds and spaces long waits to once a minute. Per-path coalescing was not added; the reply on that thread explains why. CodeRabbit then noted that a timed-out stat keeps its goroutine blocked, so distinct paths on a stalled mount could pile them up; 205d329 caps those checks at 16.🤖 Generated with Claude Code
Note
Handle Sonarr
SeriesDeleteand RadarrMovieDeleteevents with deleted filesarrwebhook.Parseturns these events into a RemovedChangewhendeletedFilesis true, using the series or movie folder as fallbackrewriteChangesnow copies eachChangeinstead of rebuilding it, so the newRemovedflag survives path rewriting; webhook setup pages gain optional Series/Movie Delete triggersautoscan.IngestResultgains a newAwaitingRemovalfield andChangegains an optionalRemovedfield (in types.go) — check that in-tree consumers of these types handle themMacroscope summarized 205d329.