fix(critical): Event-Loop-Blockade — ThreadPool-Saturation + Pulse-Interval + Classifier-Timeout
Root-Cause (Rainer): Pulse-Thread + Adapter-Calls + DDP-Fallback-Lawine sättigen den ThreadPool (asyncio.to_thread). Der Loop-Selector kann Watchdog-Probes nicht ausführen → 3 Strikes → Kill. Änderungen: - adapter.py: classify_and_route in asyncio.wait_for(4s), Timeout → STAY - adapter.py: ThreadPoolExecutor max_workers=32 in on_connected_cb - presence_engine.py: pulse_interval 1.5→5.0, sync-default, 2-stufiger CB - classifier.py: _llm_raw/_llm_classify/verify_confidence in wait_for(25s)
This commit is contained in:
@@ -469,7 +469,15 @@ class IntentClassifier:
|
||||
|
||||
async def _llm_classify(self, text: str, scores: Dict[str, float]) -> Optional[Tuple[str, float]]:
|
||||
import asyncio
|
||||
return await asyncio.to_thread(self._llm_classify_sync, text, scores)
|
||||
try:
|
||||
# P0-CRITICAL: asyncio.wait_for(25s) — verhindert ThreadPool-Saturation.
|
||||
return await asyncio.wait_for(
|
||||
asyncio.to_thread(self._llm_classify_sync, text, scores),
|
||||
timeout=25.0,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("LLM classify timed out (25s) — returning None")
|
||||
return None
|
||||
|
||||
def _llm_classify_sync(self, text: str, scores: Dict[str, float]) -> Optional[Tuple[str, float]]:
|
||||
try:
|
||||
@@ -500,7 +508,15 @@ class IntentClassifier:
|
||||
try:
|
||||
if not self._llm_client or not self._llm_enabled:
|
||||
return None
|
||||
return await asyncio.to_thread(self._llm_client.generate, prompt)
|
||||
# P0-CRITICAL: asyncio.wait_for(25s) — verhindert ThreadPool-Saturation.
|
||||
# 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=25.0,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
logger.warning("LLM raw call timed out (25s) — returning None for STAY fallback")
|
||||
return None
|
||||
except Exception as e:
|
||||
logger.warning("LLM raw call failed: %s", e)
|
||||
return None
|
||||
@@ -632,7 +648,16 @@ class IntentClassifier:
|
||||
best_score >= CONFIDENCE_THRESHOLDS["CLARIFY_NEEDED"] and
|
||||
best_score < CONFIDENCE_THRESHOLDS["AUTO_ROUTE"]
|
||||
):
|
||||
llm_result = self._llm_classify_sync(text, scores)
|
||||
# P0-CRITICAL: Timeout 25s — 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=25.0)
|
||||
except concurrent.futures.TimeoutError:
|
||||
logger.warning("LLM verify_confidence timed out (25s) — skipping verification")
|
||||
llm_result = None
|
||||
if llm_result:
|
||||
final_category, final_score = llm_result
|
||||
llm_verified = True
|
||||
|
||||
Reference in New Issue
Block a user