Skip to content

feat(scheduler): clean up torrents and data for cancelled requests - #506

Closed
ZillaGit104 wants to merge 1 commit into
kikootwo:mainfrom
ZillaGit104:featPR-torrent-cleanup
Closed

ZillaGit104 wants to merge 1 commit into
kikootwo:mainfrom
ZillaGit104:featPR-torrent-cleanup

Conversation

@ZillaGit104

Copy link
Copy Markdown
Contributor

Linked issue

No linked issue. This change introduces automated cleanup of torrents and partial files for cancelled requests.

What changed

  • Expanded the cleanup_seeded_torrents background processor with a dedicated pass that sweeps and removes torrents and files belonging to requests with status: 'cancelled'.
  • Enforced strict safety checks: verifies RMAB ownership (addedByRmab) and ensures no other live (non-cancelled, non-failed) requests share the same torrent hash before triggering deletion.
  • Designed as an additive, resilient pass where client errors or timeouts log warnings without failing the primary seeding cleanup job.
  • Updated scheduler documentation in documentation/backend/services/scheduler.md.
  • Added comprehensive unit tests in tests/processors/cleanup-seeded-torrents.cancelled.test.ts.

Why

Previously, cancelling a request only changed its database status to status: 'cancelled', leaving the associated torrent and its data active indefinitely in the download client. This caused orphaned downloads and wasted disk space that required manual intervention.

How it was tested

  • Added a new unit test suite (tests/processors/cleanup-seeded-torrents.cancelled.test.ts) covering:
    • Successful deletion of torrents/files for cancelled requests (even with unlimited seeding).
    • Proper skipping of torrents not originally added by RMAB.
    • Torrent preservation when another live request still depends on the hash.
    • Graceful handling of already-missing torrents and unreachable download clients.
    • Correct filtering to ignore Usenet requests.
  • Ran npm test locally to verify that all existing and new unit tests pass successfully.

Checklist

  • Tests added or updated, and npm test passes

  • Docs in documentation/ updated in the compact format (bullets, tables, short code blocks), plus documentation/TABLEOFCONTENTS.md if a doc was added

  • No secrets, API keys, passwords or personal data in the code, logs or screenshots

@kikootwo

kikootwo commented Nov 3, 2026

Copy link
Copy Markdown
Owner

@ZillaGit104 this landed in #554 with you as co-author, and it's out now in v1.2.13. It keeps your cleanup of cancelled requests, with a few changes: only requests cancelled after the update are swept, a finished torrent seeds to its limits before it's removed, and API tokens cancel through POST /api/requests/:id/cancel. Thanks for this one.

@kikootwo kikootwo closed this Nov 3, 2026
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