# Principle Make Operations Idempotent

Design state-changing operations to converge to the correct state regardless of how many times they run or where the previous run stopped. Ensure any leftover artifacts from a failed run are recognizable as stale and can be safely cleaned up.

**Canonical URL:** https://skillshunter.net/skills/discovered-b141ee93a4c6ad77f3d1a01b1b3777638fa0c102fc842802

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-b141ee93a4c6ad77f3d1a01b1b3777638fa0c102fc842802

**Markdown URL:** https://skillshunter.net/skills/discovered-b141ee93a4c6ad77f3d1a01b1b3777638fa0c102fc842802.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-b141ee93a4c6ad77f3d1a01b1b3777638fa0c102fc842802/download

**Category:** Software & Development

**Source URL:** https://github.com/jueyi6/empstack/blob/74181e31d2f00313f8683ba157966efcabbe109e/skills/principle-make-operations-idempotent/SKILL.md

**Source commit:** 74181e31d2f00313f8683ba157966efcabbe109e

**Listing approved at:** 2026-12-02

**Created at:** 2026-11-30T08:56:17.000000Z

**Updated at:** 2026-12-02T09:15:14.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Operations should write to a temporary path and rename files into place to ensure idempotency. This approach helps avoid leaving stale artifacts that could interfere with subsequent runs.

### When to use it

- Implementing retry logic in deployment scripts
- Ensuring data consistency in batch processing jobs
- Designing idempotent API endpoints for safe retries

## Skill instructions

---
name: principle-make-operations-idempotent
description: For steps that retry after crashes, make every rerun reach one end state.
disable-model-invocation: true
---

# Make Operations Idempotent

Design every state-changing operation to converge to the correct state however many times it runs and wherever the previous run stopped.

Derive each step from the state that exists, not from what the previous run meant to do. Read the current state, compare it to the goal, and apply only the difference.

Anything a run leaves behind (a lock, a temporary file, a half-written record, a claimed job) must be recognizable as stale by the next run, by evidence that holds wherever the previous run could have stopped. Write to a temporary path and rename it into place.

The test: what happens if this runs twice? What if the previous run crashed at every possible point? If the answer depends on what was left behind, add a reconciliation step.

