fix(archivar): Multi-Request-Resilienz — threading.Lock, asyncio.Semaphore, Catch-All-Schutz + try/except
This commit is contained in:
+10
-4
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user