Skip to content
Skillpedia
APIs & servers (backend)15k · #10979

principle-make-operations-idempotent

What it does

Gives the assistant a rule for building operations that are safe to retry after a crash. It is for engineers writing commands, jobs or processing loops.

When to use it

  • ✓When you design a command or job that might be run again after a failure.
  • ✓When restarts, retries or crashes could leave partial state behind.
  • ✓When you need a processing loop that can resume safely.

Skill link

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-make-operations-idempotent/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-make-operations-idempotent/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Make our data import job safe to rerun after a crash without duplicating records.”

5 new skills a week. 1 minute to read.

How it works

The assistant derives each step from the current state and applies only the missing difference. It makes leftover markers such as locks or temporary files recognizable as stale, then checks what happens if the job runs twice or crashes at each point.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Make Operations Idempotent

Design operations so they converge to the correct state regardless of how many times they run or where the previous run stopped. Every state-mutating operation should answer: "What happens if this runs twice? What happens if the previous run crashed halfway?"

Why: Commands, lifecycle operations, and processing loops run where crashes, restarts, and retries are normal. If partial state changes the next run's outcome, every restart becomes a debugging session.

The idea: 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. A step written this way is safe to repeat, because a repeat finds nothing left to do.

Anything a run leaves behind, such as a lock, a temporary file, a half-written record, or a claimed job, must be recognizable as stale by the next run. Judge staleness by evidence that stays true wherever the previous run could have stopped, not only in the common case. A marker that the next run cannot judge turns every crash into manual cleanup. For example, write to a temporary path and rename it into place, or compare artifacts by content instead of by creation order.

The test:

  1. What happens if this runs twice in a row?
  2. What happens if the previous run crashed at every possible point?
  3. Does re-execution converge to the same end state?

If any answer is "it depends on what state was left behind," the operation needs a reconciliation step.

FAQ

What is the key test?

Ask what happens if the operation runs twice in a row, and what happens if the last run crashed at every possible point.

How are leftover locks handled?

They must be judged stale by evidence that stays true wherever the previous run could have stopped.

Is writing to a temp file helpful?

Yes. Writing to a temporary path and renaming it into place is one way to avoid half-written results.

Details

Original description by the author

Apply when designing commands, lifecycle steps, or processing loops that run amid crashes, restarts, and retries. Converge to the same end state regardless of partial prior runs.

repo: cursor/plugins

Popularity

GitHub stars
15k
Ranking position
#10979
License
—
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills