fix: honor hyde_enabled toggle and record ping failures before client creation (Task 6 review)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
wangwei
2026-07-02 16:42:58 +08:00
co-authored by Copilot
parent 169911ab46
commit d83286edd4
2 changed files with 57 additions and 1 deletions
+16 -1
View File
@@ -169,6 +169,13 @@ def _build_model_status(role: str) -> dict[str, Any]:
# Config always wins: report "disabled" even if the reranker was
# enabled and called successfully earlier in this process's life.
status = "disabled"
elif role == "hyde_llm":
enabled = settings.hyde_enabled
if not enabled:
# Same "config always wins" override as the reranker branch above:
# report "disabled" even if HyDE ran successfully before being
# turned off in settings during this process's life.
status = "disabled"
return {
"role": role,
@@ -199,7 +206,15 @@ async def get_model_statuses():
async def _ping_main_or_hyde(role: str) -> None:
"""Send one minimal chat completion to the LLM configured for `role`."""
provider, model = _resolve_role_provider_model(role)
client = get_llm_client(provider=provider, model=model)
try:
client = get_llm_client(provider=provider, model=model)
except Exception as exc: # noqa: BLE001 - record, then re-raise so gather() still isolates this ping
# get_llm_client() can fail before any TrackedLLMClient exists to
# record the outcome itself (e.g. missing API key, unsupported
# provider string), so record the failure here directly, otherwise it
# would be invisible on the /status/models page afterward.
get_model_usage_tracker().record(provider=provider, model=model, success=False, error=str(exc))
raise
await asyncio.to_thread(client.chat, [{"role": "user", "content": "ping"}], max_tokens=1)