360 Secure SkillHub
360 安全技能中心

principle-make-operations-idempotent

该 Skill 以原则性说明为主,指导在设计命令、生命周期步骤和处理循环时实现幂等:从当前状态推导步骤、只应用差异、让残留状态可识别为陈旧,并通过临时写入后重命名确保重复运行得到同一最终状态。

分类:开发
backnotprop
热度 69.26
最近更新 2026-11-24 05:23:52

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add backnotprop/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.
disable-model-invocation
true

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.