INNER CODE UNIT · TypeScript

loadConnectionsFromBackend

Beever-AI/beever-atlas · bot/src/index.ts:681

async function loadConnectionsFromBackend(chatManager: ChatManager): Promise<void> {
  // RES-286 — compressed from [1, 2, 4, 8, 16]s (31 s worst case) so that a
  // bot restart only blocks `/bridge/...` calls for ~12 s, not ~31 s. The
  // backend health check + Redis are typically up within ~3 s; we keep five
  // retries for genuinely slow boots but cap the trailing waits at 4 s each.
  const delays = [500, 1000, 2000, 4000, 4000];

  for (let attempt = 0; attempt < delays.length; attempt++) {
    try {
      // Health-aware: check backend availability before fetching connections
      const healthy = await isBackendHealthy();
      if (!healthy) {
        throw new Error("Backend health check failed");
      }

      const synced = await syncConnectionsFromBackend(chatManager, "Startup sync");
      if (synced || chatManager.adapterCount() > 0) return;
      // No connections found — still a successful call, just nothing to load

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…