agentsclimarketplace

Script idempotency

Skill Amey-Thakur/AI-SKILLS/skills/scripting-automation/script-idempotency

Plug-and-play skills and prompts for every AI coding agent

Install
npx -y skills add Amey-Thakur/AI-SKILLS --skill script-idempotency

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 18 days oldThe repository was created 18 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Write scripts whose reruns are always safe through check-then-act steps, atomic writes, and dry-run modes. Use when automation may run twice, die halfway, or need a safe retry.

SKILL.md

3.5 KB, as published. Nobody here has run it

Script idempotency

Every script eventually runs twice: a retry, a duplicated cron slot, a nervous operator. Idempotent means the second run converges to the same end state without damage: design each step to check reality before changing it.

Method

  1. Write steps as desired-state assertions. Not "create the directory" but "ensure the directory exists" (mkdir -p, ln -sfn, INSERT ... ON CONFLICT, kubectl apply): each step describes an end state and is a no-op when reality already matches. Commands that fail on re-execution (mkdir, useradd, plain INSERT) get guarded: check-then-act, or use the tool's idempotent form (the declarative instinct of infrastructure-as-code, at script scale).
  2. Make mutations atomic. Write to a temp file in the same filesystem, then mv into place (rename is atomic; a killed script leaves the old file intact, never a half-written one); database changes in transactions; multi-file updates staged then swapped via symlink flip. A script killed at any line should leave either the old state or the new state, never a hybrid (see graceful-shutdown's crash-window thinking).
  3. Track progress for resumable multi-step work. Long scripts record completed units (a state file of processed IDs, a done/ marker per item, a database progress row) and skip them on rerun: crash recovery becomes "run it again" (see background-jobs checkpointing; data work gets this from partition-overwrite: see data-pipeline-design). Guard the state file updates with the same atomic-write rule.
  4. Separate side effects that cannot be repeated. Sending email, charging, posting to chat: gate behind a dedup record checked in the same step ("send unless sent-marker exists; write marker atomically after"), or route through systems with idempotency keys (see idempotency-keys, idempotent-consumers). A rerunnable script with one unrepeatable side effect in the middle is not rerunnable.
  5. Build --dry-run as a first-class mode. Every mutating action routed through a helper that logs-instead-of-does under the flag (run() { $DRY && echo "would: $*" || "$@"; }); dry-run output is how operators verify a fix before trusting it and how reviews check blast radius (see automation-guardrails; PowerShell gets this free via -WhatIf: see powershell-essentials).
  6. Test the rerun and the interruption. The test matrix: run twice (second run must be a clean no-op, verifiable in output), kill mid-run then rerun (must converge), run against already-partially-converged state. Ten minutes of this testing catches what makes 3am retries terrifying (see chaos-testing's ethic at the smallest scale).

Boundaries

  • Idempotency covers rerunning the same version with the same inputs; concurrent runs of the same script need locking on top (see scheduled-jobs, distributed-locks).
  • Rollback is a separate capability: converging forward is not the same as undoing; destructive transitions (dropping columns, deleting files) get backups or a two-phase expand-contract plan (see database-migrations, rollback-strategy).
  • Some operations are inherently one-shot (rotating a secret, bumping a version); isolate them, label them, and make the script detect "already done" rather than pretending the whole run is uniform.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.