360 Secure SkillHub
360 安全技能中心

principle-separate-before-serializing-shared-state

面向并发写入同一文件、分支、键或状态对象的场景,建议先让各执行者使用独立状态并在读取时合并;仅当共享写入是真实不变量时,才通过锁、单写入者或顺序阶段进行结构化串行化。

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

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add cursor/plugins/principle-separate-before-serializing-shared-state
兼容性
通用兼容
联网要求
不联网
数据出网
数据不出本机
Metadata
name
principle-separate-before-serializing-shared-state
description
Apply when concurrent actors might write to the same file, branch, key, or state object. Eliminate the sharing first; serialize structurally only when one shared writer is a real invariant.
disable-model-invocation
true

Separate Before Serializing Shared State

When concurrent actors might write the same file, branch, key, or object, first ask whether they need one shared object or are publishing independent facts. Default to giving each actor its own file, key, branch, or state directory, and merge only where the state is read. Two workers writing their own field into one state.json is still shared mutation.

Only when one shared write target is a real invariant, serialize access structurally (a lockfile, a single writer, sequential phases, compare-and-swap). Instructions are not concurrency control, and "we need a lock" is a smell to check first.