Skip to content

fix: stop rule execution when rule group is deleted mid-run#2439

Merged
enoch85 merged 5 commits into
Maintainerr:mainfrom
enoch85:fix/stop-rule-execution-on-delete
Mar 24, 2026
Merged

fix: stop rule execution when rule group is deleted mid-run#2439
enoch85 merged 5 commits into
Maintainerr:mainfrom
enoch85:fix/stop-rule-execution-on-delete

Conversation

@enoch85

@enoch85 enoch85 commented Feb 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #379 — Deleting a rule while its collection job is running caused continued execution against a deleted Plex collection (404 errors) and null-reference crashes.

Root Cause

Three bugs:

  1. onRuleGroupDeleted called removeFromQueue instead of stopProcessingRuleGroupremoveFromQueue only drops items from the pending queue; it does not abort the currently executing job. The existing AbortController infrastructure was never triggered on deletion.

  2. handleCollection else branch accessed collection.title when collection is null — this branch is specifically the "collection not found" path, so collection is always null here.

  3. handleCollection catch block accessed rulegroup.id / rulegroup.collection without null safety — if the catch fires due to a null rulegroup, it crashes again.

Changes

File Change
rule-executor-scheduler.service.ts removeFromQueuestopProcessingRuleGroup (aborts in-flight execution)
rule-executor.service.ts Optional chaining (rulegroup?.id, rulegroup?.collection?.title) and undefined instead of collection.title in else/catch blocks
rule-executor-scheduler.service.spec.ts Added stopProcessingRuleGroup to mock + test for deletion behavior

Testing

  • All 494 existing tests pass
  • New test verifies onRuleGroupDeleted calls stopProcessingRuleGroup (not just removeFromQueue)

Fixes three bugs related to issue Maintainerr#379:

1. onRuleGroupDeleted called removeFromQueue (pending-only) instead of
   stopProcessingRuleGroup (which also aborts in-flight execution via
   AbortController). Deleting a rule while it was actively executing
   never fired the abort signal.

2. handleCollection else branch accessed collection.title when
   collection is null — always crashes in that code path.

3. handleCollection catch block accessed rulegroup.id and
   rulegroup.collection without null safety — crashes if rulegroup
   was null.

Closes Maintainerr#379
@enoch85 enoch85 requested a review from ydkmlt84 as a code owner February 28, 2026 20:45
enoch85 added a commit that referenced this pull request Mar 1, 2026
PR #2438 - feat(rules): add rule Jellyfin favorited by including parents
- Added Jellyfin favorited rule that checks parent items (series/seasons)
- Includes unit tests for the new favorited-by-parents getter

PR #2439 - fix: stop rule execution when rule group is deleted mid-run
- Changed onRuleGroupDeleted to call stopProcessingRuleGroup instead of removeFromQueue
- Fires abort signal for in-flight execution, preventing null reference crashes
- Added unit test for delete-during-execution scenario

PR #2442 - fix(server): reject null/undefined in numeric rule comparisons
- Fixed null guard using proper nullish check (`firstVal != null`)
- Preserves v2.27.0 null→0 coercion for BIGGER/SMALLER to avoid upgrade breakage
- Logs warning when non-number values are encountered in numeric comparisons
- Updated regression tests for numeric comparisons including null/undefined cases
@enoch85 enoch85 self-assigned this Mar 10, 2026
@enoch85 enoch85 removed the request for review from ydkmlt84 March 24, 2026 18:10
@enoch85 enoch85 merged commit 0665e56 into Maintainerr:main Mar 24, 2026
9 checks passed
@enoch85 enoch85 deleted the fix/stop-rule-execution-on-delete branch March 24, 2026 18:49
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stop collection generation if rule was removed

1 participant