Principle Make Operations Idempotent

作者 cursorccb5507cec15無授權條款10K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

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.

AI 產生的概覽

關於讓指令、生命週期步驟與處理迴圈在崩潰與重試下保持幂等的設計指引。

功能
此技能提供一種設計模式,讓會改變狀態的操作不論執行多少次、從哪裡開始,都能收斂到相同的最終狀態。內容涵蓋收斂式啟動、以內容為基礎的清理、自癒鎖與幂等排程,並提供三個問題來檢驗某項操作是否需要加入對帳步驟。它產出的是設計指引,而非程式碼或檔案。
適用情境
在設計與崩潰、重啟和重試並存的指令、生命週期步驟或處理迴圈時使用。適合先前執行只完成一部分、可能改變下一次執行結果的情境。
執行需求
不需要任何工具、套件、執行環境、憑證或網路存取;它僅為說明性指示,不附帶指令碼。

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.

The pattern:

  • Convergent startup: scan for existing state, clean stale artifacts, adopt live sessions
  • Content-based cleanup: compare by content equivalence, not creation order
  • Self-healing locks: use PID-based stale lock detection
  • Idempotent scheduling: failed work respawns cleanly, fresh input regenerated after each cycle

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.

來源與署名

來源:cursor/plugins位於pstack/skills/principle-make-operations-idempotent提交ccb5507

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架