Skip to content

Commit 77f1e8c

Browse files
committed
fix: add default 120s request timeout when provider timeoutSeconds is not configured
When models.providers.<id>.timeoutSeconds is not set in config.yaml, resolveProviderRequestTimeoutMs() returns undefined, which cascades through buildTimeoutAbortSignal({timeoutMs: undefined}) → no AbortSignal → fetch() hangs indefinitely on TCP connections. This is a P0 defect causing session stalls when upstream API (e.g. DeepSeek) takes long to respond, leading to event loop congestion and system unresponsiveness. Fix: return DEFAULT_REQUEST_TIMEOUT_MS (120s) as fallback instead of undefined, matching the common expectation that all HTTP requests should have a bounded timeout.
1 parent be87524 commit 77f1e8c

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/agents/pi-embedded-runner/model.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ type ProviderRuntimeHooks = {
6565
normalizeProviderTransportWithPlugin: typeof normalizeProviderTransportWithPlugin;
6666
};
6767

68+
/** 当 provider timeoutSeconds 未配置时使用的默认请求超时时间(毫秒) */
69+
const DEFAULT_REQUEST_TIMEOUT_MS = 120_000;
70+
6871
const TARGET_PROVIDER_RUNTIME_HOOKS: ProviderRuntimeHooks = {
6972
buildProviderUnknownModelHintWithPlugin,
7073
prepareProviderDynamicModel,
@@ -336,13 +339,14 @@ function resolveConfiguredProviderDefaultApi(
336339
return providerConfig?.baseUrl ? "openai-completions" : undefined;
337340
}
338341

339-
function resolveProviderRequestTimeoutMs(timeoutSeconds: unknown): number | undefined {
342+
function resolveProviderRequestTimeoutMs(timeoutSeconds: unknown): number {
340343
if (
341344
typeof timeoutSeconds !== "number" ||
342345
!Number.isFinite(timeoutSeconds) ||
343346
timeoutSeconds <= 0
344347
) {
345-
return undefined;
348+
// provider timeoutSeconds 未配置或 <=0 时,回退到 120 秒默认超时,避免 HTTP 请求无限等待
349+
return DEFAULT_REQUEST_TIMEOUT_MS;
346350
}
347351
return Math.floor(timeoutSeconds) * 1000;
348352
}

0 commit comments

Comments
 (0)