principle-make-operations-idempotent

Designs state-mutating operations to converge to the same end state across crashes, restarts, and retries.

2|Updated Jun 27, 2026
One-click install
npx skills add https://github.com/imjasonh/playground --skill principle-make-operations-idempotent-imjasonh
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/imjasonh/playground/tree/main/.cursor/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/imjasonh/playground --skill principle-make-operations-idempotent-imjasonh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Commands, lifecycle steps, and processing loops that run amid crashes and retries often leave partial state behind, turning every restart into a debugging session. This Skill provides a design principle and checklist for making those operations idempotent so re-execution always converges to the correct end state. ## Core Features & Use Cases - Convergent Startup Pattern: Scan for existing state, clean stale artifacts, and adopt live sessions instead of assuming a clean slate. - Self-Healing Mechanisms: Apply content-based cleanup, PID-based stale lock detection, and idempotent scheduling that respawns failed work cleanly. - Use Case: When writing a deployment command or a queue-processing loop, apply the three-question test (runs twice, crashed halfway, converges to same state) to identify where a reconciliation step is needed before shipping. ## Quick Start Review my command or processing loop design and apply the idempotency principle to identify where partial prior runs could change the outcome.

Frequently Asked Questions about principle-make-operations-idempotent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make an operation idempotent?▼

Make an operation idempotent by designing it to converge to the correct end state no matter how many times it runs or where it starts. Scan for existing state at startup, clean stale artifacts, and add a reconciliation step wherever leftover state would change the outcome.

How to handle crashes and retries in processing loops?▼

Handle crashes by making failed work respawn cleanly and regenerating fresh input after each cycle. Use idempotent scheduling so a retried item produces the same result as a first attempt, regardless of what the crashed run completed.

What is a stale lock and how do I detect one?▼

A stale lock is a lock left behind by a process that crashed before releasing it. Detect it using PID-based checks: if the process ID recorded in the lock no longer corresponds to a live process, the lock is stale and can be safely reclaimed.

When should I use content-based cleanup instead of creation order?▼

Use content-based cleanup whenever artifacts may be recreated or reordered across runs. Comparing by content equivalence ensures cleanup decisions stay correct even when a previous run crashed halfway or items were created in a different sequence.

What are the limits of idempotent operation design?▼

Idempotency ensures convergence to the same end state but does not prevent side effects that are inherently non-repeatable, such as sending external notifications. Operations with irreversible external effects still need separate deduplication or compensation logic.