Skip to content
Skillpedia
APIs & servers (backend)15k · #10987

principle-separate-before-serializing-shared-state

What it does

Gives the assistant a rule for handling concurrent work that might write to the same file, branch or state. It is for engineers who run several workers or agents at once.

When to use it

  • ✓When several agents or processes might write to the same file or state object.
  • ✓When two branches or workers would push to the same target.
  • ✓When you are tempted to add a lock to fix intermittent race conditions.

Skill link

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-separate-before-serializing-shared-state/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-separate-before-serializing-shared-state/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Three agents write to one shared status file and it keeps getting corrupted. Fix the design.”

5 new skills a week. 1 minute to read.

How it works

The assistant asks whether the workers really need one shared object. If not, it gives each its own file or key and merges only at the reporting step. Only when a single shared writer is truly required does it add structural serialization, such as a lock.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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.
FAQ

Are instructions enough to prevent conflicts?

No. The skill says instructions and conventions are not concurrency control.

Is a lock the default fix?

No. The skill treats the need for a lock as a design smell to check first.

What is a good split?

Separate state files that each actor owns, instead of several workers writing into one shared file.

Details

Original description by the author

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.

repo: cursor/plugins

Popularity

GitHub stars
15k
Ranking position
#10987
License
—
Updated
10/31/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills