From cf979d6b6d75d14247ca3e377fbffeba5a1a184b Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 20 Jan 2026 14:17:18 +0000 Subject: [PATCH] fix(retry): resolve RETRY_BACKOFF_DELAYS initialization order error - Remove duplicate RETRY_BACKOFF_DELAYS and RETRY_JITTER_FACTOR from Defaults/index.ts - Export constants from retry-utils.ts as single source of truth - Add 'as const' for better type inference - Fixes "Cannot access 'RETRY_BACKOFF_DELAYS' before initialization" error --- src/Defaults/index.ts | 16 ++++------------ src/Utils/retry-utils.ts | 6 +++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/Defaults/index.ts b/src/Defaults/index.ts index 9116ff43..5f22f2d5 100644 --- a/src/Defaults/index.ts +++ b/src/Defaults/index.ts @@ -169,15 +169,7 @@ export const DEFAULT_CACHE_MAX_KEYS = { LID_GLOBAL: 10_000 } -/** - * Retry configuration with custom progressive backoff - * Fixed delay steps in milliseconds: 1s → 2s → 5s → 10s → 20s - * Use with 'stepped' backoff strategy in retry-utils.ts - */ -export const RETRY_BACKOFF_DELAYS = [1000, 2000, 5000, 10000, 20000] - -/** - * Jitter factor for retry delays (0.15 = ±15% randomization) - * Helps prevent thundering herd problem - */ -export const RETRY_JITTER_FACTOR = 0.15 +// NOTE: RETRY_BACKOFF_DELAYS and RETRY_JITTER_FACTOR are defined in retry-utils.ts +// to avoid circular dependency and initialization order issues. +// Import from '@whiskeysockets/baileys' Utils if needed: +// import { getRetryDelayWithJitter, getAllRetryDelaysWithJitter } from './Utils/retry-utils' diff --git a/src/Utils/retry-utils.ts b/src/Utils/retry-utils.ts index 66594804..61affb88 100644 --- a/src/Utils/retry-utils.ts +++ b/src/Utils/retry-utils.ts @@ -20,15 +20,15 @@ import type { CircuitBreaker } from './circuit-breaker.js' /** * Retry configuration with custom progressive backoff * Fixed delay steps in milliseconds: 1s → 2s → 5s → 10s → 20s - * Defined locally to avoid circular dependency with Defaults + * Exported for external use (e.g., custom retry logic) */ -const RETRY_BACKOFF_DELAYS = [1000, 2000, 5000, 10000, 20000] +export const RETRY_BACKOFF_DELAYS = [1000, 2000, 5000, 10000, 20000] as const /** * Jitter factor for retry delays (0.15 = ±15% randomization) * Helps prevent thundering herd problem */ -const RETRY_JITTER_FACTOR = 0.15 +export const RETRY_JITTER_FACTOR = 0.15 /** * Backoff strategies