principle-make-operations-idempotent

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

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/jnyross/pstack-muse --skill principle-make-operations-idempotent-jnyross
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/jnyross/pstack-muse/tree/main/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/jnyross/pstack-muse --skill principle-make-operations-idempotent-jnyross

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Commands, lifecycle steps, and processing loops run in environments where crashes, restarts, and retries are normal. When partial state from a failed run changes the outcome of the next run, every restart becomes a debugging session. This Skill provides design principles for making operations safe to re-run. ## Core Features & Use Cases - Convergent Startup Design: Scan for existing state, clean stale artifacts, and adopt live sessions instead of assuming a clean slate. - Content-Based Cleanup: Compare artifacts by content equivalence rather than creation order to avoid duplicate or orphaned resources. - Self-Healing Locks and Scheduling: Use PID-based stale lock detection and respawn failed work cleanly with fresh input each cycle. - Use Case: When writing a deployment script or a queue-processing loop, apply the three-question test (runs twice, crashes at any point, converges to same end state) to identify where a reconciliation step is needed. ## Quick Start Review my processing loop and make every state-mutating operation idempotent so it converges to the same end state after crashes or retries.

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 ensuring it converges to the same end state regardless of 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 could change the outcome.

How do I test whether my command is idempotent?

Ask three questions: what happens if it runs twice in a row, what happens if the previous run crashed at every possible point, and does re-execution converge to the same end state. If any answer depends on leftover state, add a reconciliation step.

How do I handle stale lock files after a crash?

Use PID-based stale lock detection. When acquiring a lock, check whether the process ID recorded in the lock file is still alive; if not, the lock is stale and can be safely reclaimed instead of blocking forever.

When should cleanup compare by content instead of creation order?

Compare by content equivalence whenever artifacts may be recreated in a different order across runs, such as regenerated files or rescheduled jobs. Creation-order comparison treats identical content as different, causing duplicate or orphaned resources after retries.

What are the limits of idempotent design for processing loops?

Idempotent design handles crashes and retries but does not replace transactional guarantees for operations spanning external systems you do not control. Failed work should respawn cleanly with fresh input regenerated after each cycle, but side effects on third-party APIs may still need compensation logic.