Make operations idempotent
An idempotent operation converges from any state a previous attempt could have
left behind. A duplicate request that merely happens not to fail is not enough.
Test convergence
- List every durable mutation and external side effect in execution order.
- Model two consecutive runs from the completed state. When verification is
authorized in a safe environment, run both and compare the real end state,
not only the exit code.
- Model a crash after every mutation point and the rerun from each partial
state. Fault-inject only under the verification authority described below.
- Include stale locks, abandoned temporary files, live sessions, regenerated
input, reordered records, and content-equivalent artifacts where relevant.
- Add reconciliation before mutation whenever leftover state changes the next
run's result. Prefer adoption, content comparison, atomic replacement,
single ownership, and stale-owner detection over creation-order guesses.
- Prove repeated and resumed runs satisfy the same domain invariants. Generated
identifiers or timestamps need not be byte-identical unless the domain
requires that.
Report the mutation map, failure points tested, stale-state policy, convergence
proof, and any unresolved case. Never clear or overwrite user data merely to
make a retry pass without explicit authority for that destructive behavior.
Before reclaiming a lock or live session, prove ownership and liveness.
A design or review request is analysis-only: it does not authorize executing a
mutating operation, injecting a crash, creating a disposable environment, or
causing external side effects. Run repeated or partial-failure tests only when
the request authorizes verification and the environment is disposable and
safe. Live or external effects such as charges, messages, database writes, or
process interruption require explicit authority for those exact effects. When
direct proof would exceed that authority, report the case as UNPROVEN.
Analysis alone also does not authorize edits, commits, pushes, publishing,
deployment, or external messages.
Adapted from Lauren Tan's PStack
principle-make-operations-idempotent
at commit 60c641e4fad674784b30abcf9f8915dea39df38d under the MIT License.
See third-party notices.
1---2name: qstack-make-operations-idempotent3description: Design or review commands, lifecycle steps, and processing loops so retries, partial failure, restart, and stale state converge to the same correct result. Use when an operation may run twice or resume after a crash.4license: MIT5---67# Make operations idempotent89An idempotent operation converges from any state a previous attempt could have10left behind. A duplicate request that merely happens not to fail is not enough.1112## Test convergence13141. List every durable mutation and external side effect in execution order.152. Model two consecutive runs from the completed state. When verification is16 authorized in a safe environment, run both and compare the real end state,17 not only the exit code.183. Model a crash after every mutation point and the rerun from each partial19 state. Fault-inject only under the verification authority described below.204. Include stale locks, abandoned temporary files, live sessions, regenerated21 input, reordered records, and content-equivalent artifacts where relevant.225. Add reconciliation before mutation whenever leftover state changes the next23 run's result. Prefer adoption, content comparison, atomic replacement,24 single ownership, and stale-owner detection over creation-order guesses.256. Prove repeated and resumed runs satisfy the same domain invariants. Generated26 identifiers or timestamps need not be byte-identical unless the domain27 requires that.2829Report the mutation map, failure points tested, stale-state policy, convergence30proof, and any unresolved case. Never clear or overwrite user data merely to31make a retry pass without explicit authority for that destructive behavior.32Before reclaiming a lock or live session, prove ownership and liveness.3334A design or review request is analysis-only: it does not authorize executing a35mutating operation, injecting a crash, creating a disposable environment, or36causing external side effects. Run repeated or partial-failure tests only when37the request authorizes verification and the environment is disposable and38safe. Live or external effects such as charges, messages, database writes, or39process interruption require explicit authority for those exact effects. When40direct proof would exceed that authority, report the case as **UNPROVEN**.41Analysis alone also does not authorize edits, commits, pushes, publishing,42deployment, or external messages.4344Adapted from Lauren Tan's PStack45[`principle-make-operations-idempotent`](https://github.com/cursor/plugins/blob/60c641e4fad674784b30abcf9f8915dea39df38d/pstack/skills/principle-make-operations-idempotent/SKILL.md)46at commit `60c641e4fad674784b30abcf9f8915dea39df38d` under the MIT License.47See [third-party notices](../../THIRD_PARTY_NOTICES.md).