{"agent":"claude","input":"Make the Stripe webhook handler idempotent. Read app/api/webhooks/stripe/route.ts, lib/stripe.ts, lib/subscription.ts, lib/db.ts, prisma/schema.prisma, env.mjs and package.json first. Add a StripeEvent model keyed by the event id with type, created and processedAt. In the handler, insert the event row in the same transaction as the user update, treat a P2002 on that insert as already handled and answer 200, and roll back together on any later failure. Do not move stripeCurrentPeriodEnd backwards when an older renewal arrives late. Handle customer.subscription.deleted and customer.subscription.updated, read the subscription from the event object where it is present, and acknowledge unhandled types. Write tests that sign payloads with stripe.webhooks.generateTestHeaderString and cover a redelivered checkout event and two out-of-order renewals; add a minimal test runner if the project has none. Install a MySQL in the sandbox, run the migration and the tests, run yarn lint, and open a pull request with the output.","resources":[{"url":"https://github.com/your-org/your-app"}]}