export function transientServiceUnavailableDetail( error: unknown, ): string | null { const detail = error instanceof Error ? error.message : String(error); // The Convex HTTP client surfaces socket/DNS interruptions as the native // Undici `TypeError: fetch failed`, without an HTTP envelope. Callers only // use this classifier where replay is explicitly safe (for example, reads). if (error instanceof TypeError && /^fetch failed$/i.test(detail.trim())) { return detail; } // Convex uses explicit ServiceUnavailable and ExpiredInQueue responses, as // well as this generic InternalServerError envelope for short control-plane // outages. The latter text is intentionally exact: application exceptions // must not become retryable merely because they mention an internal-server // error. return /ServiceUnavailable|Service temporarily unavailable|temporarily unavailable \(Code:\s*\d+\)|"code"\s*:\s*"ExpiredInQueue"|"code"\s*:\s*"InternalServerError"[\s\S]*(?:Your request couldn't be completed\. Try again later\.|Your request timed out performing too many system operations\.)/i.test( detail, ) ? detail : null; }