Skip to content

Fix queue rules upper bound to never allow 0#543

Merged
Flaminel merged 4 commits into
mainfrom
fix_queue_rule_bounds
Apr 3, 2026
Merged

Fix queue rules upper bound to never allow 0#543
Flaminel merged 4 commits into
mainfrom
fix_queue_rule_bounds

Conversation

@Flaminel

@Flaminel Flaminel commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Relates to #541

Summary by Sourcery

Enforce a minimum maximum-completion percentage greater than zero for queue cleaner rules and align backend validation, API constraints, and frontend validation/UI with this requirement.

Bug Fixes:

  • Prevent queue cleaner rules from being configured with a maximum completion percentage of 0% by tightening backend validation and API range constraints.
  • Fix frontend validation and error display so max completion percentage must be greater than 0 and errors are shown on the Max Completion inputs for stall and slow rules.

@Flaminel

Flaminel commented Apr 3, 2026

Copy link
Copy Markdown
Contributor Author

@sourcery-ai review

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Enforce non-zero maximum completion percentage validation

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Enforce maximum completion percentage greater than 0
• Add validation to prevent invalid 0 value in backend
• Update frontend error messages for completion range
• Correct error message text to reflect new bounds
Diagram
flowchart LR
  A["QueueRuleDto Range Constraint"] -->|"Update Range 0-100 to 1-100"| B["Backend Validation"]
  B -->|"Add zero check"| C["QueueRule.Validate()"]
  C -->|"Throw ValidationException"| D["Invalid Configuration Rejected"]
  E["Frontend Component"] -->|"Add max <= 0 check"| F["stallCompletionError & slowCompletionError"]
  F -->|"Display error message"| G["User Feedback"]
  H["HTML Template"] -->|"Move error binding to Max field"| I["Correct Error Display"]
Loading

Grey Divider

File Changes

1. code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs 🐞 Bug fix +1/-1

Update max completion percentage range constraint

• Changed MaxCompletionPercentage Range validation from [Range(0, 100, ...)] to `[Range(1, 100,
 ...)]`
• Updated error message to reflect new bounds: "between 1 and 100"

code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs


2. code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs 🐞 Bug fix +6/-1

Add zero validation and update error messages

• Added explicit validation check to reject MaxCompletionPercentage == 0
• Updated error message for upper bound check from "between 0 and 100" to "between 1 and 100"
• New validation throws ValidationException with message "Maximum completion percentage must be
 greater than 0"

code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs


3. code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts 🐞 Bug fix +2/-0

Add frontend validation for zero max percentage

• Added if (max <= 0) check in stallCompletionError computed property
• Added if (max <= 0) check in slowCompletionError computed property
• Both return error message "Max percentage must be greater than 0"

code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts


View more (1)
4. code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html 🐞 Bug fix +2/-2

Correct error binding placement for completion fields

• Moved [error]="stallCompletionError()" binding from Min Completion field to Max Completion field
• Moved [error]="slowCompletionError()" binding from Min Completion field to Max Completion field
• Ensures error messages display on the correct input field

code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Apr 3, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX Issues (0)

Grey Divider


Action required

1. MaxCompletionPercentage blocks 0%📎 Requirement gap ≡ Correctness
Description
The change set explicitly rejects MaxCompletionPercentage values of 0, which prevents
configuring a rule that matches exactly 0% completion. This violates the requirement to support
distinct StallRule behavior for exactly 0% vs >0% and the ability to configure 0–0% alongside
other ranges without skipped enforcement.
Code

code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[R51-58]

+        if (MaxCompletionPercentage == 0)
+        {
+            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be greater than 0");
+        }
+
     if (MaxCompletionPercentage > 100)
     {
-            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 0 and 100");
+            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 1 and 100");
Evidence
PR Compliance IDs 226565/226566 require configurations that can treat exactly 0% separately (e.g.,
0–0%). The PR adds backend/API/UI validation that rejects MaxCompletionPercentage == 0, and
existing matching semantics treat the max boundary as inclusive and MinCompletionPercentage == 0
as including 0%, meaning 0–0% is the straightforward way to target exactly 0%.

Support distinct StallRule behavior for exactly 0% progress versus >0% progress
Prevent overlapping StallRule progress ranges from causing skipped enforcement
code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[51-58]
code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs[23-24]
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts[236-242]
code/backend/Cleanuparr.Infrastructure.Tests/Features/QueueCleaner/QueueRuleMatchTests.cs[31-49]
code/backend/Cleanuparr.Infrastructure.Tests/Features/QueueCleaner/QueueRuleMatchTests.cs[149-165]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR disallows `MaxCompletionPercentage == 0` via DTO range validation, backend validation, and frontend error handling. This makes it impossible to configure a completion range that matches exactly `0%` (i.e., `0–0%`), which the compliance requirements expect to be configurable to support distinct behavior for `0%` vs `>0%` and to avoid skipped enforcement.
## Issue Context
Existing matching tests indicate max completion is treated as an inclusive boundary and that `MinCompletionPercentage == 0` includes `0%`, so a `0–0%` configuration is the natural way to target exactly `0%`.
## Fix Focus Areas
- code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs[20-24]
- code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[48-61]
- code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts[236-263]
- code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[261-268]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. QueueRuleTests expect max=0📘 Rule violation ☼ Reliability
Description
The PR changes QueueRule.Validate() to throw when MaxCompletionPercentage == 0, but the existing
unit tests still assert that MaxCompletionPercentage = 0 is valid and also expect the old
validation message for >100. This indicates the bug-fix behavior is not covered/updated by unit
tests as required.
Code

code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[R51-58]

+        if (MaxCompletionPercentage == 0)
+        {
+            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be greater than 0");
+        }
+
     if (MaxCompletionPercentage > 100)
     {
-            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 0 and 100");
+            throw new Cleanuparr.Domain.Exceptions.ValidationException("Maximum completion percentage must be between 1 and 100");
Evidence
PR Compliance ID 225607 requires unit tests to be added/updated for bug fixes. The PR introduces new
validation rejecting MaxCompletionPercentage == 0, while QueueRuleTests still includes
InlineData((ushort)0) in the 'valid max completion' test and expects the pre-change error message
for max values exceeding 100.

Rule 225607: Require unit tests for all new features and bug fixes
code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[51-58]
code/backend/Cleanuparr.Persistence.Tests/Models/Configuration/QueueCleaner/QueueRuleTests.cs[174-209]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`QueueRule.Validate()` now rejects `MaxCompletionPercentage == 0`, but `QueueRuleTests` still treats `0` as valid and expects an outdated error message for values `> 100`. This means the bug-fix behavior is not properly unit-tested and will likely break CI.
## Issue Context
The PR adds a new validation branch for `MaxCompletionPercentage == 0` and changes the `>100` exception message to reference `1..100`.
## Fix Focus Areas
- code/backend/Cleanuparr.Persistence.Tests/Models/Configuration/QueueCleaner/QueueRuleTests.cs[174-209]
- code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[48-61]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. UI still permits 0 max🐞 Bug ⚙ Maintainability
Description
The Max Completion % inputs still declare a minimum of 0, even though backend validation now
requires MaxCompletionPercentage in [1,100]. Users can enter 0 in the UI and will be blocked by
validation rather than prevented by the control constraint.
Code

code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[R265-268]

 <app-number-input label="Max Completion %" [(value)]="stallMaxCompletion" [min]="0" [max]="100" suffix="%"
   hint="Apply the rule to items with a completion percentage less than or equal to this value"
+      [error]="stallCompletionError()"
   helpKey="queue-cleaner:stallRule.completionRange" />
Evidence
Backend validation now enforces MaxCompletionPercentage >= 1, but the UI control still allows 0 via
[min]="0" on the Max Completion % input. The PR adds a computed error message for max<=0, which
mitigates correctness, but the UI constraint is still inconsistent with the backend contract.

code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs[20-25]
code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs[51-59]
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[262-268]
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[315-321]
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts[236-263]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Backend now requires `MaxCompletionPercentage` to be between 1 and 100, but the frontend Max Completion % inputs still allow 0 (`[min]="0"`). This is an inconsistent UI contract and leads to avoidable validation friction.
## Issue Context
The PR already added computed validation errors for `max <= 0`, so users will see an error message; however, the numeric input constraint still permits entering 0.
## Fix Focus Areas
- code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[262-268]
- code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html[315-321]
## What to change
- Change Max Completion % inputs to `[min]="1"` (stall + slow).
- Optionally adjust hint text to reflect that 0 is not a valid max value.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@sourcery-ai

sourcery-ai Bot commented Apr 3, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enforces a minimum MaxCompletionPercentage of 1% (no longer allowing 0) across backend validation, DTO annotations, and frontend UI validation for queue cleaner rules, and ensures the max completion error message is displayed on the correct input fields.

Class diagram for queue cleaner max completion validation changes

classDiagram

  class QueueRule {
    +ushort MinCompletionPercentage
    +ushort MaxCompletionPercentage
    +void Validate()
  }

  class QueueRuleDto {
    +ushort MinCompletionPercentage
    +ushort MaxCompletionPercentage
  }

  class QueueCleanerComponent {
    +stallMinCompletion
    +stallMaxCompletion
    +slowMinCompletion
    +slowMaxCompletion
    +string stallCompletionError()
    +string slowCompletionError()
  }

  QueueRuleDto --> QueueRule : maps_to_domain_rule
  QueueCleanerComponent --> QueueRuleDto : binds_via_API_requests
Loading

File-Level Changes

Change Details Files
Tighten backend domain validation so MaxCompletionPercentage cannot be 0 and update corresponding error messaging.
  • Add explicit guard in QueueRule.Validate to reject MaxCompletionPercentage equal to 0 with a dedicated validation message.
  • Adjust existing upper-bound check to state that the allowed range is 1–100 instead of 0–100.
code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs
Align API-level data annotations with new MaxCompletionPercentage lower bound of 1%.
  • Change QueueRuleDto.MaxCompletionPercentage Range attribute from 0–100 to 1–100 and update the error message accordingly.
code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs
Update frontend queue cleaner UI validation so Max Completion % cannot be 0 and ensure the error is wired to the max inputs.
  • In the Angular component, extend stallCompletionError and slowCompletionError computed functions to return an error when max is less than or equal to 0, before checking max < min.
  • Move the error binding from the Min Completion % field to the Max Completion % field for both stall and slow rules so the max-related error appears on the correct input.
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The frontend still allows a max completion of 0 via [min]="0" on the Max Completion % inputs while the backend now rejects 0; consider updating these inputs (and any related default values) to use a minimum of 1 so the UI constraints align with server-side validation.
  • You now validate MaxCompletionPercentage both with a [Range(1, 100)] attribute and explicit checks in QueueRule.Validate; consider consolidating this logic or ensuring the messages stay in sync to avoid future inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The frontend still allows a max completion of 0 via `[min]="0"` on the `Max Completion %` inputs while the backend now rejects 0; consider updating these inputs (and any related default values) to use a minimum of 1 so the UI constraints align with server-side validation.
- You now validate `MaxCompletionPercentage` both with a `[Range(1, 100)]` attribute and explicit checks in `QueueRule.Validate`; consider consolidating this logic or ensuring the messages stay in sync to avoid future inconsistencies.

## Individual Comments

### Comment 1
<location path="code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html" line_range="265-270" />
<code_context>
       hint="Apply the rule once completion percentage exceeds this value (0 includes items at 0% and above)"
-      [error]="stallCompletionError()"
       helpKey="queue-cleaner:stallRule.completionRange" />
     <app-number-input label="Max Completion %" [(value)]="stallMaxCompletion" [min]="0" [max]="100" suffix="%"
       hint="Apply the rule to items with a completion percentage less than or equal to this value"
+      [error]="stallCompletionError()"
</code_context>
<issue_to_address>
**issue (bug_risk):** Align the Max Completion % input range with the backend (min should be 1, not 0).

The DTO now enforces `[Range(1, 100)]` for `MaxCompletionPercentage` and the TS validators reject `max <= 0`, but both Max Completion inputs here still use `[min]="0"`, allowing users to pick `0` and then immediately get a validation error. Please update these to `[min]="1"` so the UI matches backend/client validation and avoids this confusing behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@greptile-apps

greptile-apps Bot commented Apr 3, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a bug where MaxCompletionPercentage on queue rules (stall and slow) could be set to 0, which is semantically meaningless (it would match no items). The fix enforces a lower bound of 1 consistently across all three layers: backend DTO validation, persistence model validation, and the Angular frontend (computed error signals + error binding placement).

Key changes:

  • QueueRuleDto.cs: Updates [Range(0, 100)][Range(1, 100)] on MaxCompletionPercentage for API-layer validation.
  • QueueRule.cs: Adds an explicit == 0 guard in Validate() before the > 100 check, so the domain model itself rejects 0 independently of the API layer.
  • queue-cleaner.component.ts: Adds a max <= 0 early-exit check in both stallCompletionError and slowCompletionError computed signals to surface the error in the UI before a save attempt.
  • queue-cleaner.component.html: Moves the [error] binding from the Min Completion % input to the Max Completion % input (more appropriate since both error conditions relate to the max value). The Max Completion % inputs for both modals still bind [min]="0", which should be [min]="1" to match the updated constraints at the input-widget level.

Confidence Score: 4/5

Safe to merge — the fix correctly enforces the new constraint across all layers with one minor HTML attribute inconsistency that has no functional impact.

The change is small, focused, and correctly applied at every validation layer (DTO, domain model, frontend signals). The only gap is that both Max Completion % app-number-input elements still carry [min]="0" instead of [min]="1", meaning the input widget itself won't prevent typing 0 — but the validation computed signal and backend guards will still catch it, so no invalid data can actually be persisted.

code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html — both Max Completion % inputs need [min]="1"

Important Files Changed

Filename Overview
code/backend/Cleanuparr.Api/Features/QueueCleaner/Contracts/Requests/QueueRuleDto.cs Updates the [Range] attribute on MaxCompletionPercentage from [Range(0, 100)] to [Range(1, 100)], correctly enforcing the new minimum of 1 at the API DTO validation layer.
code/backend/Cleanuparr.Persistence/Models/Configuration/QueueCleaner/QueueRule.cs Adds an explicit == 0 guard in Validate() before the > 100 check, providing a clear error message when MaxCompletionPercentage is 0. Also updates the > 100 error message to reflect the new 1–100 range. Logic is sound and complementary to the DTO-level validation.
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.ts Adds max <= 0 early-return checks in both stallCompletionError and slowCompletionError computed signals. Logic is correct — the ?? 100 fallback for null means only an explicit 0 triggers the guard.
code/frontend/src/app/features/settings/queue-cleaner/queue-cleaner.component.html Moves the [error] binding from Min Completion % to Max Completion % for both stall and slow modals, which is a sensible UX improvement. However, both Max Completion % inputs still carry [min]="0", which should be [min]="1" to match the new backend and validation constraints.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User enters MaxCompletion value] --> B{Value == 0?}
    B -- Yes --> C[stallCompletionError / slowCompletionError returns 'Max percentage must be greater than 0']
    C --> D[Error shown on Max Completion % field - Save blocked]
    B -- No --> E{Value < Min?}
    E -- Yes --> F[stallCompletionError / slowCompletionError returns 'Max must be >= Min']
    F --> D
    E -- No --> G[Frontend validation passes - Save request sent]
    G --> H[QueueRuleDto Range validation - Range 1 to 100]
    H -- Invalid --> I[400 Bad Request]
    H -- Valid --> J[QueueRule.Validate called]
    J -- MaxCompletion == 0 --> K[ValidationException thrown]
    J -- MaxCompletion > 100 --> K
    J -- MaxCompletion < MinCompletion --> K
    J -- Valid --> L[Rule saved to DB]
Loading

Reviews (1): Last reviewed commit: "fixed queue rules upper bound to never a..." | Re-trigger Greptile

@codecov

codecov Bot commented Apr 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Flaminel Flaminel merged commit ef280ec into main Apr 3, 2026
9 of 12 checks passed
@Flaminel Flaminel deleted the fix_queue_rule_bounds branch April 3, 2026 13:11
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