principle-make-operations-idempotent

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Commands, lifecycle steps, and processing loops often 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 a design discipline for making operations safe to re-run. ## Core Features & Use Cases - Convergent Startup Design: Guides scanning for existing state, cleaning stale artifacts, and adopting live sessions instead of assuming a clean slate. - Self-Healing Patterns: Covers content-based cleanup, PID-based stale lock detection, and idempotent scheduling where failed work respawns cleanly. - Idempotency Test Checklist: Applies three concrete questions (run twice, crash at every point, converge to same end state) to audit any operation. - Use Case: When writing a deployment script or a queue-processing loop, use this Skill to restructure it so a mid-run crash leaves the system recoverable on the next invocation. ## Quick Start Review my processing loop and make it idempotent so it converges to the same state even if it crashes halfway through a run.

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 script or operation idempotent?▼

Make an operation idempotent by having it scan for existing state at startup, clean stale artifacts, and converge to the target end state rather than assuming a clean slate. Test it by running twice and simulating a crash at every possible point.

What is the test for whether an operation 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: 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 cleanup compare by content instead of creation order?▼

Content-based cleanup is appropriate whenever artifacts may be recreated in a different order across runs. Comparing by content equivalence avoids deleting or keeping the wrong items when a previous run crashed partway through.

When is idempotency not worth the effort?▼

Idempotency adds reconciliation logic that may be unnecessary for one-shot, manually supervised operations with no retries. It matters most for automated commands, lifecycle hooks, and processing loops that run unattended where crashes and restarts are routine.