principle-make-operations-idempotent

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

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

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 a design principle for making operations safe to re-run. ## Core Features & Use Cases - Convergent Startup: 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 stale leftovers. - Self-Healing Locks: Use PID-based stale lock detection so crashed processes do not block future runs. - Idempotent Scheduling: Respawn failed work cleanly and regenerate fresh input after each cycle. - Use Case: When writing a CLI command or background worker that processes files, apply the three-question test (runs twice, crashed midway, converges to same state) to identify where reconciliation steps are needed. ## Quick Start Review my command or processing loop and make it idempotent so it converges to the same end state after crashes and 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 a command or script idempotent?▼

Make a command idempotent by designing it to converge to the same end state regardless of prior partial runs. Scan for existing state at startup, clean stale artifacts by content equivalence, and add reconciliation steps wherever leftover state could change the outcome.

How do I test 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 process 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 the new run.

Why does my processing loop behave differently after a restart?▼

Restart-dependent behavior means partial state from the previous run is changing the next run's outcome. Fix it with convergent startup that scans existing state, adopts live sessions, and regenerates fresh input after each cycle.

When should I compare artifacts by content instead of creation order?▼

Compare by content equivalence whenever cleanup or deduplication decisions depend on which artifacts are stale. Creation order is unreliable after crashes and retries, while content comparison identifies true duplicates and leftovers deterministically.