360 Secure SkillHub
360 安全技能中心

principle-make-operations-idempotent

该 Skill 给出设计幂等状态变更操作的原则:从当前状态推导步骤、仅应用差异、识别陈旧遗留物,并用临时路径加重命名保证收敛。

分类:开发
michael-denyer
热度 0.00
最近更新 2026-11-25 17:33:00

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add michael-denyer/pstack-claude/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.
user-invocable
false

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.