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 API — 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 writer’s last whole 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 boundary 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 workspace’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-API 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. - commit_
written - Commit what
actionalready wrote, the doc’s open transaction underactor, as its change recorded withcontext, and return its replayable envelope: the changeapply_local_with_contextwould have made, without applying it again.describedis what the action said it does, read from the document before its first write. - current_
step - The undo step open on this thread, if any (see
open_step). - dispatch
- The locus-aware front API, 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 last whole entry when the change differs from it only in its gesture and action payload, else whole. Changes of others in between do not matter. 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 writer’s last whole entry with the continuation’s gesture and action (found by following its writer’s earlier changes). - envelope_
at - The envelope
apply_local_with_contextwrites foractionat the doc’s current heads, under the invocation id and origin time (seconds since the Unix epoch) the caller pins rather than fresh ones: a device applying an app’s verb from its package mints both from the request, so every holder given the same request writes the same change. - 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. - is_
replaying - Whether the executor is reproducing an existing action rather than admitting a new invocation. Replay must reproduce document writes without issuing host-local approvals or other outside effects again.
- 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. - reading_
invoking_ context - What
readmakes of theinvoking_context, without copying it: it carries the action’s arguments, which may be large. - recorded_
form - The action as its change records it: itself when the change documents it
whole, else with its large parts kept, sealed, in the content store of
the window that records it (
crate::content::register). Built once, on the device that invokes the action. An action too large even then is refused, and so is one whose parts no store would keep: 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. - replay_
decoded replayofaction, the envelope’s action already decoded: what a device replays an app’s verb with when the app’s own code is the model module its package carries rather than a type in this process.- replaying_
as - Call
workwithis_replayingsayingreplaying: an app’s model module applies its verb as the device that called it does, reproducing or admitting. - 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 server’s grant check: an author granted an action who wrote something else inside its storage units is caught here. - with_
invoking_ context - Call
workwithcontextas theinvoking_context: an operation the app carries out itself (a write into a part of a chain) keeps the agent session and purpose its invocation came with.