[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F7YT6J38ZPYYF1RRH3YYD7":3,"skill-same:01M7F7YT6J38ZPYYF1RRH3YYD7":44},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":23,"commitSha":24,"skillDirectory":25,"forksCount":26,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M7F7YT6J38ZPYYF1RRH3YYD7","principle-separate-before-serializing-shared-state",null,"Apply when concurrent actors may write the same file, branch, key, or state: remove the sharing first, and serialize only when one writer is a real invariant.","bitgineer\u002Fopencode-pstack","bitgineer","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F133060368?v=4","01M7F7V139SDYHXSH9GXXM8EV7","01M7F7V13Y1ZZCY3J922JX06QC",1,"MIT","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Fprinciple-separate-before-serializing-shared-state\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: principle-separate-before-serializing-shared-state\ndescription: \"Apply when concurrent actors may write the same file, branch, key, or state: remove the sharing first, and serialize only when one writer is a real invariant.\"\n\n---\n\n# Separate Before Serializing Shared State\n\nWhen 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.\n\n**Why:** Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.\n\n**Pattern:**\n1. **Identify shared mutable state** (files both read and write, branches both push to, APIs both define and consume).\n2. **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\u002Freporting boundary. Two workers writing their own `lastX` field into one `state.json` is still shared mutation. `indexer-state.json` + `metrics-state.json` is not.\n3. **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.\n","# Separate Before Serializing Shared State\n\nWhen 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.\n\n**Why:** Concurrent writes to shared state create race conditions that are intermittent, hard to reproduce, and expensive to debug.\n\n**Pattern:**\n1. **Identify shared mutable state** (files both read and write, branches both push to, APIs both define and consume).\n2. **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\u002Freporting boundary. Two workers writing their own `lastX` field into one `state.json` is still shared mutation. `indexer-state.json` + `metrics-state.json` is not.\n3. **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.\n",{"name":5,"description":7},"main","dbb7a4935f614ebaec65ca3beb181bf74ed53431","skills\u002Fpstack\u002Fprinciple-separate-before-serializing-shared-state",0,"https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack","https:\u002F\u002Fgithub.com\u002Fbitgineer","2026-10-21 18:58:00",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add bitgineer\u002Fopencode-pstack --skill principle-separate-before-serializing-shared-state",{"tool":36,"command":37},"bunx","bunx skills add bitgineer\u002Fopencode-pstack --skill principle-separate-before-serializing-shared-state",{"tool":39,"command":40},"pnpm","pnpm dlx skills add bitgineer\u002Fopencode-pstack --skill principle-separate-before-serializing-shared-state","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Fprinciple-separate-before-serializing-shared-state\u002FSKILL.md",true,[],[45,52,59,66,73,80],{"skillNo":46,"name":47,"nameZh":6,"description":48,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M7F8095YEQBD1R95S3CQNM7M","why","Trace why code works this way or why a design was chosen, from source control, trackers, docs, and telemetry. Use for rationale, regressions, or postmortems.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Fwhy\u002FSKILL.md",[],[],{"skillNo":53,"name":54,"nameZh":6,"description":55,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":56,"categories":57,"keywords":58,"publishedAt":18},"01M7F807MX84XR7FGZ1YTDPNPP","unslop","Cut AI tells from any writing.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Funslop\u002FSKILL.md",[],[],{"skillNo":60,"name":61,"nameZh":6,"description":62,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":63,"categories":64,"keywords":65,"publishedAt":18},"01M7F804Y0KW517P76ZAYQ86ED","typescript-best-practices","TypeScript best practices. Use when reading or editing any .ts or .tsx file.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Ftypescript-best-practices\u002FSKILL.md",[],[],{"skillNo":67,"name":68,"nameZh":6,"description":69,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":70,"categories":71,"keywords":72,"publishedAt":18},"01M7F800R1VV08YF0AKMNTPZ2J","technical-writing","Write or review docs, RFCs, readmes, PR descriptions, and commit messages in Diataxis structure with Google style, STE, and Global English.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Ftechnical-writing\u002FSKILL.md",[],[],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":18},"01M7F7ZX5TJ2049PWXHB07MA7Y","teach","Explain a body of work so a person actually understands it, running how and why and weaving both into one clear explanation. Use for teach me this.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Fteach\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":18},"01M7F7ZSN544YPV34WWVFW332X","tdd","Use only when the user asks for TDD, a failing test, or a regression test, or when a bug has a cheap local test target; skip unclear or costly test paths.","https:\u002F\u002Fgithub.com\u002Fbitgineer\u002Fopencode-pstack\u002Fblob\u002Fmain\u002Fskills\u002Fpstack\u002Ftdd\u002FSKILL.md",[],[]]