principle-separate-before-serializing-shared-state

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

Updated Sep 2, 2026
One-click install
npx skills add https://github.com/jnyross/pstack-muse --skill principle-separate-before-serializing-shared-state-jnyross
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/jnyross/pstack-muse/tree/main/skills/principle-separate-before-serializing-shared-state
Command: npx skills add https://github.com/jnyross/pstack-muse --skill principle-separate-before-serializing-shared-state-jnyross

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 framework for removing shared mutable state first, and only serializing access when a single shared writer is a genuine invariant. ## Core Features & Use Cases - Shared State Identification: Detects files both read and written, branches both pushed to, and APIs both defined and consumed by multiple actors. - Separation-First Pattern: Guides giving each actor its own owned file, key, branch, or state directory, merging only at the read/reporting boundary. - Structural Serialization Fallback: When one shared write target is truly required, enforces lockfiles, sequential phases, single-writer actors, or atomic compare-and-swap instead of conventions. - Use Case: Two workers each writing a lastX field into one state.json is still shared mutation; splitting into indexer-state.json and metrics-state.json removes the race entirely. ## Quick Start Ask the AI to review your concurrent workflow for shared mutable state and propose per-actor ownership or structural serialization where sharing is unavoidable.

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 between concurrent workers?

First check whether the workers truly need the same mutable object. Give each actor its own owned file, key, or branch and merge only at the read boundary; serialize access structurally with lockfiles or sequential phases only when one shared writer is a real invariant.

What counts as shared mutable state in a concurrent system?

Shared mutable state includes files multiple actors both read and write, branches multiple actors push to, keys in a shared state object, and APIs both defined and consumed by different actors. Even two workers writing separate fields into one state.json file is shared mutation.

When should I use a lock instead of separating state?

Use a lock only when a single shared write target is a genuine invariant that cannot be split. Treat needing a lock as a design smell to verify first; when locking is required, enforce it structurally through lockfiles, single-writer actors, or atomic compare-and-swap.

Why don't instructions or conventions prevent concurrent write conflicts?

Telling agents or goroutines to take turns does not work because conventions are not enforced by the system. Race conditions from shared writes are intermittent and hard to reproduce, so only structural mechanisms like ownership separation or lockfiles reliably prevent them.

How do I split a shared state file between multiple agents?

Assign each agent its own state file scoped to its responsibility, such as indexer-state.json and metrics-state.json instead of one shared state.json. Merge the separate files only at the read or reporting boundary where a combined view is needed.