360 Secure SkillHub
360 安全技能中心

principle-separate-before-serializing-shared-state

该 Skill 以原则说明形式指导开发者处理并发写入同一文件、分支、键或状态对象的问题:默认让各执行者使用独立状态并在读取时合并,仅在共享写入是真实不变量时采用锁、单写者或顺序阶段等结构化序列化方式。

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

安装

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