principle-separate-before-serializing-shared-state

Eliminate shared mutable state between concurrent actors before applying structural serialization.

6.6k|542|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/cursor/plugins --skill principle-separate-before-serializing-shared-state
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: principle-separate-before-serializing-shared-state
Source: https://github.com/cursor/plugins/tree/main/pstack/skills/principle-separate-before-serializing-shared-state
Command: npx skills add https://github.com/cursor/plugins --skill principle-separate-before-serializing-shared-state

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Concurrent actors writing to the same file, branch, key, or state object create race conditions that are intermittent, hard to reproduce, and expensive to debug. This Skill provides a decision pattern for removing shared mutable state first, and only serializing access structurally when a single shared writer is a genuine invariant.

Core Features & Use Cases

  • Shared State Identification: Locate files both read and written, branches both pushed to, and APIs both defined and consumed by concurrent actors.
  • Separation-First Pattern: Give each actor its own owned file, key, branch, or state directory, merging only at the read or reporting boundary.
  • Structural Serialization Fallback: When one shared write target is a real invariant, enforce lockfiles, sequential phases, single-writer actors, or atomic compare-and-swap instead of conventions.
  • Use Case: Two parallel workers each writing their own lastX field into one state.json still share mutation; splitting into indexer-state.json and metrics-state.json removes the race entirely.

Quick Start

Ask the agent to review your concurrent workflow for shared mutable state and split each actor's writes into separately owned files before adding any locking.

Frequently Asked Questions about principle-separate-before-serializing-shared-state

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent race conditions when multiple agents write to the same file?

Give each concurrent actor its own owned file or state directory and merge results only at the read or reporting boundary. If one shared file is truly required, enforce serialization structurally with lockfiles, sequential phases, or atomic compare-and-swap rather than instructions.

What is the separate-before-serializing pattern for shared state?

It is a three-step pattern: identify shared mutable state, default to eliminating the shared write target by giving each actor its own object, and serialize access structurally only when one shared writer is a real invariant. Conventions and instructions are not concurrency control.

Why doesn't telling concurrent workers to take turns work?

Instructions and conventions are not enforced by the runtime, so concurrent writes still interleave unpredictably. Race conditions from shared mutable state are intermittent and hard to reproduce, which is why ownership separation or structural mechanisms like lockfiles are required.

When should I use a lock instead of splitting state?

Use a lock only when a single shared write target is a genuine invariant that cannot be split, such as one canonical resource multiple actors must update. Treat needing a lock as a design smell to verify first, since per-actor ownership usually removes the contention entirely.

Does writing different fields to one shared JSON file avoid races?

No. Two workers writing their own fields into one state.json still perform shared mutation of the same file, which can corrupt or lose updates. Separate files like indexer-state.json and metrics-state.json eliminate the shared write target.