{"id":18106,"plugin_id":"plugins_6a85a87df50c8191bd7f010bb7b17794","kind":"skill","collection_source":null,"comparison_source":null,"observed_at":"2026-09-30T23:14:37.599Z","digest":"7b08b3ece492665f9c136624c4914532217e15df9efba5a78d5f02a4e2771670","against":null,"payload":{"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.","included_files":[],"name":"principle-make-operations-idempotent","skill_md_contents":"---\nname: principle-make-operations-idempotent\ndescription: \"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.\"\ndisable-model-invocation: true\n---\n\n# Make Operations Idempotent\n\nDesign 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?\"\n\n**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.\n\n**The pattern:**\n- Convergent startup: scan for existing state, clean stale artifacts, adopt live sessions\n- Content-based cleanup: compare by content equivalence, not creation order\n- Self-healing locks: use PID-based stale lock detection\n- Idempotent scheduling: failed work respawns cleanly, fresh input regenerated after each cycle\n\n**The test:**\n1. What happens if this runs twice in a row?\n2. What happens if the previous run crashed at every possible point?\n3. Does re-execution converge to the same end state?\n\nIf any answer is \"it depends on what state was left behind,\" the operation needs a reconciliation step.\n"},"changes":[],"summary":"First saved snapshot. No earlier version is available for comparison.","summary_kind":"deterministic","summary_metadata":{}}