MCPcopy Create free account
hub / github.com/Noumena-Network/code / withRetry

Function withRetry

src/bridge/remoteBridgeCore.ts:878–899  ·  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

876
877/** Retry an async init call with exponential backoff + jitter. */
878async function withRetry<T>(
879 fn: () => Promise<T | null>,
880 label: string,
881 cfg: EnvLessBridgeConfig,
882): Promise<T | null> {
883 const max = cfg.init_retry_max_attempts
884 for (let attempt = 1; attempt <= max; attempt++) {
885 const result = await fn()
886 if (result !== null) return result
887 if (attempt < max) {
888 const base = cfg.init_retry_base_delay_ms * 2 ** (attempt - 1)
889 const jitter =
890 base * cfg.init_retry_jitter_fraction * (2 * Math.random() - 1)
891 const delay = Math.min(base + jitter, cfg.init_retry_max_delay_ms)
892 logForDebugging(
893 `[remote-bridge] ${label} failed (attempt ${attempt}/${max}), retrying in ${Math.round(delay)}ms`,
894 )
895 await sleep(delay)
896 }
897 }
898 return null
899}
900
901// Moved to codeSessionApi.ts so the SDK /bridge subpath can bundle them
902// without pulling in this file's heavy CLI tree (analytics, transport).

Callers 2

initEnvLessBridgeCoreFunction · 0.70
recoverFromAuthFailureFunction · 0.70

Calls 2

logForDebuggingFunction · 0.50
sleepFunction · 0.50

Tested by

no test coverage detected