fix: V8.1.1 — 3 Blocker (Catch-All-Guard, Ring-GC, Tests)
R1 (P0): Catch-All-Sticky-Vergiftung behoben - Session-Sticky-Block (adapter.py:1581) prüft jetzt is_catch_all und should_stay_in_room VOR dem Auto-Route - Catch-All-Zielraum → Sticky wird gelöscht, Fall-Through zu Archivar - stay_in_room=always/never_route → Sticky wird gelöscht, Fall-Through R2 (P1): MultiRoomContextRing.move_gc() implementiert - Neue Methode entfernt stale Topics aus Ursprungsraum bei Move - Fügt neuen Ring-Eintrag für Zielraum hinzu - Aufruf bei confirm_move (Button 1) und Auto-Route (100%-Match) R3 (P1): 4 neue Test-Suites (56 Tests) - test_multiroom_context.py: Ring-Buffer, move_gc, System-Prompt - test_sticky_session.py: temporäres Sticky, 30 Min TTL, Guards - test_auto_route.py: 100%-Match, self-match, Catch-All - test_edge_cases.py: leerer Ring, Catch-All+Auto-Route, Move-Ketten R4 (P2): Doc-Kommentar für _CURRENT_ORIGIN_ROOM ContextVar-Reset Verifikation: 401 passed, 1 pre-existing fail (test_no_env_vars)
This commit is contained in:
+113
-28
@@ -73,6 +73,16 @@ if not logger.handlers:
|
||||
# though the Hermes session uses a synthetic user-based chat_id.
|
||||
# This is the mechanism that makes "one agent for all rooms" work
|
||||
# without touching Hermes Core.
|
||||
#
|
||||
# V8.1.1 R4: _CURRENT_ORIGIN_ROOM ist eine ContextVar — sie wird bei jedem
|
||||
# neuen Turn (handle_message-Aufruf) zurückgesetzt. Der Wert lebt nur für
|
||||
# die Dauer eines einzelnen Agent-Turns und wird NICHT zwischen Turns
|
||||
# persistiert. Das verhindert, dass der Zielraum einer vorherigen Nachricht
|
||||
# an der aktuellen klebt (z.B. DM nach Projektraum-Turn → Antwort im
|
||||
# Projektraum). Reset erfolgt implizit durch ContextVar-Semantik: jeder
|
||||
# asyncio-Task hat seinen eigenen Context, und handle_message setzt den
|
||||
# Wert explizit neu (entweder auf Zielraum bei Move/Auto-Route oder auf
|
||||
# den Ursprungsraum bei stay_in_room).
|
||||
_CURRENT_ORIGIN_ROOM: contextvars.ContextVar[str] = contextvars.ContextVar(
|
||||
"_rocketchat_origin_room", default=""
|
||||
)
|
||||
@@ -1436,6 +1446,17 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
"target_name": move_req.get("target_name", "Zielraum"),
|
||||
"expires_at": time.time() + 1800, # 30 Minuten
|
||||
}
|
||||
# V8.1.1 R2: Ring-GC bei Move — stale Topics aus Ursprungsraum entfernen
|
||||
if _MULTIROOM() and self._multiroom_context is not None:
|
||||
move_topic = move_req.get("text", "")[:80].replace("\n", " ").strip()
|
||||
if move_topic:
|
||||
target_name = move_req.get("target_name", "")
|
||||
await self._multiroom_context.move_gc(
|
||||
origin_room_id=room_id,
|
||||
target_room_id=move_req["target_room"],
|
||||
topic=move_topic,
|
||||
room_name=target_name,
|
||||
)
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky gesetzt — "
|
||||
"room=%s → target=%s (30 Min)",
|
||||
@@ -1573,34 +1594,88 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
if time.time() < pref["expires_at"]:
|
||||
target_room_id = pref["target_room"]
|
||||
target_name = pref.get("target_name", "Zielraum")
|
||||
# Kopiere Nachricht in den Zielraum
|
||||
target_txt = f"*(Auftrag von @{username}, Session-Sticky)*\n{text}"
|
||||
await self._post_message_with_retry(target_room_id, target_txt)
|
||||
_CURRENT_ORIGIN_ROOM.set(target_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set(target_room_id)
|
||||
routing_counter.increment('session_sticky_auto_route')
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky active — "
|
||||
"auto-routing '%s' → %s (%.0fs remaining)",
|
||||
text[:80], target_name,
|
||||
pref["expires_at"] - time.time(),
|
||||
)
|
||||
# Dispatch direkt — kein Archivar
|
||||
target_room_info = self._room_info.get(target_room_id, {})
|
||||
target_room_name = target_room_info.get("name", target_name)
|
||||
target_room_type = target_room_info.get("type", "c")
|
||||
await self._dispatch_agent(
|
||||
text=text,
|
||||
room_id=target_room_id,
|
||||
room_name=target_room_name,
|
||||
room_type=target_room_type,
|
||||
username=username,
|
||||
msg_id=msg_id,
|
||||
msg_obj=msg_obj,
|
||||
is_button_response=is_button_response,
|
||||
category="work_order",
|
||||
)
|
||||
return
|
||||
# V8.1.1 R1: Catch-All-Guard — nicht in Catch-All-Raum auto-routen
|
||||
if self.archivar is not None and self.archivar._room_map is not None:
|
||||
target_entry = self.archivar._room_map.get_room_by_id(target_room_id)
|
||||
if target_entry and target_entry.catch_all:
|
||||
logger.debug(
|
||||
"[rocketchat] V8.1.1 R1: Session-Sticky target %s is catch_all — "
|
||||
"skipping auto-route, falling through to Archivar",
|
||||
target_name[:20],
|
||||
)
|
||||
# Sticky aufräumen — nicht mehr gültig
|
||||
del self._session_room_preferences[room_id]
|
||||
# Fall through to Archivar classification
|
||||
else:
|
||||
# V8.1.1 R1: stay_in_room-Guard — nicht routen wenn Raum stay_in_room hat
|
||||
origin_state = self.archivar._state.should_stay_in_room(room_id)
|
||||
if origin_state in ("always", "never_route"):
|
||||
logger.debug(
|
||||
"[rocketchat] V8.1.1 R1: Session-Sticky origin room %s has "
|
||||
"stay_in_room=%s — skipping auto-route, falling through to Archivar",
|
||||
room_id[:8], origin_state,
|
||||
)
|
||||
del self._session_room_preferences[room_id]
|
||||
# Fall through to Archivar classification
|
||||
else:
|
||||
# Guards passed — auto-route
|
||||
# Kopiere Nachricht in den Zielraum
|
||||
target_txt = f"*(Auftrag von @{username}, Session-Sticky)*\n{text}"
|
||||
await self._post_message_with_retry(target_room_id, target_txt)
|
||||
_CURRENT_ORIGIN_ROOM.set(target_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set(target_room_id)
|
||||
routing_counter.increment('session_sticky_auto_route')
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky active — "
|
||||
"auto-routing '%s' → %s (%.0fs remaining)",
|
||||
text[:80], target_name,
|
||||
pref["expires_at"] - time.time(),
|
||||
)
|
||||
# Dispatch direkt — kein Archivar
|
||||
target_room_info = self._room_info.get(target_room_id, {})
|
||||
target_room_name = target_room_info.get("name", target_name)
|
||||
target_room_type = target_room_info.get("type", "c")
|
||||
await self._dispatch_agent(
|
||||
text=text,
|
||||
room_id=target_room_id,
|
||||
room_name=target_room_name,
|
||||
room_type=target_room_type,
|
||||
username=username,
|
||||
msg_id=msg_id,
|
||||
msg_obj=msg_obj,
|
||||
is_button_response=is_button_response,
|
||||
category="work_order",
|
||||
)
|
||||
return
|
||||
else:
|
||||
# Kein Archivar/RoomMap — direkt routen (Fallback)
|
||||
target_txt = f"*(Auftrag von @{username}, Session-Sticky)*\n{text}"
|
||||
await self._post_message_with_retry(target_room_id, target_txt)
|
||||
_CURRENT_ORIGIN_ROOM.set(target_room_id)
|
||||
_THEMATIC_TARGET_ROOM.set(target_room_id)
|
||||
routing_counter.increment('session_sticky_auto_route')
|
||||
logger.info(
|
||||
"[rocketchat] V8.1 P2: Session-Sticky active — "
|
||||
"auto-routing '%s' → %s (%.0fs remaining)",
|
||||
text[:80], target_name,
|
||||
pref["expires_at"] - time.time(),
|
||||
)
|
||||
# Dispatch direkt — kein Archivar
|
||||
target_room_info = self._room_info.get(target_room_id, {})
|
||||
target_room_name = target_room_info.get("name", target_name)
|
||||
target_room_type = target_room_info.get("type", "c")
|
||||
await self._dispatch_agent(
|
||||
text=text,
|
||||
room_id=target_room_id,
|
||||
room_name=target_room_name,
|
||||
room_type=target_room_type,
|
||||
username=username,
|
||||
msg_id=msg_id,
|
||||
msg_obj=msg_obj,
|
||||
is_button_response=is_button_response,
|
||||
category="work_order",
|
||||
)
|
||||
return
|
||||
else:
|
||||
# Abgelaufen → aufräumen
|
||||
del self._session_room_preferences[room_id]
|
||||
@@ -1698,6 +1773,16 @@ class RocketChatAdapter(BasePlatformAdapter):
|
||||
"Agent dispatched in target room",
|
||||
text[:80], target_name,
|
||||
)
|
||||
# V8.1.1 R2: Ring-GC bei Auto-Route — stale Topics aus Ursprungsraum entfernen
|
||||
if _MULTIROOM() and self._multiroom_context is not None:
|
||||
auto_topic = text[:80].replace("\n", " ").strip()
|
||||
if auto_topic:
|
||||
await self._multiroom_context.move_gc(
|
||||
origin_room_id=room_id,
|
||||
target_room_id=target_room_id,
|
||||
topic=auto_topic,
|
||||
room_name=target_name,
|
||||
)
|
||||
# V8.1 P2: Temporäres Sticky für aktive Session (30 Min TTL)
|
||||
self._session_room_preferences[room_id] = {
|
||||
"target_room": target_room_id,
|
||||
|
||||
Reference in New Issue
Block a user