Skip to content

fix: align Undici headersTimeout with apiRequestTimeout for OpenAI-compatible providers#12245

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/undici-headers-timeout-12244
Draft

fix: align Undici headersTimeout with apiRequestTimeout for OpenAI-compatible providers#12245
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/undici-headers-timeout-12244

Conversation

@roomote-v0
Copy link
Copy Markdown
Contributor

@roomote-v0 roomote-v0 Bot commented Apr 30, 2026

Related GitHub Issue

Closes: #12244

Description

This PR attempts to address Issue #12244. Feedback and guidance are welcome.

The OpenAI SDK's timeout option only controls the SDK-level request timeout but does not override Undici's default headersTimeout of 300 seconds (5 minutes). When time-to-first-byte exceeds 300s (common with large local models via LM Studio, Ollama, or other OpenAI-compatible providers), Undici throws a HeadersTimeoutError before the SDK timeout fires.

How it works:

  • Created a shared createFetchWithUndiciTimeout() utility in src/api/providers/utils/undici-fetch.ts that builds a custom fetch function backed by an Undici Agent with headersTimeout and bodyTimeout aligned to the configured apiRequestTimeout.
  • Applied the custom fetch to all three provider paths that create OpenAI SDK clients:
    • lm-studio.ts (LM Studio provider)
    • openai.ts (generic OpenAI-compatible provider, including Azure variants)
    • base-openai-compatible-provider.ts (base class for providers like DeepSeek, xAI, etc.)
  • No new dependencies needed -- undici is already in src/package.json.

As noted by @yangzetao in the issue, this fix covers not just LM Studio but the generic OpenAI-compatible provider path as well, ensuring consistency across all providers using the OpenAI SDK transport layer.

Test Procedure

  • Added unit tests for the new createFetchWithUndiciTimeout() utility (undici-fetch.spec.ts)
  • Updated existing timeout tests for all three providers to verify the custom fetch option is passed to the OpenAI SDK constructor
  • All 18 tests pass across 4 test files

Run tests:

cd src && npx vitest run api/providers/utils/__tests__/undici-fetch.spec.ts api/providers/__tests__/lm-studio-timeout.spec.ts api/providers/__tests__/openai-timeout.spec.ts api/providers/__tests__/base-openai-compatible-provider-timeout.spec.ts

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes.
  • Documentation Impact: No documentation changes needed -- this is an internal transport-layer fix.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A -- no UI changes.

Documentation Updates

No documentation updates needed. This is an internal fix to the Undici transport layer timeout configuration.

Interactively review PR in Roo Code Cloud

…mpatible providers

Fixes #12244. The OpenAI SDK timeout option only controls the SDK-level
request timeout but does not override Undici default headersTimeout of
300s. This causes premature HeadersTimeoutError for slow providers like
LM Studio when time-to-first-byte exceeds 5 minutes.

Creates a shared createFetchWithUndiciTimeout() utility that builds a
custom fetch function backed by an Undici Agent with headersTimeout and
bodyTimeout aligned to the configured apiRequestTimeout. Applied to all
three provider paths that create OpenAI clients: lm-studio, openai
(generic OpenAI-compatible), and base-openai-compatible-provider.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LM Studio provider hits 5-minute timeout due to Undici headersTimeout default, despite apiRequestTimeout set to 600s

1 participant