Runtime architecture
macp-runtime v0.4.0 is organized as a small set of explicit layers.
1. Transport adapter (src/server.rs)
Responsibilities:
- receive gRPC requests
- authenticate request metadata
- derive the runtime sender identity
- enforce payload limits and rate limits
- translate runtime errors into gRPC responses and MACP
Ackvalues
2. Coordination kernel (src/runtime.rs)
Responsibilities:
- route envelopes by message type
- validate and create sessions
- apply mode authorization and mode transitions
- enforce accepted-history ordering
- enforce lazy TTL expiry on reads and writes
- persist updated session snapshots
3. Mode Registry (src/mode_registry.rs)
The ModeRegistry is the single source of truth for mode dispatch, replay, and discovery. It eliminates the previous pattern of hardcoded mode maps in runtime.rs, main.rs, and replay.rs.
Responsibilities:
- register all mode implementations
- provide mode lookup for dispatch and replay
- provide standards-track mode names for
ListModes - provide mode descriptors for
ListModesandGetManifest
The registry uses RwLock for thread-safe dynamic mode registration.
Key methods:
build_default()— constructs the canonical mode set (5 standards-track + 1 built-in extension)get_mode(name)— mode lookup for dispatchstandard_mode_names()— drivesListModesstandard_mode_descriptors()— drivesListModesresponseall_mode_names()— drivesGetManifestandInitialize(all modes)extension_mode_descriptors()— drivesListExtModesregister_extension(descriptor)— dynamic extension registrationunregister_extension(mode)— dynamic extension removal (built-in modes cannot be removed)promote_mode(mode, new_name)— promote extension to standards-tracksubscribe_changes()— broadcast channel forWatchModeRegistry
4. Mode layer (src/mode/*)
Responsibilities:
- encode coordination semantics per mode
- validate mode-specific payloads
- authorize mode-specific message types
- return declarative
ModeResponsevalues for the kernel to apply
Implemented modes:
- Decision — enforced phase transitions (Proposal -> Evaluation -> Voting -> Committed)
- Proposal — negotiation with counterproposals, acceptance convergence, terminal rejections
- Task — delegated task with serial assignment, progress tracking, terminal reports
- Handoff — serial handoff offers with accept/decline disposition
- Quorum — threshold approval with ballots
- MultiRound (
ext.multi_round.v1) — built-in extension: iterative value convergence with explicit Commitment - PassthroughMode — generic handler for dynamically registered extension modes
5. Storage layer
Storage backend (src/storage.rs)
Provides the StorageBackend trait with two implementations:
FileBackend— per-session directories containingsession.jsonand append-onlylog.jsonl, with crash recovery and atomic writesMemoryBackend— no-op backend forMACP_MEMORY_ONLY=1
Session registry (src/registry.rs)
In-memory cache of all sessions, loaded from FileBackend on startup. Stores:
- session metadata
- bound versions
- participants
- dedup state
- current session state
Supports optional file-backed snapshot persistence for backward compatibility.
Log store (src/log_store.rs)
In-memory cache of accepted-history logs. Stores:
- accepted incoming envelopes
- runtime-generated internal events such as TTL expiry and session cancellation
On-disk persistence is handled by FileBackend, not by LogStore.
6. Security layer (src/security.rs)
Responsibilities:
- load token-to-identity mappings
- derive sender identities from metadata
- enforce allowed-mode policy
- enforce session-start policy
- enforce per-sender rate limits
Architecture diagram
Client Request
|
[Transport/gRPC] -- server.rs, security.rs
|
[Coordination Kernel] -- runtime.rs
|
[Mode Registry] -- mode_registry.rs
| \
[Mode Logic] [Discovery + Extension Lifecycle]
mode/*.rs ListModes, ListExtModes, GetManifest,
RegisterExtMode, UnregisterExtMode, PromoteMode
|
[Storage Layer] -- storage.rs, log_store.rs
|
[Replay] -- replay.rsRequest path summary
- gRPC request arrives in
MacpServer - request metadata is authenticated
- sender identity is derived and envelope spoofing is rejected
- runtime processes the envelope
- accepted messages mutate state and log history
- updated session snapshots are persisted
- an
Ackis returned to the caller
Freeze-profile design choice
The runtime now exposes StreamSession as a per-session accepted-envelope stream. Each gRPC stream binds to one session and receives canonical MACP envelopes in runtime acceptance order. Unary Send remains the path for explicit per-message acknowledgement semantics.