Skip to content

Refactor mode registry to factory/provider pattern and enhance confor…#17

Merged
ajit-zer07 merged 2 commits intomainfrom
mode-registry-update
Mar 27, 2026
Merged

Refactor mode registry to factory/provider pattern and enhance confor…#17
ajit-zer07 merged 2 commits intomainfrom
mode-registry-update

Conversation

@ajit-zer07
Copy link
Copy Markdown
Contributor

Summary

  • Mode registry refactor: Replace direct Box<dyn Mode> storage with a
    factory/provider architecture (ModeFactory, ModeDescriptorProvider,
    ModeSchemaProvider, ModeConformanceProvider traits). Modes are now
    instantiated per-call via ModeRef::factory(), eliminating shared mutable
    state 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_start to
    ModeRegistration and requires_strict_session_start() query, replacing
    the hard-coded is_standard_mode() || mode_name == "ext.multi_round.v1"
    check in runtime.rs and replay.rs. Promoted extensions automatically
    gain strict session-start enforcement.

  • Extension registration validation: register_extension now rejects
    descriptors with empty message_types, blank mode_version, or
    terminal_message_types entries not present in message_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 ProposalPhase enum
    (Negotiating, Converged, TerminalRejected, Committed) persisted in
    ProposalState. refresh_phase() recalculates after every state mutation.
    commitment_ready() now checks phase rather than recomputing convergence.

  • Handoff mode fix: Reject HandoffContext on offers whose disposition
    is no longer Offered (e.g., already accepted/declined).

  • Async storage I/O: Convert FileBackend from blocking std::fs to
    tokio::fs for atomic_write, create_dir_all, read, read_dir,
    OpenOptions, and existence checks.

  • Strict recovery mode: New MACP_STRICT_RECOVERY=1 env var makes
    startup 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 for
    Evaluation, Objection, CounterProposal, Reject, Withdraw,
    HandoffDecline, and HandoffContext. New unit tests cover phase
    transitions, malformed payload rejection, and post-phase-transition guards.

Test plan

  • cargo test — all existing and new unit/conformance tests pass
  • cargo clippy — no new warnings
  • Manual smoke test with MACP_STRICT_RECOVERY=1 to verify fatal replay
  • Verify MACP_ALLOW_INSECURE=1 MACP_ALLOW_DEV_SENDER_HEADER=1 cargo run
    starts cleanly with no regressions
  • Review conformance fixture JSON for correctness of expected_resolution
    and expected_mode_state assertions

…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.
@ajit-zer07 ajit-zer07 merged commit 27b52e5 into main Mar 27, 2026
10 checks passed
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