Skip to main content

Module step

Module step 

Source
Expand description

The per-message coordination step — the pure, I/O-free kernel invariants.

Every accepted MACP message passes the same per-message invariants: dedup (RFC-MACP-0001 §8 idempotency), mode-binding, TTL, and the monotonic OPEN gate (§7.2/§7.3), then mode validation, then commit. Historically these lived welded into the gRPC server’s process_message, so any other consumer of the coordination core (e.g. an embedding library) had to re-implement them and risk drift. This module hosts them once — synchronous and free of tokio, storage, transport, and the wall clock (the caller injects now_ms).

Two ways to drive it:

  • step — all-in-one, for in-memory consumers that do not interpose durable storage between validation and commit.
  • check_preconditions + validate_message + commit — the phases, for a durable consumer (the runtime) that must write the message to its append-only log between validation and commit, so a failed write never consumes a dedup slot.

Enums§

Precheck
Outcome of the mode-independent precondition checks.
StepOutcome
Outcome of step.

Functions§

check_preconditions
Mode-independent per-message invariants. Pure: no mutation, no I/O, no clock.
commit
Commit a validated message into the session: consume the dedup slot, record participant activity, and apply the mode response. Returns the resulting session state.
step
All-in-one per-message step for in-memory consumers: preconditions → mode validation → commit, mirroring the runtime’s external contract. Expiry marks the session Expired and returns MacpError::TtlExpired; a duplicate is reported as StepOutcome::Duplicate; any other rejection returns its error without consuming a dedup slot or applying state.
validate_message
Mode-dependent validation: sender authorization + mode rules. Pure — returns the ModeResponse to apply and mutates nothing. Call only after check_preconditions returns Precheck::Proceed.