Repository navigation
feat(events): add event deduplication primitive, stream driver, and r… - #90
Merged
Merged
Conversation
…eorg rewind handling
13 tasks
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.
SummaryThis PR resolves event processing vulnerabilities across the SDK by introducing a deduplication primitive (ProcessedSet), a managed polling stream driver (EventStream), and ledger-reorg rewind capabilities. It guarantees idempotent event processing and eliminates per-repository polling loop divergence.Key Changes1. Deduplication Primitive (src/events/processed-set.ts)Introduced the ProcessedSet interface and an InMemoryProcessedSet implementation.Uses an$O(1)$ FIFO-evicting strategy with a default capacity of 10,000 entries to prevent memory leaks while blocking duplicate event execution.2. Stream Driver & Reorg Handling (src/events/stream.ts)Created the EventStream class to own polling loops, pagination, and backoff logic.Features exponential back-off with 10% random jitter and native AbortSignal support.Detects unresolvable cursors during ledger reorganizations and rewinds to the last known-good state.Guarantees zero active timer handles when stop() is invoked.3. Cursor & Deduplication Integration (src/events/cursor.ts)Added optional StreamEvent.id field and integrated ProcessedSet checks into EventCursor.process().Preserves strict no-skip ordering: execution proceeds only if unprocessed, followed by store.set() and then processedSet.add().Added a reset() method to support cursor rewinds during reorgs.4. Public Exports & Test Coverage (src/events/index.ts, src/tests/events.test.ts)Re-exported ProcessedSet, InMemoryProcessedSet, and EventStream.Added 16 new unit tests across 5 describe blocks validating deduplication, timer cleanup, throw safety, and reorg rewinds.Quality GatesUnit Tests: npm test $\rightarrow$ 214/214 passed (100%)TypeScript: npm run typecheck $\rightarrow$ 0 errorsLinter: npm run lint $\rightarrow$ 0 errorsBuild: npm run build $\rightarrow$ Clean CJS & ESM outputs
Closes #87