feat(stripe): queue webhooks in dedicated FIFO worker#2385
Conversation
Verify and enqueue Stripe events before acknowledging requests. Process events serially per customer with retries, preserved sync and cache behavior, and subscription lock snapshots.
|
Capy auto-review is paused for this organization because the usage-cycle auto-review limit has been reached. Increase the limit or turn it off in billing settings to resume automatic reviews. |
| try { | ||
| processed.push(await processMessage(message)); | ||
| } catch { |
There was a problem hiding this comment.
FIFO visibility expires while waiting
When a receive contains multiple webhooks for one customer and an earlier handler consumes a substantial part of its 270-second timeout, later messages wait in this sequential loop under the same 300-second visibility window. Their visibility can expire before processing begins, allowing another worker to process the customer group concurrently or out of order while the original worker also continues through the batch.
Knowledge Base Used: Queue, Cron, and Trigger.dev Background Work
Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/queue/processFifoMessageGroups.ts
Line: 22-24
Comment:
**FIFO visibility expires while waiting**
When a receive contains multiple webhooks for one customer and an earlier handler consumes a substantial part of its 270-second timeout, later messages wait in this sequential loop under the same 300-second visibility window. Their visibility can expire before processing begins, allowing another worker to process the customer group concurrently or out of order while the original worker also continues through the batch.
**Knowledge Base Used:** [Queue, Cron, and Trigger.dev Background Work](https://app.greptile.com/autumn-org-2/-/custom-context/knowledge-base/useautumn/autumn/-/docs/server-queue-workers.md)
How can I resolve this? If you propose a fix, please make it concise.
Summary
Deployment
STRIPE_WEBHOOK_SQS_QUEUE_URLto point to the provisioned FIFO queue, with producer and worker IAM accessTests
bunx tsgo --build --noEmitbun test tests/unit/queue(8 passed)bun test tests/unit/webhooks tests/integration/scopes/scope-403.test.ts(269 passed)Summary by cubic
Queues Stripe webhooks to a dedicated FIFO SQS worker that processes events per customer in order with retries and deduplication. Replaces early-ack + Redis idempotency while preserving Stripe sync and customer cache refresh.
New Features
StripeWebhookwith longer timeouts (visibility 300s; 270s processing) and FIFO group handling.Migration
Written for commit f13b84a. Summary will update on new commits.
Greptile Summary
Moves verified Stripe webhooks into a dedicated FIFO SQS processing path.
STRIPE_WEBHOOK_SQS_QUEUE_URL.Confidence Score: 2/5
The PR is not safe to merge until FIFO visibility and deletion handling prevent concurrent or duplicate Stripe webhook processing.
Later messages in a customer batch can become visible while waiting behind a slow predecessor, and per-entry batch deletion failures are silently ignored, allowing the same billing events to run concurrently or more than once.
server/src/queue/processFifoMessageGroups.ts, server/src/queue/initWorkers.ts
Important Files Changed
Sequence Diagram
sequenceDiagram participant Stripe participant API as Webhook API participant SQS as FIFO Queue participant Worker participant DB Stripe->>API: Signed webhook API->>API: Verify signature and resolve org API->>SQS: Enqueue by org/env/customer SQS-->>API: Accepted API-->>Stripe: HTTP 200 SQS->>Worker: Receive customer message group loop Sequentially per group Worker->>DB: Load context and process event Worker->>DB: Refresh customer cache end Worker->>SQS: Batch-delete successful messagesComments Outside Diff (1)
server/src/queue/initWorkers.ts, line 278-285 (link)When SQS accepts
DeleteMessageBatchbut returns individual entries in itsFailedcollection, this code discards the response and treats every deletion as successful. Those processed Stripe webhooks remain queued and are delivered again, repeating their billing mutations and downstream side effects.Knowledge Base Used: Queue, Cron, and Trigger.dev Background Work
Prompt To Fix With AI
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "feat(stripe): 🎸 queue stripe webhooks i..." | Re-trigger Greptile
Context used: