360 Secure SkillHub
360 安全技能中心

principle-make-operations-idempotent

该 Skill 提供幂等操作的设计原则:每个改变状态的操作都应从当前状态推导步骤,读取现状、与目标比较,仅应用差异;写入采用临时路径再重命名,并增加对账步骤以处理上次运行遗留的锁、临时文件或半写记录。

分类:开发
cursor
热度 47.30
最近更新 2026-11-17 11:40:35

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add cursor/plugins/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.