fix: use native fetch for Ollama embedding to ensure AbortController works#362
Open
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
Open
fix: use native fetch for Ollama embedding to ensure AbortController works#362jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
Conversation
…works Root cause: OpenAI SDK HTTP client does not reliably abort Ollama TCP connections when AbortController.abort() fires in Node.js. This causes stalled sockets that hang until the gateway-level 120s timeout. Fix: Add isOllamaProvider() to detect localhost:11434 endpoints, and embedWithNativeFetch() using Node.js 18+ native fetch instead of the OpenAI SDK. Native fetch properly closes TCP connections on abort. Added Test 8 (testOllamaAbortWithNativeFetch) to cjk-recursion-regression test suite. Also added standalone test (pr354-standalone.mjs) and 30-iteration stress test (pr354-30iter.mjs). Fixes CortexReach#361.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Problem
When using Ollama as the embedding provider, the \embedQuery\ timeout (EMBED_TIMEOUT_MS = 10s) does not reliably abort stalled Ollama HTTP requests. This causes the gateway-level \autoRecallTimeoutMs\ (120s) to fire instead.
Evidence from gateway logs:
\
20:48:46 auto-recall query truncated from 1233 to 1000 chars
[120 seconds of silence]
20:50:46 auto-recall timed out after 120000ms
\\
CPU ~20%, Ollama CPU ~0% — signature of a hanging HTTP connection.
Root Cause
\embedder.ts\ uses the OpenAI SDK to call Ollama. The SDK HTTP client in Node.js does not reliably abort the underlying TCP connection when \AbortController.abort()\ is called. Ollama keeps processing and the socket hangs until the 120s gateway timeout fires.
Fix
Use *native \etch* for Ollama endpoints. Node.js 18+ native \etch\ correctly respects \AbortController\ — TCP connection is properly closed when the signal fires.
Added
Modified
\embedWithRetry()\ now routes Ollama URLs through \embedWithNativeFetch()\ instead of the OpenAI SDK.
Test
30 iterations — all passed ✅
Abort time consistent at ~208–215ms (signal fires at 200ms).
Fixes #361