Separate before serializing shared state
Instructions and conventions are not concurrency control. Start by removing
the shared write target. Add serialization only when one canonical writer is a
real domain invariant.
Decide from ownership
- Inventory every mutable object and every actor that can write it. Include
files, branches, database rows, keys, caches, queues, and in-memory state.
- Ask whether the actors publish independent facts. If they do, give each
actor its own file, key, branch, or state directory and merge only at a
read-only reporting boundary.
- Confirm that the split removes shared mutation. Two workers writing separate
fields of one JSON document still share a write target; separate documents
with one owner each do not.
- If one shared object is required, choose structural serialization: a
single-writer actor, sequential phases, a lockfile with defined stale-lock
behavior, an atomic transaction, or compare-and-swap.
- Prove the design under overlap, retry, crash, and stale-state scenarios.
Report the ownership map, the sharing that can be removed, any invariant that
requires serialization, and the concrete mechanism enforcing it. A request for
analysis does not authorize changing the system. Assess compatibility and
migration before changing a persisted format, public interface, or branch
workflow. It also does not authorize commits, pushes, publishing, deployment,
or external messages.
Adapted from Lauren Tan's PStack
principle-separate-before-serializing-shared-state
at commit 60c641e4fad674784b30abcf9f8915dea39df38d under the MIT License.
See third-party notices.
1---2name: qstack-separate-before-serializing-shared-state3description: Redesign concurrent work that shares a mutable file, branch, key, or state object by separating ownership before adding serialization. Use when actors may race, a lock is proposed, or coordination relies on taking turns.4license: MIT5---67# Separate before serializing shared state89Instructions and conventions are not concurrency control. Start by removing10the shared write target. Add serialization only when one canonical writer is a11real domain invariant.1213## Decide from ownership14151. Inventory every mutable object and every actor that can write it. Include16 files, branches, database rows, keys, caches, queues, and in-memory state.172. Ask whether the actors publish independent facts. If they do, give each18 actor its own file, key, branch, or state directory and merge only at a19 read-only reporting boundary.203. Confirm that the split removes shared mutation. Two workers writing separate21 fields of one JSON document still share a write target; separate documents22 with one owner each do not.234. If one shared object is required, choose structural serialization: a24 single-writer actor, sequential phases, a lockfile with defined stale-lock25 behavior, an atomic transaction, or compare-and-swap.265. Prove the design under overlap, retry, crash, and stale-state scenarios.2728Report the ownership map, the sharing that can be removed, any invariant that29requires serialization, and the concrete mechanism enforcing it. A request for30analysis does not authorize changing the system. Assess compatibility and31migration before changing a persisted format, public interface, or branch32workflow. It also does not authorize commits, pushes, publishing, deployment,33or external messages.3435Adapted from Lauren Tan's PStack36[`principle-separate-before-serializing-shared-state`](https://github.com/cursor/plugins/blob/60c641e4fad674784b30abcf9f8915dea39df38d/pstack/skills/principle-separate-before-serializing-shared-state/SKILL.md)37at commit `60c641e4fad674784b30abcf9f8915dea39df38d` under the MIT License.38See [third-party notices](../../THIRD_PARTY_NOTICES.md).