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 从公开仓库中收录这些内容。

举报或申请下架