agentleFS
PradnyeshpPradnyeshp/Claude-Skills/.claude/skills/idempotency/SKILL.md

idempotency

Skill2 starsChanged 4 months agoMITView on GitHub

Make a write endpoint or operation safe to retry by adding idempotency keys — so a duplicate request (from a client retry, double-click, or network timeout) produces one effect, not two. Use when the user says "add idempotency", "make this endpoint idempotent", "prevent duplicate charges", "add an idempotency key", "deduplicate requests", "handle double submits", or "this can be called twice and double-writes".

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Accept a client-supplied key: Read an Idempotency-Key header (or a body field for internal callers).

    line 20
  2. Very specific:

    Bound retention: Keep keys long enough to cover realistic client retry windows (commonly 24h–7d) and expire them (TTL in Redis, or a …

    line 26
  3. Distinctive:

    Verify: Add/adjust a test that fires the same request twice with one key and asserts a single side effect plus identical responses, and a …

    line 27

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Framework, store & existing idempotency signals

!grep -rilE "idempoten|Idempotency-Key|dedup|express|fastify|nestjs|flask|fastapi|django|redis|prisma|sequelize|sqlalchemy|typeorm" --include='*.*' package.json pyproject.toml go.mod Gemfile 2>/dev/null | grep -vE 'node_modules|\.git|dist|build' | head -8

Instructions

Make the operation in $ARGUMENTS safe to execute more than once with the same input, so retries and double-submits don't create duplicate side effects (a second charge, a second order, a second email). Reuse the project's existing web framework and datastore rather than introducing new infrastructure.

Method

  1. Decide whether a key is even needed. Naturally idempotent operations (GET, PUT/DELETE by id, upserts keyed on a unique column) may already be safe — a UNIQUE constraint on a natural key is often the simplest fix. Reach for an idempotency key when the operation is a non-idempotent POST with real side effects (payments, orders, sends).
  2. Accept a client-supplied key. Read an Idempotency-Key header (or a body field for internal callers). The client generates a stable UUID per logical operation and reuses it across retries. Validate it's present and well-formed for the endpoints that require it.
  3. Persist request → response, atomically. On first request, insert the key with a status of in-progress inside the same transaction as the side effect (or use an atomic INSERT ... ON CONFLICT DO NOTHING / SETNX). Store the eventual response (status + body) against the key so a replay can return it verbatim.
  4. Handle the replay paths:
    • Completed key → return the stored response with the original status code; do not re-run the side effect.
    • In-progress key (concurrent duplicate still running) → return 409 Conflict or have the client back off, rather than racing a second execution.
    • Same key, different request body → reject with 422; a key must map to exactly one request payload, or a client bug could mask a real second operation.
  5. Bound retention. Keep keys long enough to cover realistic client retry windows (commonly 24h–7d) and expire them (TTL in Redis, or a created_at + sweep for SQL). Say what window you chose and why.
  6. Verify. Add/adjust a test that fires the same request twice with one key and asserts a single side effect plus identical responses, and a test that a different body under the same key is rejected.

Rules

  1. The side effect and the key record must commit together — never write the effect first and the key second, or a crash between them defeats the guarantee. Use one transaction or an atomic insert.
  2. A replay of a completed key must return the stored response and must not re-execute the side effect; an in-progress duplicate must not run concurrently.
  3. Bind a key to its request payload — reject a reused key with a different body rather than silently returning the old response.
  4. Reuse the project's datastore for key storage and set a TTL/retention window; don't let the key table grow unbounded.
  5. End by summarizing which operations are now idempotent, the header/field used, the store and retention window, and the replay behavior for completed / in-progress / mismatched requests. Cross-reference the retry skill, since safe client retries depend on this.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.