From e15f30e47b87e3fc3d29d5d2c08f565dbd99fd2f Mon Sep 17 00:00:00 2001 From: Hannes Rudolph Date: Tue, 9 Dec 2025 15:22:25 -0700 Subject: [PATCH] fix: return undefined instead of 0 for disabled API timeout OpenAI SDK interprets setTimeout(..., 0) as 'abort immediately', causing instant request failures when apiRequestTimeout is set to 0. Return undefined to let the SDK use its default timeout instead. --- .../utils/__tests__/timeout-config.spec.ts | 11 +++++++---- src/api/providers/utils/timeout-config.ts | 14 +++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/api/providers/utils/__tests__/timeout-config.spec.ts b/src/api/providers/utils/__tests__/timeout-config.spec.ts index f74e14afad0..02604b5070f 100644 --- a/src/api/providers/utils/__tests__/timeout-config.spec.ts +++ b/src/api/providers/utils/__tests__/timeout-config.spec.ts @@ -41,20 +41,23 @@ describe("getApiRequestTimeout", () => { expect(timeout).toBe(1200000) // 1200 seconds in milliseconds }) - it("should handle zero timeout (no timeout)", () => { + it("should return undefined for zero timeout (disables timeout)", () => { mockGetConfig.mockReturnValue(0) const timeout = getApiRequestTimeout() - expect(timeout).toBe(0) // No timeout + // Zero means "no timeout" - return undefined so SDK uses its default + // (OpenAI SDK interprets 0 as "abort immediately", so we avoid that) + expect(timeout).toBeUndefined() }) - it("should handle negative values by clamping to 0", () => { + it("should return undefined for negative values (disables timeout)", () => { mockGetConfig.mockReturnValue(-100) const timeout = getApiRequestTimeout() - expect(timeout).toBe(0) // Negative values should be clamped to 0 + // Negative values also mean "no timeout" - return undefined + expect(timeout).toBeUndefined() }) it("should handle null by using default", () => { diff --git a/src/api/providers/utils/timeout-config.ts b/src/api/providers/utils/timeout-config.ts index c9f2f0257ce..39adec62027 100644 --- a/src/api/providers/utils/timeout-config.ts +++ b/src/api/providers/utils/timeout-config.ts @@ -4,9 +4,10 @@ import { Package } from "../../../shared/package" /** * Gets the API request timeout from VSCode configuration with validation. * - * @returns The timeout in milliseconds. Returns 0 for no timeout. + * @returns The timeout in milliseconds. Returns undefined to disable timeout + * (letting the SDK use its default), or a positive number for explicit timeout. */ -export function getApiRequestTimeout(): number { +export function getApiRequestTimeout(): number | undefined { // Get timeout with validation to ensure it's a valid non-negative number const configTimeout = vscode.workspace.getConfiguration(Package.name).get("apiRequestTimeout", 600) @@ -15,8 +16,11 @@ export function getApiRequestTimeout(): number { return 600 * 1000 // Default to 600 seconds } - // Allow 0 (no timeout) but clamp negative values to 0 - const timeoutSeconds = configTimeout < 0 ? 0 : configTimeout + // 0 or negative means "no timeout" - return undefined to let SDK use its default + // (OpenAI SDK interprets 0 as "abort immediately", so we return undefined instead) + if (configTimeout <= 0) { + return undefined + } - return timeoutSeconds * 1000 // Convert to milliseconds + return configTimeout * 1000 // Convert to milliseconds }