The MACP governance policy framework (RFC-MACP-0012 (Policy)) allows you to register, resolve, and apply governance rules that control how coordination sessions reach commitment. Policies define voting algorithms, quorum requirements, objection handling, and commitment authority.
PolicyDescriptor — A registered policy definition containing rules encoded as JSON bytes, targeting a specific mode (or "*" for mode-agnostic).
Default policy (policy.default) — Every runtime ships with this pre-registered. When policy_version is empty, the default policy applies, preserving backward compatibility.
Evaluation semantics — The runtime evaluates policy at commitment time. If the policy denies the commitment (e.g., quorum not met), the runtime rejects the Commitment envelope with POLICY_DENIED.
Read-only registry (MACP_POLICIES_DIR). When the runtime is started with
a policies directory, its registry is read-only: Initialize advertises
capabilities.policyRegistry.registerPolicy: false, and registerPolicy /
unregisterPolicy fail with MacpAckError whose failure.code is
'FAILED_PRECONDITION' (inspect via err.failure.code, not
MacpTransportError.code — the gRPC-level rejection is reclassified into the
same Ack-error model every NACK uses; see
error-handling.md). On runtime ≥ 0.9.0,
err.macpErrorCode === REGISTRY_READ_ONLY identifies this case exactly —
failure.code stays 'FAILED_PRECONDITION' for compatibility. Check the
capability flag before attempting to register:
See Policy API Reference for the full input types and defaults. The builders emit rules JSON matching the spec's Rule Schemas by Mode; how the runtime interprets each rule (including commitment authority) is documented in the runtime policy guide.
// List all registered policiesconst allPolicies = await client.listPolicies();// Filter by modeconst decisionPolicies = await client.listPolicies('macp.mode.decision.v1');// Get a specific policyconst policy = await client.getPolicy('policy.fraud.majority-veto');// Unregisterawait client.unregisterPolicy('policy.fraud.majority-veto');
Before you switch a session type to a new policy, replay a finished session
under it with client.whatIfReplay(sessionId, candidate). Nothing is registered or
changed. The result shows where the two replays first diverge, every message the
candidate would have denied, and both final outcomes. The runtime must advertise
capabilities.policyRegistry.whatIfReplay; otherwise the client throws before
sending. See the API reference.
Use PolicyWatcher to react to policy registration/unregistration events.
It needs auth ({ auth } or the client's own), like listPolicies: from
runtime 0.12.0 the runtime refuses an unauthenticated WatchPolicies, so
without a credential the SDK throws MacpSdkError before sending anything.
import { PolicyWatcher } from 'macp-sdk-typescript';const watcher = new PolicyWatcher(client, { auth: Auth.devAgent('observer') });for await (const change of watcher.changes()) { console.log('Policy registry changed:', change.descriptors.length, 'policies');}
When policy_version is empty or set to policy.default, the runtime applies the default policy — no voting threshold, vetoes disabled, initiator-only commitment authority. This matches the runtime's behavior before the policy framework was introduced. The full default rule set is specified in the spec's Default Policy section.