Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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