Bug: Delays are not properly restored when machine created from snapshot
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- backend
Research direction
Start by creating a minimal XState v5 machine with an after delay, persist it during the delay, and restore it from the snapshot. Then inspect the delay scheduling and snapshot restoration paths. Done means the delay resumes after restoration and transitions immediately when its expected deadline has already passed.
Written by the indexing model from the issue text.
Description
XState version
XState version 5
Description
When using delays (after: { 1000: "myTarget" }), if the state machine is persisted during a delay and then restored by re-creating it from the snapshot, then the delay will never trigger.
Seems like the delay information is lost when snapshotting.
I've worked around it by using a fromPromise actor with a promise resolving after a setTimeout. The input of that actor is a deadline computed when it is created (Date.now() + delay in ms).
Expected result
The delay should be resumed and possibly trigger its resolution condition if it is past the expected time it should've completed.
Actual result
The delay never resolves and the state machine is stuck forever.
Reproduction
I didn't prepare any, but should be easy?
Additional context
No response
- Dominant language
- TypeScript
- Stars
- 30.6k
- Forks
- 1.4k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 90
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from statelyai/xstate
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Bug: store.inspect retains observers that throw during initial notificationPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Bug (v5, v6): `always` on a final state is taken, and the parent's `onDone` still firesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
machineFromJSON drops a context key named __proto__Possibly taken @kolinabir claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Maintainers usually reply within 1 day
All issues in statelyai/xstate
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zabuton-app/meguri#875 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
iruzen-dono/workless#117 ·
Maintainers usually reply within 1 day
-
area:api area:web wave wave:trivial
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
vetro-protocol/vetro-monorepo#1321 ·
Maintainers usually reply within 1 day