Add lazy actors owned by parent state scopes - #85
Merged
Merged
Conversation
cevr
commented
Sep 7, 2026
| return value; | ||
| }), | ||
| ); | ||
| const scope = yield* Scope.fork(generation); |
Owner
Author
There was a problem hiding this comment.
- State ownership and shutdown order
+ host(input)
+ generation scope
+ inner scope: startup fiber and actor
+ close generation
+ mark closed; fail waiting consumers
+ close inner scope; stop actor
+ remove the matching generationFinalizers run in reverse registration order. The slow-cleanup test verifies that consumers fail closed and a new host remains rejected until cleanup ends. This trace comes from the source. calldiff could not resolve the Effect.fn generator entry point.
| entry.actor, | ||
| Deferred.await(entry.requested).pipe( | ||
| Effect.flatMap((requested) => | ||
| Machine.scoped(options.spawn(requested).pipe(Effect.tap((actor) => actor.start))), |
Owner
Author
There was a problem hiding this comment.
- Shared lazy startup
+ acquire(input)
+ select matching generation
+ supply the first request input
+ await shared actor
+ host startup fiber
+ Machine.scoped(factory(input))
+ actor.start
+ publish shared resultConsumer cancellation only ends that consumer's wait. The generation scope owns startup. Tests cover real recovery cancellation, direct Machine.spawn startup, and typed failures from a nested host. This trace comes from the source; the calldiff entry point was not resolved.
Merged
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.
Problem / Intent
A consumer that requests a lazy child actor must not own its startup or lifetime. Applications currently need their own request sharing and state-scope cleanup code.
Approach
Add
ActorHost.make({ identity, spawn }). The parent state hosts one generation. Consumers share the first matching request and receive an actor only after it starts. State exit or host service shutdown closes the generation. Consumers receive a typed closed error before actor cleanup; consumer cancellation leaves startup running.The factory keeps its typed failures and captured services. Both
Machine.spawnandsystem.spawnfactories work. Session validation stays in the application.Validation: full gate passed, including 395 tests and 902 assertions, typecheck, lint, build, and all examples. Ten real actor tests cover cancellation, native reentry, first-request input, slow cleanup, nested host errors, and direct actor startup. Two Counsel rounds are complete; all accepted findings are fixed. Includes a minor changeset.