Skip to content

Add command side effect handlers for Chronicle reactors#2290

Draft
Copilot wants to merge 12 commits into
mainfrom
copilot/command-sideeffect-for-reactors
Draft

Add command side effect handlers for Chronicle reactors#2290
Copilot wants to merge 12 commits into
mainfrom
copilot/command-sideeffect-for-reactors

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Reactors can now return commands as side effects, executed transactionally via IReactorSideEffectHandler.

Added

  • CommandResultHandler for single command return values from reactors
  • CommandsResultHandler for multiple command return values from reactors
  • CommandExecutionFailedException thrown when command execution fails within a reactor

Implementation Details

Both handlers implement IReactorSideEffectHandler from Cratis.Chronicle, marked [Singleton] for auto-discovery. Each creates a dedicated IServiceScope per execution for transactional behavior. Commands validated using existing IsCommand() extension. Failed commands throw CommandExecutionFailedException to fail the reactor. Multiple commands execute sequentially in the same scope.

Usage

// Single command
public class MyReactor : IObserver<SomeEvent>
{
    public object OnNext(SomeEvent @event) => new MyCommand("data");
}

// Multiple commands (atomic in single scope)
public class MyReactor : IObserver<SomeEvent>
{
    public object OnNext(SomeEvent @event) => new[]
    {
        new FirstCommand("data1"),
        new SecondCommand("data2")
    };
}

Copilot AI linked an issue Jun 11, 2026 that may be closed by this pull request
Comment thread Source/DotNET/Chronicle/Reactors/CommandResultHandler.cs Fixed
Comment thread Source/DotNET/Chronicle/Reactors/CommandsResultHandler.cs Fixed
Comment thread Source/DotNET/Chronicle/Reactors/CommandsResultHandler.cs Fixed
Copilot AI changed the title [WIP] Implement Command SideEffect support for Reactors Add command side effect handlers for Chronicle reactors Jun 11, 2026
Copilot AI requested a review from einari June 11, 2026 10:21
@github-actions

Copy link
Copy Markdown

NuGet packages for this PR, e.g. Cratis.Arc:
https://github.com/cratis/arc/packages/1655206?version=20.40.2-pr2290.74fc00e

@einari

einari commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

@copilot Rebase on top of origin/main and then add documentation for this new capability.

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Rebase on top of origin/main and then add documentation for this new capability.

I've completed the rebase on top of origin/main and added comprehensive documentation for the new command side effect handlers.

The documentation includes:

  • A new "Reactors" section in the Chronicle documentation
  • Detailed guide on "Returning Commands as Side Effects" with examples
  • Coverage of single and multiple command returns
  • Transactional behavior explanation
  • Error handling examples with CommandExecutionFailedException
  • References to existing documentation

All markdown linting and link verification checks pass. The changes are now in commit 44d38c5.

Comment thread Source/DotNET/Chronicle/Reactors/CommandResultHandler.cs Fixed
Comment thread Source/DotNET/Chronicle/Reactors/CommandsResultHandler.cs Fixed
einari and others added 2 commits June 17, 2026 08:19
… expression'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
… expression'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@einari

einari commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Copilot AI added 2 commits June 17, 2026 06:31
BehaviorSubject is wrapped in DisposableQueryHealthSubject which correctly
handles disposal of both the subject and the subscription.
Use conditional access operator (?.) instead of null checks
followed by method calls to satisfy Roslynator RCS1146 rule.

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the build errors: https://github.com/Cratis/Arc/actions/runs/27669886997/job/81831677028?pr=2290

Fixed the build errors. The issues were:

  1. CA2000 in QueryHealth.cs (line 70): Added pragma directive to suppress the false positive. The BehaviorSubject is correctly wrapped in DisposableQueryHealthSubject which handles disposal.

  2. RCS1146 in CommandResultHandler.cs and CommandsResultHandler.cs: Fixed by using conditional access operator (?.) instead of null-check-then-method-call pattern:

    • value?.GetType().IsCommand() == true instead of value is not null && value.GetType().IsCommand()

The Chronicle project now builds successfully with no errors or warnings.

Comment thread Source/DotNET/Chronicle/Reactors/CommandResultHandler.cs Fixed
Comment thread Source/DotNET/Chronicle/Reactors/CommandsResultHandler.cs Fixed
… expression'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
einari and others added 2 commits June 17, 2026 09:17
… expression'

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

NuGet packages for this PR, e.g. Cratis.Arc:
https://github.com/cratis/arc/packages/1655206?version=20.43.3

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.

Command SideEffect for Reactors

2 participants