pub trait EffectHandler: Send + Sync {
Show 13 methods
// Required methods
fn handle_send(
&self,
role: &str,
partner: &str,
label: &str,
state: &[Value],
) -> EffectResult<Value>;
fn handle_recv(
&self,
role: &str,
partner: &str,
label: &str,
state: &mut Vec<Value>,
payload: &Value,
) -> EffectResult<()>;
fn handle_choose(
&self,
role: &str,
partner: &str,
labels: &[String],
state: &[Value],
) -> EffectResult<String>;
fn step(&self, role: &str, state: &mut Vec<Value>) -> EffectResult<()>;
// Provided methods
fn handler_identity(&self) -> String { ... }
fn handle_effect(&self, request: EffectRequest) -> EffectOutcome { ... }
fn send_decision(
&self,
input: SendDecisionInput<'_>,
) -> EffectResult<SendDecision> { ... }
fn handle_acquire(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_state: &[Value],
) -> EffectResult<Value> { ... }
fn handle_release(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_evidence: &Value,
_state: &[Value],
) -> EffectResult<()> { ... }
fn supports_wal_sync(&self) -> bool { ... }
fn wal_sync(&self, _sync: &WalSyncRequest) -> EffectResult<()> { ... }
fn topology_events(
&self,
_tick: u64,
) -> EffectResult<Vec<TopologyPerturbation>> { ... }
fn output_condition_hint(
&self,
_sid: SessionId,
_role: &str,
_state: &[Value],
) -> Option<OutputConditionHint> { ... }
}Expand description
ProtocolMachine-level effect handler.
This is the interface between a guest runtime and the surrounding host runtime. Each choreography can bind a different handler at session open time.
Host-contract rules:
- Methods on this trait are synchronous. Async I/O, transport polling, storage flushes, and background retries must happen outside handler execution and feed their results back through canonical ingress.
- Implementations must treat the provided
stateas session-local scratch for the current request only. They must not rely on unrelated session state or mutate ProtocolMachine session metadata through side channels. - Host-managed session-local mutation should flow through an explicit
ownership capability such as
OwnedSession, not through ad hoc access to the session store while handlers are executing.
Required Methods§
Sourcefn handle_send(
&self,
role: &str,
partner: &str,
label: &str,
state: &[Value],
) -> EffectResult<Value>
fn handle_send( &self, role: &str, partner: &str, label: &str, state: &[Value], ) -> EffectResult<Value>
Compute the payload for a send instruction.
Helper hook used by the default send_decision implementation and by
custom runners that want direct payload computation.
§Arguments
role- The sending rolepartner- The receiving rolelabel- The message labelstate- The coroutine’s register file (for reading state)
Returns a typed outcome for the request.
Sourcefn handle_recv(
&self,
role: &str,
partner: &str,
label: &str,
state: &mut Vec<Value>,
payload: &Value,
) -> EffectResult<()>
fn handle_recv( &self, role: &str, partner: &str, label: &str, state: &mut Vec<Value>, payload: &Value, ) -> EffectResult<()>
Process a received value.
§Arguments
role- The receiving rolepartner- The sending rolelabel- The message labelstate- The coroutine’s register file (mutable for state updates)payload- The received value
Returns a typed outcome for the request.
Sourcefn handle_choose(
&self,
role: &str,
partner: &str,
labels: &[String],
state: &[Value],
) -> EffectResult<String>
fn handle_choose( &self, role: &str, partner: &str, labels: &[String], state: &[Value], ) -> EffectResult<String>
Choose which branch to take for internal choice (select).
Branch-selection helper for custom runners.
The canonical ProtocolMachine resolves branch labels from received payloads and does not call this method in default dispatch paths.
§Arguments
role- The choosing rolepartner- The partner rolelabels- The available branch labelsstate- The coroutine’s register file (for reading state)
Returns a typed outcome for the request.
Provided Methods§
Sourcefn handler_identity(&self) -> String
fn handler_identity(&self) -> String
Stable identifier for effect-trace attribution.
Sourcefn handle_effect(&self, request: EffectRequest) -> EffectOutcome
fn handle_effect(&self, request: EffectRequest) -> EffectOutcome
Canonical typed effect boundary for guest-runtime execution.
Runtime code must route host-facing effect work through this method so the request/outcome contract remains explicit and replay-visible.
The default implementation preserves compatibility for existing
helper-method-based handlers by translating each typed request into the
corresponding helper method. New code should prefer overriding
handle_effect directly.
Sourcefn send_decision(
&self,
input: SendDecisionInput<'_>,
) -> EffectResult<SendDecision>
fn send_decision( &self, input: SendDecisionInput<'_>, ) -> EffectResult<SendDecision>
Decide how to handle a send, optionally with a precomputed payload.
Middleware can override this to model loss/delay/corruption. The default
behavior computes a payload via handle_send unless one is provided.
Returns a typed outcome for the request.
Sourcefn handle_acquire(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_state: &[Value],
) -> EffectResult<Value>
fn handle_acquire( &self, _sid: SessionId, _role: &str, _layer: &str, _state: &[Value], ) -> EffectResult<Value>
Attempt to acquire a guard layer.
Returning EffectResult::Blocked causes the coroutine to block.
Success(evidence) grants the acquire and binds the evidence value.
Sourcefn handle_release(
&self,
_sid: SessionId,
_role: &str,
_layer: &str,
_evidence: &Value,
_state: &[Value],
) -> EffectResult<()>
fn handle_release( &self, _sid: SessionId, _role: &str, _layer: &str, _evidence: &Value, _state: &[Value], ) -> EffectResult<()>
Release a guard layer using previously acquired evidence.
Sourcefn supports_wal_sync(&self) -> bool
fn supports_wal_sync(&self) -> bool
Whether this handler can service the internal wal_sync effect.
Sourcefn wal_sync(&self, _sync: &WalSyncRequest) -> EffectResult<()>
fn wal_sync(&self, _sync: &WalSyncRequest) -> EffectResult<()>
Confirm that the agreement WAL has been durably synchronized.
Sourcefn topology_events(&self, _tick: u64) -> EffectResult<Vec<TopologyPerturbation>>
fn topology_events(&self, _tick: u64) -> EffectResult<Vec<TopologyPerturbation>>
Topology perturbations injected by the environment for this scheduler tick.
The ProtocolMachine ingests these before selecting coroutines for the round. This is a canonical ingress surface for external events; implementations should stage async discoveries before this method is called rather than doing async work from inside request handling.
Returns a typed outcome for the request.
Sourcefn output_condition_hint(
&self,
_sid: SessionId,
_role: &str,
_state: &[Value],
) -> Option<OutputConditionHint>
fn output_condition_hint( &self, _sid: SessionId, _role: &str, _state: &[Value], ) -> Option<OutputConditionHint>
Optional output-condition metadata for commit gating.
The ProtocolMachine calls this only when a step emits observable events. Returning None
delegates to ProtocolMachine-default metadata.