MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / withRetry

Function withRetry

source code/bridge/remoteBridgeCore.ts:894–915  ·  view source on GitHub ↗

Retry an async init call with exponential backoff + jitter.

(
  fn: () => Promise<T | null>,
  label: string,
  cfg: EnvLessBridgeConfig,
)

Source from the content-addressed store, hash-verified

892
893/** Retry an async init call with exponential backoff + jitter. */
894async function withRetry<T>(
895 fn: () => Promise<T | null>,
896 label: string,
897 cfg: EnvLessBridgeConfig,
898): Promise<T | null> {
899 const max = cfg.init_retry_max_attempts
900 for (let attempt = 1; attempt <= max; attempt++) {
901 const result = await fn()
902 if (result !== null) return result
903 if (attempt < max) {
904 const base = cfg.init_retry_base_delay_ms * 2 ** (attempt - 1)
905 const jitter =
906 base * cfg.init_retry_jitter_fraction * (2 * Math.random() - 1)
907 const delay = Math.min(base + jitter, cfg.init_retry_max_delay_ms)
908 logForDebugging(
909 `[remote-bridge] ${label} failed (attempt ${attempt}/${max}), retrying in ${Math.round(delay)}ms`,
910 )
911 await sleep(delay)
912 }
913 }
914 return null
915}
916
917// Moved to codeSessionApi.ts so the SDK /bridge subpath can bundle them
918// without pulling in this file's heavy CLI tree (analytics, transport).

Callers 2

initEnvLessBridgeCoreFunction · 0.70
recoverFromAuthFailureFunction · 0.70

Calls 2

logForDebuggingFunction · 0.85
sleepFunction · 0.85

Tested by

no test coverage detected