-
fix(llm): preflight uses litellm ping instead of structured-output (1.0.7) (#2784)
发布于
2026-05-05 18:36:36 +00:00 Summary
The startup connection check in
cognee/infrastructure/llm/utils.py::test_llm_connectionran a full
structured-output call (LLMGateway.acreate_structured_output(..., response_model=str)) for what is supposed to be a lightweight ping. For
non-OpenAI providers this routes through the provider-specific adapter,
whose tenacity retry decorator (stop_after_delay(128)with
wait_exponential_jitter(8, 128)) can mask a fast underlying failure
behind exponential backoff, tripping the 30 sasyncio.wait_forand
surfacing a misleading "endpoint unreachable" message even when the
endpoint is healthy (verified with the same key/model via rawcurlin
<1 s in the original report).This PR replaces the preflight with a uniform
litellm.acompletionping
(max_tokens=1,num_retries=0, no structured-output wrapper).
Authentication or routing errors now surface immediately instead of
being eaten by the inner retry stack. Provider routing is made explicit
viacustom_llm_providerso it's correct regardless of whether
LLM_MODELis written asclaude-haiku-4-5or
anthropic/claude-haiku-4-5.Stacking
This PR is stacked on top of #2783 (the
max_tokensAnthropic fix,
basemain). The two are related: the original 30 s timeout on
LLM_PROVIDER=anthropicwas triggered by the missingmax_tokens
causing the adapter retry loop to spin. The first PR fixes the symptom;
this PR fixes the preflight design so future provider-specific bugs
don't get masked the same way. Merge #2783 first, then this. Otherwise
expect apyproject.toml/uv.lockversion conflict on 1.0.6.Test plan
LLM_PROVIDER=anthropic, bad key: now raises
AuthenticationErrorin ~0.2 s instead ofTimeoutErrorin 30 sLLM_PROVIDER=openai, valid key: preflight returns successfullyruff check+ruff format --checkclean on changed fileLLM_MODELcontaining duplicated provider prefix (e.g.,
anthropic/claude-haiku-4-5) routes correctly- CI on PR: full unit + integration suite
- Cross-provider sanity: gemini, ollama, custom (OpenAI-compatible)
endpoints
Note on branching
Repo convention is to branch from
dev. Targetingmainper the
request to ship as a hotfix release alongside #2783. A follow-up
cherry-pick / merge intodevis needed for both PRs.🤖 Generated with Claude Code
Summary by CodeRabbit
-
Bug Fixes
-
More reliable LLM connectivity check: uses a lightweight ping, better
provider/model routing, treats token/output-limit responses as
successful health checks, and improves error handling. -
Chores
- Package version bumped to 1.0.7.
下载附件