Skip to content

fix: swarm schedulers return Result instead of panicking on unimplemented patterns this is title #1645 - #1646

Open
workonlly wants to merge 3 commits into
mofa-org:mainfrom
workonlly:temper
Open

workonlly wants to merge 3 commits into
mofa-org:mainfrom
workonlly:temper

Conversation

@workonlly

@workonlly workonlly commented Apr 19, 2026

Copy link
Copy Markdown

Summary
This PR refactors the Swarm Coordination API to introduce fallible scheduler creation. By transitioning CoordinationPattern::into_scheduler() to return a Result, we enable the system to gracefully handle patterns that are defined in the schema but not yet active in the current execution phase.

Related Issues
Related to #1645

Context
In the current architecture, several coordination patterns (Debate, Consensus, MapReduce, etc.) are defined as part of the CoordinationPattern enum but do not yet have active scheduler implementations (targeted for Phase 2).

Previously, the interface lacked a mechanism to report these as unsupported at runtime without a hard failure. This PR establishes a standard error-handling contract, allowing the foundation layer to report "not yet implemented" status as a catchable GlobalError. This aligns the Swarm module with CLAUDE.md Section I error-handling standards.

Changes
Fallible Interface: Changed into_scheduler() signature from returning a raw Box to Result<Box, GlobalError>.

Pattern Validation:

Sequential and Parallel now return Ok.

Debate, Consensus, MapReduce, Supervision, and Routing now return a descriptive GlobalError::Other.

Enum Enhancements: Added Copy and Clone derivations to CoordinationPattern to simplify usage in testing and configuration contexts.

Call Site Migration: Updated integration tests and internal scheduler logic to handle the new fallible return type.

How you Tested
Unit Testing: Added a comprehensive test suite in swarm/patterns.rs to verify that every enum variant returns the expected Ok or Err result.

Integration Testing: Updated tests/swarm_scheduler_integration.rs to ensure the end-to-end swarm execution flow correctly unwraps the new Result.

Workspace Verification:

Bash
cargo test -p mofa-foundation swarm
Result: ✅ 89 tests passed (including 2 new specialized error-handling tests).

Breaking Changes
[ ] No breaking changes

[x] Breaking change (describe below)

Impact: The into_scheduler() method is now fallible. Any direct calls to this method must now handle the Result type (using ?, match, or .expect()).

Checklist
Code Quality
[x] Code follows Rust idioms and project conventions

[x] cargo fmt run

[x] cargo clippy passes without warnings

Testing
[x] Tests added/updated for all coordination variants

[x] cargo test passes locally without any error

image

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