principle-make-operations-idempotent

Designs commands and processing loops that converge to correct state despite crashes and retries.

1|Updated Jul 5, 2026
One-click install
npx skills add https://github.com/yersonargotev/packy --skill principle-make-operations-idempotent-yersonargotev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/yersonargotev/packy/tree/main/bundle/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/yersonargotev/packy --skill principle-make-operations-idempotent-yersonargotev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Operations that run amid crashes, restarts, and retries often leave partial state behind, turning every restart into a debugging session. This Skill provides a design discipline for making commands, lifecycle steps, and processing loops converge to the same end state regardless of how many times they run or where they start from. ## Core Features & Use Cases - Convergent Startup Pattern: 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 outputs. - Self-Healing Locks and Scheduling: Use PID-based stale lock detection and respawn failed work cleanly with fresh input regenerated after each cycle. - Use Case: When writing a CLI command that installs resources or a worker loop that processes a queue, apply the three-question test (runs twice, crashed midway, converges to same state) to identify where reconciliation steps are needed. ## Quick Start Ask the AI to review your command or processing loop for idempotency using the make-operations-idempotent principle and identify where partial state could break re-runs.

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 a command idempotent?▼

Make a command idempotent by having it scan for existing state at startup, clean stale artifacts, and converge to the desired end state rather than assuming a fresh environment. Test it by running twice and simulating a crash at every step.

What is the test for idempotent operations?▼

Ask three questions: what happens if this runs twice, what happens if the previous run crashed at any 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: record the owning process ID in the lock and check whether that process is still alive before honoring the lock. Dead PIDs indicate stale locks that can be safely reclaimed.

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

Use content-based cleanup whenever creation order or timestamps can be misleading, such as after retries or partial runs. Comparing artifacts by content equivalence ensures duplicates and orphans are detected regardless of when they were created.

What are the limitations of idempotency design?▼

Idempotency ensures convergence to the same end state but does not guarantee correctness of that state or handle external side effects like sent emails or charged payments. Operations with irreversible external effects need compensation logic instead.