principle-make-operations-idempotent

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

136|8|Updated May 9, 2026
One-click install
npx skills add https://github.com/Sma1lboy/rove --skill principle-make-operations-idempotent-sma1lboy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: principle-make-operations-idempotent
Source: https://github.com/Sma1lboy/rove/tree/main/.agents/skills/pstack/skills/principle-make-operations-idempotent
Command: npx skills add https://github.com/Sma1lboy/rove --skill principle-make-operations-idempotent-sma1lboy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Operations that run amid crashes, restarts, and retries often leave partial state behind, causing every restart to behave differently and turning recovery into a debugging session. This Skill provides a design discipline for making state-mutating operations converge to the same end state no matter 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 fresh start. - 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 operation. - Use Case: When writing a CLI command that creates worktrees and branches, apply this Skill to ensure re-running the command after a mid-execution crash reconciles leftover state instead of failing or duplicating resources. ## Quick Start Ask the AI to review your command or processing loop using the make-operations-idempotent principle and identify where partial state could break re-execution.

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 CLI command idempotent?▼

Make the command scan for existing state at startup, clean stale artifacts, and adopt live sessions rather than assuming a fresh start. Verify it by running it twice and checking that both runs converge to the same end state.

What is the test for whether an operation is idempotent?▼

Ask three questions: what happens if it runs twice, 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, add a reconciliation step.

How do I handle stale lock files after a process 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. Dead PIDs indicate stale locks that can be safely reclaimed.

Why does my processing loop behave differently after a restart?▼

The loop likely depends on partial state left by the previous run, such as creation-order-based cleanup or non-regenerated input. Apply content-based cleanup comparison and regenerate fresh input after each cycle so restarts converge cleanly.

When should failed work be respawned in a processing loop?▼

Failed work should be respawned cleanly on each scheduling cycle, with fresh input regenerated after every cycle. This idempotent scheduling ensures retries do not accumulate stale state or duplicate in-flight work.