Repository navigation
fix: Deluge lookups and the shared-torrent guard ignore the letter case of a hash - #461
Merged
Merged
Conversation
normalizeTorrentId() now lower-cases a valid 40-hex ID as well as converting base32. A row with no client ID falls back to the indexer's infohash, which can be upper case; Deluge looks torrents up by exact lower-case key, so the seeding cleanup marked such a row removed and request delete left the torrent. torrentHashForms() keeps the stored form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
torrentHashForms() lists the stored hash as hex and base32 in both lower and upper case, so the guard sees another active request's row for the same torrent whatever case either row stores. It only adds matches, so cleanup and request delete only keep more torrents. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kikootwo
marked this pull request as ready for review
October 27, 2026 04:57
Merged
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 #460
What changed
normalizeTorrentId()(src/lib/integrations/torrent-ids.ts) lower-cases a valid 40-hex ID as well as converting base32. Every client lookup that goes through it (Deluge status, probe, pause, resume, delete and set-label; Transmissiontorrent-get; qBittorrent's lookups) now sends lower-case hex.torrentHashForms()now lists the stored hash, then hex and base32, each in lower and upper case. Its only caller isotherActiveRequestsUsingTorrent()(src/lib/utils/shared-torrent.ts), the check the seeding cleanup and request delete run before removing a torrent, so a lower-case row now sees another active request's upper-case row for the same torrent.documentation/phase3/download-clients.md(Torrent IDs: lookups, plus two Fixed Deluge lookups miss a torrent when its stored hash is upper case #460 lines).Why
When a download row has no
downloadClientId, the seeding cleanup and request delete fall back totorrentHash, which holds the indexer's infohash and is often upper case. Deluge'score.get_torrent_statuslooks torrents up by exact lower-case key, so the lookup would find nothing: the cleanup would mark the rowremovedand never clean the torrent, and request delete would leave it in Deluge. qBittorrent and Transmission already matched ignoring case.No write path, today or since Deluge support was added, stores a Deluge row without its client ID, and that ID is always saved in lower case. So no installs are known to be affected; this part is hardening for the fallback path.
The guard had a case gap of its own, on every client. It matched rows with a case-sensitive Prisma
in, and the list only held the stored form, lower-case hex and lower-case base32.torrentHashkeeps the indexer's infohash in whatever case it came in, so two requests for the same torrent can store it in different cases: one grabbed from an indexer that sent no infohash (lower-case v1), the other from one that sent it in upper case. Cleaning or deleting the first request then missed the second, and could remove the torrent and its files while the second request still used it.Evidence
tests/utils/shared-torrent.test.tsruns the real guard with afindManythat applies itswhereto fixture rows using a case-sensitivein, as PostgreSQL does. A request whose row is lower-case hex sees an active request whose row is the same hash in upper case, and the same for upper- and lower-case base32. Deleted requests, unselected rows, other torrents and the request itself are still left out.tests/integrations/torrent-client-ids.test.tsruns the realDelugeServiceagainst the exact-key fake: an upper-case stored hash (the fallback a row with no client ID uses) is found byprobeDownloadandgetDownloadand removed bydeleteDownload, with lower case sent on every call.tests/integrations/qbittorrent-ids.test.ts: upper-case hex comes back lower case fromnormalizeTorrentId, andtorrentHashForms()lists both cases. The guard's filter assertion intests/processors/qbittorrent-hybrid-ownership.test.tslists the new forms.main'storrent-ids.tsandshared-torrent.ts(0fd98ef) and this branch's four test files: 7 failed, 68 passed, all on an assertion (3 guard cases return no other request; the probe answers{ found: false }; the hash forms lack the upper-case entries). On this branch: 75/75 pass.Checks
vitest relatedontorrent-ids.tsandshared-torrent.ts, plus the new test file): PASS, 107 files, 1691/1691tsc --noEmitclean; ESLint reports no errors or warnings in the 6 touched files)src/libonlyRisk and rollback
torrentHashis upper-case hex and that aren't already markedremoved. The seeding cleanup and request delete can now find those torrents (non-hybrid). No write path is known to create such rows, so this should reach few or none.removedor recorded as taken over gets no client call; every other row goes throughresolveOwnership()before any remove. Rows without a client ID predate ownership tracking, so the legacy rule applies: the torrent counts as RMAB's only if the client added it between 15 minutes before and 5 minutes after RMAB's grab. Added 24 hours or more before means not RMAB's (recorded, kept); anything else is kept and checked again.removedstayremoved; they are not cleaned.Release note
🤖 Generated with Claude Code