principle-make-operations-idempotent

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

1|Updated Aug 27, 2025
One-click install
npx skills add https://github.com/IgorGanapolsky/Random-Timer --skill principle-make-operations-idempotent-igorganapolsky
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/IgorGanapolsky/Random-Timer/tree/main/.cursor/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/IgorGanapolsky/Random-Timer --skill principle-make-operations-idempotent-igorganapolsky

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Commands, lifecycle steps, and processing loops that run amid crashes, restarts, and retries can leave partial state behind, turning every restart into a debugging session. This Skill provides a design principle for making operations converge to the correct 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. - Self-Healing Mechanisms: Apply content-based cleanup, PID-based stale lock detection, and idempotent scheduling that respawns failed work cleanly. - Idempotency Test: A three-question checklist (run twice, crash at any point, converge to same end state) to audit any state-mutating operation. - Use Case: When designing a retryable job queue or a CLI command that may be interrupted mid-run, apply this principle to add reconciliation steps so re-execution always reaches the same result. ## Quick Start Ask the AI to review your command or processing loop for idempotency using the make-operations-idempotent principle and add reconciliation steps where partial state could change outcomes.

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 no matter how many times it runs. Scan for existing state at startup, clean stale artifacts, adopt live sessions, and add a reconciliation step wherever partial state could change the next run's outcome.

How do I test whether a 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, the operation needs a reconciliation step.

What is a stale lock and how do I handle it?▼

A stale lock is a lock file left behind by a process that crashed before releasing it. Use PID-based stale lock detection: record the owning process ID in the lock and check whether that process is still alive before treating the lock as valid.

Why do retries cause bugs in processing loops?▼

Retries cause bugs when partial state from a failed run changes the outcome of the next run, such as duplicate records or skipped work. Idempotent scheduling fixes this by respawning failed work cleanly and regenerating fresh input after each cycle.

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

Use content-based cleanup whenever artifacts may be created in varying order across runs, such as after crashes or parallel execution. Comparing by content equivalence avoids deleting or keeping the wrong items when creation order is unreliable.