fix: apply configurable timeout to Ollama native client#11933
Draft
roomote-v0[bot] wants to merge 1 commit intomainfrom
Draft
fix: apply configurable timeout to Ollama native client#11933roomote-v0[bot] wants to merge 1 commit intomainfrom
roomote-v0[bot] wants to merge 1 commit intomainfrom
Conversation
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
|
See also ollama-js issue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11932
Description
This PR attempts to address Issue #11932, where the Ollama native handler ignores the
apiRequestTimeoutsetting, causing requests to fail after 5 minutes (the Node.js/Undici default fetch timeout).Root cause: The
NativeOllamaHandlercreated an Ollama client without configuring any fetch timeout. The ollama npm package uses Node.js nativefetchinternally (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:
ensureClient()method inNativeOllamaHandlernow passes a customfetchwrapper to the Ollama client via theConfig.fetchoptionAbortSignal.timeout()using the value fromgetApiRequestTimeout()(the existingapiRequestTimeoutuser setting, default 600s)This is consistent with how other providers (OpenAI-compatible, LM Studio, etc.) already honor the same setting.
Feedback and guidance are welcome.
Test Procedure
native-ollama.spec.ts:fetchfunction whengetApiRequestTimeout()returns a positive valuefetchis passed whengetApiRequestTimeout()returnsundefinedcd src && npx vitest run api/providers/__tests__/native-ollama.spec.tsPre-Submission Checklist
Documentation Updates
Additional Notes
The ollama npm package exposes a
Config.fetchoption specifically for this kind of customization. This approach avoids monkey-patching or modifying the package itself.Interactively review PR in Roo Code Cloud