fix(critical): Timeout-Hierarchie umkehren — innere Timeouts 3s < äußere 4s + Semaphore-Timeout + Embedding-Deadline

ROOT-CAUSE: Die Timeout-Hierarchie war umgekehrt. Der äußere
wait_for(4s) in adapter.py konnte nie feuern, weil die inneren
wait_for(25s) in classifier.py die Coroutine blockierten.

AENDERUNGEN:
- classifier.py: _llm_raw, _llm_classify, verify_confidence: 25.0s → 3.0s
- classifier.py: OllamaEmbeddingClient.get_embedding: ThreadPoolExecutor
  mit .result(timeout=3.0) statt nacktem urllib.urlopen
- router.py: _llm_semaphore.acquire() mit asyncio.wait_for(timeout=3.0)
  an 3 Stellen (_llm_room_lookup, _detect_recursive,
  _validate_sentence_marker_llm)
- config.py: LLM_CONFIG timeout 10.0 → 3.0
- config.py: OLLAMA_CONFIG timeout 10.0 → 3.0

TIMEOUT-HIERARCHIE (nach Fix):
  adapter.py wait_for: 4.0s (äußerst)
  router.py semaphore acquire: 3.0s
  classifier.py LLM-Calls: 3.0s
  classifier.py Embedding-Calls: 3.0s
  config.py LLM_CONFIG timeout: 3.0s
  config.py OLLAMA_CONFIG timeout: 3.0s

Der äußere 4s-Timeout gewinnt jetzt immer.
This commit is contained in:
Bernd (Hermes)
2026-07-27 17:03:00 +02:00
parent 4bfac6a689
commit d265624f1c
3 changed files with 156 additions and 39 deletions
+52 -23
View File
@@ -1578,8 +1578,17 @@ class BidirectionalRouter:
# Try LLM — expects room ID directly or "STAY"
# Semaphore schützt vor parallelen Ollama-Aufrufen (qwen2.5:7b = single-request)
async with self._llm_semaphore:
# P0-CRITICAL: Semaphore-Acquire mit 3s Timeout — muss KLEINER sein als
# der äußere 4s-Timeout in adapter.py.
try:
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=3.0)
except asyncio.TimeoutError:
logger.warning("LLM semaphore acquire timed out (3s) — skipping LLM room lookup")
return None, False, True # LLM-Aufruf fehlgeschlagen
try:
llm_result = await self._classifier._llm_raw(prompt)
finally:
self._llm_semaphore.release()
if llm_result is None:
return None, False, True # LLM-Aufruf fehlgeschlagen
@@ -1839,19 +1848,28 @@ class BidirectionalRouter:
old_topic=old_topic or "(kein altes Thema)",
)
# LLM-Aufruf mit 5s Timeout
# 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.
try:
async with self._llm_semaphore:
await asyncio.wait_for(self._llm_semaphore.acquire(), timeout=3.0)
except asyncio.TimeoutError:
logger.warning("V7-4: LLM-Semaphore Timeout (3s) → Fallback: NEU")
return None
try:
try:
llm_result = await asyncio.wait_for(
self._classifier._llm_raw(prompt),
timeout=5.0,
timeout=3.0,
)
except asyncio.TimeoutError:
logger.warning("V7-4: LLM-Check Timeout (5s) → Fallback: NEU")
return None
except Exception as e:
logger.warning("V7-4: LLM-Check fehlgeschlagen: %s → Fallback: NEU", e)
return None
except asyncio.TimeoutError:
logger.warning("V7-4: LLM-Check Timeout (3s) → Fallback: NEU")
return None
except Exception as e:
logger.warning("V7-4: LLM-Check fehlgeschlagen: %s → Fallback: NEU", e)
return None
finally:
self._llm_semaphore.release()
if llm_result is None:
logger.warning("V7-4: LLM-Check returned None → Fallback: NEU")
@@ -2189,24 +2207,35 @@ async def validate_sentence_marker(
v7_3_state=v7_3_state,
)
# ── LLM-Aufruf mit 5s Timeout ─────────────────────────────────────
# ── 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.
try:
async with llm_semaphore:
llm_result = await asyncio.wait_for(
classifier._llm_raw(prompt),
timeout=5.0,
)
await asyncio.wait_for(llm_semaphore.acquire(), timeout=3.0)
except asyncio.TimeoutError:
logger.warning(
"A1b Stufe 4/5: LLM-Validierung Timeout (5s) → Fallback: unentscheidbar"
)
return None
except Exception as e:
logger.warning(
"A1b Stufe 4/5: LLM-Validierung fehlgeschlagen: %s → Fallback: unentscheidbar",
e,
"A1b Stufe 4/5: LLM-Semaphore Timeout (3s) → Fallback: unentscheidbar"
)
return None
try:
try:
llm_result = await asyncio.wait_for(
classifier._llm_raw(prompt),
timeout=3.0,
)
except asyncio.TimeoutError:
logger.warning(
"A1b Stufe 4/5: LLM-Validierung Timeout (3s) → Fallback: unentscheidbar"
)
return None
except Exception as e:
logger.warning(
"A1b Stufe 4/5: LLM-Validierung fehlgeschlagen: %s → Fallback: unentscheidbar",
e,
)
return None
finally:
llm_semaphore.release()
if llm_result is None:
logger.warning("A1b Stufe 4/5: LLM returned None → Fallback: unentscheidbar")