Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Reminder: Make sure to review CONTRIBUTING.MD and make sure you've sent in your signed contributor agreement.

Reminder: Add issue number for work item (e.g. #123)

Description

Async rules currently fire in parallel regardless of priority, defeating short-circuiting behavior. A priority-0 async rule failure doesn't prevent priority-1 async rules from starting since they've already been dispatched.

This PR adds a plan document (docs/dev/Async-Rule-Priority-Execution-Plan.md) proposing:

  • New AsyncRuleExecutionMode enum with Parallel (default, backward-compatible) and Serial options
  • New AsyncExecutionMode property on IBusinessRuleBase interface
  • Priority-group-based execution algorithm in RunRules that:
    • Groups rules by priority
    • Executes serial async rules with await, enabling short-circuit checks
    • Fires parallel async rules without waiting (current behavior)
public enum AsyncRuleExecutionMode
{
    Parallel = 0,  // Current behavior, default
    Serial = 1     // Await completion, enable short-circuiting
}

The plan includes:

  • Current implementation analysis
  • Conceptual algorithm pseudocode
  • Breaking changes assessment
  • 5-phase implementation roadmap (10-17 days estimate)
  • Open design questions for review
Original prompt

Create a plan in a markdown file for changing the way business rules are run in CSLA.rules.businessrules so async rules also honor priority alongside sync rules.

Async rules should get a property indicating that they can run serial or in parallel. Default to parallel like today.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Update business rules to honor priority for async execution Add plan document for async business rules priority execution Nov 25, 2025
Copilot AI requested a review from rockfordlhotka November 25, 2025 01:44
@StefanOssendorf
Copy link
Contributor

How is the "grouping" inteded to be?
Assume the following Setup (all rules async):
R1, R2, R3 : Prio 1
R4, R5: Prio 2

Will R1, R2 and R3 run in parallel or serial before proceeding.

Copy link

@mtavares628 mtavares628 left a comment

Choose a reason for hiding this comment

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

I think this solution will work well, and solve a lot of issues that I'm currently having with dependent async rules. How soon could this change be implemented?

Break (don't process higher priority rules)
```

### 5. Alternative Approach: Priority-Group-Based Execution

Choose a reason for hiding this comment

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

I like this approach better, since it allows for sync and async rules at the same priority to run in the intended order instead of processing sync rules first and then async rules.

1. **Should serial async rules at the same priority run in sequence or can they run in parallel with each other?**
- Option A: All serial rules at same priority run one after another
- Option B: Serial rules at same priority can run in parallel, but all must complete before next priority
- Recommendation: Option A for maximum control

Choose a reason for hiding this comment

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

I would go with Option A to maintain consistency and give full control.

2. **How to handle a mix of sync and async rules at the same priority?**
- Option A: Run sync first, then async
- Option B: Maintain original order within priority group
- Recommendation: Option B to preserve developer intent

Choose a reason for hiding this comment

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

I also vote for option B here.


3. **Should there be a timeout for serial async rules?**
- Could prevent one slow rule from blocking the entire validation
- Could use existing `CheckRulesAsync` timeout mechanism

Choose a reason for hiding this comment

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

I like the idea of it having a timeout similar to CheclRulesAsync.

4. **Should the `ProcessThroughPriority` property affect serial async rules?**
- Current behavior allows continuing past broken rules up to a certain priority
- Should serial async rules respect this?
- Recommendation: Yes, maintain consistent behavior

Choose a reason for hiding this comment

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

I think ProcessThroughPriority should affect serial async rules for consistency.

- No changes to rule interfaces required for basic usage

### Medium Risk
- The internal `RunRules` method signature may need to become async

Choose a reason for hiding this comment

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

By making this async, it will also have the added benefit of awaiting for RunRules to finish before cycling through and running rules on affected properties. Currently, affected property rules are potentially being executed before the primary async rule has finished executing and as a result the affected property rules are using stale values from other properties that haven't been outputted yet from the original rule.

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.

4 participants