Compile, lint, draw and run an order chart
In seven commands, you compile an order chart and catch a misspelt timeout event with lint without running it. After the fix, a scripted session retries an unanswered charge after 30 seconds and ends in paid.
mise use github:tinyactors-dev/tinyactors-core@0.5.0tinyactors-core 0.5.0, 26 November 2026What changed
1. Compile the order chart
Your order chart starts in open to collect items, moves to paying at checkout and sends a charge request for the order total. When the payment service does not answer within 30 seconds, paying sends a delayed timeout event so the order retries up to three times before moving to cancelled.
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="order" datamodel="ecmascript" initial="open">
<datamodel>
<data id="total" expr="0"/>
<data id="attempts" expr="0"/>
<data id="charge" expr="null"/>
</datamodel>
<state id="open">
<transition event="item.added" cond="_event.data.price > 0">
<assign location="total" expr="total + _event.data.price"/>
</transition>
<transition event="checkout" cond="total > 0" target="paying"/>
<transition event="cancel" target="cancelled"/>
</state>
<state id="paying">
<onentry>
<assign location="attempts" expr="attempts + 1"/>
<send type="payments" target="charges" event="charge" id="pay">
<param name="amount" expr="total"/>
</send>
<send event="payment.timeout" delay="30s" id="deadline"/>
</onentry>
<onexit>
<cancel sendid="deadline"/>
</onexit>
<transition event="charge.ok" target="paid">
<assign location="charge" expr="_event.data.charge"/>
</transition>
<transition event="charge.declined error.communication payment.timedout" cond="attempts < 3" target="paying"/>
<transition event="charge.declined error.communication payment.timedout" target="cancelled"/>
</state>
<state id="paid">
<transition event="shipped" target="shipped"/>
</state>
<final id="shipped">
<donedata>
<param name="charge" expr="charge"/>
</donedata>
</final>
<final id="cancelled"/>
</scxml>Save this chart as order.scxml and run tinyactors compile with -o so the compiler writes an image file at order.tai for your application. You will see zero diagnostics because the SCXML syntax is valid, which still leaves logic errors in your state transitions unchecked.
tinyactors compile order.scxml -o order.tai# Compile
- **Compiled**: yes
- **Output**: order.tai
- **Emit**: image
- **Bytes**: 2776
- **Hash**: c4c69c91aae0ba21
- **Charts**: 1
- **Boot actors**: 1
## Diagnostics
_none_2. Catch unhandled events with lint
Valid syntax does not guarantee your order can finish, so run tinyactors lint to inspect the chart's transition logic without executing a session. The linter compares events sent to the chart against its transitions, which lets you catch unhandled events before testing a live session.
tinyactors lint order.scxml# Lint
- **Warnings**: 1
- **Notes**: 0
- **Denied**: 0
## Findings
| Rule | Severity | Chart | State | Transition | Event | Line | Message |
| --- | --- | --- | --- | --- | --- | --- | --- |
| unhandled-event | warning | order | paying | | payment.timeout | 0 | the event is sent to the chart itself, and no transition there handles it |The report shows one unhandled-event warning in paying because that state sends payment.timeout to the chart while its transitions listen for payment.timedout. Without a matching transition, an order whose payment service never answers misses the 30-second timeout event and stays in paying instead of retrying or cancelling.
3. Fix the event and check again
Update both transitions in paying from payment.timedout to payment.timeout so their event list matches what the state sends after 30 seconds. Changing both lines fixes the retry loop when attempts < 3 and restores the final transition to cancelled after three failed attempts.
<transition event="charge.declined error.communication payment.timeout" cond="attempts < 3" target="paying"/>
<transition event="charge.declined error.communication payment.timeout" target="cancelled"/>Next, run tinyactors check with -W to validate order.scxml and turn compiler warnings into errors without writing an output file. Seeing Valid: yes and zero diagnostics confirms that the updated chart compiles with neither syntax errors nor warnings.
tinyactors check -W order.scxml# Check
## Inputs
- order.scxml
- **Valid**: yes
- **Bytes**: 2720
- **Hash**: 5e66ab57693504aa
- **Charts**: 1
- **Boot actors**: 1
## Diagnostics
_none_Now run tinyactors lint with --deny all so any remaining warning or note fails the command with exit code 1. Because both transitions now handle payment.timeout, lint reports zero findings and exits with 0, which shows no unhandled timeout events remain.
tinyactors lint --deny all order.scxml# Lint
- **Warnings**: 0
- **Notes**: 0
- **Denied**: 0
## Findings
_none_4. Trace the path to shipped
Run tinyactors path with --to shipped to verify that an order starting in open can reach the final shipped state. The output lists three transitions through paying and paid and notes the total > 0 condition on checkout, so an order must have a positive total before charging.
tinyactors path order.scxml --to shipped# Path
- **Chart**: order
- **From**:
- **To**: shipped
- **Result**: found
- **Meaning**: the steps below reach it, if their events come and their conditions hold
- **Transitions**: 3
- **Explored**: 5
- **Start**: open
## Steps
| Step | Events | Eventless | Condition | Source | Targets | Active |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | checkout | no | total > 0 | open | paying | paying |
| 2 | charge.ok | no | | paying | paid | paid |
| 3 | shipped | no | | paid | shipped | shipped |5. Draw the order chart
Run tinyactors graph with -f svg and redirect the output to order.svg to inspect your order chart as state boxes and labelled transition routes. The resulting diagram adapts to your system's light or dark setting and lets you verify that paying loops back to itself on retries before reaching paid or cancelled.
tinyactors graph -f svg order.scxml > order.svg6. Run an order session
To test your retry flow, save these JSON-RPC requests in session.jsonl so you can pipe them into tinyactors run one request per line. The script spawns an order actor, adds a pen priced at 1200, sends checkout, advances the clock by 30 seconds and answers the second charge.
{"jsonrpc":"2.0","id":1,"method":"run.spawn","params":{"chart":"order","name":"order-1"}}
{"jsonrpc":"2.0","id":2,"method":"run.send","params":{"target":1,"event":"item.added","data":{"sku":"pen","price":1200}}}
{"jsonrpc":"2.0","id":3,"method":"run.send","params":{"target":1,"event":"checkout"}}
{"jsonrpc":"2.0","id":4,"method":"run.turn"}
{"jsonrpc":"2.0","id":5,"method":"run.advanceTime","params":{"by":"30s"}}
{"jsonrpc":"2.0","id":6,"method":"run.turn"}
{"jsonrpc":"2.0","id":7,"method":"run.send","params":{"target":1,"event":"charge.ok","sendid":"pay","origintype":"payments","data":{"charge":"ch_81"}}}
{"jsonrpc":"2.0","id":8,"method":"run.turn"}
{"jsonrpc":"2.0","id":9,"method":"actor.state","params":{"session":1}}Run tinyactors run with --io-processor payments and redirect session.jsonl to standard input so your session handles outgoing payments requests without an external service. When the order enters paying, the command writes an effect.send notification for each charge event, which lets your script observe and answer outgoing payment requests.
tinyactors run --io-processor payments order.scxml < session.jsonl{"jsonrpc":"2.0","id":1,"result":{"session":1,"address":"tinyactors://tinyactors-run/#_scxml_1"}}
{"jsonrpc":"2.0","id":2,"result":{}}
{"jsonrpc":"2.0","id":3,"result":{}}
{"jsonrpc":"2.0","method":"effect.send","params":{"batch":1,"index":0,"session":1,"type":"payments","target":"charges","event":"charge","sendid":"pay","data":{"amount":1200},"traceparent":"00-bba5ad4a1f842e59ffef8375d9ebcaca-94e8a8f3181c87c4-03","waiting":true}}
{"jsonrpc":"2.0","id":4,"result":{"status":"idle","runs":2,"fuel":22,"time":0,"nextDeadline":30000000000}}
{"jsonrpc":"2.0","id":5,"result":{"time":30000000000,"wallNs":30000000000}}
{"jsonrpc":"2.0","method":"effect.send","params":{"batch":2,"index":0,"session":1,"type":"payments","target":"charges","event":"charge","sendid":"pay","data":{"amount":1200},"traceparent":"00-bba5ad4a1f842e59ffef8375d9ebcaca-14c089f1b8c1eac4-03","waiting":true}}
{"jsonrpc":"2.0","id":6,"result":{"status":"idle","runs":2,"fuel":14,"time":30000000000,"nextDeadline":60000000000}}
{"jsonrpc":"2.0","id":7,"result":{}}
{"jsonrpc":"2.0","id":8,"result":{"status":"idle","runs":1,"fuel":12,"time":30000000000,"nextDeadline":null}}
{"jsonrpc":"2.0","id":9,"result":{"value":"paid","history":{}}}Request 4 leaves the actor idle with a 30-second deadline, so advancing the clock in request 5 lets request 6 fire payment.timeout and emit a second charge notification. Request 7 then supplies charge.ok, which cancels the next 30-second deadline in request 8 when the actor leaves paying. Request 9 inspects the actor state and finds it in paid.
Put the checks in your build
Once your chart works locally, run check and lint in CI so your build catches syntax errors or unhandled events before a pull request merges. You can pair those checks with fmt and diff, or drive sessions from a script that pauses and answers outgoing sends.
- Check charts in CIAutomate
check,lint,fmtanddiffon every pull request. - Drive a host from a scriptPause an outgoing send until your script replies to it.