Index of every page on this site: llms.txt
All skills
kr4chinin avatar

/convert-state-machines-to-actors

@c46b93c
Run it yourself

Convert a database-backed implicit state machine to an actor, the one owner every writer of the persisted state goes through. Use when asked to put writers behind one owner, or to fix a race or lost update across several writers, such as a find-implicit-state-machines finding.

Use this Skill: https://skilld.dev/gh/kr4chinin/skills/convert-state-machines-to-actors

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesstatechart-libraries.md

≈705 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Statechart libraries

Read before using a statechart library the project already has. The transition stays pure, effects come back as data, and the actor acts on them; if the library has no call that returns effects as data, use a plain transition function instead of its interpreter. Check every API name against the installed version.

XState v5

The exported transition exists since 5.19. On older versions, or if a name below is missing, use a plain transition function.

const machine = setup({ types, guards, actions }).createMachine({ ... });

// First write, no row yet: runs the context factory; entry actions come back
// in firstActions, not executed.
const [first, firstActions] = initialTransition(machine, input);

// Later writes: rebuild from the stored value and the full stored context.
const snapshot = machine.resolveState({ value, context });
if (!snapshot.can(event)) {
  return rejected(); // no transition, or a guard said no
}
const [next, actions] = transition(machine, snapshot, event);
  • transition and initialTransition run no action implementations; assign is already applied. Translate firstActions like actions, in the insert. If the creating event is itself a transition, check first.can(event) and run transition(machine, first, event) before inserting, then insert next with both action lists.
  • Only named actions with serializable params become effects, mapped by type and params. xstate.* entries (raise, log, emit, send, cancel, spawn, stop), anonymous actions or unserializable params put the machine outside this recipe. An immediate xstate.raise is already applied; replaying it doubles the event.
  • XState has no rejected result. Decide with snapshot.can(event), which runs the guards, so keep them pure. It cannot tell "no transition" from "guard failed"; check the state's transitions if callers need both. Comparing state values misses a targetless transition that changes only context.
  • Persist next.value and the whole next.context; resolveState with a partial context leaves fields undefined. Context and effect params must survive the round trip through storage (JSON turns a Date into a string): decode them to their types, and test the round trip.
  • Sound only without history states, invoked or spawned actors, after delays, delayed raise, sendTo, emit and inline actions: resolveState rebuilds with no history or children, and a pure transition never fires timers, so the process stalls with no error. Model delays as a persisted due time plus a scheduler event and external work as an awaiting state; otherwise ask the user.
  • Use the exported transition(machine, snapshot, event), not machine.transition. Never call createActor or actor.start.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning7d3 checks · Risk SAFE
  • Gen Agent Trust Hub7d

    The skill provides structured architectural guidance for refactoring database-backed implicit state machines into a robust actor model. It emphasizes data consistency through guarded writes, atomic transactions, and comprehensive scenario-based testing, showing no signs of malicious intent or unauthorized data access.

  • Socket7d

    No alerts

  • Snyk7d

    Risk: MEDIUM · 1 issue

Signed by skilld at c46b93c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last week.

Activeupdated 2 weeks ago

README badge

README badge for kr4chinin/skills/convert-state-machines-to-actors