Skip to content

fix(core): make sendParent a no-op when actor has no parent - #5552

Open
JSap0914 wants to merge 1 commit into
statelyai:mainfrom
JSap0914:fix/sendParent-noop-when-no-parent
Open

fix(core): make sendParent a no-op when actor has no parent#5552
JSap0914 wants to merge 1 commit into
statelyai:mainfrom
JSap0914:fix/sendParent-noop-when-no-parent

Conversation

@JSap0914

Copy link
Copy Markdown
Contributor

Summary

Fixes #5120.

sendParent() is documented as sending an event to the parent actor "if it exists", but calling it from a root (parentless) actor previously caused the actor to enter an error state with:

Unable to send event to actor '#_parent' from machine '(machine)'.

This fix makes sendParent silently skip when there is no parent, matching the documented semantics.

Root cause

In resolveSendTo (packages/core/src/actions/send.ts), when the resolved target is SpecialTargets.Parent and actorScope.self._parent is undefined, the existing guard if (!targetActorRef) { throw ... } did not distinguish the #_parent case from genuinely missing named actors.

Fix

  • Return a no-op [snapshot, undefined, undefined] resolution when resolvedTarget === SpecialTargets.Parent and no parent exists.
  • Guard retryResolveSendTo and executeSendTo to early-return on undefined params (which only occurs via this path).
  • Added a regression test confirming the actor remains 'active' after sendParent fires with no parent.

AI-assisted contribution.

Previously, calling sendParent() from a root (parentless) actor would cause
the actor to enter an error state with the message:
"Unable to send event to actor '#_parent' from machine '(machine)'."

This contradicts the documented behaviour where sendParent sends an event
to the parent "if it exists".

The fix returns a no-op resolution from resolveSendTo when the target is
SpecialTargets.Parent and no parent actor exists, and guards the matching
execute/retryResolve helpers against undefined params.

Fixes statelyai#5120
Copilot AI review requested due to automatic review settings June 23, 2026 04:50
@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 22c4e81

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
xstate Patch

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: sendParent throws an error when no parent exists

2 participants