fix: remove phantom offline books on 404#742
Merged
Conversation
When a Komga book file is replaced, the server issues a new UUID and the old UUID becomes an orphan. KMReader's policy-driven auto-download keeps attempting the old UUID, 404s, marks it as .failed, and then re-enqueues it on the next sweep — producing a stuck failed task that no in-app action can clear. Handle the 404 as a permanent "gone" signal instead of a transient failure: - Add `markBookUnavailable` to DatabaseOperator. Mirrors the effect of a server-delivered `deleted: true` on the book DTO: sets isUnavailable = true, resets download state, and re-syncs the series so counters are correct. - Add `isPermanentNotFound` helper to OfflineManager (APIError.notFound pattern-match, parallel to isNetworkRelatedError). - In the three download catch sites (background startup, background failure callback, foreground catch), treat 404 as permanent: call markBookUnavailable and return before falling through to the .failed path. - Pre-filter isUnavailable books in handlePolicyActions so they neither consume a slot in allowedUnreadIds nor get re-enqueued. This is what makes the auto-download limit silently promote the next real book when the phantom 404s. Closes the user-visible symptom (stuck phantom in Download Tasks). The root cause of phantom accumulation — the SSE BookDeleted event only refreshes the dashboard and doesn't delete the book from SwiftData — is left as a follow-up for the maintainer. Refs #737
Handle confirmed book 404s by deleting the stale local SwiftData record instead of mutating the server-mirrored deleted flag. Clean up offline files, refresh derived download status, and keep offline policy filtering for server-deleted books.
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.
Problem
Offline auto-downloads can keep retrying a stale Komga book ID after the server replaces or removes the original file and the old book endpoint starts returning 404. The retry loop needs to be broken without mixing a server-mirrored deleted state with a locally detected orphan.
Approach
Handle confirmed 404 responses by removing the stale local SwiftData book record instead of setting
isUnavailable. The removal path also clears offline files, updates Spotlight where supported, refreshes queue status, and re-syncs derived series/read-list download state.Scope
Validation
make formatmake buildCloses #737
Closes #738