feat: add auto-reconnect with exponential backoff to admin webhook SSE stream (Closes #300) [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #380
Open
waterWang wants to merge 1 commit into
Conversation
…vents (Adamantine-guild#300) - Replace single fetch call with tryConnect loop that auto-reconnects - Add SSE-specific backoff constants (lazy reads for testability) - Add sseBackoffDelayMs() using capped exponential backoff with jitter - Add onReconnecting callback to notify caller of reconnect attempts - Reset backoff counter on successful connection - Reset backoff after stability window of successful frames - Clean up timeouts and abort controller on unsubscribe - Add comprehensive test suite with node:test - Fix pre-existing syntax errors in connectors.ts and mock.ts
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
Closes #300
Adds automatic reconnection with capped exponential backoff to the
subscribeWebhookEvents()SSE stream inlib/api/live.ts.Changes
Core reconnect logic (
lib/api/live.ts)fetch+.then()call with an asynctryConnect()loop that auto-reconnects on failureNEXT_PUBLIC_SSE_RECONNECT_MAX_ATTEMPTS(default: 10)NEXT_PUBLIC_SSE_RECONNECT_BASE_DELAY_MS(default: 100ms)NEXT_PUBLIC_SSE_RECONNECT_MAX_DELAY_MS(default: 10s)NEXT_PUBLIC_SSE_STABILITY_WINDOW_MS(default: 30s)sseBackoffDelayMs()— capped exponential backoff with jitter (same pattern as RESTbackoffDelayMs)onReconnectingcallback parameter to notify callers of reconnect attemptsunsubscribe()now properly cleans up: setsstoppedflag, clears pending reconnect timeout, aborts the controllerAPI surface (
lib/api/types.ts,lib/api/mock.ts)onReconnecting?: (attempt: number, delayMs: number) => voidto theAdminAccessApiinterfaceMockAccessApito accept the new parameter (no-op)Bug fixes
lib/wallet/connectors.ts(missing= [in array literal)lib/api/mock.ts(duplicateanalyticsproperty)Tests (
test/webhook-stream-reconnect.test.ts)onErroris still invoked so polling fallback works