Type persisted snapshot round-trips - #5646
Merged
Merged
Conversation
actor.getPersistedSnapshot() now returns a snapshot branded to its source logic, and ActorOptions['snapshot'] accepts persisted snapshots from any version of the same machine ID (cross-version restore stays assignable for runtime migration via migrate). Restoring into a machine with a different ID is now a compile-time error, mirroring the existing runtime guard.
🦋 Changeset detectedLatest commit: b227c42 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Addresses Devin review: the persisted-snapshot brand collapsed to never for unversioned machines, so cross-ID restore was silently accepted. The brand identity now requires only a machine id (version falls back to string), and provide() returns 'this' so the MachineIdentity intersection from createMachine survives providing implementations.
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.
What changed
actor.getPersistedSnapshot()now returnsSnapshot<unknown> & PersistedSnapshotFor<TLogic>, branding the persisted snapshot with its source logic's machineid/version.ActorOptions['snapshot']now uses a newRestorablePersistedSnapshotFor<TLogic>type that checks the machine id only: restoring a snapshot into a machine with a differentidis a compile-time error (mirroring the existing runtime guard), while snapshots from other versions of the same machine remain assignable, since cross-version restore viamigrateis a supported runtime path. Unbranded (e.g. JSON-revived) snapshots remain accepted.packages/core/test/persistedSnapshot.types.test.ts: castless round-trip (plain + versioned), cross-version accepted, cross-id rejected, revived JSON accepted.as AnyMachineSnapshotcast and@ts-ignores inexamples/express-workflow.UseActortest fixture'spersistedStateprop was retyped fromAnyMachineSnapshot(incorrect — a persisted snapshot is not a machine snapshot) toSnapshot<unknown>, dropping its cast.Why
Persist/restore round-trips previously required casts because
getPersistedSnapshot()returned an unbrandedSnapshot<unknown>with no link to its source logic. The brand makes same-machine round-trips castless and catches cross-machine restores at compile time.Reviewer notes
versionstrictly; that broke the versioning/migration tests, which intentionally restore old-version snapshots into newer machines — hence the id-only check on the restore side.machineVersions.test.tsnow carries an intentional@ts-expect-error; a stale version-mismatch@ts-expect-errorinmachineVersions.types.test.tswas removed.tscclean, 2159 core tests pass, svelte tests pass, lint/format pass. Changeset included.