principle-make-operations-idempotent

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

4|1|Updated Dec 16, 2023
One-click install
npx skills add https://github.com/Shtian/AuthentiClash --skill principle-make-operations-idempotent-shtian
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/Shtian/AuthentiClash/tree/main/.claude/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/Shtian/AuthentiClash --skill principle-make-operations-idempotent-shtian

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 such operations idempotent so re-execution always converges to the correct end state. ## Core Features & Use Cases - Convergent Startup Pattern: Scan for existing state, clean stale artifacts, and adopt live sessions instead of assuming a fresh start. - Self-Healing Mechanisms: Apply content-based cleanup, PID-based stale lock detection, and idempotent scheduling that respawns failed work cleanly. - Three-Question Idempotency Test: Evaluate any operation by asking what happens if it runs twice, if the previous run crashed at any point, and whether re-execution converges to the same end state. - Use Case: When designing a deployment script or a batch processing loop, apply this principle to add reconciliation steps so a crashed run can be safely retried without manual cleanup. ## Quick Start Review my command or processing loop design and apply the make-operations-idempotent principle to identify where partial state could break 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 script or command idempotent?▼

Make a script idempotent by designing it to converge to the correct end state regardless of starting conditions. Scan for existing state at startup, clean stale artifacts, adopt live sessions, and add reconciliation steps wherever partial state could change the next run's outcome.

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 whether re-execution converges to the same end state. If any answer depends on leftover state, the operation needs a reconciliation step.

How do I handle stale lock files after a crash?▼

Use PID-based stale lock detection: record the process ID in the lock and check whether that process is still alive before treating the lock as valid. This lets a restarted operation self-heal instead of blocking on a lock left by a crashed run.

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

Use content-based cleanup whenever artifacts may be recreated or reordered across runs. Comparing by content equivalence avoids deleting or keeping the wrong items when a previous run crashed midway and left partial outputs behind.

Why do retries fail after a crashed processing loop?▼

Retries fail when partial state from the crashed run changes the next run's behavior, such as leftover locks, half-written outputs, or consumed inputs. Idempotent scheduling respawns failed work cleanly and regenerates fresh input after each cycle.