principle-make-operations-idempotent
它能做什么
为智能体提供一条规则,用于构建崩溃后可以安全重试的操作。适合编写命令、任务或处理循环的工程师。
适用场景
- ✓当你设计的命令或任务可能在失败后再次运行的时候。
- ✓当重启、重试或崩溃可能留下部分状态的时候。
- ✓当你需要一个能够安全恢复的处理循环的时候。
技能链接
https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-make-operations-idempotent/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请让我们的数据导入任务在崩溃后可以安全地重新运行,且不会重复创建记录。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会根据当前状态推导每一步,只应用缺失的差异。它会让锁或临时文件等遗留标记能被识别为陈旧的,然后检查任务在每个节点运行两次或中途崩溃时会发生什么。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Make Operations Idempotent
Design operations so they converge to the correct state regardless of how many times they run or where the previous run stopped. 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 idea: derive each step from the state that exists, not from what the previous run meant to do. Read the current state, compare it to the goal, and apply only the difference. A step written this way is safe to repeat, because a repeat finds nothing left to do.
Anything a run leaves behind, such as a lock, a temporary file, a half-written record, or a claimed job, must be recognizable as stale by the next run. Judge staleness by evidence that stays true wherever the previous run could have stopped, not only in the common case. A marker that the next run cannot judge turns every crash into manual cleanup. For example, write to a temporary path and rename it into place, or compare artifacts by content instead of by creation order.
The test:
- What happens if this runs twice in a row?
- What happens if the previous run crashed at every possible point?
- 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.
常见问题
关键的测试是什么?
要问操作连续运行两次会发生什么,以及上一次运行在每个可能的节点崩溃时会发生什么。
遗留的锁如何处理?
必须依据在上一次运行可能停止的任何位置都依然成立的证据,来判定它已经陈旧。
写入临时文件有帮助吗?
有。先写入临时路径,再重命名到目标位置,是避免写入一半结果的一种方法。
详情
作者的原始描述
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.
repo: cursor/plugins
热度
- GitHub 星标
- 15k
- 排名
- #10979
- 许可证
- —
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
advisor
15k如果你开启该功能,让你的智能体在关键节点咨询一个更强的第二模型,例如在重大决定之前,或在错误上卡住时。
check-agent-compatibility
15k全面检查 AI 编程智能体能否启动、验证和记录某个代码仓库,并返回一个兼容性评分以及主要问题。
cli-for-agents
15k教你的智能体设计或审查命令行工具,使 AI 智能体无需提示即可运行,并提供清晰的帮助文字和示例。
continual-learning
15k通过把回顾过往对话的工作交给专门的记忆更新程序,使你的 AGENTS.md 笔记保持最新。