fix(ai): raise default chunk timeout to fifteen minutes (#55032)

This commit is contained in:
Aiden Cline
2026-10-13 00:03:44 -05:00
committed by GitHub
Unverified
parent b4f19bfe74
commit d8129ca1e0
5 changed files with 23 additions and 9 deletions
+4 -3
View File
@@ -7,6 +7,7 @@ import type { HttpMiddleware, Transport, TransportPrepareInput } from "./index.j
import * as ProviderShared from "../../protocols/shared.js"
import {
AIError,
DEFAULT_CHUNK_TIMEOUT_MS,
DEFAULT_HTTP_TIMEOUT_MS,
mergeJsonRecords,
TransportError,
@@ -124,7 +125,7 @@ export const httpJson = <Body, Frame>(input: HttpJsonInput<Body, Frame>): HttpJs
frames: prepared.framing.frame(
RequestExecutor.responseStream(response).pipe(
Stream.timeoutOrElse({
duration: timeoutDuration(request.http?.chunkTimeout),
duration: timeoutDuration(request.http?.chunkTimeout, DEFAULT_CHUNK_TIMEOUT_MS),
orElse: () => Stream.fail(timeout("read", "Timed out waiting for response data", http)),
}),
Stream.interruptWhen(
@@ -140,8 +141,8 @@ export const httpJson = <Body, Frame>(input: HttpJsonInput<Body, Frame>): HttpJs
}),
})
const timeoutDuration = (value: HttpTimeout | undefined) =>
value === false ? Duration.infinity : Duration.millis(value ?? DEFAULT_HTTP_TIMEOUT_MS)
const timeoutDuration = (value: HttpTimeout | undefined, fallback = DEFAULT_HTTP_TIMEOUT_MS) =>
value === false ? Duration.infinity : Duration.millis(value ?? fallback)
export const sseJson = {
id: "http-json/sse",
+7 -1
View File
@@ -52,9 +52,15 @@ export const mergeProviderOptions = (
export const HttpTimeout = Schema.Union([Schema.Number.check(Schema.isGreaterThan(0)), Schema.Literal(false)])
export type HttpTimeout = Schema.Schema.Type<typeof HttpTimeout>
/** Applied to `headerTimeout` and `chunkTimeout` when a request leaves them unset. */
/** Applied to `headerTimeout` when a request leaves it unset. */
export const DEFAULT_HTTP_TIMEOUT_MS = 300_000
/**
* Applied to `chunkTimeout` when a request leaves it unset. Some providers, such as DeepSeek, have specifically asked
* clients to allow at least 15 minutes, because their models can stream nothing for minutes while they reason.
*/
export const DEFAULT_CHUNK_TIMEOUT_MS = 900_000
/** `Content-Encoding` for JSON request bodies; `none` sends plain JSON. */
export const RequestEncoding = Schema.Literals(["zstd", "gzip", "none"])
export type RequestEncoding = Schema.Schema.Type<typeof RequestEncoding>
+2 -2
View File
@@ -69,7 +69,7 @@ describe("HTTP transport timeouts", () => {
}),
)
it.effect("fails when the response body stalls for five minutes", () =>
it.effect("fails when the response body stalls for fifteen minutes", () =>
Effect.gen(function* () {
const server = yield* stalledServer
const fiber = yield* LLMClient.generate(LLM.request({ model, prompt: "Hello" })).pipe(
@@ -79,7 +79,7 @@ describe("HTTP transport timeouts", () => {
)
yield* Deferred.await(server.stalled)
yield* Effect.yieldNow
yield* TestClock.adjust("5 minutes")
yield* TestClock.adjust("15 minutes")
const error = yield* Fiber.join(fiber)
expect(error.reason).toMatchObject({ _tag: "Transport", transport: "http", operation: "read", code: "Timeout" })
+9 -2
View File
@@ -166,9 +166,16 @@ export function modelSettings(settings: Settings | undefined) {
const decodeTimeout = Schema.decodeUnknownOption(HttpTimeout)
/** Applied to `headerTimeout` and `chunkTimeout` when provider settings leave them unset or invalid. */
/** Applied to `headerTimeout` when provider settings leave it unset or invalid. */
export const DEFAULT_TIMEOUT_MS = 300_000
/**
* Applied to `chunkTimeout` when provider settings leave it unset or invalid. Some providers, such as DeepSeek, have
* specifically asked clients to allow at least 15 minutes, because their models can stream nothing for minutes while
* they reason.
*/
export const DEFAULT_CHUNK_TIMEOUT_MS = 900_000
/** One timeout setting without a default; invalid values are dropped. */
export function timeout(value: unknown) {
return Option.getOrUndefined(decodeTimeout(value))
@@ -179,7 +186,7 @@ export function timeouts(settings: Readonly<Record<string, unknown>>) {
return {
timeout: timeout(settings.timeout),
headerTimeout: timeout(settings.headerTimeout) ?? DEFAULT_TIMEOUT_MS,
chunkTimeout: timeout(settings.chunkTimeout) ?? DEFAULT_TIMEOUT_MS,
chunkTimeout: timeout(settings.chunkTimeout) ?? DEFAULT_CHUNK_TIMEOUT_MS,
}
}
+1 -1
View File
@@ -393,7 +393,7 @@ Provider options can include `timeout`, `headerTimeout`, `chunkTimeout`, and `se
- `timeout` - Request timeout in milliseconds (default: 300000). Set to `false` to disable.
- `headerTimeout` - Timeout in milliseconds to wait for response headers (default: 300000, or 5 minutes). This timer stops once headers arrive and does not limit the streamed response body. Set to `false` to disable.
- `chunkTimeout` - Timeout in milliseconds between streamed response chunks (default: 300000, or 5 minutes). If no chunk arrives in time, the request is aborted. Set to `false` to disable.
- `chunkTimeout` - Timeout in milliseconds between streamed response chunks (default: 900000, or 15 minutes). If no chunk arrives in time, the request is aborted. Set to `false` to disable.
- `setCacheKey` - Ensure a cache key is always set for designated provider.
You can also configure [local models](/docs/models#local). [Learn more](/docs/models).