<< All versions

Skill v1.0.1

currentAutomated scan100/100
jtaroreh/agystack/principle-make-operations-idempotent

+1 new

──Details
PublishedNovember 5, 2026 at 07:26 PM
Content Hashsha256:8000f978baf5744c...
Git SHA93f43a58ade4
Bump Typepatch
Compare with v1.0.0
──Files
Files (1 file, 2.2 KB)
SKILL.md2.2 KBactive
SKILL.md · 38 lines · 2.2 KB

name: principle-make-operations-idempotent description: "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." disable-model-invocation: true metadata: version: "1.0.1"


Make Operations Idempotent

Design operations so they converge to the correct state regardless of how many times they run or where they start from. 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.

Derive State Deltas

Compute state deltas instead of executing imperative mutation sequences.

  1. Inspect actual and desired state. Given the current actual state and the target desired state, compute delta = desired - actual.
  2. Apply only the delta. Execute mutations only for the missing or diverged elements. Do not re-run actions for state that already matches the target.
  3. Safe no-ops on converged state. Re-running the operation on an already-converged state results in delta = empty. The operation exits immediately with zero side effects.
  4. Crash recovery by design. An operation that crashes midway leaves a partially converged state. On retry, the reconciliation step computes the remaining delta and finishes the transition without duplicating work.

Patterns

  • Convergent startup. Scan for existing state, clean stale artifacts, and adopt live sessions.
  • Content-based cleanup. Compare by content equivalence rather than creation order or timestamps.
  • Self-healing locks. Use PID-based or lease-based stale lock detection.
  • Idempotent scheduling. Ensure failed work respawns cleanly and fresh input is regenerated after each cycle.

The Test

  1. What happens if this operation 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.

← v1.0.0All versions