- Home
- Skills
- APIs & Backend
- API Retry, Webhook & Idempotency Surgeon
Works with the AI Agents you already use
API Retry, Webhook & Idempotency Surgeon
by Badung
If your app handles payments, emails, or background tasks, small errors in how it retries can cause big problems.
$3.99
What it does
- Catches missing idempotency keys that let a network glitch charge a customer twice
- Detects race conditions where two identical requests might pass through at the same time
- Spots unsafe retry loops that can overwhelm your server during a crash
- Checks if your webhooks are properly secured against hackers replaying old messages
- Provides a line by line code fix to patch reliability gaps in your specific framework
Who it's for
Founders managing payment systems
Stop double charges and lost orders before they hurt your reputation.
Try asking: “Check my payment processing code for double charge risks.”
Shop owners with custom checkouts
Ensure your customer orders are processed exactly once, even if the site crashes.
Try asking: “Audit my checkout webhook for race conditions.”
Freelance developers building backends
Fix tricky retry bugs and security gaps in your API handlers.
Try asking: “Scan my webhook handler for signature verification and retry issues.”
API Retry, Webhook & Idempotency Surgeon
Example session with this skill installed
Review app/api/webhooks/billing/route.ts before we ship:
export async function POST(req: Request) {
const event = await req.json();
if (event.type === "invoice.paid") {
const sub = await db.subscription.findUnique({ where: { id: event.data.id } });
if (sub && sub.status !== "active") {
await db.subscription.update({
where: { id: sub.id },
data: { status: "active", credits: sub.credits + 100 },
});
await sendReceiptEmail(sub.userEmail);
}
}
return Response.json({ ok: true });
}
- Read your context and instructions
- Compiled the api retry webhook
Summary: Audited app/api/webhooks/billing/route.ts —
BLOCK: missing webhook signature verification, TOCTOU duplicate credit grant under concurrent deliveries, and non-transactional email side effect.
Findings
- [BLOCKER]
REPLAY_OR_SIGNATURE_GAP(lines 2–3):req.json()parses the payload with no HMAC signature or timestamp check on the raw body, allowing forgedinvoice.paidrequests to grant credits. - [BLOCKER]
PARTIAL_COMMIT_OR_RACE(lines 5–10): Read-then-write (sub.status !== "active"followed bycredits: sub.credits + 100) is not atomic. Two concurrent retries of the sameevent.idcan both pass the check and add+200credits. - [HIGH]
MISSING_IDEMPOTENCY_KEY(line 10):sendReceiptEmail(sub.userEmail)runs outside any deduplicated event log and has no idempotency key; a crash or retry after DB commit resends duplicate emails. - [MED]
UNBOUNDED_TIMEOUT_OR_DLQ_BLACKHOLE: No explicit timeout or dead-letter handling ifsendReceiptEmailfails transiently after the DB update.
Minimal Diff Patch
--- a/app/api/webhooks/billing/route.ts
+++ b/app/api/webhooks/billing/route.ts
@@ -1,14 +1,32 @@
export async function POST(req: Request) {
- const event = await req.json();
+ const rawBody = await req.text();
+ const sig = req.headers.get("x-webhook-signature") ?? "";
+ if (!verifyWebhookSignature(rawBody, sig, process.env.WEBHOOK_SECRET!, { toleranceSec: 300 })) {
+ return Response.json({ error: "invalid_signature" }, { status: 401 });
+ }
+
+ const event = JSON.parse(rawBody);
if (event.type === "invoice.paid") {
- const sub = await db.subscription.findUnique({ where: { id: event.data.id } });
- if (sub && sub.status !== "active") {
- await db.subscription.update({
- where: { id: sub.id },
- data: { status: "active", credits: sub.credits + 100 },
- });
- await sendReceiptEmail(sub.userEmail);
- }+ const claimed = await db.$transaction(async (tx) => {
+ const inserted = await tx.webhookEvent.createMany({
+ data: [{ eventId: event.id, type: event.type }],
+ skipDuplicates: true,
+ });
+ if (inserted.count === 0) return null;
+
+ return tx.subscription.update({
+ where: { id: event.data.id },
+ data: { status: "active", credits: { increment: 100 } },
+ });
+ });
+
+ if (claimed) {
+ await sendReceiptEmail(claimed.userEmail, { idempotencyKey: `receipt:${event.id}` });
+ }
}
return Response.json({ ok: true });
}
Verification (Pending local run)
- Replay the exact same
invoice.paidpayload concurrently (Promise.allwith 5 requests) against a test DB and confirmcreditsincrements once andwebhookEventholds 1 row. - Send a request with a tampered body or timestamp older than 300s and confirm
401 invalid_signature.
Assumptions
webhookEvent.eventIdhas aUNIQUEindex in the database schema.verifyWebhookSignatureuses constant-time comparison (crypto.timingSafeEqual).
Connects securely to your tools. The creator never sees your data.
About this skill
If your app handles payments, emails, or background tasks, small errors in how it retries can cause big problems. You might charge a customer twice, send ten emails instead of one, or lose an order entirely when a server hiccups. This skill audits your code to find these hidden reliability risks. It looks for missing safety keys, bad retry loops, and security gaps in your webhooks.
How it works
- Provide a code snippet, a file path, or ask your AI agent to search your project for payment and webhook code.
- The skill scans the code for five specific reliability flaws like missing double-check guards or unsafe retries.
- You get a list of risks ranked by how badly they could break your system.
- The skill provides a precise code fix that you can copy and paste to solve the issue.
What you get: A structured reliability report with a ready-to-use code patch that prevents duplicate actions.
This skill only reads your code. It cannot run tests or fix your database settings for you.
Audits code for idempotency and reliability using Read, Grep, and Glob tools. It specifically targets MISSING_IDEMPOTENCY_KEY, UNSAFE_RETRY_STORM, PARTIAL_COMMIT_OR_RACE, REPLAY_OR_SIGNATURE_GAP, and UNBOUNDED_TIMEOUT. Built to work with typical backend patterns like Stripe webhooks, Axios/Fetch clients, and Prisma/SQL transactions. Returns surgical diffs for Node.js, Python, and other common languages.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 1 day ago
Nothing to install. It runs in your AI agent.
No shell, network or API keys needed: paste the handler, client or worker (or give its file path) and the skill reads it with Read, Grep and Glob.
Permissions
What's inside
Frequently Asked Questions
New in APIs & Backend
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.