Skip to content

Run LocalMachine on the owned step, as one driver - #323

Merged
SandroMaglione merged 11 commits into
mainfrom
claude/project-thread-rdxl84
Nov 28, 2026
Merged

SandroMaglione merged 11 commits into
mainfrom
claude/project-thread-rdxl84

Conversation

@SandroMaglione

@SandroMaglione SandroMaglione commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Requested by Sandro · project thread

Summary

Third of three steps that make the pure step function the base of every host. LocalMachine now has one driver, the local process in runtimeCompiled.ts:

  • Machines run on the internal owned step (stepHost.ts). Each message goes to the step; the host runs its commands, stops stop, commits, emits, starts start, and stops stopAfter through the child registry. Outcomes of work come back through the mailbox as WorkMessages and are planned in a later turn. The host extends Step.PlanningBase, so an idle machine keeps one compact object for both.
  • Machine.logic (and logic spawned by a machine) runs on the same process as a resident program: it starts in its starter's turn, receives from the same mailbox, and its exit ends the process. Changes of state are applied one at a time, as before.
  • Deleted: runtimeGeneric.ts, invocation.ts, invocationGeneration.ts, the generic drain loop in process.ts, and the generation bookkeeping of the child registry. Late outcomes, run order, stop order, and invocation lifecycle are decided by step.ts only.
  • AtomMachine keeps using LocalMachine unchanged.
  • Conformance keeps two local columns: the reference planner ("generic" strategy, now passing ExecutionPlan.referenceExecutionPlan(machine) on the same driver) and the indexed planner (ExecutionPlan.compileExecutionPlan(machine)).

Decided behaviour changes

  • a) send of a LocalMachine reference rejects an event that the schema refuses with MachineSchemaDecodeError, and the machine keeps running. The Machine.toStep conformance column has no recorded difference left.
  • b) Work.Timer.duration() returns one Exit (a throwing mapper or source, or an input that names no duration).
  • c) One documented rule for a transition that throws, on MachineRef.send: the error goes to the sender when one waits, otherwise the machine fails.

Structural follow-ups

1. Planner passed as a value, not a name

  • Before: Step.kernel, StepHost.makeExecution, and process.ts threaded a "Compiled" | "Reference" string; "Reference" called ExecutionPlan.selectExecutionPlanForTesting(machine, "generic").plan from production code.
  • Now: ExecutionPlan.referenceExecutionPlan(machine) is a cached, non-test production helper in executionPlan.ts (reused by compileExecutionPlan when a machine cannot be indexed). Step.kernel(machine, ownership, plan), StepHost.makeExecution, and process.ts take CompiledExecutionPlan directly, with Step.kernel cached by (ownership, plan). build documents every difference between "Owned" and "Persistent" in one place, unused duplicate move was collapsed into a single Kernel.move, and move, retain, ambient, rest, and fromSnapshot are documented on Kernel and covered by forced compiled-vs-reference and owned-vs-persistent differential tests in stepDifferential.test.ts.
  • Deviations: None.

2. Invocation outcome decisions owned by step.ts only

  • Before: stepHost.ts imported invocationOutcome.js and called InvocationOutcome.decide, decideSnapshot, and decideElement directly in onOutcome, onSnapshot, and stream programLogic, routing failures to scope.failCause without going through the step.
  • Now: stepHost.ts reports raw work exits/elements/snapshots via WorkMessage and step.ts decides every outcome in settle / element / report. Pre-step queries needed before stepping (observesSnapshots, settleEvent, elementEvent, snapshotEvent) live on Step.Kernel in step.ts; runtimeCompiled.ts skips wrapping WorkMessage in an inspected event envelope when settleEvent returns undefined (direct failure), preserving the exact existing inspection event order. scripts/check-architecture.mjs enforces ARCH015 forbidding host modules (including stepHost.ts) from importing invocationOutcome.ts, tested in scripts/check-architecture.test.mjs.
  • Deviations: None; all existing inspection and conformance tests pass with unchanged event ordering.

3. End-of-machine stop order owned by step.ts

  • Before: step.ts concatenated exited work and non-exited remaining work into [...stop, ...latestFirst(kept)], and stepHost.ts (continueEffectful) split step.stop back apart using new Set(step.exited) so non-exited work stopped after publishing the final state and emitted events, while MachineStep.Step and the docs only described one stop group before publishing.
  • Now: Pinned first with a new conformance scenario (stops work of states that stay active after publishing the final state and emissions, running across all 5 host columns; Machine.toStep failed before the change and passes after). step.ts now emits stop (exited states' work, or all work on failure/owner stop) and stopAfter (non-exited states' remaining work, latest first, on a final step) directly on MachineStep.Step. stepHost.ts, clusterInstance.ts (progressAfter and alignWork), and the conformance stepHost carry out both groups without deriving them from exited. Updated MachineStep.Step JSDoc in Machine.ts, ai-docs/src/37_new-host/index.md, regenerated LLMS.md, and .changeset/local-rejects-refused-events.md.
  • Deviations: The conformance scenario observes interruption of the non-exited work (outer) relative to the final state and emitted events (and keeps exited work inner running so both groups are populated), because ClusterMachine commits state and enqueues emissions inside one storage transaction before alignWork interrupts in-memory fibers (so on ClusterMachine, both stop and stopAfter run after the transaction commits, in stop-then-stopAfter order). All 5 conformance columns run the scenario without adding a new difference entry.

Performance & heap fixes (since a260598)

  • Protocol & event decoding: Added fast symbol check in isEventConstruction, lazy cached result decoders, makeEventDecoderSync, and deferred error-option object allocation to failure paths only.
  • Step & drain hot path: Added PlanningBase (avoiding duplicated slots on Host), in-place restInPlace and childless owned move (zero State/Step allocation per drain-burst event), synchronous childless uninspected startup on plan.initial, single acknowledgment check per drained message, and lazy capability resolution with cached static ChildInvocations.
  • Compact runtime & child ownership: Compact prototype-based CompiledAddress and OwnedChildParent, synchronous nextSessionIdSync(), in-place single-child registry replacement, and single-pass offerMessage.

Changeset

  • Updated (.changeset/local-rejects-refused-events.md, minor — includes MachineStep.Step.stopAfter)

Validation

  • pnpm format:check & pnpm lint (0 errors, 0 warnings)
  • pnpm check:architecture (including ARCH015 test) & pnpm check:ci
  • pnpm ai-docgen:check, pnpm docs:api:check, pnpm docs:site:check
  • pnpm typecheck, pnpm typecheck:ts7, pnpm build
  • pnpm test, pnpm doctest, pnpm doctest:types, pnpm test:types, pnpm test:consumer, pack checks
  • pnpm perf:types (within budgets)
  • pnpm perf:runtime (local smoke test and heap profiles improved vs main; awaiting authoritative CI base-vs-PR comparison)

… for a transition that throws

send of a local reference decodes the event and rejects one that the
schema refuses with MachineSchemaDecodeError, and the machine keeps
running. Deliveries from work, children, parents and commands are
decoded as they enter the mailbox and fail the machine as before. The
drains plan decoded events, so nothing is decoded twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
@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.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.33s 0.33s
declared transition (10 named branches) 0.53s 0.52s
atomic construction, guards, and reentry 0.60s 0.57s
registered invocation (input-taking Effect) 0.31s 0.32s
registered invocations (Stream, Logic, child) 0.59s 0.58s
machine.handle (depth 24) 0.66s 0.65s
machine.handle (wide depth 16) 0.72s 0.71s
machine.handle (parallel/history/choice) 0.62s 0.62s
machine definition (3 independent implementations) 0.60s 0.58s
machine exact input/output/error/services 0.56s 0.56s
execution adapter readiness 0.51s 0.49s

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 AMD EPYC 9V45 96-Core Processor with Node v24.22.3.

Pull request baseline

Scenario Effect Machine
Plan counter transitions 184,244 transitions/s
Drain burst with terminal fence 673,328 increments/s
Drain burst with a change observer 634,461 increments/s
Lookup and send to one child 546,550 increments/s
Start and stop a machine 193,498 machines/s
Start and stop a parent with one child 64,214 families/s
Complete an Effect invocation with tracing enabled 26,132 invocations/s
Complete an Effect invocation with tracing disabled 28,975 invocations/s
Plan transitions through a compound state 165,070 transitions/s
Plan transitions through parallel regions 132,382 transitions/s
Drain burst through a compound state 551,604 events/s
Drain burst through two parallel regions 514,198 events/s
Drain a compound-state burst with a change observer 525,412 events/s
Step counter transitions 876,332 transitions/s
Step transitions through a compound state 702,277 transitions/s
Step transitions through parallel regions 638,297 transitions/s
Step counter transitions with owned states 889,601 transitions/s
Step transitions through a compound state with owned states 703,363 transitions/s
Step transitions through parallel regions with owned states 639,812 transitions/s

Process runtime reference points

Scenario Effect Machine
Start and stop a raw generic process 83,486 processes/s
Start and stop a raw compiled process 123,426 processes/s
Memory profile Effect Machine
Idle machine 1.7 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 183,631 transitions/s 0.1% MAD 184,244 transitions/s 0.9% MAD +0.3%
Drain burst with terminal fence 649,793 increments/s 2.3% MAD 673,328 increments/s 1.1% MAD +3.6%
Drain burst with a change observer 618,492 increments/s 1.7% MAD 634,461 increments/s 2.1% MAD +2.6%
Lookup and send to one child 528,723 increments/s 1.2% MAD 546,550 increments/s 1.1% MAD +3.4%
Start and stop a machine 193,498 machines/s 1.2% MAD 193,498 machines/s 0.8% MAD +0.0%
Start and stop a parent with one child 61,293 families/s 2.1% MAD 64,214 families/s 1.8% MAD +4.8%
Complete an Effect invocation with tracing enabled 22,179 invocations/s 0.9% MAD 26,132 invocations/s 1.5% MAD +17.8%
Complete an Effect invocation with tracing disabled 24,956 invocations/s 0.4% MAD 28,975 invocations/s 1.2% MAD +16.1%
Plan transitions through a compound state 164,751 transitions/s 1.4% MAD 165,070 transitions/s 1.8% MAD +0.2%
Plan transitions through parallel regions 130,910 transitions/s 0.9% MAD 132,382 transitions/s 2.7% MAD +1.1%
Drain burst through a compound state 544,564 events/s 0.3% MAD 551,604 events/s 0.8% MAD +1.3%
Drain burst through two parallel regions 509,195 events/s 1.5% MAD 514,198 events/s 0.5% MAD +1.0%
Drain a compound-state burst with a change observer 518,568 events/s 1.1% MAD 525,412 events/s 1.3% MAD +1.3%
Step counter transitions 820,661 transitions/s 2.0% MAD 876,332 transitions/s 1.6% MAD +6.8%
Step transitions through a compound state 685,307 transitions/s 1.7% MAD 702,277 transitions/s 0.6% MAD +2.5%
Step transitions through parallel regions 628,539 transitions/s 1.4% MAD 638,297 transitions/s 1.0% MAD +1.6%
Step counter transitions with owned states 846,181 transitions/s 1.7% MAD 889,601 transitions/s 1.9% MAD +5.1%
Step transitions through a compound state with owned states 683,242 transitions/s 1.5% MAD 703,363 transitions/s 0.6% MAD +2.9%
Step transitions through parallel regions with owned states 625,778 transitions/s 1.4% MAD 639,812 transitions/s 1.5% MAD +2.2%
Idle machine heap per unit 1.9 KiB 0.3% MAD 1.7 KiB 2.6% MAD -10.7%
Raw generic managed process heap per unit 11.4 KiB 0.0% MAD 4.2 KiB 0.1% MAD -63.5%
Raw compiled process heap per unit 3.2 KiB 0.0% MAD 3.0 KiB 0.1% MAD -5.1%
Two independent idle machines heap per unit 3.6 KiB 0.8% MAD 3.1 KiB 0.4% MAD -13.7%
Idle parent with one child heap per unit 6.1 KiB 0.1% MAD 5.5 KiB 0.1% MAD -9.7%
Parent with observed child registry heap per unit 9.7 KiB 0.0% MAD 9.1 KiB 0.0% MAD -6.1%
Parent with observed invoked child snapshots heap per unit 7.1 KiB 0.3% MAD 6.5 KiB 0.0% MAD -7.8%

Process runtime reference change from base

Metric Base Base variability PR PR variability Difference
Start and stop a raw generic process 66,520 processes/s 1.2% MAD 83,486 processes/s 0.7% MAD +25.5%
Start and stop a raw compiled process 119,147 processes/s 0.9% MAD 123,426 processes/s 2.0% MAD +3.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.

The endpoint delivers through prototype methods, the event decoder is
shared per machine, and logic that neither decodes nor is inspected
offers directly, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
…e compiled process

A machine of LocalMachine runs as a compiled process whose drain takes each
message to its owned step. Work runs through the child registry of the
process, and its outcomes come back through the mailbox. The generic loop
over machines is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
…untime

Logic other than a machine runs as a resident program of the local process:
it starts in its starter's turn, receives from the same mailbox, and its exit
ends the process. The generic runtime, the invocation host and its generation
bookkeeping are gone; the step owns those rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
@SandroMaglione SandroMaglione changed the title Run LocalMachine on the owned step (in progress: decided changes a, b, c) Run LocalMachine on the owned step, as one driver Nov 28, 2026
claude and others added 5 commits November 28, 2026 09:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
An event whose transitions start, stop and emit nothing now moves the
owned state in place of building a Step, so a drain burst allocates as
it did before the one driver.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
An array that a push grows from empty reserves seventeen slots, and the
running work stays on the machine's state while it is idle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNdA7BM5kaFHqECsKFr
@SandroMaglione
SandroMaglione marked this pull request as ready for review November 28, 2026 20:04
@SandroMaglione
SandroMaglione merged commit b7a8888 into main Nov 28, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the claude/project-thread-rdxl84 branch November 28, 2026 20:11
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.

2 participants