Skip to content

Support enqueue.stop(Child) and per-entity client.start on ClusterMachine - #314

Merged
SandroMaglione merged 1 commit into
mainfrom
cluster-machine-stop-and-start
Nov 25, 2026
Merged

SandroMaglione merged 1 commit into
mainfrom
cluster-machine-stop-and-start

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

  • Support enqueue.stop(Child) in synchronous transitions on ClusterMachine: when given a ChildMachine descriptor, stops the running child entity in the same transaction as the parent checkpoint, marks its invocation progress as Settled so it does not restart while its state stays active, drops subsequent sends/stops to the stopped child without emitting duplicate stops, and keeps rejecting local ChildAddress targets as UnsupportedProcessLocal.
  • Add client.start(...input) on ClusterMachine.Client and ClusterMachineProxy.Client (plus ${Type}.start in ClusterMachineProxy.toRpcGroup), validating startup input locally before sending and returning Accepted / Rejected (InvalidEvent for invalid input or sending before start without a default, MachineFailed for failed/stopped entities, idempotent no-op for active entities).
  • Allow omitting the static default input in ClusterMachine.make for input-bearing machines so each entity can be initialized with per-entity input via client.start(input), while preserving optional default input auto-start and enforcing JSON-compatible encoded schemas for input.
  • Add runtime tests (including Web Worker MessagePort RPC proxy tests), type tests, documentation updates, and a minor changeset.

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

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,085 45,085 0 (0.0%)
declared transition (10 named branches) 71,452 71,452 0 (0.0%)
atomic construction, guards, and reentry 83,762 83,762 0 (0.0%)
registered invocation (input-taking Effect) 41,264 41,264 0 (0.0%)
registered invocations (Stream, Logic, child) 89,562 89,562 0 (0.0%)
machine.handle (depth 24) 191,846 191,846 0 (0.0%)
machine.handle (wide depth 16) 215,905 215,905 0 (0.0%)
machine.handle (parallel/history/choice) 106,289 106,289 0 (0.0%)
machine definition (3 independent implementations) 97,653 97,653 0 (0.0%)
machine exact input/output/error/services 86,092 86,092 0 (0.0%)
execution adapter readiness 75,016 75,034 +18 (+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,512 36,512 0 (0.0%)
declared transition (10 named branches) 63,258 63,258 0 (0.0%)
atomic construction, guards, and reentry 68,807 68,807 0 (0.0%)
registered invocation (input-taking Effect) 34,454 34,454 0 (0.0%)
registered invocations (Stream, Logic, child) 53,504 53,504 0 (0.0%)
machine.handle (depth 24) 176,165 176,165 0 (0.0%)
machine.handle (wide depth 16) 201,170 201,170 0 (0.0%)
machine.handle (parallel/history/choice) 94,523 94,523 0 (0.0%)
machine definition (3 independent implementations) 87,449 87,449 0 (0.0%)
machine exact input/output/error/services 74,268 74,268 0 (0.0%)
execution adapter readiness 26,876 26,894 +18 (+0.1%)
Check times (informational)
Scenario Base PR
Effect only 0.03s 0.03s
Import effect-machine 0.03s 0.03s
Machine.state (3 children) 0.09s 0.09s
Machine.make (3 states, 2 events) 0.16s 0.16s
machine.handle (3 states, 2 transitions) 0.34s 0.36s
declared transition (10 named branches) 0.46s 0.46s
atomic construction, guards, and reentry 0.55s 0.56s
registered invocation (input-taking Effect) 0.32s 0.32s
registered invocations (Stream, Logic, child) 0.60s 0.62s
machine.handle (depth 24) 0.64s 0.65s
machine.handle (wide depth 16) 0.70s 0.71s
machine.handle (parallel/history/choice) 0.61s 0.61s
machine definition (3 independent implementations) 0.57s 0.55s
machine exact input/output/error/services 0.54s 0.55s
execution adapter readiness 0.48s 0.47s

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

@github-actions

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 192,468 transitions/s
Drain burst with terminal fence 761,225 increments/s
Drain burst with a change observer 687,758 increments/s
Lookup and send to one child 596,459 increments/s
Start and stop a machine 195,008 machines/s
Start and stop a parent with one child 58,462 families/s
Complete an Effect invocation with tracing enabled 20,311 invocations/s
Complete an Effect invocation with tracing disabled 23,765 invocations/s
Plan transitions through a compound state 171,532 transitions/s
Plan transitions through parallel regions 134,776 transitions/s
Drain burst through a compound state 602,015 events/s
Drain burst through two parallel regions 535,353 events/s
Drain a compound-state burst with a change observer 551,655 events/s

Process runtime reference points

Scenario Effect Machine
Start and stop a raw generic process 62,093 processes/s
Start and stop a raw compiled process 112,183 processes/s
Memory profile Effect Machine
Idle machine 1.9 KiB
Raw generic managed process 11.3 KiB
Raw compiled process 3.2 KiB
Two independent idle machines 3.6 KiB
Idle parent with one child 6.1 KiB
Parent with observed child registry 9.7 KiB
Parent with observed invoked child snapshots 7.1 KiB

Effect Machine change from base

Metric Base Base variability PR PR variability Difference
Plan counter transitions 192,483 transitions/s 1.1% MAD 192,468 transitions/s 0.1% MAD -0.0%
Drain burst with terminal fence 746,298 increments/s 0.7% MAD 761,225 increments/s 0.5% MAD +2.0%
Drain burst with a change observer 688,104 increments/s 1.3% MAD 687,758 increments/s 0.4% MAD -0.1%
Lookup and send to one child 586,129 increments/s 1.3% MAD 596,459 increments/s 0.5% MAD +1.8%
Start and stop a machine 195,618 machines/s 0.8% MAD 195,008 machines/s 0.7% MAD -0.3%
Start and stop a parent with one child 56,638 families/s 0.7% MAD 58,462 families/s 1.6% MAD +3.2%
Complete an Effect invocation with tracing enabled 20,807 invocations/s 1.0% MAD 20,311 invocations/s 1.4% MAD -2.4%
Complete an Effect invocation with tracing disabled 23,595 invocations/s 0.6% MAD 23,765 invocations/s 0.2% MAD +0.7%
Plan transitions through a compound state 169,378 transitions/s 0.3% MAD 171,532 transitions/s 0.8% MAD +1.3%
Plan transitions through parallel regions 133,865 transitions/s 0.2% MAD 134,776 transitions/s 1.1% MAD +0.7%
Drain burst through a compound state 599,313 events/s 0.4% MAD 602,015 events/s 0.4% MAD +0.5%
Drain burst through two parallel regions 529,246 events/s 1.2% MAD 535,353 events/s 0.4% MAD +1.2%
Drain a compound-state burst with a change observer 562,485 events/s 0.3% MAD 551,655 events/s 0.3% MAD -1.9%
Idle machine heap per unit 1.9 KiB 1.4% MAD 1.9 KiB 0.5% MAD +1.5%
Raw generic managed process heap per unit 11.4 KiB 0.0% MAD 11.3 KiB 0.0% MAD -0.9%
Raw compiled process heap per unit 3.2 KiB 0.0% MAD 3.2 KiB 0.0% MAD -1.1%
Two independent idle machines heap per unit 3.6 KiB 0.1% MAD 3.6 KiB 0.5% MAD -1.2%
Idle parent with one child heap per unit 6.1 KiB 0.3% MAD 6.1 KiB 0.1% MAD -0.3%
Parent with observed child registry heap per unit 9.7 KiB 0.0% MAD 9.7 KiB 0.0% MAD +0.1%
Parent with observed invoked child snapshots heap per unit 7.1 KiB 0.0% MAD 7.1 KiB 0.0% MAD -0.4%

Process runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw generic process 62,143 processes/s 0.4% MAD 62,093 processes/s 0.5% MAD -0.1%
Start and stop a raw compiled process 112,829 processes/s 0.3% MAD 112,183 processes/s 1.1% MAD -0.6%

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 52bb1cd into main Nov 25, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the cluster-machine-stop-and-start branch November 25, 2026 05:46
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