intense-visions/harness-engineering/xstate-invoke-pattern
Claude Code and agent skill by intense-visions/harness-engineering
- community
Checking that the SKILL.md file is still in the repository.
Install
npx vskill@latest install intense-visions/harness-engineering/xstate-invoke-patternSKILL.md
The same SKILL.md was published earlier as intense-visions/harness-engineering/xstate-invoke-pattern.
XState Invoke Pattern
Invoke promises, callbacks, observables, and child machines as services tied to state node lifecycles
When to Use
- Fetching data when entering a state (API calls, database queries)
- Running long-lived processes tied to a state (WebSocket connections, timers)
- Delegating a sub-workflow to a child machine
- Any async operation that should start on state entry and cancel on state exit
Instructions
- Use
invokeinside a state node. The service starts when the state is entered and is automatically stopped when the state is exited. - Handle results with
onDone(success) andonError(failure) on the invoke config. - For promises, the resolved value becomes
event.datainonDone. The rejected value becomesevent.datainonError. - For callbacks, return a cleanup function — XState calls it when the state is exited.
- Define services in the machine options under
services(v4) oractors(v5) to keep machines testable and serializable. - Use
input(v5) orwithContext(v4) to pass data to invoked machines.
Details
Service types in v4:
- Promise — resolves once, triggers
onDoneoronError - Callback —
(sendBack, onReceive) => cleanup— long-lived, bidirectional - Observable — emits events over time, completes triggers
onDone - Machine — child statechart,
onDonefires when child reaches final state
XState v5 equivalents: Services become actors defined with helper functions:
Automatic cancellation: When the state that owns the invoke exits, XState automatically stops the service. For promises, the AbortController.signal is not used automatically — you must wire it yourself if needed. For callbacks, the cleanup function runs.
Multiple invocations: A state can have multiple invoke entries (use an array). All start on entry and stop on exit.
Testing: Replace services with mocks in tests by passing { services: { fetchService: mockService } } to interpret(machine.withConfig({ services: ... })).
Source
https://stately.ai/docs/invoke
Process
- Read the instructions and examples in this document.
- Apply the patterns to your implementation, adapting to your specific context.
- Verify your implementation against the details and edge cases listed above.
Harness Integration
- Type: knowledge — this skill is a reference document, not a procedural workflow.
- No tools or state — consumed as context by other skills and agents.
Success Criteria
- The patterns described in this document are applied correctly in the implementation.
- Edge cases and anti-patterns listed in this document are avoided.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingagents/skills/gemini-cli/xstate-invoke-pattern/SKILL.md
Popularity
- Repository stars
- 14
- Repository forks
- 7
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/intense-visions/harness-engineering/xstate-invoke-pattern)