Skip to content

feat(core): observe emissions across an actor system - #5820

Merged
davidkpiano merged 2 commits into
nextfrom
feature/system-emitted-events
Oct 20, 2026
Merged

davidkpiano merged 2 commits into
nextfrom
feature/system-emitted-events

Conversation

@davidkpiano

@davidkpiano davidkpiano commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Why

Analytics attached to a root actor miss child emissions. Systems can now observe actor emissions with source identity without forwarding them into machine event handlers.

What changed

  • Add createSystem({ onEmitted }) and removable system.onEmitted(listener) subscriptions.
  • Release canceled pending listeners while preserving cancellation across initialization and actor-local delivery.
  • Add usage docs, README guidance, and an XState Changeset.

Scope

Observes actor emission requests before runtime delivery across all actors sharing a system. Direct low-level runtime delivery calls remain delivery-only.

Blast Radius

Changes emission execution and lazy system initialization. Regression tests cover constructor and startup emissions, snapshot views, listener failures, unsubscribe, multiple roots, and runtime overrides.

Verification

  • pnpm test:core --maxWorkers=3 passed. 165 files, 2,764 tests.
  • pnpm typecheck, pnpm lint, pnpm format:check, pnpm check:exports, and pnpm build passed.
  • A native built-package GC probe reproduced retained callbacks before the cleanup and confirmed collection after cancellation. Independent review found no blocking findings.

Devin Review

@changeset-bot

changeset-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1f62a03

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

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

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

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aad9253f-d6cc-4466-b82d-275ddfad025a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Comment thread packages/core/src/setup.ts
Addresses review finding: "Canceled emission listeners remain in memory".
@davidkpiano
davidkpiano merged commit 749955a into next Oct 20, 2026
3 checks passed
@davidkpiano
davidkpiano deleted the feature/system-emitted-events branch October 20, 2026 10:10
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.

1 participant