fix: LLM-Timeout 15s — qwen2.5:7b auf CPU braucht 9s, 3s war zu kurz

This commit is contained in:
Bernd (Hermes)
2026-07-27 17:38:06 +02:00
parent d265624f1c
commit 407014db98
4 changed files with 37 additions and 37 deletions
+14 -14
View File
@@ -551,15 +551,15 @@ class IntentClassifier:
async def _llm_classify(self, text: str, scores: Dict[str, float]) -> Optional[Tuple[str, float]]:
import asyncio
try:
# P0-CRITICAL: asyncio.wait_for(3s) — muss KLEINER sein als
# der äußere 4s-Timeout in adapter.py, damit die Timeout-Hierarchie
# korrekt ist: 4s (außen) > 3s (innen).
# P0-CRITICAL: asyncio.wait_for(15s) — muss KLEINER sein als
# der äußere 20s-Timeout in adapter.py, damit die Timeout-Hierarchie
# korrekt ist: 20s (außen) > 15s (innen).
return await asyncio.wait_for(
asyncio.to_thread(self._llm_classify_sync, text, scores),
timeout=3.0,
timeout=15.0,
)
except asyncio.TimeoutError:
logger.warning("LLM classify timed out (3s) — returning None")
logger.warning("LLM classify timed out (15s) — returning None")
return None
def _llm_classify_sync(self, text: str, scores: Dict[str, float]) -> Optional[Tuple[str, float]]:
@@ -591,16 +591,16 @@ class IntentClassifier:
try:
if not self._llm_client or not self._llm_enabled:
return None
# P0-CRITICAL: asyncio.wait_for(3s) — muss KLEINER sein als
# der äußere 4s-Timeout in adapter.py, damit die Timeout-Hierarchie
# korrekt ist: 4s (außen) > 3s (innen).
# P0-CRITICAL: asyncio.wait_for(15s) — muss KLEINER sein als
# der äußere 20s-Timeout in adapter.py, damit die Timeout-Hierarchie
# korrekt ist: 20s (außen) > 15s (innen).
# Bei Timeout: return None → Router wählt STAY-Fallback (router.py Z.1583).
return await asyncio.wait_for(
asyncio.to_thread(self._llm_client.generate, prompt),
timeout=3.0,
timeout=15.0,
)
except asyncio.TimeoutError:
logger.warning("LLM raw call timed out (3s) — returning None for STAY fallback")
logger.warning("LLM raw call timed out (15s) — returning None for STAY fallback")
return None
except Exception as e:
logger.warning("LLM raw call failed: %s", e)
@@ -733,16 +733,16 @@ class IntentClassifier:
best_score >= CONFIDENCE_THRESHOLDS["CLARIFY_NEEDED"] and
best_score < CONFIDENCE_THRESHOLDS["AUTO_ROUTE"]
):
# P0-CRITICAL: Timeout 3s — muss KLEINER sein als der äußere
# 4s-Timeout in adapter.py. Verhindert ThreadPool-Saturation
# P0-CRITICAL: Timeout 15s — muss KLEINER sein als der äußere
# 20s-Timeout in adapter.py. Verhindert ThreadPool-Saturation
# durch hängende verify_confidence-Calls.
import concurrent.futures
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as _exec:
_future = _exec.submit(self._llm_classify_sync, text, scores)
try:
llm_result = _future.result(timeout=3.0)
llm_result = _future.result(timeout=15.0)
except concurrent.futures.TimeoutError:
logger.warning("LLM verify_confidence timed out (3s) — skipping verification")
logger.warning("LLM verify_confidence timed out (15s) — skipping verification")
llm_result = None
if llm_result:
final_category, final_score = llm_result