fix(archivar): Multi-Request-Resilienz — threading.Lock, asyncio.Semaphore, Catch-All-Schutz + try/except

This commit is contained in:
Bernd (Hermes)
2026-06-17 07:54:12 +02:00
parent a3875f5fbf
commit ea96ebbde7
2 changed files with 254 additions and 205 deletions
+10 -4
View File
@@ -50,7 +50,9 @@ _THEMATIC_TARGET_ROOM: contextvars.ContextVar[str] = contextvars.ContextVar(
)
# Globaler Monoton-Zähler für Archivar-Fragen
import threading
_question_counter: int = 0
_question_counter_lock: threading.Lock = threading.Lock()
try:
from gateway.platforms.base import (
@@ -810,7 +812,8 @@ class RocketChatAdapter(BasePlatformAdapter):
if hasattr(decision, 'target_room') and decision.target_room:
_THEMATIC_TARGET_ROOM.set(decision.target_room)
global _question_counter
_question_counter += 1
with _question_counter_lock:
_question_counter += 1
# ── Ende Kontext-Weitergabe ──────────────────────────────
# Archivar v4 Move-Request: _pending_move_requests befüllen, damit
# der Button-Response-Handler (lines 717-764) die Antwort korrekt
@@ -836,7 +839,8 @@ class RocketChatAdapter(BasePlatformAdapter):
}
except asyncio.TimeoutError:
logger.warning("[rocketchat] Archivar classify_and_route() timed out")
_question_counter += 1
with _question_counter_lock:
_question_counter += 1
# _THEMATIC_TARGET_ROOM bleibt leer → Prompt sagt "Timeout"
except Exception as e:
logger.debug("[rocketchat] Archivar classification skipped: %s", e)
@@ -954,13 +958,15 @@ class RocketChatAdapter(BasePlatformAdapter):
target_room_id = _THEMATIC_TARGET_ROOM.get()
if target_room_id:
target_name = self._room_info.get(target_room_id, {}).get("name", target_room_id[:12] + "…")
archivar_suffix = f" [Frage {_question_counter}, {room_name} -> {target_name}]"
with _question_counter_lock:
archivar_suffix = f" [Frage {_question_counter}, {room_name} -> {target_name}]"
else:
# Timeout-Fallback: Agent braucht Raumliste für autonome Entscheidung
room_names = [info.get("name", "?") for rid, info in self._room_info.items()
if info.get("type") in ("c", "p") and rid != room_id]
rooms_str = ", ".join(room_names) if room_names else "keine weiteren Räume"
archivar_suffix = f" [Frage {_question_counter}, Timeout — Räume: {rooms_str}]"
with _question_counter_lock:
archivar_suffix = f" [Frage {_question_counter}, Timeout — Räume: {rooms_str}]"
# ── Ende Kontext-Weitergabe ──────────────────────────────────────
source = SessionSource(
platform=Platform("rocketchat"),