Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)15k · #10987

principle-separate-before-serializing-shared-state

Skill này làm gì

Cung cấp cho agent một quy tắc xử lý công việc đồng thời có thể cùng ghi vào một file, nhánh hoặc trạng thái. Dành cho kỹ sư chạy nhiều worker hoặc agent cùng lúc.

Khi nào nên dùng

  • ✓Khi nhiều agent hoặc tiến trình có thể cùng ghi vào một file hoặc đối tượng trạng thái.
  • ✓Khi hai nhánh hoặc worker sẽ cùng push vào một đích.
  • ✓Khi bạn bị cám dỗ thêm khóa để sửa các race condition thoáng qua.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-separate-before-serializing-shared-state/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Ba agent cùng ghi vào một file trạng thái chung và nó liên tục bị hỏng. Hãy sửa thiết kế.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent hỏi liệu các worker có thật sự cần chung một đối tượng hay không. Nếu không, nó cho mỗi worker một file hoặc khóa riêng và chỉ gộp ở bước báo cáo. Chỉ khi thật sự cần một bên ghi chung duy nhất thì nó mới thêm tuần tự hóa có cấu trúc, như khóa.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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.
Câu hỏi thường gặp

Hướng dẫn có đủ để ngăn xung đột không?

Không. Skill nói rằng hướng dẫn và quy ước không phải là cơ chế kiểm soát đồng thời.

Khóa có phải là cách sửa mặc định không?

Không. Skill coi nhu cầu về khóa là một dấu hiệu thiết kế cần kiểm tra trước.

Cách chia tốt là gì?

Các file trạng thái riêng mà mỗi worker sở hữu, thay vì nhiều worker cùng ghi vào một file chung.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
15k
Vị trí xếp hạng
#10987
Giấy phép
—
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự