360 Secure SkillHub
360 安全技能中心

principle-make-operations-idempotent

该 Skill 给出幂等操作的设计原则:从当前状态推导步骤并只应用差异;对锁、临时文件、半写记录和已认领任务等残留物,提供可识别为过期的依据;通过临时路径写入并重命名落位,并用“运行两次”和“任意点崩溃”测试检查是否需要核对步骤。

分类:开发
mdsmithaustin
热度 0.00
最近更新 2026-11-26 11:31:37

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add mdsmithaustin/pstack/principle-make-operations-idempotent
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
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.

Make Operations Idempotent

Design every state-changing operation to converge to the correct state however many times it runs and wherever the previous run stopped.

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.

Anything a run leaves behind (a lock, a temporary file, a half-written record, a claimed job) must be recognizable as stale by the next run, by evidence that holds wherever the previous run could have stopped. Write to a temporary path and rename it into place.

The test: what happens if this runs twice? What if the previous run crashed at every possible point? If the answer depends on what was left behind, add a reconciliation step.