baphuongna/pi-crew/state-mutation-locking

Claude Code and agent skill by baphuongna/pi-crew

Trust tier 1
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Durable state mutation and locking workflow. When NOT to use: read-only inspection (use runtime-state-reader); single-process non-concurrent edits.

Install

npx vskill@latest install baphuongna/pi-crew/state-mutation-locking

SKILL.md

state-mutation-locking

Use this skill before modifying pi-crew run state.

Source patterns distilled

  • src/state/locks.ts — run-level sync/async locks
  • src/state/state-store.ts — manifest/tasks persistence
  • src/state/contracts.ts — allowed status transitions
  • src/state/mailbox.ts, src/state/task-claims.ts, src/state/atomic-write.ts
  • src/runtime/crash-recovery.ts, src/runtime/stale-reconciler.ts, src/runtime/team-runner.ts

Rules

  • Mutations to a run's manifest.json, tasks.json, mailbox delivery state, claims, or recovery status must be protected by a run lock when concurrent actions are possible.
  • Re-read manifest/tasks inside the lock before making a decision; pre-lock reads are only for locating the run.
  • Persist with atomic write helpers (atomicWriteJson, async variants, or state-store helpers). Do not partially write JSON files.
  • Respect status contracts. Do not transition terminal tasks/runs unless the action explicitly supports force semantics.
  • Separate analysis from persistence: pure reconcilers should return intended repaired state; locked callers should persist it.
  • In retry/resume paths, reload fresh task status immediately before execution and skip if the task is no longer retryable/runnable.
  • Include event-log entries for externally visible state changes.

Enforcement — State Mutation Locking Gate

Before mutating run state, verify:

  • [ ] Run lock acquired before mutation (concurrent actions possible)
  • [ ] Manifest/tasks re-read inside the lock before decision
  • [ ] Atomic write helpers used (atomicWriteJson or state-store helpers)
  • [ ] Status contracts respected (no terminal transitions without force semantics)
  • [ ] Event-log entries emitted for externally visible state changes
  • [ ] Retry paths reload fresh task status before execution

If ANY answer is NO → Stop. Verify locking and atomicity before mutating.

Anti-patterns

  • Reading state, waiting/doing async work, then writing the old copy.
  • Updating tasks.json from a reconciler or watcher without a lock.
  • Cancelling/responding to runs owned by another session.
  • Using fs.writeFileSync for JSON state outside atomic helpers.

Verification

bash
cd pi-crew
npx tsc --noEmit
node --experimental-strip-types --test test/unit/cancel-ownership.test.ts test/unit/respond-tool.test.ts test/unit/stale-reconciler.test.ts test/unit/api-claim.test.ts
npm test

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
5

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/baphuongna/pi-crew/state-mutation-locking/badge)](https://verified-skill.com/skills/baphuongna/pi-crew/state-mutation-locking)

Something wrong with this skill or its page? Tell us.