fix(openai): disable header timeout for websockets

This commit is contained in:
Aiden Cline 2026-06-03 16:11:02 -05:00
parent a41f774cad
commit 44208fcd09
2 changed files with 31 additions and 0 deletions

View file

@ -358,6 +358,13 @@ export async function CodexAuthPlugin(input: PluginInput, options: CodexAuthPlug
const websocketFetches: Array<ReturnType<typeof OpenAIWebSocketPool.createWebSocketFetch>> = []
return {
async config(config) {
if (!options.experimentalWebSockets) return
config.provider ??= {}
config.provider.openai ??= {}
config.provider.openai.options ??= {}
config.provider.openai.options.headerTimeout ??= false
},
async dispose() {
for (const websocketFetch of websocketFetches) websocketFetch.close()
websocketFetches.length = 0

View file

@ -140,6 +140,30 @@ describe("plugin.codex", () => {
await enabled.dispose?.()
})
test("disables the HTTP header timeout when websocket transport is enabled", async () => {
const disabled = await CodexAuthPlugin({} as never)
const hooks = await CodexAuthPlugin({} as never, { experimentalWebSockets: true })
const disabledConfig = {} as Parameters<NonNullable<typeof hooks.config>>[0]
const config = {} as Parameters<NonNullable<typeof hooks.config>>[0]
await disabled.config!(disabledConfig)
await hooks.config!(config)
expect(disabledConfig.provider).toBeUndefined()
expect(config.provider?.openai?.options?.headerTimeout).toBe(false)
})
test("preserves explicit header timeout configuration when websocket transport is enabled", async () => {
const hooks = await CodexAuthPlugin({} as never, { experimentalWebSockets: true })
const config = { provider: { openai: { options: { headerTimeout: 30_000 } } } } as Parameters<
NonNullable<typeof hooks.config>
>[0]
await hooks.config!(config)
expect(config.provider.openai.options.headerTimeout).toBe(30_000)
})
test("deduplicates concurrent Codex token refreshes", async () => {
let auth = {
type: "oauth" as const,