feat: production Stripe webhook async architecture with Redis, Jules worker, and optional AI providers#355
Open
Copilot wants to merge 5 commits into
Open
Conversation
…worker and AI providers
…orts, unused return value, token comparison)
Copilot
AI
changed the title
feat: production Stripe webhook async architecture with Redis, Jules worker and AI providers
feat: production Stripe webhook async architecture with Redis, Jules worker, and optional AI providers
Jun 2, 2026
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Copilot created this pull request from a session on behalf of
LVT-ENG
June 2, 2026 14:32
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the monolithic Stripe webhook handler with a layered async architecture: the HTTP layer validates, deduplicates, and enqueues in <10ms; all business logic runs in a separate Jules worker process consuming from Redis.
HTTP layer (
api/index.py→ thin adapter)services/webhook(): verify sig → Redis idempotency check →mark_event_received→enqueue_event→ 200WebhookVerificationErrorresponses (fixes CodeQLpy/stack-trace-exposure)processed_events: set/queued_events: list(not safe across Vercel invocations)Services layer (
api/services/)redis_client— singleton with_MemoryRedisfallback for dev (no Redis required locally)redis_lock— distributed lock viaSET NX EXwith token-checked release (prevents releasing a different worker's lock on TTL expiry)stripe_service—verify_webhook()decoupled from Flask; raises typedWebhookVerificationErrorevent_store— Redis hash state machine:RECEIVED → PROCESSING → PROCESSED / FAILED; includes retry counter and TOCTOU guard (re-check after lock acquisition)queue_service—LPUSH/BRPOPmain queue + sorted-set delayed requeue + DLQJules worker (
api/orchestrators/)decision_engine— pure Python, no I/O;decide_event_flow(event, context) → Decisionexecution_engine— dispatches to handler; calls AI enrichment via_run_ai_optional()(swallows all errors — AI failure never blocks business logic)jules_worker— blocking loop: flush delayed → dequeue → lock → decide → execute → mark done or exponential-backoff retry (2s/4s/8s) → DLQ atMAX_RETRIES# Run worker externally (not on Vercel) PYTHONPATH=api python -m orchestrators.jules_workerAI providers (
api/ai_providers/)AIProviderABC +GoogleAIStudioProvider(optionalgoogle-generativeaiSDK) +ManusAIProvider(plain HTTP)CircuitBreaker(3-failure threshold, 60s recovery window)run_ai_task(task_type, payload, provider=None)— provider selected byAI_PROVIDERenv var; never called from the HTTP layerModels & config
Decisiondataclass:action,reason,priority,requires_ai,provider,retryable,metadataEventActionenum covers:mark_order_paid,mark_payment_failed,activate_subscription,handle_refund,request_manual_review,invoke_ai_enrichment,ignore_eventapi/config.py— single source of truth for all env vars withvalidate()at startupInfrastructure
api/requirements.txt— addedredis>=5.0.0.env.example— documents all vars: Stripe, Redis, AI providers, worker tuningWhat's mocked / needs real implementation
handlers/stripe_handlers.py— TODO stubs for DB writes, emails, fulfillmentManusAIProvider._build_request_body/_parse_response— update once Manus API schema is confirmed_MemoryRedis— single-process dev only; setREDIS_URLfor any multi-process deployment