fix: LLM-Timeout 15s — qwen2.5:7b auf CPU braucht 9s, 3s war zu kurz
This commit is contained in:
+2
-2
@@ -3123,10 +3123,10 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
try:
|
||||
decision = await asyncio.wait_for(
|
||||
self.archivar.classify_and_route(routing_text, origin_room_id=room_id, is_dm=_is_dm),
|
||||
timeout=4.0,
|
||||
timeout=20.0,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("[rocketchat] Archivar classify_and_route() timed out (4s) — STAY fallback")
|
||||
logger.warning("[rocketchat] Archivar classify_and_route() timed out (20s) — STAY fallback")
|
||||
decision = RoutingDecision(
|
||||
category='direct_question',
|
||||
target_room=room_id,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,7 +17,7 @@ OLLAMA_CONFIG: dict = {
|
||||
"base_url": os.getenv("ARCHIVAR_EMBEDDING_BASE_URL", "http://localhost:11434"),
|
||||
"model": "nomic-embed-text",
|
||||
"timeout": 3.0, # Sekunden — HARD deadline via ThreadPoolExecutor
|
||||
# Muss KLEINER sein als äußerer 4s-Timeout in adapter.py
|
||||
# Muss KLEINER sein als äußerer 20s-Timeout in adapter.py
|
||||
"embedding_dim": 768, # nomic-embed-text produziert 768-dimensionale Vektoren
|
||||
}
|
||||
|
||||
@@ -157,8 +157,8 @@ wird sie entsprechend klassifiziert. Alles andere → FAKT.
|
||||
LLM_CONFIG = {
|
||||
"enabled": os.getenv("ARCHIVAR_ENABLE_LLM", "").strip().lower() in ("1", "true", "yes"),
|
||||
"model": "qwen2.5:7b",
|
||||
"timeout": 3.0, # HARD deadline via ThreadPoolExecutor.result(timeout=X)
|
||||
# Muss KLEINER sein als äußerer 4s-Timeout in adapter.py
|
||||
"timeout": 15.0, # HARD deadline via ThreadPoolExecutor.result(timeout=X)
|
||||
# Muss KLEINER sein als äußerer 20s-Timeout in adapter.py
|
||||
"base_url": os.getenv(
|
||||
"ARCHIVAR_LLM_BASE_URL",
|
||||
os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
|
||||
|
||||
+18
-18
@@ -1578,12 +1578,12 @@ class BidirectionalRouter:
|
||||
|
||||
# Try LLM — expects room ID directly or "STAY"
|
||||
# Semaphore schützt vor parallelen Ollama-Aufrufen (qwen2.5:7b = single-request)
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 3s Timeout — muss KLEINER sein als
|
||||
# der äußere 4s-Timeout in adapter.py.
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 18s Timeout — muss KLEINER sein als
|
||||
# der äußere 20s-Timeout in adapter.py.
|
||||
try:
|
||||
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=3.0)
|
||||
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=18.0)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("LLM semaphore acquire timed out (3s) — skipping LLM room lookup")
|
||||
logger.warning("LLM semaphore acquire timed out (18s) — skipping LLM room lookup")
|
||||
return None, False, True # LLM-Aufruf fehlgeschlagen
|
||||
try:
|
||||
llm_result = await self._classifier._llm_raw(prompt)
|
||||
@@ -1848,22 +1848,22 @@ class BidirectionalRouter:
|
||||
old_topic=old_topic or "(kein altes Thema)",
|
||||
)
|
||||
|
||||
# LLM-Aufruf mit 3s Timeout (Semaphore + LLM-Call)
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 3s Timeout — muss KLEINER sein als
|
||||
# der äußere 4s-Timeout in adapter.py.
|
||||
# LLM-Aufruf mit 18s Semaphore + 15s LLM-Call Timeout
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 18s Timeout — muss KLEINER sein als
|
||||
# der äußere 20s-Timeout in adapter.py.
|
||||
try:
|
||||
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=3.0)
|
||||
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=18.0)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("V7-4: LLM-Semaphore Timeout (3s) → Fallback: NEU")
|
||||
logger.warning("V7-4: LLM-Semaphore Timeout (18s) → Fallback: NEU")
|
||||
return None
|
||||
try:
|
||||
try:
|
||||
llm_result = await asyncio.wait_for(
|
||||
self._classifier._llm_raw(prompt),
|
||||
timeout=3.0,
|
||||
timeout=15.0,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("V7-4: LLM-Check Timeout (3s) → Fallback: NEU")
|
||||
logger.warning("V7-4: LLM-Check Timeout (15s) → Fallback: NEU")
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.warning("V7-4: LLM-Check fehlgeschlagen: %s → Fallback: NEU", e)
|
||||
@@ -2207,25 +2207,25 @@ async def validate_sentence_marker(
|
||||
v7_3_state=v7_3_state,
|
||||
)
|
||||
|
||||
# ── LLM-Aufruf mit 3s Timeout (Semaphore + LLM-Call) ──────────────
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 3s Timeout — muss KLEINER sein als
|
||||
# der äußere 4s-Timeout in adapter.py.
|
||||
# ── LLM-Aufruf mit 18s Semaphore + 15s LLM-Call Timeout ──────────
|
||||
# P0-CRITICAL: Semaphore-Acquire mit 18s Timeout — muss KLEINER sein als
|
||||
# der äußere 20s-Timeout in adapter.py.
|
||||
try:
|
||||
await asyncio.wait_for(llm_semaphore.acquire(), timeout=3.0)
|
||||
await asyncio.wait_for(llm_semaphore.acquire(), timeout=18.0)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning(
|
||||
"A1b Stufe 4/5: LLM-Semaphore Timeout (3s) → Fallback: unentscheidbar"
|
||||
"A1b Stufe 4/5: LLM-Semaphore Timeout (18s) → Fallback: unentscheidbar"
|
||||
)
|
||||
return None
|
||||
try:
|
||||
try:
|
||||
llm_result = await asyncio.wait_for(
|
||||
classifier._llm_raw(prompt),
|
||||
timeout=3.0,
|
||||
timeout=15.0,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning(
|
||||
"A1b Stufe 4/5: LLM-Validierung Timeout (3s) → Fallback: unentscheidbar"
|
||||
"A1b Stufe 4/5: LLM-Call Timeout (15s) → Fallback: unentscheidbar"
|
||||
)
|
||||
return None
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user