Skip to content

fix(automations): preserve cross-seeds for season pack and episode subpaths - #2308

Open
MaKTaiL wants to merge 1 commit into
autobrr:developfrom
MaKTaiL:fix/automations-crossseed-subpath-preservation
Open

fix(automations): preserve cross-seeds for season pack and episode subpaths#2308
MaKTaiL wants to merge 1 commit into
autobrr:developfrom
MaKTaiL:fix/automations-crossseed-subpath-preservation

Conversation

@MaKTaiL

@MaKTaiL MaKTaiL commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes an issue in the automations service where deleting a torrent using deleteWithFilesPreserveCrossSeeds ("Preserve cross-seeds") failed to detect cross-seed relationships between season pack directories and individual episode files.

Previously, detectCrossSeeds and findCrossSeedGroup only checked for exact string equality of ContentPath. When evaluating a season pack torrent (e.g. /downloads/Show.S01) against an episode file torrent inside it (e.g. /downloads/Show.S01/Show.S01E01.mkv), detectCrossSeeds returned false, causing the automation to fall back to DeleteModeWithFiles and delete the season pack directory and its files from disk.

Changes Included:

  • Added isPathSubpath helper to evaluate parent-child directory containment between content paths.
  • Added isCrossSeedMatch helper to identify cross-seeds sharing exact paths or non-ambiguous parent-child directory relationships.
  • Updated detectCrossSeeds and findCrossSeedGroup in internal/services/automations/service.go to support parent-child subpath matching while protecting ambiguous root paths (ContentPath == SavePath).

How has this been tested?

  • Added unit tests in internal/services/automations/service_test.go covering:
    • Season pack directory target vs episode subpath file.
    • Episode subpath file target vs season pack directory.
    • Ambiguous root download paths ensuring unrelated downloads in the root directory are not falsely matched.
  • Verified package tests (go test -count=1 ./internal/services/automations/...) pass with 0 errors.
  • Verified Go compilation (go build ./cmd/qui).

Checklist

  • My PR title follows the Conventional Commits format (it becomes the squashed commit message)
  • I have read CONTRIBUTING.md
  • I ran make precommit and the tests pass locally
  • If this changes the database schema, I have added migrations for both SQLite and PostgreSQL

AI disclosure

Assisted by Antigravity (Gemini 3.6 Flash) for root-cause analysis, subpath cross-seed logic implementation, and unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved cross-seed detection for exact content paths and clear parent-child directory relationships.
    • Excluded identical torrents and ambiguous or unrelated path matches.
    • Ensured discovered groups include the target torrent first and avoid duplicate entries.
  • Tests

    • Added coverage for season packs matching episode subpaths in either direction.
    • Added validation that root paths do not match unrelated files.

…bpaths

Expand detectCrossSeeds and findCrossSeedGroup to recognize parent-child
directory containment between season pack directories and episode files.

Previously, detectCrossSeeds checked only for exact string equality of
ContentPath. When deleting a season pack torrent with preserve-cross-seeds
mode, nested episode torrents were missed, causing shared data files to
be deleted from disk.
@itoqa

itoqa Bot commented Aug 12, 2026

Copy link
Copy Markdown

⚠️ Ito did not review this pull request because the PR author doesn't have an Ito seat.

An admin can assign one in Ito team settings.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dfa1471d-900b-431c-81b1-b2e9fe9a0567

📥 Commits

Reviewing files that changed from the base of the PR and between c3932cb and 7c66967.

📒 Files selected for processing (2)
  • internal/services/automations/service.go
  • internal/services/automations/service_test.go

Walkthrough

Cross-seed detection now supports exact and safe parent-child content-path matches. Group discovery filters candidates with these rules, includes the target, excludes unrelated paths, and deduplicates torrents by hash. Tests cover season-pack and episode subpath matching in both directions.

Changes

Cross-seed matching

Layer / File(s) Summary
Path matching rules
internal/services/automations/service.go, internal/services/automations/service_test.go
Normalized paths now support exact and non-ambiguous parent-child matches. Tests cover both target directions and reject ambiguous root-path matches.
Group discovery
internal/services/automations/service.go, internal/services/automations/service_test.go
findCrossSeedGroup filters candidates through the matching rules, includes the target first, excludes unrelated content, and deduplicates hashes. Tests cover season-pack and episode subpath grouping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: bugfix, cross-seed, area/backend

Suggested reviewers: s0up4200, nitrobass24

Poem

A rabbit checks each path with care,
Exact matches hop through air.
Parent paths join, false ones stay,
Hashes merge in neat array.
“Cross-seeds found!” the bunny sings,
While tests guard all matching things.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix for preserving cross-seeds between season packs and episode subpaths.
Description check ✅ Passed The description explains the problem, implementation, tests, checklist status, and AI usage; the unfilled issue reference is non-critical.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant