Skip to content

Align send/sendTo error types and clean up step and host internals - #324

Merged
SandroMaglione merged 2 commits into
mainfrom
step-cleanup-and-send-types
Nov 28, 2026
Merged

SandroMaglione merged 2 commits into
mainfrom
step-cleanup-and-send-types

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

Follow-up cleanup and alignment pass over the unified step/host architecture from #323:

  1. Deduplicate childless step construction in step.ts: Extracted a single childlessStep helper inside build shared by advance, move (now delegating to advance), and moveChildlessOwned (preserving its zero-allocation in-place snapshot return path while sharing step creation when a Step is returned). Full reference-vs-indexed and owned-vs-persistent differential coverage is preserved.
  2. Align every send and sendTo surface with its runtime behavior: Every caller-awaited send / sendTo Effect now includes MachineSchemaDecodeError in its error channel and rejects events refused by the receiving machine's schema while leaving the receiver running across LocalMachine, AtomMachine, and ClusterMachine. Transition commands (enqueue.sendTo) have no waiting caller and continue to deliver directly (failing the receiver on LocalMachine, or refusing the sending step on ClusterMachine).
  3. Rename stale planner strategy names and update comments:
    • Renamed the two local conformance columns from LocalMachine (generic) / LocalMachine (compiled) to LocalMachine (reference planner) / LocalMachine (indexed planner) (only the header row of matrix.txt changed; all cell values are unchanged).
    • Replaced "generic" | "compiled" test strategy parameters in process.ts and internal tests with LocalPlannerStrategy = "reference" | "indexed" (preserving runtime.ts's startProcessWithStrategyForTesting compatibility with perf/runtime/counter.mjs).
    • Simplified selectExecutionPlanForTesting in executionPlan.ts to delegate to cached referenceExecutionPlan / compileExecutionPlan.
    • Updated stale comments in step.ts, runtime.ts, runtimeCompiled.ts, runtimeProtocol.ts, and CONTRIBUTING.md (removing references to the deleted runtimeGeneric.ts).
  4. Document MachineTest detours in trace.ts: Verified that neither detour can move through step.start / step.send without breaking MachineTest's public contract (InitialTrace.startingState, effectful RunServices<M>, raw RunError<M> vs StartupError, and idempotent post-final Machine.plan behavior) and documented the exact constraints at both call sites.
  5. Deep review cleanups:
    • Fixed: Moved stepHost.ts's direct kernel.plan.initial + toStartupFailure bypass onto kernel.startSnapshot in step.ts (with differential coverage in stepDifferential.test.ts); removed redundant entry._tag === "Initial" check and Exit.Success casts in stepHost.ts; replaced this as unknown as Children cast in step.ts Planning with a default parameter; removed dead runCommands in commandRuntime.ts; replaced unused sendParent on ProcessInitialContext/StartInternalOptions with deliverTo (eliminating an extra per-invoked-child closure); switched clusterInstance.ts snapshotFor from last.microsteps.length > 0 to last.planned to avoid eagerly materializing microstep snapshots.
    • Noted without changing (out of scope — behavioral, public API, or persisted Cluster storage): stepHost.ts exitsWork checking step.exited (moving settled work into MachineStep.Step.stop would change MachineStep.test.ts); testing/machine/work.ts reading work[Step.WorkTypeId].channels; clusterWork.ts supportOf reading toImpl(machine).handlers directly; clusterInstance.ts snapshotForCommit re-reading isFinal/getFinalOutputEffect and childTarget resolving persisted child ids via ClusterProgress.

send / sendTo audit

Surface Host(s) Before (type / behavior on refused event) After (type / behavior on refused event)
MachineRef.send Local StoppedError | MachineSchemaDecodeError / rejects, receiver stays active Unchanged
MachineTarget.send (self) Local StoppedError | MachineSchemaDecodeError / delivered & failed receiver StoppedError | MachineSchemaDecodeError / rejects, receiver stays active
MachineTarget.send (parent) Local StoppedError | MachineSchemaDecodeError / delivered & failed parent StoppedError | MachineSchemaDecodeError / rejects, parent stays active
MachineTarget.send (external ref) Local StoppedError | MachineSchemaDecodeError / rejects, receiver stays active Unchanged
MachineTarget.send (self, parent, ClusterMachine.target) Cluster StoppedError | MachineSchemaDecodeError / died with Rejected("InvalidEvent") StoppedError | MachineSchemaDecodeError / rejects with MachineSchemaDecodeError, entity stays active
ChildOwner.sendTo Local, Cluster StoppedError / failed child (Local) or died (Cluster) StoppedError | MachineSchemaDecodeError / rejects, child stays active
Machine.sendTo(child) / ChildMachineRuntime.sendTo Local, Cluster StoppedError / failed child (Local) or died (Cluster) StoppedError | MachineSchemaDecodeError / rejects, child stays active
Machine.sendTo(address) / MachineRuntime.sendTo Local StoppedError / failed child machine (or delivered to Logic) StoppedError | MachineSchemaDecodeError / rejects if addressed child is a machine (delivers to Logic), child stays active
Logic.Endpoint.send / Logic.InitialContext.sendTo Local StoppedError (endpoint & address) / delivered & failed receiver StoppedError | MachineSchemaDecodeError / rejects if receiver is a machine, receiver stays active
MachineStep.Children.sendTo Machine.toStep StoppedError StoppedError | MachineSchemaDecodeError
AtomMachine MachineAtom.send / ChildMachineAtom.send Atom StoppedError | MachineSchemaDecodeError (+ ChildNotActiveError) / rejects, stays active Unchanged (focused coverage added)
ClusterMachine Client.send Cluster Rejected | ClientError / rejects with Rejected("InvalidEvent"), entity stays active Unchanged
enqueue.sendTo transition commands Local, Cluster No waiting caller / fails receiver (Local) or refuses sender step (Cluster) Unchanged (focused coverage added)

Changeset

  • Added or updated for a library or package-metadata change
  • Not required because this PR does not change a publishable package

Validation

  • pnpm check
  • Automated type-performance measurement passed or was not required
  • Automated runtime- and memory-performance measurement passed or was not required

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Type performance

Measured with TypeScript 6.0.3 and skipLibCheck=true.

Scenario Base PR Difference
Effect only 55 55 0 (0.0%)
Import effect-machine 55 55 0 (0.0%)
Machine.state (3 children) 2,396 2,396 0 (0.0%)
Machine.make (3 states, 2 events) 8,573 8,573 0 (0.0%)
machine.handle (3 states, 2 transitions) 45,094 45,094 0 (0.0%)
declared transition (10 named branches) 81,455 81,455 0 (0.0%)
atomic construction, guards, and reentry 92,602 92,602 0 (0.0%)
registered invocation (input-taking Effect) 41,275 41,275 0 (0.0%)
registered invocations (Stream, Logic, child) 89,719 89,719 0 (0.0%)
machine.handle (depth 24) 193,615 193,615 0 (0.0%)
machine.handle (wide depth 16) 217,674 217,674 0 (0.0%)
machine.handle (parallel/history/choice) 108,058 108,058 0 (0.0%)
machine definition (3 independent implementations) 99,429 99,429 0 (0.0%)
machine exact input/output/error/services 87,575 87,575 0 (0.0%)
execution adapter readiness 77,856 77,856 0 (0.0%)

Marginal instantiations are measured against the matching setup without that API call:

Scenario Base PR Difference
Import effect-machine 0 0 0
Machine.state (3 children) 2,341 2,341 0 (0.0%)
Machine.make (3 states, 2 events) 6,169 6,169 0 (0.0%)
machine.handle (3 states, 2 transitions) 36,521 36,521 0 (0.0%)
declared transition (10 named branches) 73,261 73,261 0 (0.0%)
atomic construction, guards, and reentry 77,647 77,647 0 (0.0%)
registered invocation (input-taking Effect) 34,465 34,465 0 (0.0%)
registered invocations (Stream, Logic, child) 53,651 53,651 0 (0.0%)
machine.handle (depth 24) 177,934 177,934 0 (0.0%)
machine.handle (wide depth 16) 202,939 202,939 0 (0.0%)
machine.handle (parallel/history/choice) 96,292 96,292 0 (0.0%)
machine definition (3 independent implementations) 89,225 89,225 0 (0.0%)
machine exact input/output/error/services 75,751 75,751 0 (0.0%)
execution adapter readiness 29,707 29,707 0 (0.0%)
Check times (informational)
Scenario Base PR
Effect only 0.02s 0.02s
Import effect-machine 0.02s 0.02s
Machine.state (3 children) 0.06s 0.06s
Machine.make (3 states, 2 events) 0.11s 0.11s
machine.handle (3 states, 2 transitions) 0.24s 0.23s
declared transition (10 named branches) 0.36s 0.37s
atomic construction, guards, and reentry 0.41s 0.41s
registered invocation (input-taking Effect) 0.22s 0.22s
registered invocations (Stream, Logic, child) 0.41s 0.42s
machine.handle (depth 24) 0.44s 0.44s
machine.handle (wide depth 16) 0.48s 0.48s
machine.handle (parallel/history/choice) 0.43s 0.43s
machine definition (3 independent implementations) 0.42s 0.41s
machine exact input/output/error/services 0.41s 0.40s
execution adapter readiness 0.34s 0.34s

Type instantiations are the comparison metric. Check time varies with runner load and is informational only.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Runtime performance

Median of 5 independent benchmark processes on Intel(R) Xeon(R) 6975P-C with Node v24.22.3.

Pull request baseline

Scenario Effect Machine
Plan counter transitions 187,660 transitions/s
Drain burst with terminal fence 740,798 increments/s
Drain burst with a change observer 687,026 increments/s
Lookup and send to one child 599,952 increments/s
Start and stop a machine 191,865 machines/s
Start and stop a parent with one child 59,242 families/s
Complete an Effect invocation with tracing enabled 23,052 invocations/s
Complete an Effect invocation with tracing disabled 26,364 invocations/s
Plan transitions through a compound state 162,575 transitions/s
Plan transitions through parallel regions 125,807 transitions/s
Drain burst through a compound state 605,292 events/s
Drain burst through two parallel regions 537,625 events/s
Drain a compound-state burst with a change observer 561,444 events/s
Step counter transitions 993,197 transitions/s
Step transitions through a compound state 808,427 transitions/s
Step transitions through parallel regions 694,763 transitions/s
Step counter transitions with owned states 1,009,347 transitions/s
Step transitions through a compound state with owned states 793,808 transitions/s
Step transitions through parallel regions with owned states 691,903 transitions/s

Process runtime reference points

Scenario Effect Machine
Start and stop a raw generic process 75,999 processes/s
Start and stop a raw compiled process 115,221 processes/s
Memory profile Effect Machine
Idle machine 1.6 KiB
Raw generic managed process 4.2 KiB
Raw compiled process 3.0 KiB
Two independent idle machines 3.1 KiB
Idle parent with one child 5.5 KiB
Parent with observed child registry 9.1 KiB
Parent with observed invoked child snapshots 6.5 KiB

Effect Machine change from base

Metric Base Base variability PR PR variability Difference
Plan counter transitions 184,794 transitions/s 0.2% MAD 187,660 transitions/s 0.6% MAD +1.6%
Drain burst with terminal fence 755,632 increments/s 1.6% MAD 740,798 increments/s 1.4% MAD -2.0%
Drain burst with a change observer 698,964 increments/s 1.0% MAD 687,026 increments/s 0.6% MAD -1.7%
Lookup and send to one child 602,682 increments/s 0.6% MAD 599,952 increments/s 0.3% MAD -0.5%
Start and stop a machine 191,828 machines/s 0.0% MAD 191,865 machines/s 0.5% MAD +0.0%
Start and stop a parent with one child 59,032 families/s 0.7% MAD 59,242 families/s 0.5% MAD +0.4%
Complete an Effect invocation with tracing enabled 23,088 invocations/s 0.6% MAD 23,052 invocations/s 0.7% MAD -0.2%
Complete an Effect invocation with tracing disabled 26,347 invocations/s 0.2% MAD 26,364 invocations/s 0.7% MAD +0.1%
Plan transitions through a compound state 162,863 transitions/s 1.2% MAD 162,575 transitions/s 0.8% MAD -0.2%
Plan transitions through parallel regions 127,516 transitions/s 1.9% MAD 125,807 transitions/s 0.6% MAD -1.3%
Drain burst through a compound state 603,693 events/s 0.6% MAD 605,292 events/s 2.0% MAD +0.3%
Drain burst through two parallel regions 546,871 events/s 0.8% MAD 537,625 events/s 1.0% MAD -1.7%
Drain a compound-state burst with a change observer 559,894 events/s 0.9% MAD 561,444 events/s 0.7% MAD +0.3%
Step counter transitions 986,602 transitions/s 1.1% MAD 993,197 transitions/s 2.2% MAD +0.7%
Step transitions through a compound state 802,897 transitions/s 1.1% MAD 808,427 transitions/s 0.4% MAD +0.7%
Step transitions through parallel regions 719,280 transitions/s 1.6% MAD 694,763 transitions/s 1.0% MAD -3.4%
Step counter transitions with owned states 1,007,963 transitions/s 2.3% MAD 1,009,347 transitions/s 1.1% MAD +0.1%
Step transitions through a compound state with owned states 799,207 transitions/s 0.5% MAD 793,808 transitions/s 1.4% MAD -0.7%
Step transitions through parallel regions with owned states 717,412 transitions/s 1.7% MAD 691,903 transitions/s 0.8% MAD -3.6%
Idle machine heap per unit 1.7 KiB 0.1% MAD 1.6 KiB 0.6% MAD -1.4%
Raw generic managed process heap per unit 4.2 KiB 0.2% MAD 4.2 KiB 0.0% MAD +0.9%
Raw compiled process heap per unit 3.0 KiB 0.0% MAD 3.0 KiB 0.3% MAD +1.9%
Two independent idle machines heap per unit 3.1 KiB 0.0% MAD 3.1 KiB 0.1% MAD -0.5%
Idle parent with one child heap per unit 5.5 KiB 0.0% MAD 5.5 KiB 0.0% MAD -0.6%
Parent with observed child registry heap per unit 9.1 KiB 0.0% MAD 9.1 KiB 0.0% MAD -0.3%
Parent with observed invoked child snapshots heap per unit 6.5 KiB 0.1% MAD 6.5 KiB 0.0% MAD -0.1%

Process runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw generic process 75,523 processes/s 0.5% MAD 75,999 processes/s 0.1% MAD +0.6%
Start and stop a raw compiled process 114,247 processes/s 0.4% MAD 115,221 processes/s 0.5% MAD +0.9%

Regression guard

No large, noise-adjusted throughput or heap regressions detected.

Versions and interpretation
  • Effect Machine: 0.47.1

Higher throughput is better; lower heap is better. Variability is the median absolute deviation across independent processes, relative to their median. Small differences on shared GitHub-hosted hardware remain informational; the required guard rejects only large changes beyond the measured noise allowance.

@SandroMaglione
SandroMaglione merged commit 7d198dd into main Nov 28, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the step-cleanup-and-send-types branch November 28, 2026 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant