Add structural ActorRef boundary - #43
Merged
Merged
Conversation
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
Separate the consumer-facing actor reference contract from the concrete actor lifecycle while preserving precise types for actors created from known logic.
Rationale
XState v5 and the v6 architecture research distinguish what an actor consumer may do from what the concrete runtime owns. Python benefits from the same boundary through structural protocols: application code can depend on send, snapshot, and subscription capabilities without receiving start, stop, spawn, or backend details.
This is a typing and interface boundary. Runtime actors, mailboxes, invocation reconciliation, and lifecycle behavior remain unchanged.
Scope
ActorRef[SendEventT, SnapshotT]as a runtime-checkable structural protocol.Actor.send()returning the current snapshot for backward compatibility.Actor[SendEventT, SnapshotT, OutputT]lifecycle and spawn methods.ActorSystem.get()toActorRef[Any, Any] | Nonefor heterogeneous lookup.ActorRef.create_actor()andspawn()return types as precise concrete actors for known machine, promise, callback, and observable logic.CompletionSnapshot[OutputT]for completion-capable snapshots.to_promise()for concrete actors and compatible actor references while preserving output inference.ActorRef,CompletionSnapshot, andSubscriptionProtocolfromxstate.Compatibility
Existing actor construction, start, stop, send, subscribe, get_snapshot, state, spawn, invoke, parent-child ownership, and system registration behavior is unchanged. Raw and unparameterized consumers remain
Anycompatible. Known logic still returns concreteActorvalues, so this PR does not remove lifecycle methods from existing call sites.Non-scope
Validation
Local Python 3.14 on exact head
9072aed:poetry run python -m pytest tests/ --ignore=tests/test_scxml.py: 482 passed.poetry run python -m pytest tests/test_scxml.py: 57 passed.poetry run mypy src/xstate/: passed.poetry run mypy --strict src/xstate/algorithm.py: passed.poetry check --lock: passed.poetry build: passed.poetry run python scripts/validate_distribution.py: installed-wheel smoke passed.Hosted exact head
9072aedfe6c9a4003fe6ff4cebfcf13c4d4357bd:Risks and rollback
The main risk is variance or overload behavior widening too much or rejecting valid structural implementations. Strict-mypy fixtures cover invalid sends and snapshots, concrete actor precision, widened system lookup, and
to_promiseinference through both concrete actors and actor references. Runtime tests cover structural protocol recognition and completion.Rollback is a revert of this PR. It changes no persisted data, dependency, runtime effect order, or public lifecycle behavior.
Review focus
ActorRef.CompletionSnapshotstructural compatibility andto_promiseinference.Actor.send()and lifecycle methods.Stack and merge order
This is PR 3 of 3. PR 1 and PR 2 have merged, so this PR now targets
masterand is the final layer in the stack.