Repository navigation
Bind started machines to the caller's Scope - #235
Merged
Merged
Conversation
`Machine.start`, `Machine.resume`, and `prepared.start` now require `Scope.Scope`. Closing that scope stops the machine like `ref.stop`, and a machine that stops or completes earlier releases its place in the scope. `AtomMachine` is unaffected. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L
Contributor
Type performanceMeasured with TypeScript 6.0.3 and
Marginal instantiations are measured against the matching setup without that API call:
Check times (informational)
Type instantiations are the comparison metric. Check time varies with runner load and is informational only. |
Contributor
Runtime performanceMedian of 5 independent benchmark processes on Pull request baseline
Process runtime reference points
Effect Machine change from base
Process runtime reference change from base
Regression guardNo large, noise-adjusted throughput or heap regressions detected. Versions and interpretation
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. |
Fork the owner scope only after a successful start, register the ref's own stop effect, and close the owner scope synchronously on termination. This avoids a per-machine copy of the services map and per-start closures. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L
Each owning Scope keeps one finalizer and a live set. The runtime registers a machine when it is ready and releases it synchronously when it terminates, so ownership costs one set entry per machine. Benchmarks start machines through one shared service context with a long-lived scope. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L
The ownership record's ready hook refuses a machine once its scope closed, so the runtime stops it itself and the start path needs no extra step. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Machine.start,Machine.resume, andprepared.startnow requireScope.Scope, matchingEffect.forkScoped. Closing the scope is equivalent toref.stop: active invocations are interrupted, owned children stop, the snapshot becomesstopped, and later sends fail withStoppedError.ref.stopor completion leaves no finalizer behind and ownership costs one set entry per machine. Forprepared.start, the scope of the first evaluation owns the machine. Starting inside an already closed scope stops the machine immediately.StartInternalOptions.onStopSyncnow receives the terminated ref, so the record can release it without a per-machine closure.AtomMachinealready acquires machines inside a scope and is unaffected. README, agent guide, and JSDoc examples now showEffect.scopedand the explicitScope.make/Scope.providepattern for a machine that must outlive its caller. Benchmarks start machines through one shared service context with a long-lived scope, as a program would.prepared.start; explicit detached lifetime; generic-versus-compiled strategy coverage; single-finalizer ownership, reverse-order stopping, and closed-scope starts; typetests for the new requirement and Atom bridge acceptance.This resolves the leak reported by a production migration, where machines started inside
Effect.scopedkept running with their streams, effects, timers, and children after the scope closed.Changeset
Minor: public signatures of
start,resume, andpreparechange (breaking, pre-1.0).Validation
pnpm check— all steps pass locally exceptformat:check, which could not download the dprint plugins through this environment's proxy; CI's format check passes.🤖 Generated with Claude Code
https://claude.ai/code/session_01MHnF2EL6ReDTKwoM9TVH7L