Refactor mode registry to factory/provider pattern and enhance confor…#17
Merged
ajit-zer07 merged 2 commits intomainfrom Mar 27, 2026
Merged
Refactor mode registry to factory/provider pattern and enhance confor…#17ajit-zer07 merged 2 commits intomainfrom
ajit-zer07 merged 2 commits intomainfrom
Conversation
…mance tests Restructure ModeRegistry to use trait-based ModeFactory, ModeDescriptorProvider, ModeSchemaProvider, and ModeConformanceProvider instead of storing boxed Mode instances directly. This decouples mode instantiation from registration, enables per-invocation mode creation, and adds introspectable conformance catalogs. Also hardens decision/proposal/handoff mode validation (phase-gated transitions, stricter payload checks), converts FileBackend storage to async tokio I/O, adds MACP_STRICT_RECOVERY for fatal-on-error session replay, and expands conformance fixtures with expected_error_code, expected_resolution, expected_mode_state, and replay equivalence assertions.
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
Mode registry refactor: Replace direct
Box<dyn Mode>storage with afactory/provider architecture (
ModeFactory,ModeDescriptorProvider,ModeSchemaProvider,ModeConformanceProvidertraits). Modes are nowinstantiated per-call via
ModeRef::factory(), eliminating shared mutablestate across the registry read-lock boundary. Each built-in mode registers
conformance fixture paths, exposed through
all_mode_conformance().Strict session-start flag: Add
strict_session_starttoModeRegistrationandrequires_strict_session_start()query, replacingthe hard-coded
is_standard_mode() || mode_name == "ext.multi_round.v1"check in
runtime.rsandreplay.rs. Promoted extensions automaticallygain strict session-start enforcement.
Extension registration validation:
register_extensionnow rejectsdescriptors with empty
message_types, blankmode_version, orterminal_message_typesentries not present inmessage_types.Decision mode hardening: Introduce phase-gated guard methods
(
ensure_can_propose,ensure_can_deliberate,ensure_can_vote,ensure_not_committed) that enforce the Proposal → Evaluation → Voting →Committed phase machine. Evaluations and Objections are now rejected once
voting has begun.
Proposal mode phase tracking: Add explicit
ProposalPhaseenum(
Negotiating,Converged,TerminalRejected,Committed) persisted inProposalState.refresh_phase()recalculates after every state mutation.commitment_ready()now checks phase rather than recomputing convergence.Handoff mode fix: Reject
HandoffContexton offers whose dispositionis no longer
Offered(e.g., already accepted/declined).Async storage I/O: Convert
FileBackendfrom blockingstd::fstotokio::fsforatomic_write,create_dir_all,read,read_dir,OpenOptions, and existence checks.Strict recovery mode: New
MACP_STRICT_RECOVERY=1env var makesstartup replay failures fatal instead of warn-and-skip.
Conformance test enhancements: Fixtures now support
expected_error_code,expected_resolution,expected_mode_state(subset-matched via
assert_json_contains),expect_resolution_present,and
verify_replay_equivalence. New payload encoders added forEvaluation,Objection,CounterProposal,Reject,Withdraw,HandoffDecline, andHandoffContext. New unit tests cover phasetransitions, malformed payload rejection, and post-phase-transition guards.
Test plan
cargo test— all existing and new unit/conformance tests passcargo clippy— no new warningsMACP_STRICT_RECOVERY=1to verify fatal replayMACP_ALLOW_INSECURE=1 MACP_ALLOW_DEV_SENDER_HEADER=1 cargo runstarts cleanly with no regressions
and expected_mode_state assertions