fate: A Statechart Engine for Go
Harel statecharts in Go, hierarchy, parallel regions, history, guards and delayed transitions. Zero dependencies, deterministic, and snapshots that restore exactly, including inside Temporal workflows. As of v0.14.1 it also records what every step did, previews an event without sending it, lints a machine and reports the Go line each guard and action is written on.
fate is an implementation of Harel statecharts in Go: nested states, parallel regions, shallow and deep history. Not a flat finite automaton. The semantics follow SCXML and XState v5, expressed with generics so context and events are strongly typed.
import (
"github.com/arisros/fate/action"
"github.com/arisros/fate/engine"
)
The current release is v0.14.1, tagged on 2026-10-13. When this post was first written it was v0.5.1 (2026-09-17); the nine minor releases in between all landed from 2026-10-03 to 2026-10-13. Most of them answer one question a host keeps asking a running machine: not just “where are you” but “what just happened, what can happen next, and where is that written”.
Two rules that shaped everything
First: zero dependencies. The root module’s go.mod requires nothing at all, and CI enforces it: a job named “engine has zero external dependencies” fails the build if go list -m all returns anything besides the module itself. That rule is what keeps go get github.com/arisros/fate light, it’s why the Temporal integration is a separate module (fate/temporal), and it’s why fate-studio lives in a different repository entirely.
It also drove two package splits. In v0.5.0 the renderers moved to fate/render and snapshot diffing to fate/diff, so anyone who only needs the engine no longer carries visualisation code. In v0.6.0 the engine itself was split by concern: engine (Machine, Actor, the config structs), action (actions, guards, conditions), effect (timers and invocations), persist (state values and snapshots) and describe (the JSON descriptor for tooling). Every fate.X became engine.X, action.X and so on, with the symbol names unchanged. It’s a breaking change, but the old root names stay behind as frozen // Deprecated: aliases, so existing code keeps compiling while it migrates. The reasoning is in docs/adr/0007-package-layout.md: 17 source files and 24 test files had lived in one folder, and nothing in the layout said which were the runtime and which were tooling.
Second: determinism. A Machine is immutable and shareable; the Actor holds the state, and that state serialises to JSON and restores byte for byte:
blob, _ := a.Persist()
b, _ := engine.NewActorFromSnapshot[Ctx, Evt](m, blob)
Since v0.7.0 the restore also checks the snapshot against the machine. Before, it accepted a state the machine does not have, and the actor then handled no events at all; now an unknown state, a missing parallel region or two active children of one compound state return ErrSnapshotMismatch.
The engine doesn’t decide what time it is
This is the part that shaped the design most. Delayed (after) transitions don’t call time.After inside the engine. The engine only reports which timers are outstanding, and something outside decides when they fire:
for _, pt := range a.PendingTimers() {
a.FireTimer(pt.ID)
}
That looks roundabout until you remember who the consumer is. Inside a Temporal workflow, reading a real clock is forbidden: a replay has to produce identical results. With timers pulled rather than pushed, the core is blind to the clock and safe in any deterministic environment. The same pattern covers invocations: PendingInvocations, ResolveInvocation and RejectInvocation.
The bug v0.5.0 exists for
The biggest fix in v0.5.0 was in parallel regions, and it was the kind of bug that the state value alone never shows.
computeExitSet walked up from the alphabetically first active leaf instead of from the transition’s domain. So a transition fired inside one region could run another region’s Exit actions and disarm its timers and invocations, while the snapshot still reported that region active. The result was an armed-looking state with a delayed transition that could never fire. The entry side had the mirror problem: entering a parallel node entered the node and none of its regions, so their Entry actions never ran.
The old exit set had been hiding the entry bug, because it never disarmed those effects on the way out either. Fixing one exposed the other. Now the exit set is every active node below the transition’s domain, the entry set enters every region on the path, and no result depends on which region’s name sorts first. Shallow history had the same first-leaf assumption and was fixed with it.
v0.5.1 is the follow-up, and it is only that fix: an internal transition that targets its own state now re-enters its initial states, and deep history into a parallel node restores the saved states instead of the defaults.
The changelog also kept a “known limitations” section, which I think matters as much as the fixes. It listed three. One is gone: v0.7.0 made a parallel state complete when all its regions reach a final state, fires a compound’s OnDone in every region rather than only the one that sorts first, and ends the actor when a top-level parallel state is done. Two still hold at v0.14.1: a cross-region transition moves only the target’s region, and exit order is by depth rather than reverse document order. Those are narrower than SCXML, and saying so is cheaper than someone finding out.
”The machine ignored that” is now visible
In a statechart, an event that no state handles is not an error, so Send drops it silently. That is correct, and it is also exactly what makes “nothing happened” hard to debug. v0.5.0 added Can, which evaluates guards without touching the actor:
if !actor.Can(evt) {
// the machine would ignore this event in its current state
}
_ = actor.Send(ctx, evt)
Because guards are pure by contract, the answer is exact, not a guess. v0.7.0 widened the same idea. NextEvents lists the events the active states declare a transition for, Enabled narrows that to the ones whose guards pass right now, and Preview returns the snapshot Send would leave behind, run on a copy so the actor itself never moves:
a.NextEvents() // [APPROVE REJECT]
a.Enabled(byName) // [REJECT], the APPROVE guard fails
next, _ := a.Preview("REJECT") // next.Value.Path() == "rejected"
That’s from the package’s own ExampleActor_NextEvents. The copy is restored from Persist, so a value stored in an any comes back in its JSON form; MachineConfig.CloneContext (v0.8.0) lets a machine supply its own copy instead.
v0.11.0 closed the other way an event could go missing. A named string type used to dispatch on its type name instead of its value, and an int enum collapsed every value into one name. Now an event that has no name (a nil event, an anonymous struct, an int with no EventName method) makes Send return ErrUnnamedEvent and Can report false, instead of quietly matching a "*" handler. That one is in the changelog’s breaking section, as is v0.12.0, where StateValue.Path() started printing the full path of every parallel region (order.fulfillment.packing | order.payment.pending, not ... | payment.pending).
What a step did
A snapshot says where the machine is. It doesn’t say how it got there, and one case is invisible from snapshots alone: a state that a step leaves and enters again. Timer and invocation ids come from the state path, so the pending lists look identical before and after, and an adapter keeps the old timer running instead of restarting it.
v0.8.0 adds step records. Every unit of work (start, an event, a raised event, an OnDone, a fired timer, an invocation result) produces a Step with its cause, the transitions that fired, and the states exited and entered in the order their actions ran:
a.SubscribeSteps(func(s engine.Step) {
fmt.Println(s.Seq, s.Cause, s.Event, s.Exited, s.Entered)
})
// 2 event SUBMIT [draft] [review]
// 3 event RETURN [review] [review]
The second line is the case snapshots could not show. The Temporal module uses exactly this since its temporal/v0.10.0 tag: it cancels and restarts the timers and activities of a state that is left and entered again. ADR-0008 has the design.
Metadata for tools, not for the engine
A guard is a Go function, so a diagram cannot say what it checks. CondMeta lets you describe it:
engine.TransitionConfig[Ctx, Evt]{
Guard: approved,
CondMeta: action.Gates(
action.Field("$.score").Gte(60),
action.Field("$.status").Eq("approved"),
).Sample(`{"score": 65, "status": "approved"}`),
}
It never affects whether a transition fires; the guard still decides. It only travels in the machine’s descriptor so a viewer can show it. describe.UIStateOf does the same for per-state view models, action.Named and TransitionConfig.GuardName give actions and guards readable names, and v0.9.0 added a free-form Meta map on states and transitions, so a host can hang a form name or a button title on a state instead of keeping a parallel table keyed by state path.
Two later additions are for the same audience:
Machine.Lint(v0.10.0, extended inv0.13.0) reports states that are legal but probably mistakes: unreachable states, dead ends, anOnDonethat can never fire, and a transition shadowed by an unconditional one listed before it.CreateMachinestill accepts all of these, so the intended use is callingLintfrom a test. The descriptor also marks the unconditional transition that ends a guarded list as the fallback.Machine.Sources(v0.14.0, corrected inv0.14.1) reports where the machine and each guard and action are written: file, line and function, plus the module version and VCS revision of the build. It’s kept out of the descriptor on purpose, so a descriptor doesn’t change when a line number does. This is what lets fate-studio jump from a state on the chart to the Go line behind it.
What’s in it
| Statechart concept | In fate |
|---|---|
| Atomic / compound / parallel / final states | engine.NodeAtomic / NodeCompound / NodeParallel / NodeFinal |
| Shallow & deep history | engine.NodeHistory with HistoryShallow / HistoryDeep |
| Guards | TransitionConfig.Guard plus action.And / Or / Not / StateIn |
| Entry, exit and transition actions | action.Assign, Raise, Log, EnqueueActions, Named |
| Delayed transitions | StateNodeConfig.After |
| Invoked or spawned child actors | StateNodeConfig.Invoke |
| Persistence | Actor.Persist / engine.NewActorFromSnapshot |
| Asking before sending | Actor.Can, NextEvents, Enabled, Preview |
| What happened | Actor.SubscribeSteps |
| Tooling metadata | CondMeta, Meta, UIState, Machine.Lint, Machine.Sources |
| Rendering and diffing | fate/render, fate/diff |
The hardest part lives in engine/algorithm.go, which adapts the SCXML transition algorithm: find the LCCA (least common compound ancestor) of source and target, then build the exit set deepest-first and the entry set outermost-first. That ordering isn’t cosmetic: it determines the order exit and entry actions run in, and getting it wrong means actions running against states that are no longer active. The parallel bug above is what getting it wrong looks like.
Around the engine
fate/httphandlerwraps a machine as an HTTP simulator: an SSE stream plus endpoints to send events, fire timers, resolve invocations, undo and export. It speaks the same wire format as fate-studio’s simulator, so the studio can proxy to a machine running inside your own service. It has no authentication and is meant for development only;SECURITY.mdsays so.fate/snapshotwrites a machine’s descriptor to<dir>/<name>.json. Point it at.fate/, the directory fate-studio loads by default, and the studio can draw the machine without running anything.cmd/fateis a small CLI (go install github.com/arisros/fate/cmd/fate@latest) that renders descriptors to ASCII, Mermaid or a JSON graph, inspects a snapshot and diffs two of them.fate/temporalis the separate module that runs a machine inside a Temporal workflow. It pins a published engine tag rather than a local copy, currentlyv0.11.0, so CI tests it against what adopters actually get.
Status
Still v0.x: the API can change between minor releases until v1.0.0, and breaking changes are listed explicitly in CHANGELOG.md. CI also enforces that: on every pull request an API compatibility job runs apidiff against the base branch, and an incompatible change fails unless the PR title carries a breaking marker (feat!:).
Releases are cut by release-please, which keeps a release PR open and, when it is merged, tags the version and lets GoReleaser attach the CLI binaries. Every GitHub Action is pinned to a commit SHA, Dependabot watches the actions, the Temporal module and the docs site’s npm packages, and the test suite (260 tests across 45 files, run with -race on Go 1.24 and 1.25) has an 85% coverage gate. The documentation lives in the repo’s docs/ directory and is served at fate.arisjirat.com.