Skip to content

Implement event handler system for message passing and callbacks#587

Merged
bvdmitri merged 40 commits intorelease-6from
callbacks
Mar 20, 2026
Merged

Implement event handler system for message passing and callbacks#587
bvdmitri merged 40 commits intorelease-6from
callbacks

Conversation

@bvdmitri
Copy link
Copy Markdown
Member

Summary

  • Introduces a generic event-driven callback system (Event{E}, handle_event, invoke_callback) that lets users hook into every major step of the message passing algorithm: rule calls, message products, form constraint application, and marginal
    computation
  • Adds MessageProductContext to replace bare product strategy arguments, bundling prod_constraint, form_constraint, check strategy, and callbacks into a single context object
  • Refactors variable types with labels, docstrings, and cleaner file organization (variable.jl → generic.jl)

Callback events:

  • BeforeMessageRuleCallEvent / AfterMessageRuleCallEvent
  • BeforeProductOfTwoMessagesEvent / AfterProductOfTwoMessagesEvent
  • BeforeFormConstraintAppliedEvent / AfterFormConstraintAppliedEvent
  • BeforeMarginalComputationEvent / AfterMarginalComputationEvent

Callback handlers can be nothing (no-op), a callable, a Tuple of callables, or a Dict keyed by event name. Includes CallbackResultReducer for aggregating results across events.

Other changes:

  • Removed hardcoded DefaultMessageProdFn / DefaultMarginalProdFn in favor of MessageProductContext
  • Added MethodError hint for mismatched handle_event signatures
  • Added label field to RandomVariable, ConstVariable, DataVariable
  • Improved docstrings for form constraints and variable types
  • Documentation page for callbacks

Test plan

  • New test/callbacks_tests.jl covering all event types, handler variants (nothing, function, tuple, dict), reducers, and merging
  • Extended test/message_tests.jl for MessageProductContext and callback integration in product computations
  • Extended test/variables/random_tests.jl for labels and callback-aware activation
  • Existing tests updated for new API (clusters_tests, dependencies_tests, mixture_tests)

bvdmitri added 30 commits March 5, 2026 15:15
Introduce a new event handler mechanism that allows users to hook into
the message passing procedure via `Event`, `handle_event`, and
`broadcast_event` functions. Events are broadcast before and after
message rule calls, enabling debugging and monitoring capabilities.

Key changes:
- Add `event_handler.jl` with event types and handler interfaces
- Extend `MessageMapping` to include an event handler parameter
- Support both custom handler types and NamedTuple-based handlers
- Add documentation for the events system
- Include comprehensive tests for event handler functionality
this is required to inject the callbacks properly, plus we do the breaking
release already. Could break (and improve) more things as well then
- `compute_product_of_messages` now accepts the `AbstractVariable`,
  makes it easier to identify the variable inside the callback
@bvdmitri bvdmitri added this to RxInfer Mar 20, 2026
@bvdmitri bvdmitri added enhancement New feature or request breaking labels Mar 20, 2026
@github-project-automation github-project-automation bot moved this to Backlog in RxInfer Mar 20, 2026
@bvdmitri bvdmitri merged commit a40573e into release-6 Mar 20, 2026
0 of 2 checks passed
@bvdmitri bvdmitri deleted the callbacks branch March 20, 2026 14:19
@github-project-automation github-project-automation bot moved this from Backlog to ✅ Done in RxInfer Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant