PluginBench
Skill
Pass
Audit score 90

principle-separate-before-serializing-shared-state

cursor/plugins

Eliminate concurrent write conflicts by separating mutable state before applying serialization.

What is principle-separate-before-serializing-shared-state?

This principle guides you to avoid race conditions in concurrent systems by first eliminating shared mutable state between actors, and only applying structural serialization (locks, sequential phases, atomic operations) when sharing is truly unavoidable. Use it when multiple processes or threads might write to the same file, branch, key, or state object.

  • Identify shared mutable state across concurrent actors (files, branches, API definitions, state objects)
  • Separate write targets so each actor owns its own state and publishes independent facts
  • Apply structural serialization only when one shared write target is a genuine invariant
  • Distinguish between true shared mutation and independent state that can be merged at read boundaries

How to install principle-separate-before-serializing-shared-state

npx skills add https://github.com/cursor/plugins --skill principle-separate-before-serializing-shared-state
Claude Code
Cursor
Windsurf
Cline

How to use principle-separate-before-serializing-shared-state

  1. 1.Identify all mutable state that concurrent actors read or write
  2. 2.Map which actors write to the same target (file, branch, key, or object)
  3. 3.For each shared target, ask whether all actors truly need one canonical object or are publishing independent facts
  4. 4.Separate write targets by actor (e.g., separate state files per worker) when possible
  5. 5.Only when sharing is unavoidable, enforce serialization structurally via lockfiles, sequential phases, single-writer patterns, or atomic operations

Use cases

Good for
  • Preventing race conditions when multiple workers write to the same state file
  • Refactoring shared JSON state into per-actor files that merge at reporting time
  • Designing multi-branch CI/CD pipelines where each actor pushes to its own branch
  • Ensuring atomic updates in distributed systems by eliminating unnecessary shared write targets
Who it's for
  • Backend engineers designing concurrent systems
  • DevOps and infrastructure teams managing multi-worker deployments
  • Distributed systems architects
  • Teams debugging intermittent race conditions

principle-separate-before-serializing-shared-state FAQ

When should I use locks instead of separating state?

Only when one shared write target is a genuine invariant—i.e., the system truly requires a single canonical object. Treat the need for a lock as a design smell; first verify that separation is not possible.

What's the difference between shared mutation and independent state?

Shared mutation is when multiple actors write to the same object (e.g., two workers both updating fields in one state.json). Independent state is when each actor owns its own file or key; merging happens only at read/reporting boundaries.

How do I merge state from separate actors?

Merge at the read or reporting boundary, not at the write boundary. Each actor writes to its own owned file or key; a coordinator or aggregator reads all of them when needed.

Can I use conventions or instructions instead of structural serialization?

No. Conventions and instructions are not concurrency control and will fail under load or timing variations. Use structural mechanisms: lockfiles, sequential phases, exclusive ownership, or atomic operations.

What counts as a real invariant requiring shared state?

A real invariant is when the system logically requires one canonical source of truth that all actors must read and write. Most cases are not true invariants; they just appear that way until you redesign for separation.

Full instructions (SKILL.md)

Source of truth, from cursor/plugins.


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 share mutable state, first ask whether they need the same mutable object. If not, eliminate the sharing. When sharing is real, enforce serialization structurally: lockfiles, sequential phases, exclusive ownership. Instructions and conventions are not concurrency control.

Why: Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.

Pattern:

  1. Identify shared mutable state (files both read and write, branches both push to, APIs both define and consume).
  2. Default: eliminate the shared write target. Ask: do these actors need one canonical object, or are they publishing independent facts? Give each actor its own owned file, key, branch, or state directory, and merge only at the read/reporting boundary. Two workers writing their own lastX field into one state.json is still shared mutation. indexer-state.json + metrics-state.json is not.
  3. Only when one shared write target is a real invariant, serialize access structurally (lockfiles, sequential phases, single-writer actor, or atomic compare-and-swap). Treat "we need a lock" as a design smell to check, not as the default answer.