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

principle-make-operations-idempotent

Skill này làm gì

Cung cấp cho agent một quy tắc xây dựng các thao tác an toàn khi thử lại sau sự cố. Dành cho kỹ sư viết lệnh, job hoặc vòng lặp xử lý.

Khi nào nên dùng

  • ✓Khi bạn thiết kế một lệnh hoặc job có thể được chạy lại sau lỗi.
  • ✓Khi khởi động lại, thử lại hoặc sự cố có thể để lại trạng thái dở dang.
  • ✓Khi bạn cần một vòng lặp xử lý có thể tiếp tục an toàn.

Liên kết skill

https://github.com/cursor/plugins/blob/main/harness/pstack/claude-code/skills/principle-make-operations-idempotent/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-make-operations-idempotent/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

“Hãy làm cho job nhập dữ liệu của chúng tôi an toàn khi chạy lại sau sự cố mà không tạo bản ghi trùng.”

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

Cách hoạt động

Agent suy ra mỗi bước từ trạng thái hiện tại và chỉ áp dụng phần chênh lệch còn thiếu. Nó làm cho các dấu hiệu còn sót lại như khóa hoặc file tạm có thể nhận ra là đã cũ, rồi kiểm tra điều gì xảy ra nếu job chạy hai lần hoặc gặp sự cố ở từng điểm.

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.

Make Operations Idempotent

Design operations so they converge to the correct state regardless of how many times they run or where the previous run stopped. Every state-mutating operation should answer: "What happens if this runs twice? What happens if the previous run crashed halfway?"

Why: Commands, lifecycle operations, and processing loops run where crashes, restarts, and retries are normal. If partial state changes the next run's outcome, every restart becomes a debugging session.

The idea: derive each step from the state that exists, not from what the previous run meant to do. Read the current state, compare it to the goal, and apply only the difference. A step written this way is safe to repeat, because a repeat finds nothing left to do.

Anything a run leaves behind, such as a lock, a temporary file, a half-written record, or a claimed job, must be recognizable as stale by the next run. Judge staleness by evidence that stays true wherever the previous run could have stopped, not only in the common case. A marker that the next run cannot judge turns every crash into manual cleanup. For example, write to a temporary path and rename it into place, or compare artifacts by content instead of by creation order.

The test:

  1. What happens if this runs twice in a row?
  2. What happens if the previous run crashed at every possible point?
  3. Does re-execution converge to the same end state?

If any answer is "it depends on what state was left behind," the operation needs a reconciliation step.

Câu hỏi thường gặp

Bài kiểm tra then chốt là gì?

Hỏi điều gì xảy ra nếu thao tác chạy hai lần liên tiếp, và điều gì xảy ra nếu lần chạy trước bị sự cố ở mọi điểm có thể.

Khóa còn sót lại được xử lý thế nào?

Chúng phải được đánh giá là cũ dựa trên bằng chứng vẫn đúng ở bất kỳ điểm nào lần chạy trước có thể đã dừng.

Ghi vào file tạm có giúp ích không?

Có. Ghi vào một đường dẫn tạm rồi đổi tên vào đúng chỗ là một cách tránh kết quả ghi dở dang.

Chi tiết

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

Apply when designing commands, lifecycle steps, or processing loops that run amid crashes, restarts, and retries. Converge to the same end state regardless of partial prior runs.

repo: cursor/plugins

Độ phổ biến

Sao GitHub
15k
Vị trí xếp hạng
#10979
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ự