pitcheye.dev← All 30 rules
severity: warnpack: webhooksv1.0 core

webhooks/payment-update-missing-idempotency

Payment webhook update has no lifecycle predicate

npx @pitcheye/check . --pack webhooks

whyItBreaks

Providers deliver at-least-once: the same event arrives twice on a retry, a duplicate subscription, or a replay. An update keyed only on the row id re-applies the transition — marking a refunded order paid again, re-crediting a balance, re-firing the emails. The database never objects, so nothing surfaces it.

✖ Bad — triggers warnfixtures/webhooks-payment-update-missing-idempotency/bad
.update(orders).set({ status: "paid" }).where(eq(orders.id, id))
✓ Good — passes checkfixtures/webhooks-payment-update-missing-idempotency/good
.update(orders).set({ status: "paid" }).where(and(eq(orders.id, id), eq(orders.status, "pending")))

suggestedFix

Put the current state in the predicate: `.where(and(eq(orders.id, id), eq(orders.status, "pending")))` and treat 0 updated rows as "already applied".

explain_rule({"webhooks/payment-update-missing-idempotency"})

Agent & MCP JSON output contract

{
  "ruleId": "webhooks/payment-update-missing-idempotency",
  "pack": "webhooks",
  "severity": "warn",
  "file": "apps/web/src/app/api/uploadthing/core.ts",
  "line": 6,
  "message": "a webhook `.update(...)` whose `where` clause has no status/state condition",
  "whyItBreaks": "Providers deliver at-least-once: the same event arrives twice on a retry, a duplicate subscription, or a replay. An update keyed only on the row id re-applies the transition — marking a refunded order paid again, re-crediting a balance, re-firing the emails. The database never objects, so nothing surfaces it.",
  "suggestedFix": "Put the current state in the predicate: `.where(and(eq(orders.id, id), eq(orders.status, \"pending\")))` and treat 0 updated rows as \"already applied\".",
  "docsUrl": "https://pitcheye.dev/rules/webhooks-payment-update-missing-idempotency"
}

Markdown: curl -H "Accept: text/markdown" https://pitcheye.dev/rules/webhooks-payment-update-missing-idempotency

raw markdown
# webhooks/payment-update-missing-idempotency

- **severity:** warn
- **pack:** webhooks
- **docs:** https://pitcheye.dev/rules/webhooks-payment-update-missing-idempotency

## whyItBreaks

Providers deliver at-least-once: the same event arrives twice on a retry, a duplicate subscription, or a replay. An update keyed only on the row id re-applies the transition — marking a refunded order paid again, re-crediting a balance, re-firing the emails. The database never objects, so nothing surfaces it.

## bad

```ts
.update(orders).set({ status: "paid" }).where(eq(orders.id, id))
```

## good

```ts
.update(orders).set({ status: "paid" }).where(and(eq(orders.id, id), eq(orders.status, "pending")))
```

## suggestedFix

Put the current state in the predicate: `.where(and(eq(orders.id, id), eq(orders.status, "pending")))` and treat 0 updated rows as "already applied".

## commands

```bash
npx @pitcheye/check . --pack webhooks
```

```json
{"tool":"explain_rule","arguments":{"ruleId":"webhooks/payment-update-missing-idempotency"}}
```
← webhooks/unverified-signatureBack to rule catalog