idempotent-script-design
Idempotent Script Design
An idempotent operation produces the same result whether run once or ten times.
Techniques:
- Check before create:
CREATE TABLE IF NOT EXISTS,mkdir -p, check file existence before writing. - Upsert instead of insert: Use
INSERT ... ON CONFLICT DO UPDATEin SQL. - Atomic writes: Write to a temp file, then rename — prevents corrupt partial output.
- Track progress: Write a completion marker or checkpoint so reruns skip done work.
Testing idempotency: Run your script twice on the same input and verify the output is identical.
Anti-patterns:
- Appending to a file without checking if the data is already there.
- Inserting rows without checking for duplicates.
More from aiming-lab/metaclaw
structured-step-by-step-reasoning
Use this skill for any problem that involves multiple steps, tradeoffs, or non-trivial logic. Think out loud before answering to improve accuracy and transparency. Apply whenever the answer is not immediately obvious.
13codebase-navigation
Use this skill when exploring an unfamiliar codebase, tracing code paths, or answering questions about how the system works. Read before writing, and build a mental model of the architecture before making changes.
12graceful-error-recovery
Use this skill when a tool call, command, or API request fails. Diagnose the root cause systematically before retrying or changing approach. Do not retry the same failing call without first understanding why it failed.
11uncertainty-acknowledgment
Use this skill when you are not sure about a fact, have outdated knowledge, or the question is contested. Explicitly communicate the level of confidence instead of asserting uncertain things as fact.
11secure-code-review
Use this skill when reviewing or writing code that handles user input, authentication, file I/O, network requests, or database queries. Always check for common security vulnerabilities before considering the code complete.
10plan-before-multi-step-execution
Use this skill before executing a sequence of 3 or more steps, especially when steps are irreversible or depend on each other. Write out the plan and verify it before starting execution.
9