Skip to content

fix: apply configurable timeout to Ollama native client#11933

Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/ollama-timeout-config
Draft

fix: apply configurable timeout to Ollama native client#11933
roomote-v0[bot] wants to merge 1 commit intomainfrom
fix/ollama-timeout-config

Conversation

@roomote-v0
Copy link
Contributor

@roomote-v0 roomote-v0 bot commented Mar 16, 2026

Related GitHub Issue

Closes: #11932

Description

This PR attempts to address Issue #11932, where the Ollama native handler ignores the apiRequestTimeout setting, causing requests to fail after 5 minutes (the Node.js/Undici default fetch timeout).

Root cause: The NativeOllamaHandler created an Ollama client without configuring any fetch timeout. The ollama npm package uses Node.js native fetch internally (Undici), which has a hardcoded 300-second default timeout. The comment in the code saying "The ollama npm package handles timeouts internally" was incorrect.

How it works:

  • The ensureClient() method in NativeOllamaHandler now passes a custom fetch wrapper to the Ollama client via the Config.fetch option
  • The wrapper applies AbortSignal.timeout() using the value from getApiRequestTimeout() (the existing apiRequestTimeout user setting, default 600s)
  • If the caller already provides its own signal (e.g., for cancellation), that signal is preserved
  • When the timeout setting is 0 or negative (meaning "no timeout"), no custom fetch is applied, letting the SDK use its default behavior

This is consistent with how other providers (OpenAI-compatible, LM Studio, etc.) already honor the same setting.

Feedback and guidance are welcome.

Test Procedure

  • Added two new tests to native-ollama.spec.ts:
    1. Verifies the Ollama client constructor receives a custom fetch function when getApiRequestTimeout() returns a positive value
    2. Verifies no custom fetch is passed when getApiRequestTimeout() returns undefined
  • All 17 existing tests continue to pass
  • Run: cd src && npx vitest run api/providers/__tests__/native-ollama.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 updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

Additional Notes

The ollama npm package exposes a Config.fetch option specifically for this kind of customization. This approach avoids monkey-patching or modifying the package itself.

Interactively review PR in Roo Code Cloud

The NativeOllamaHandler was not honoring the apiRequestTimeout setting,
causing requests to time out after 5 minutes (Node.js/Undici default).
This adds a custom fetch wrapper that applies the user-configured timeout
via AbortSignal.timeout(), consistent with how other providers handle it.

Closes #11932
@nalimcos
Copy link

See also ollama-js issue

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] Fetch failed after 5m0s regardless of configured timeout

2 participants