feat: add event worker deduplication and request ID tracing#400
Open
WISDOM-WOKE22 wants to merge 1 commit intoLabsCrypt:mainfrom
Open
feat: add event worker deduplication and request ID tracing#400WISDOM-WOKE22 wants to merge 1 commit intoLabsCrypt:mainfrom
WISDOM-WOKE22 wants to merge 1 commit intoLabsCrypt:mainfrom
Conversation
- Add unique constraint on StreamEvent(transactionHash, eventType) to prevent duplicate event processing on worker restart - Replace streamEvent.create with upsert pattern that detects and logs duplicate events - Add migration for the unique constraint - Add test_event_processing_is_idempotent_on_restart test verifying no duplicates on replay - Add AsyncLocalStorage-based request ID middleware for end-to-end correlation - Include requestId in all Winston log entries automatically - Add X-Request-ID response header (reads X-Request-ID from request if valid) - Include requestId in SSE connected event payload for client-side tracking - Log request received/response sent with method, path, status, duration, and requestId closes LabsCrypt#383, closes LabsCrypt#381 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Contributor
|
hey, main was failing CI from broken auth imports + frontend parse errors. fixed and pushed to main now. please rebase to pick up the fixes: git fetch upstream
git rebase upstream/main
git push --force-with-leaseif there's a conflict, resolve it locally and we'll review once CI is green. |
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.
Summary
Implements two critical hardening features to improve system reliability and observability:
1. Event Worker Deduplication (Addresses #383)
StreamEvent(transactionHash, eventType)to prevent duplicate event processing2. Request ID Tracing (Addresses #381)
AsyncLocalStorageand UUID generationrequestIdfield for trace correlationX-Request-IDheader (echoes client-provided ID if valid, up to 128 chars)requestIdfor client-side connection trackingChanges
Backend Schema & Migrations:
backend/prisma/schema.prisma— Added unique constraintbackend/prisma/migrations/20260428000000_add_stream_event_unique_constraint/— Migration SQLEvent Worker Deduplication:
backend/src/workers/soroban-event-worker.ts— Updated 6 event handlers (CREATED, TOPPED_UP, WITHDRAWN, CANCELLED, COMPLETED, FEE_COLLECTED) to use upsert pattern with duplicate detectionbackend/tests/soroban-event-worker.test.ts— New test suite validating idempotencyRequest ID Middleware:
backend/src/middleware/requestId.ts— New middleware (AsyncLocalStorage + logging)backend/src/logger.ts— Added requestContext export and Winston format enhancementbackend/src/app.ts— Mounted requestId middleware in request chainbackend/src/controllers/sse.controller.ts— Added requestId to SSE connected eventTest Results
✅ All event worker idempotency tests pass
✅ All previously passing tests still pass
✅ Zero impact on existing functionality
closes #383, closes #381
🤖 Generated with Claude Code