@typeonce/effect-machine 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,680 @@
1
+ # Effect Machine agent guide
2
+
3
+ This is the model-facing reference for the currently published
4
+ `@typeonce/effect-machine` API. Prefer these patterns over reconstructing the API
5
+ from its internal implementation.
6
+
7
+ ## Public imports
8
+
9
+ ```ts
10
+ import { Machine } from "@typeonce/effect-machine"
11
+ import { AtomMachine } from "@typeonce/effect-machine/reactivity"
12
+ import { ClusterMachine } from "@typeonce/effect-machine/cluster"
13
+ ```
14
+
15
+ Do not import the published package as `effect/unstable/machine`. The package is
16
+ currently coupled to the exact Effect peer version listed in its `package.json`.
17
+
18
+ ## Definition order
19
+
20
+ Use this order so inference has all schemas available when handlers are
21
+ declared:
22
+
23
+ 1. Domain schemas used by state and event fields.
24
+ 2. Tagged state schemas.
25
+ 3. Tagged public-event, internal-event, and emitted-event schemas.
26
+ 4. `Machine.defineStates`.
27
+ 5. `Machine.make`, including input, events, internal events, emits, and the
28
+ initial function.
29
+ 6. One or more `.handle(...)` calls.
30
+ 7. Child descriptors.
31
+ 8. Runtime, Atom, or Cluster adapters.
32
+
33
+ `Schema.TaggedUnion` avoids one class declaration per case:
34
+
35
+ ```ts
36
+ const State = Schema.TaggedUnion({
37
+ Idle: {},
38
+ Saving: { draft: Draft },
39
+ Failed: { message: Schema.String }
40
+ })
41
+
42
+ const Event = Schema.TaggedUnion({
43
+ Save: {}
44
+ })
45
+
46
+ const InternalEvent = Schema.TaggedUnion({
47
+ Saved: { id: Schema.String },
48
+ SaveFailed: { message: Schema.String }
49
+ })
50
+
51
+ const States = Machine.defineStates(State.cases)
52
+ ```
53
+
54
+ Construct values with `State.cases.Idle.make({})` or
55
+ `Event.cases.Save.make({})`. Use `Schema.TaggedClass` instead when a case needs
56
+ class methods or nominal class identity.
57
+
58
+ ## Hard invariants
59
+
60
+ - `Machine.make({ initial })` expects a function, including for `Schema.Void`
61
+ input.
62
+ - State, emit, input, and output schemas validate their runtime boundaries.
63
+ Event schemas provide decoders, but the local public/internal distinction is
64
+ a TypeScript boundary; Cluster additionally validates public commands at its
65
+ transport boundary.
66
+ - Return snapshots or typed target-builder results from transitions. Do not
67
+ return raw decoded state values.
68
+ - Effects returned by handlers are planning Effects. Wrap external effects in
69
+ `Machine.action`.
70
+ - Put data on the narrowest state where it is valid. Put data shared by sibling
71
+ phases on their compound parent.
72
+ - Declare finality only in the state definition. Do not put `type: "final"` in
73
+ a handler.
74
+ - Every declared output schema needs a matching handler implementation before
75
+ planning or execution.
76
+ - `parents` keys are full dotted paths.
77
+ - Invoke lifetimes follow state entry and exit, not the spelling of the target
78
+ builder.
79
+ - Recover expected invoked Effect failures into machine events. Unrecovered
80
+ child failures terminate the owning machine.
81
+ - Reuse the exact child descriptor value for `invokeMachine`, `sendTo`, and
82
+ child lookup.
83
+ - `events` is the public input protocol. `internalEvents` contains machine-local
84
+ deliveries such as invoke results and invoked-child emissions. Handlers see
85
+ both; typed public `send` and `Machine.plan` accept only `events`.
86
+ - Event tags in `events` and `internalEvents` must be disjoint.
87
+ - Event tags must also be unique within each protocol list.
88
+
89
+ ## Canonical API choices
90
+
91
+ Choose one helper from the intent, and reach for the lower-level form only when
92
+ its extra control is required:
93
+
94
+ - Bind a shared Atom runtime once with `AtomMachine.bind(runtime)`, then use the
95
+ returned `make`. Use `AtomMachine.make(machine)` for a service-free machine.
96
+ - Use `Machine.invokeEffect` for a typed one-shot Effect and `Machine.after` for
97
+ a timer. Use `Machine.invoke` with `Machine.effect` only for custom child
98
+ process behavior or snapshot mapping.
99
+ - Use `Machine.child(id, machine)` for a complete statechart descriptor and
100
+ `Machine.childAddress<Event>(id)` for a low-level process address. An
101
+ invocation is addressable only when `Machine.invoke` receives that address
102
+ explicitly.
103
+ - Stage external effects with `Machine.action`; its optional second argument is
104
+ the same operation with a returned transition value, not a separate action
105
+ API.
106
+
107
+ ## Atomic, compound, parallel, and history states
108
+
109
+ Use an atomic state when no child phase can be active beneath it.
110
+
111
+ Use a compound state when exactly one child phase is active. It must declare an
112
+ `initial` child:
113
+
114
+ ```ts
115
+ const FormState = Schema.TaggedUnion({
116
+ Form: { draft: Schema.String },
117
+ Editing: {},
118
+ Saving: {}
119
+ })
120
+
121
+ const FormStates = Machine.defineStates({
122
+ Form: {
123
+ schema: FormState.cases.Form,
124
+ initial: "Editing",
125
+ states: {
126
+ Editing: FormState.cases.Editing,
127
+ Saving: FormState.cases.Saving
128
+ }
129
+ }
130
+ })
131
+ ```
132
+
133
+ Use a parallel state when every direct region is active:
134
+
135
+ ```ts
136
+ const ParallelState = Schema.TaggedUnion({
137
+ Screen: {},
138
+ Network: {},
139
+ Online: {},
140
+ Offline: {},
141
+ Panel: {},
142
+ Closed: {},
143
+ Open: {}
144
+ })
145
+
146
+ const ParallelStates = Machine.defineStates({
147
+ Screen: {
148
+ schema: ParallelState.cases.Screen,
149
+ type: "parallel",
150
+ states: {
151
+ network: {
152
+ schema: ParallelState.cases.Network,
153
+ initial: "Online",
154
+ states: {
155
+ Online: ParallelState.cases.Online,
156
+ Offline: ParallelState.cases.Offline
157
+ }
158
+ },
159
+ panel: {
160
+ schema: ParallelState.cases.Panel,
161
+ initial: "Closed",
162
+ states: {
163
+ Closed: ParallelState.cases.Closed,
164
+ Open: ParallelState.cases.Open
165
+ }
166
+ }
167
+ }
168
+ }
169
+ })
170
+ ```
171
+
172
+ Every parallel region needs an active state in initial and full snapshot
173
+ builders. The same rule applies when a local or branch target enters an
174
+ inactive nested parallel state.
175
+
176
+ Use `type: "final"` for a terminal leaf in `Machine.defineStates`. A final
177
+ child completes its compound parent. Put `onDone` on that completed parent,
178
+ never on the final leaf. The definition owns the output schema and the handler
179
+ computes its value:
180
+
181
+ ```ts
182
+ const States = Machine.defineStates({
183
+ Done: {
184
+ schema: State.cases.Done,
185
+ type: "final",
186
+ output: Schema.String
187
+ }
188
+ })
189
+
190
+ const machine = Machine.make({
191
+ states: States.states,
192
+ events: [],
193
+ initial: () => States.initial.Done(State.cases.Done.make({}))
194
+ }).handle({
195
+ Done: {
196
+ output: () => "done"
197
+ }
198
+ })
199
+ ```
200
+
201
+ Do not repeat `type: "final"` in `handle`. Execution APIs reject a machine
202
+ until every declared output schema has an implementation.
203
+
204
+ Declare a history pseudo-state below the active parent whose configuration it
205
+ should remember. It has no schema, is excluded from active state identifiers,
206
+ and is addressed only through `target.history`:
207
+
208
+ ```ts
209
+ const States = Machine.defineStates({
210
+ checkout: {
211
+ schema: Checkout,
212
+ initial: "shipping",
213
+ states: {
214
+ shipping: Shipping,
215
+ payment: {
216
+ schema: Payment,
217
+ initial: "cardEntry",
218
+ states: {
219
+ cardEntry: CardEntry,
220
+ verifying: Verifying
221
+ }
222
+ },
223
+ recent: { type: "history" },
224
+ exact: { type: "history", history: "deep" }
225
+ }
226
+ },
227
+ support: Support
228
+ })
229
+ ```
230
+
231
+ Every history node needs a default parent snapshot for the first use:
232
+
233
+ ```ts
234
+ checkout: {
235
+ history: {
236
+ recent: { default: () => initialCheckoutSnapshot },
237
+ exact: { default: () => initialCheckoutSnapshot }
238
+ }
239
+ }
240
+ ```
241
+
242
+ Target it without a value:
243
+
244
+ ```ts
245
+ Resume: ({ target }) => target.history.checkout.exact()
246
+ ```
247
+
248
+ Deep history restores the complete remembered subtree and its decoded values.
249
+ Shallow history restores only parent and direct-child values. If the remembered
250
+ child is compound, its configured initial child needs a freshly constructed
251
+ value, so implement `initial` only on paths required by shallow history:
252
+
253
+ ```ts
254
+ payment: {
255
+ initial: ({ state }) => new CardEntry({ attempt: state.attempt, cardNumber: "" })
256
+ }
257
+ ```
258
+
259
+ The machine's readiness type tracks missing defaults and shallow initializers.
260
+ History is an overwriteable register, not a stack: restoration does not consume
261
+ it, and the next parent exit replaces it. Entry actions and invokes run again;
262
+ prior effects, actors, and timers are not rewound.
263
+
264
+ ## Choosing a target
265
+
266
+ | Builder | Use it when | What it preserves |
267
+ | ---------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------- |
268
+ | `target.local` | The destination is inside the nearest compound scope containing the source | The compound value, active ancestors, and unrelated parallel regions |
269
+ | `target.branch` | The destination is elsewhere under the active top-level root | Omitted current ancestor values and parallel regions |
270
+ | `target.full` | The destination may be under any top-level root | Nothing is inferred for a newly selected root; build its complete active snapshot |
271
+ | `target.history` | The destination is a declared history pseudo-state | Its parent's remembered configuration, or its default before the first capture |
272
+
273
+ Entering an inactive parallel state through `target.local` or `target.branch`
274
+ requires a complete callback with one selection per region. A parallel state
275
+ that is already active remains partially addressable through `target.branch`;
276
+ unmentioned active regions are preserved.
277
+
278
+ These describe configuration construction, not automatic process restart.
279
+ Machine planning compares active paths and derives the actual exit and entry
280
+ sets. A `target.full` result with the same active paths can update values without
281
+ exiting shared states. To force the source to exit and enter again:
282
+
283
+ ```ts
284
+ Refresh: {
285
+ reenter: true,
286
+ transition: ({ state, target }) =>
287
+ target.full.Ready(new Ready({ value: state.value }))
288
+ }
289
+ ```
290
+
291
+ Do not use `target.full` merely because it is easiest to discover. Prefer the
292
+ narrowest builder that expresses the intended configuration change.
293
+
294
+ Every state builder method has two construction forms:
295
+
296
+ ```ts
297
+ target.local.Ready(decodedReady)
298
+ target.local.Ready.from({ value: event.value })
299
+ ```
300
+
301
+ The direct call accepts the schema's decoded `Type`. `.from` accepts its
302
+ `~type.make.in`, so callers do not need to invoke a TaggedUnion case's `make`
303
+ or instantiate a TaggedClass. The machine resolves `.from` with
304
+ `schema.makeEffect` during planning. Constructor defaults and class identity
305
+ are retained; refinement failures use `MachineSchemaDecodeError` at the state
306
+ boundary rather than throwing synchronously. This applies recursively to
307
+ initial, full, local, branch, compound, parallel, final, and `local.with`
308
+ builders.
309
+
310
+ If `{}` satisfies the schema's constructor input, omit it:
311
+
312
+ ```ts
313
+ target.local.Idle.from()
314
+ target.local.Flow.from((flow) => flow.Idle.from())
315
+ ```
316
+
317
+ This shorthand also applies to schemas whose constructor fields are all
318
+ optional or defaulted. It does not make required fields optional. Compound and
319
+ parallel builders still require a callback selecting their active child or
320
+ every active region. Omitted input is normalized to `{}` and still passes
321
+ through `schema.makeEffect`, including refinements.
322
+
323
+ ## Reading state and parents
324
+
325
+ `Machine.defineStates` returns typed helpers:
326
+
327
+ ```ts
328
+ States.get(snapshot, "Route.Ready")
329
+ States.getWithParents(snapshot, "Route.Ready.Editing")
330
+ States.getSnapshot(snapshot, "Route.Ready")
331
+ States.matches(snapshot, "Route.Ready.Saving")
332
+ ```
333
+
334
+ All paths are checked against the definition. `context.parent` is the immediate
335
+ typed parent (`undefined` at a root). Use `parents` when another ancestor is
336
+ needed:
337
+
338
+ ```ts
339
+ parents["Route.Ready"]
340
+ parents["Route.Ready.Editing"]
341
+ ```
342
+
343
+ Do not guess short properties such as `parents.Ready`.
344
+
345
+ Use `Machine.retag(TargetCase, source, patch?)` when sibling state payloads
346
+ share fields. It removes the source discriminator, reuses only compatible
347
+ fields, and requires a patch for every missing or incompatible required field.
348
+ Prefer moving broadly shared data to the compound parent rather than retagging
349
+ it through every phase.
350
+
351
+ ## Planning, actions, raised events, and emissions
352
+
353
+ A transition may return a target directly or compute it in an Effect:
354
+
355
+ ```ts
356
+ Submit: Effect.fn(function* ({ state, target }) {
357
+ const service = yield* SaveService
358
+ const canSave = yield* service.validate(state.draft)
359
+
360
+ return canSave ? target.local.Saving(new Saving({ draft: state.draft })) : undefined
361
+ })
362
+ ```
363
+
364
+ That Effect runs during planning. External side effects must be staged:
365
+
366
+ ```ts
367
+ Submit: ({ target }) => Machine.action(writeAuditLog, target.local.Saving(new Saving({})))
368
+ ```
369
+
370
+ `Machine.action(effect)` stages the action and returns `void`.
371
+ `Machine.action(effect, next)` stages the same action and returns `next`, which
372
+ is convenient when the transition does not otherwise need an Effect generator.
373
+
374
+ The managed runtime executes staged actions before publishing the planned
375
+ state. If an action fails, it retains the previous state and suppresses planned
376
+ emissions.
377
+
378
+ Plans have a discriminated completion result:
379
+
380
+ ```ts
381
+ const planned = yield * Machine.plan(machine, state, event)
382
+ if (planned.done) {
383
+ planned.output // schema-derived structural terminal union
384
+ }
385
+ ```
386
+
387
+ When `done` is false, `output` is `undefined`. `MachineRef.join` and invoked
388
+ child `onDone.output` use the same structural terminal union rather than adding
389
+ an unconditional optional value. Output-less structural terminal paths
390
+ contribute `undefined`; active atomic roots do not. Handler behavior can make
391
+ the type conservative—for example, a root `onDone` transition can move away
392
+ before that root becomes the machine's terminal result.
393
+
394
+ `raise` queues an event for the same machine's current macrostep. `emit` queues
395
+ an event for the parent. Both operations validate their schemas.
396
+
397
+ ## Public and internal event protocols
398
+
399
+ `events` defines the protocol callers can send. `internalEvents` augments the
400
+ union handled inside the statechart:
401
+
402
+ ```ts
403
+ const machine = Machine.make({
404
+ states: States.states,
405
+ events: [Event.cases.Save],
406
+ internalEvents: [InternalEvent.cases.Saved, InternalEvent.cases.SaveFailed],
407
+ initial: () => States.initial.Idle(State.cases.Idle.make({}))
408
+ })
409
+ ```
410
+
411
+ Use the exported utility types when another API must preserve the boundary:
412
+
413
+ ```ts
414
+ type PublicEvent = Machine.Machine.InputEvent<typeof machine>
415
+ type AnyHandledEvent = Machine.Machine.Event<typeof machine>
416
+ ```
417
+
418
+ `MachineRef.send`, `machineAtom.send`, and `Machine.plan` use `InputEvent` at
419
+ their TypeScript boundary. Transition handlers, raised events, invoke results,
420
+ and mapped child events use the complete `Event` union. The local planner and
421
+ runtime intentionally share the complete decoder to support those internal
422
+ deliveries, so JavaScript or `any` can bypass the local public distinction.
423
+ Cluster RPC payloads are additionally decoded against the public `events`
424
+ schemas at the transport boundary. Never repeat an `_tag` within a list or
425
+ across both configuration lists.
426
+
427
+ ## Recoverable state-scoped work
428
+
429
+ Use `Machine.invokeEffect` for a one-shot Effect. Its callbacks preserve the
430
+ typed success and failure channels while mapping both into machine events:
431
+
432
+ ```ts
433
+ invoke: ({ state }) =>
434
+ Machine.invokeEffect({
435
+ id: "save",
436
+ effect: SaveService.save(state.draft),
437
+ onSuccess: (entry) => new Saved({ entry }),
438
+ onFailure: (error) => new SaveFailed({ message: error.message })
439
+ })
440
+ ```
441
+
442
+ The owning state scopes the child. Owner-driven interruption on state exit is
443
+ normal cancellation and stale output is ignored. A child Effect that defects
444
+ or self-interrupts fails the parent. Omit `onFailure` only when the Effect error
445
+ type is `never`; defects and interruption are not mapped.
446
+
447
+ Successful non-void output is delivered as a parent event. Include every
448
+ possible mapped result schema in the parent machine's `internalEvents` array and
449
+ add handlers for the relevant tags. Leave defects and interruption fatal;
450
+ recover only expected typed failures.
451
+
452
+ A cancellable timer uses `Machine.after`:
453
+
454
+ ```ts
455
+ invoke: Machine.after("3 seconds", new ClearStatus({}), {
456
+ id: "clear-status"
457
+ })
458
+ ```
459
+
460
+ The timer starts on state entry and is interrupted on exit. Supply an explicit
461
+ id when more than one active timer could deliver the same event tag. Use
462
+ lower-level `Machine.invoke` with `Machine.effect` when custom child logic or
463
+ snapshot mapping is required. In that API, `id` is only the invocation's
464
+ state-local lifecycle key. To communicate with the invocation, create a
465
+ `Machine.childAddress<Event>("worker")` and pass it as `address`; TypeScript
466
+ checks the address protocol against the child logic. Lifecycle ids must be
467
+ unique among simultaneously active invokes owned by the same state.
468
+
469
+ ## Invoked child statecharts
470
+
471
+ Create a complete child-statechart descriptor:
472
+
473
+ ```ts
474
+ const Editor = Machine.child("editor", EditorMachine)
475
+ ```
476
+
477
+ Invoke it from its owning state:
478
+
479
+ ```ts
480
+ invoke: Machine.invokeMachine({
481
+ child: Editor,
482
+ input: editorInput,
483
+ onDone: ({ output }) => new EditorCompleted({ output })
484
+ })
485
+ ```
486
+
487
+ Use `Editor` for:
488
+
489
+ ```ts
490
+ Machine.sendTo(Editor, new Reset({}))
491
+ parentRef.child(Editor)
492
+ parentAtom.child(Editor)
493
+ ```
494
+
495
+ Child emissions, mapped snapshots, and mapped completion output are delivered as
496
+ parent events and must be accepted by the parent's `internalEvents` list.
497
+ Invoked child IDs must be unique while simultaneously active.
498
+
499
+ Descriptors with the same id and machine identity address the same child, even
500
+ when independently constructed. The descriptor objects themselves are not
501
+ canonicalized. Prefer exporting one descriptor as the application boundary.
502
+ Use the separate
503
+ `Machine.childAddress<Event>(id)` constructor only for lower-level process
504
+ logic that does not have a complete machine descriptor.
505
+
506
+ ## AtomMachine and React
507
+
508
+ `AtomMachine.make(machine, ...input)` works when the machine has no external
509
+ service requirements. For an application runtime, the canonical form is to
510
+ bind it once at the composition boundary:
511
+
512
+ ```ts
513
+ const runtime = Atom.runtime(AppLayer)
514
+ const machines = AtomMachine.bind(runtime)
515
+ const machineAtom = machines.make(machine, input)
516
+ ```
517
+
518
+ One bridge owns one machine instance per `AtomRegistry`. In React:
519
+
520
+ 1. Render a `RegistryProvider` from `@effect/atom-react`.
521
+ 2. Keep a component-owned bridge referentially stable, normally with
522
+ `useMemo`.
523
+ 3. Use scalar dependencies that define when the machine should restart.
524
+ 4. Expect a new bridge identity to create a new instance once mounted.
525
+
526
+ The root bridge shapes are:
527
+
528
+ ```ts
529
+ machineAtom.state
530
+ // Atom<AsyncResult<State, StartError>>
531
+
532
+ machineAtom.result
533
+ // Atom<AsyncResult<State, StartError | RuntimeError>>
534
+
535
+ machineAtom.snapshot
536
+ // Atom<AsyncResult<RuntimeSnapshot<State, RuntimeError, Output>, StartError>>
537
+ ```
538
+
539
+ `state` remains a successful last-state value after a post-start runtime
540
+ failure. Prefer `result` for ordinary fail-aware UI state. Use `snapshot` when
541
+ the full lifecycle, completion output, cause, or stopped status matters.
542
+
543
+ Use equality-aware selectors instead of repeating AsyncResult/Option unwrapping.
544
+ Paths and selected values are inferred from the bridge snapshot, so do not pass
545
+ the `DefinedStates` object:
546
+
547
+ ```ts
548
+ AtomMachine.select(machineAtom, "Ready")
549
+ AtomMachine.matches(machineAtom, "Ready.Saving")
550
+ AtomMachine.selectChild(childAtom, "Editing")
551
+ AtomMachine.matchesChild(childAtom, "Editing")
552
+ ```
553
+
554
+ Like ordinary Effect Atom combinators, each selector call returns a derived
555
+ atom. Define it at a stable composition boundary or memoize it when constructing
556
+ it inside a component.
557
+
558
+ An invoked child bridge adds an inactivity axis. Keep the descriptor stable;
559
+ the bridge uses Effect's `Atom.family` identity semantics:
560
+
561
+ ```ts
562
+ const editorAtom = parentAtom.child(Editor)
563
+
564
+ editorAtom.state
565
+ // Atom<AsyncResult<Option<State>, StartError>>
566
+ ```
567
+
568
+ `Option.none()` means the child is not currently active or has not become
569
+ active yet. A child command while inactive fails with `ChildNotActiveError`.
570
+ Use `AtomMachine.ChildMachineAtom<typeof Editor>` for a descriptor-based child prop,
571
+ or `AtomMachine.ChildOf<typeof parentAtom, typeof Editor>` to infer the exact
572
+ bridge from a parent.
573
+
574
+ ## Persistence
575
+
576
+ Use `Machine.encodeSnapshot` and `Machine.decodeSnapshot` for validated logical
577
+ statechart data. Persist machine identity and an application migration/version
578
+ next to the encoded snapshot.
579
+
580
+ Encoding does not preserve:
581
+
582
+ - running invokes or spawned children;
583
+ - subscriptions, timers, or services;
584
+ - the machine definition;
585
+ - application migration metadata.
586
+
587
+ Do not treat decoding as resuming the previous process. It reconstructs logical
588
+ state only.
589
+
590
+ ## Common compiler errors
591
+
592
+ ### `initial` is not callable
593
+
594
+ Wrap the initial builder result:
595
+
596
+ ```ts
597
+ initial: () => States.initial.Idle(new Idle({}))
598
+ ```
599
+
600
+ ### Invoked child output must be a machine event
601
+
602
+ Add the output's tagged schema to the parent machine's `internalEvents` array,
603
+ or map/ignore the output before it reaches the parent.
604
+
605
+ ### Invoked child emits events not accepted by the parent
606
+
607
+ Add the child's emitted schemas to the parent machine's `internalEvents` array:
608
+
609
+ ```ts
610
+ events: [Submit],
611
+ internalEvents: [...ChildMachine.emits]
612
+ ```
613
+
614
+ ### An internal event is rejected by `send`
615
+
616
+ This is intentional. Public input boundaries accept only schemas declared in
617
+ `events`. Handle the event as an invoke result, child delivery, or raised event;
618
+ move it to `events` only if external callers should genuinely be allowed to
619
+ send it.
620
+
621
+ ### Public and internal event tags overlap
622
+
623
+ Give the cases distinct `_tag` values. The split is a protocol boundary, so one
624
+ tag cannot be both externally sendable and machine-local.
625
+
626
+ ### Missing output implementation
627
+
628
+ An output schema is a runtime contract, not an optional annotation. Add the
629
+ corresponding nested handler:
630
+
631
+ ```ts
632
+ Done: {
633
+ output: ({ state }) => state.value
634
+ }
635
+ ```
636
+
637
+ Keep `type: "final"` and `output: Schema...` in the state definition; do not
638
+ repeat the final marker in this handler.
639
+
640
+ ### `type: "final"` is rejected by `handle`
641
+
642
+ Move it to `Machine.defineStates`. Definitions own statechart topology;
643
+ handlers own behavior.
644
+
645
+ ### Parent property does not exist
646
+
647
+ Use its full path:
648
+
649
+ ```ts
650
+ parents["Route.Ready"]
651
+ ```
652
+
653
+ ### Child descriptor types are unrelated
654
+
655
+ Use the descriptor exported by the module that configured `invokeMachine`.
656
+ An independently created descriptor with the same id and machine identity also
657
+ matches; the same id paired with a different machine remains a distinct child.
658
+
659
+ ### Child atom start error defaults to `unknown`
660
+
661
+ `ChildMachineAtom<Child>` is suitable for a general boundary because its startup
662
+ error defaults to `unknown`. Atoms created with an `AtomRuntime<R, E>` include
663
+ `E` in their startup error type. Use `ChildOf<ParentAtom, Child>` to infer that
664
+ exact channel from a parent instead of restating it manually.
665
+
666
+ ### Handler tree is too deeply nested
667
+
668
+ Type inference traverses at most eight nested handler objects. Split or flatten
669
+ a deeper statechart instead of casting away the diagnostic.
670
+
671
+ ## Unsupported and intentionally imperative features
672
+
673
+ The current API does not include:
674
+
675
+ - declarative first-class guards;
676
+ - a complete inspectable graph for arbitrary transition Effects.
677
+
678
+ Use ordinary TypeScript conditions for guards and `Machine.after` for
679
+ state-scoped timers. Do not invent undocumented state-node properties such as
680
+ `guard`.