Retry an async init call with exponential backoff + jitter.
( fn: () => Promise<T | null>, label: string, cfg: EnvLessBridgeConfig, )
| 937 | |
| 938 | /** Retry an async init call with exponential backoff + jitter. */ |
| 939 | async function withRetry<T>( |
| 940 | fn: () => Promise<T | null>, |
| 941 | label: string, |
| 942 | cfg: EnvLessBridgeConfig, |
| 943 | ): Promise<T | null> { |
| 944 | const max = cfg.init_retry_max_attempts |
| 945 | for (let attempt = 1; attempt <= max; attempt++) { |
| 946 | const result = await fn() |
| 947 | if (result !== null) return result |
| 948 | if (attempt < max) { |
| 949 | const base = cfg.init_retry_base_delay_ms * 2 ** (attempt - 1) |
| 950 | const jitter = |
| 951 | base * cfg.init_retry_jitter_fraction * (2 * Math.random() - 1) |
| 952 | const delay = Math.min(base + jitter, cfg.init_retry_max_delay_ms) |
| 953 | logForDebugging( |
| 954 | `[remote-bridge] ${label} failed (attempt ${attempt}/${max}), retrying in ${Math.round(delay)}ms`, |
| 955 | ) |
| 956 | await sleep(delay) |
| 957 | } |
| 958 | } |
| 959 | return null |
| 960 | } |
| 961 | |
| 962 | // Moved to codeSessionApi.ts so the SDK /bridge subpath can bundle them |
| 963 | // without pulling in this file's heavy CLI tree (analytics, transport). |
no test coverage detected