principle-make-operations-idempotent

Designs commands and processing loops that converge to the same state after crashes and retries.

6.6k|542|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/cursor/plugins --skill principle-make-operations-idempotent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/cursor/plugins/tree/main/pstack/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/cursor/plugins --skill principle-make-operations-idempotent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Commands, lifecycle steps, and processing loops that run amid crashes, restarts, and retries often leave partial state behind, turning every restart into a debugging session. This Skill provides design principles for making state-mutating operations idempotent so re-execution always converges to the correct end state.

Core Features & Use Cases

  • Convergent Startup Patterns: 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 Checklist: Evaluate any operation with three questions—what happens if it runs twice, if it crashed at any point, and whether re-execution converges.
  • Use Case: When designing a retry-able job queue or a CLI command that may be interrupted mid-run, apply these patterns so a second run reconciles leftover state rather than corrupting it.

Quick Start

Ask the agent to review your command or processing loop for idempotency using the make-operations-idempotent principles and add reconciliation steps where partial state could leak between runs.

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 idempotent?

Make a command idempotent by having it scan for existing state at startup, clean stale artifacts, and converge to the desired end state rather than assuming a clean slate. Test it by running twice and simulating a crash at every step.

How to handle stale lock files after a crash?

Use PID-based stale lock detection: record the owning process ID in the lock and check whether that process is still alive before honoring the lock. If the process is gone, reclaim the lock and continue safely.

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, add a reconciliation step.

Why do retries cause duplicate or corrupted state?

Retries cause corruption when operations append or mutate without checking existing state, so partial results from the failed run alter the next run's outcome. Content-based comparison and convergent startup prevent this by treating prior output as input to reconcile.

When should failed scheduled work be respawned?

Failed work should be respawned cleanly with fresh input regenerated after each cycle, rather than resuming from potentially stale intermediate state. This keeps each scheduling cycle independent and safe to repeat.