[Bug] OpenAI VLM backend: default httpx keepalive_expiry=5s connection reuse causes intermittent httpcore.ReadTimeout on image-understanding calls
Environment
- OpenViking 0.4.7 (verified unfixed through 0.4.16; 0.4.16 raised request timeout 60s→600s but did not address connection reuse)
- VLM: cloud OpenAI-compatible vision endpoint (sensenova) used for memory extraction over images
Summary
openviking/models/vlm/backends/openai_vlm.py builds its OpenAI client from kwargs without any httpx client customization, so the SDK default keepalive_expiry=5.0s applies:
def _build_openai_client_kwargs(...):
kwargs = {"api_key": api_key, "base_url": api_base}
kwargs["timeout"] = timeout # 0.4.16: default 600s (was 60s)
Sequence of the failure:
- VLM call finishes; connection returned to pool with keepalive window of 5s
- Next call arrives after the server has already closed the idle connection
- The reused connection blocks until
ReadTimeout— the raised exception ishttpcore.ReadTimeout, not the configured overall timeout
Intermittent by construction (depends on idle gap), and it hits memory-extraction pipelines especially hard because they fire VLM calls in bursts.
Observed evidence
- Recurring
httpcore.ReadTimeouton VLM calls in production logs, correlated with request gaps >5s - Zero ReadTimeout after injecting
keepalive_expiry=0(fresh connection per request); stable for weeks
Fix that works here
import httpx
_custom_http = httpx.AsyncClient(
limits=httpx.Limits(max_connections=100, max_keepalive_connections=10, keepalive_expiry=0),
timeout=httpx.Timeout(self.timeout, connect=10.0),
)
kwargs["http_client"] = _custom_http
Suggestion
Allow configuring (or at least don't leave at SDK default) the VLM backend's keepalive_expiry. Grep of 0.4.16 shows no keepalive handling anywhere in the package. Note the 600s timeout in 0.4.16 actually makes this worse to diagnose — a stale-connection ReadTimeout inside a 600s budget surfaces as a long hang in some retry paths.
I'd like to take this separately from #4462. I'll reproduce stale keep-alive reuse against a controlled OpenAI-compatible VLM endpoint, then scope the fix to the VLM backend's HTTP client configuration and lifecycle. I'll add focused timeout and reuse coverage without changing retry policy or model request semantics.
@ranxi2001 offering our production environment as a repro data point since you're picking this up:
- OV 0.4.16, VLM backend:
openaiprovider,api_base: https://token.sensenova.cn/v1(OpenAI-compatible), modelsensenova-6.8-flash-lite,max_concurrent: 3,timeout: 600 - Local workaround in place since 2026-07-05: patched
openai_vlm.pyto construct the async client withkeepalive_expiry=0(disables keep-alive entirely). Symptom before the patch: recurringhttpx.ReadTimeouton VLM extraction calls mid-run while the connection pool held stale keep-alive sockets; after the patch, zero occurrences over ~2 months of continuous multi-agent operation. - The same endpoint does NOT show the issue for low-frequency clients — it only manifests under our sustained concurrent extraction load (queue-driven, hours-long), which matches the stale-keep-alive-reuse theory: the server closes idle keep-alive connections earlier than our client's expiry, and the race hits in-flight request reuse.
If it helps the fix scoping: the patch is a one-liner (httpx.Limits(keepalive_expiry=0) passed as http_client to both AsyncOpenAI/AsyncAzureOpenAI construction sites in openai_vlm.py). Happy to test a candidate build against our endpoint + workload — just ping here.