Module executor
Expand description
Applying, replaying, and dispatching actions.
Three entry points, one commit discipline: apply_local runs an
action on the local replica, minting a fresh envelope (the origin);
replay decodes an envelope’s action and applies it, reproducing
the identical change on any replica at the same base state (peers);
dispatch is the locus-aware front door — ClientLocal applies
and hands to the transport for replication; ServerPreferred submits to
an authoritative host and fails closed when none answers.
The commit discipline is what makes replay deterministic: every
apply pins the Automerge actor id (from the envelope’s ActionId)
and the commit time, then restores the doc’s previous actor. A fresh
actor id per action means its single change is seq == 1 on every
replica, so the change hash is content-addressed identical everywhere.
Structs§
- Compensating
Scope - The undo or redo of the steps
marks(their change hashes) applying its compensating action on this thread: an outside consequence the action queues reads them (await_compensation), and the step counts as taken back (or brought back) only once that consequence settles (settle_compensation). - Entry
Reader - The entries of a document’s changes read in causal order, each continuation folded into its gesture’s first entry as it is read.
- Local
Transport - A transport that only replicates locally (no host); records every replicated envelope for a caller/test to inspect. The default the toolkit installs when a session has no peer/host wiring yet.
Enums§
- Dispatched
- What
dispatchdid with an action. - Host
Decision - A host’s answer to a
ServerPreferredsubmission. - Verified
- What replaying a received change showed.
Constants§
- UNDONE_
KEY - The document key prefix of a step’s undo marker, followed by the step’s
change hash:
trueonce taken back, a negative attempt count while its undo waits for an outside consequence to settle, a positive one while its redo does.
Traits§
- Action
Transport - The transport an action is handed to after (or instead of) local execution — the seam between the pure action model and whatever moves bytes (in-process broker, compositor socket, Iroh). The model never imports a transport, only calls this trait.
Functions§
- apply_
local - Apply
actionto the local replica and return its replayable envelope.encodedis the serialized form carried to peers — must encode the same action. - apply_
local_ by apply_local, attributing the resulting change toactor: the Automerge change commits under their actor so the room’s history names them the way it names a typing person.Nonekeeps theActionId-derived actor, as before.- apply_
local_ with_ context apply_local, with semantic provenance embedded in the resulting durable change. Use this at framework/action-door boundaries where the resource and human action label are already known.- await_
compensation - The steps an outside consequence queued now settles, recording that their undo or redo waits for it; empty outside a compensation.
- await_
settlement - Mark the step
hashas waiting for the outside consequence its undo (or, withredo, its redo) queued: the next attempt’s marker, negative for an undo, positive for a redo. The step stays as it was untilsettle_compensationcompletes it. - current_
step - The undo step open on this thread, if any (see
open_step). - dispatch
- The locus-aware front door, routing
actionper itsExecutionLocus:ClientLocal→apply_localthentransport.replicate;ServerPreferred→transport.submit_to_host, refusing when no authoritative host is reachable. The envelope’s id/timestamp are fixed before submission. - dispatch_
by dispatch, attributing the resulting change toactor— the executor owns the commit boundary, so it’s the only place that chooses which actor a change commits under, rather than each app remembering.- dispatch_
by_ with_ context - Attributed variant of
dispatch_with_context. - dispatch_
with_ context dispatch, carrying semantic provenance into the replicated envelope and the committed CRDT change.- entry_
message - The message
contextis written with byactorondoc: as the continuation of the actor’s previous entry when the change continues its gesture (a head ofdocis the actor’s, of the same gesture and step), else whole. A function of the document, so a replaying device writes the same message, hence the same change. - entry_
of - The entry of the change
hash: its message’s, or for a continuation its gesture’s first entry with the continuation’s action (found by following its writer’s earlier changes). - inverse_
as - The action’s
inverse_encodedatdoc, as the change written byactorrecords it: what the action mints depends on its writer. - invoking_
context - The context of the action whose
Action::applyis running on this thread: who invoked it and in which work group (an agent run). Pinned by the envelope like the actor and the time, so a replica replaying the action reads the same value.Noneoutside an apply, or for an action dispatched with no context. - open_
step - Open the undo step the changes committed on this thread join until the
next one opens: every action applied meanwhile records it as its
gesture, so the document’s history takes them back as one step. The host’s history opens one at every step boundary;Nonecloses it. - recorded_
form - The action as its change records it: itself when it fits the history
budget, else with its large parts kept as content
(
EncodedAction::with_content_parts). An action too large even then is refused: a change never commits without the action it ran. - replay
- Replay an envelope received from a peer: decode its action via
registryand apply under the envelope’s pinned actor + timestamp. Applied at the envelope’sbase_heads, this reproduces the identical document. - settle_
compensation - Mark the undo (or redo) of the step
hashcomplete: its outside consequence settled. - verified_
compensation - Decode a recorded inverse only after reproducing its original change. Descriptive CRDT metadata alone cannot install executable history.
- verify_
change - Replay the action the change
hashrecords on the document it was authored against, and check that it produces exactly that change: same operations, same actor, time and message, so the same hash. This is what a device that has the app does with every change it receives, beside the relay’s grant check: an author granted an action who wrote something else inside its storage units is caught here.