You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug: LLM HTTP client has no configurable request timeout, causing scan to hang indefinitely #237
The ocr scan command can hang indefinitely when the LLM API does not respond. The HTTP client used for LLM API calls does not have a properly configurable request timeout, causing the process to block forever on stuck connections.
Root Cause
In internal/llm/client.go, the NewLLMClient factory function creates a ClientConfig without setting the Timeout field:
funcNewLLMClient(epResolvedEndpoint) LLMClient {
cfg:=ClientConfig{
URL: ep.URL,
APIKey: ep.Token,
Model: ep.Model,
AuthHeader: ep.AuthHeader,
ExtraBody: ep.ExtraBody,
// Timeout is NOT set — defaults to 0
}
While NewOpenAIClient and NewAnthropicClient both have a fallback default of 5 minutes:
ifcfg.Timeout<=0 {
cfg.Timeout=5*time.Minute
}
There are two problems:
ResolvedEndpoint has no Timeout field — users cannot configure the HTTP timeout via config file or environment variables
Streaming responses may bypass the timeout — the OpenAI/Anthropic SDKs WithRequestTimeout applies to the overall request lifecycle, but streaming responses that send data slowly (or stop sending data mid-stream) may not trigger the timeout
Reproduction
Configure ocr with an LLM API that occasionally hangs (e.g., rate-limited or overloaded)
Run ocr scan on a repository
The process hangs indefinitely with 0% CPU usage, holding an ESTABLISHED TCP connection to the API server
The process never exits until manually killed
Expected Behavior
The ocr binary should:
Support a configurable HTTP request timeout (e.g., via OCR_LLM_TIMEOUT env var or config file)
Have a reasonable default timeout (e.g., 120 seconds per LLM call)
Properly enforce the timeout on streaming responses
Environment
ocr version: v1.6.4 (darwin/arm64)
OS: macOS
LLM Provider: Xiaomi MiMo API (OpenAI-compatible)
Suggested Fix
Add a Timeout field to ResolvedEndpoint
Add OCR_LLM_TIMEOUT environment variable support
Pass the timeout from ResolvedEndpoint to ClientConfig in NewLLMClient
Add per-request timeout enforcement that works with streaming responses
Activity
fix: add configurable HTTP timeout for LLM API calls (alibaba#238)
fix: add configurable HTTP timeout for LLM API calls (alibaba#238)