Repository navigation
fix: a book removed from the library frees its request - #471
Merged
Merged
Conversation
…ck in Processing (#214) The library scan moved an available request back to downloaded whenever the book's library item disappeared, and nothing moved it on. Both reset sites (stale library record, orphaned audiobook link) now make it failed with "Removed from library" when the organized folder is gone too, or none is on record, so it can be requested again; it stays downloaded while the folder is still there. Shelf sync and watched lists never request such a book again, for any user; a manual request does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…library # Conflicts: # src/lib/constants/request-statuses.ts
The library scan now fails a removed book's request when its organized folder holds no audio (only cover.jpg, ebooks or other files), not only when the folder itself is gone. Audio directly in the folder or in a disc folder one level down keeps it downloaded; an unreadable folder still counts as present. The message no longer claims RMAB had files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #214
What changed
src/lib/processors/library-removal.tsresetRequestsAfterLibraryRemoval(), called from both places in the library scan (scan-plex.processor.ts) that unlink a book whose library item is gone: the stale library record cleanup and the orphaned audiobook cleanup. Those were the only two sites that movedavailableback todownloaded. The book'savailablerequests now become:failedwitherrorMessage"Removed from library. Request it again to download it." (REMOVED_FROM_LIBRARY_MESSAGE,src/lib/constants/request-statuses.ts) when no audio file is left in the organized folder (Audiobook.filePath), the folder no longer exists, or no folder is on record. Only cover.jpg, ebooks or other non-audio files left counts as no audio. The check reads the book's own folder and one level of child folders (disc folders), no deeper, using the audio extension list fromsrc/lib/utils/files-hash.ts(now exported asisAudioFilename()). The constant's doc comment says not to reword it: rows are matched by equality.downloaded, as before, while audio is still there. A folder that can't be read or listed (permission or I/O error, not "not found") counts as still there.createRequestForUserwithautomatic: true(shelf sync, watched authors and series) now returnsremoved_from_libraryand creates nothing while any user's request for the book is failed with that message (removedFromLibrarySkip()insrc/lib/services/auto-rerequest.ts). This runs before the Shelf sync re-creates failed requests every 6 hours when nothing was blocked #409 backoff, so neither "a release was blocked" nor a due retry brings the book back.documentation/backend/services/scheduler.md(plex_library_scan, Fixed Issues line),documentation/admin-features/release-blocklist.md(automatic re-request table row),documentation/TABLEOFCONTENTS.md.Why
When a delivered book was deleted from Audiobookshelf or Plex, the next full scan set its request back to
downloaded("files may still be there") and nothing ever moved it on. The book showed Processing forever, anddownloadedblocks every new request for it, from its owner and from anyone else. The only way out was deleting the request as an admin.With the audio gone there is nothing left for a scan to match, so the request fails with a reason the user can read, and it can be requested again. When the audio is still there, the next scan can match it once the library picks them up again, so that case keeps today's behavior.
A user who deletes a book usually meant to. Shelf sync and watched lists would otherwise pick a failed request up again (the owner's after the backoff, another user's straight away, since nothing blocks them anymore), so they skip the book until someone requests it by hand.
Other automatic paths checked, none of which can search or download for this request:
retry_missing_torrentsandmonitor_rss_feedsonly takeawaiting_search/awaiting_release;retry_failed_importsonly takesawaiting_import;find_missing_ebooksonly takesdownloaded/availableparents, so it also stops fetching ebooks for the removed book. The scan's own matching step still takesfailedrequests, so a book that comes back to the library becomesavailableagain with no download.Evidence
tests/processors/scan-plex.library-removal.test.tsruns the real scan with real temp folders: folder gone at the stale record site and at the orphan site becomesfailedwith the exact message; no folder on record becomesfailed; a folder left with onlycover.jpg, only an ebook and its cover, or audio two levels down becomesfailed; an m4b in the folder at either site staysdownloadedwith no error; audio in disc folders staysdownloaded;fs.statorfs.readdirrejecting withEACCESstaysdownloaded; a book still in the library is untouched; onlyavailablerequests move; nothing is searched, downloaded or notified.tests/services/request-creator-removed-from-library.test.tsruns the realcreateRequestForUseragainst a stand-in requests table: the owner's manual request replaces the failed request and queues a search; another user's manual request is created and searched; an automatic caller for the owner or another user returnsremoved_from_librarywith nothing created, searched or notified, also when a release was blocked during that attempt.tests/processors/scan-plex.processor.test.ts: the existing stale and orphan reset test now gives its books a temp folder holding an m4b, so it still checks thedownloadedpath.main'ssrc(08dc816) and this branch's 3 test files: 12 failed, 14 passed, all on an assertion (the scan writesdownloadedinstead offailed; the automatic caller getssuccess: true;readdiris never called). On this branch: 26/26 pass.src(513a971, folder existence only): 11 failed, 15 passed, all on an assertion. Folders left with onlycover.jpg, only an ebook, or audio too deep staydownloadedinstead offailed; the old message text no longer matches;readdiris never called. The m4b and disc folder cases pass there too, as they should.Checks
vitest relatedon the 7 changedsrcfiles plus the 3 test files): PASS, 97 files, 1234/1234tsc --noEmitclean; ESLint reports nothing new in the 10 touched code files compared withmain)src/libonlyRisk and rollback
failedfor a request whose book left the library while its folder holds no audio, is missing, or is not on record. Audio kept more than one folder level below the book folder is not seen, so such a book fails; RMAB itself writes audio straight into the book folder. A request that was matched to a book the user added to the library outside RMAB has no folder on record, so it now fails instead of sitting indownloaded.failedrequests and makes themavailable, with no download.downloadedbefore this release are not repaired. Their library item is already gone, so neither site sees them again. To clear one: delete the request in the admin UI, then request the book again.Release note
🤖 Generated with Claude Code