Skip to content

fix: don't grab past MAM's unsatisfied limit when its count lags; respect its download freeze - #65

Merged
mikaeltarquin merged 1 commit into
mainfrom
fix/mam-unsat-safeguards
Oct 5, 2026
Merged

mikaeltarquin merged 1 commit into
mainfrom
fix/mam-unsat-safeguards

Conversation

@mikaeltarquin

Copy link
Copy Markdown
Owner

Why

When mousehole failed ("Invalid session - ASN mismatch"), MAM rejected Deluge's announces ("Unrecognized host/PassKey"). MAM only counts a snatch once its tracker hears from the client, so its unsatisfied count sat ~20 short (130 vs. 150 actually in Deluge). Shelfmark only covered MAM's lag for snatches from the last 15 minutes, so it kept grabbing. When announces resumed, the account was at the limit, and the next grab froze MAM downloads for a day.

What changes

  • Cross-check against the torrent client. Each grab also counts the MAM torrents in the client that are still downloading or have seeded under 72 hours (plus snatches handed off since that read), and uses the higher of that and MAM's count. The header's "slots full" signal and the queue-time check use it too.
  • Hold MAM downloads while MAM rejects the client's announces. TrackerTorrent gains tracker_error, reported by Deluge (tracker_status), Transmission (trackerStats) and qBittorrent (/torrents/trackers). Only rejections of the client itself trigger the hold (passkey, unrecognized host, unauthorized). Timeouts and errors on a single torrent don't.
  • The check before each grab now holds when MAM can't be read. Before, it let the download through.
  • MAM's download freeze (new mam_freeze module, persisted to the config dir):
    • Detected from a refused .torrent reply ("Time Till Download Allowed: 1d 02:04:02"; a day if no time is given).
    • Can also be entered or cleared by hand in a new Download pause section of the account dialog (POST/DELETE /api/mam/freeze, admin only).
    • MAM downloads wait it out, and the top-bar button shows a red countdown to when it lifts.
  • Waiting downloads show the specific reason on Activity → Queued: freeze, rejected announces, MAM unreadable, or no free slot.
  • qBittorrent: torrents with no working tracker (empty tracker field) were dropped from the MAM list. They're now looked up individually, with each torrent's tracker cached and idle torrents skipped.
  • Docs, troubleshooting, changelog and the setting description are updated.

Testing

  • New tests/prowlarr/test_mam_unsat_safeguards.py: the incident replayed (MAM 130, client 150), parsing MAM's refusal text, how the freeze is stored and when it ends, holds for each reason, tracker errors from each client, and the qBittorrent cache.
  • Existing slot-wait tests were updated for grab_allowance, and there are route tests for the freeze endpoints.
  • pytest (excluding integration/e2e): 3758 passed. 7 failures also happen on a clean main in this container (entrypoint/hardlink permission tests that fail when run as root).
  • Ruff, BasedPyright (backend and tests) and Vulture are clean. Frontend: tsc, oxlint and oxfmt are clean, and 356 vitest tests pass.
  • Not checked visually in a browser.

🤖 Generated with Claude Code

https://claude.ai/code/session_0184DMrDNkAEmGzPntj3ziqB


Generated by Claude Code

…pect its download freeze

MAM only counts a snatch once its tracker hears from the torrent client. While it
rejected the client's announces (an unregistered IP after mousehole failed), its
count stayed ~20 short and Shelfmark grabbed up to the limit, freezing downloads
for a day.

- Each grab also counts the MAM torrents in the torrent client still downloading
  or short of 72 hours' seeding, and goes by the higher of that and MAM's count.
- MAM downloads wait while the client's MAM torrents show rejected announces
  ("Unrecognized host/PassKey"), and while MAM can't be read (the per-grab check
  no longer fails open).
- MAM's download freeze is read from a refused torrent download, or entered by
  hand in the account panel; MAM downloads wait it out, and the top bar counts
  down to it. Kept across restarts.
- Deluge, qBittorrent and Transmission report each MAM torrent's tracker error;
  qBittorrent's torrents with no working tracker are no longer missed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0184DMrDNkAEmGzPntj3ziqB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants