fix(archivar): Blocklist gegen Raumnamen als gelernte Keywords + F5.3 Cap (P-112)
This commit is contained in:
@@ -78,6 +78,9 @@ class ArchivarState:
|
||||
# Struktur: keyword → room_id → {"count": int, "timestamps": [iso, ...], "last_use": iso}
|
||||
# 30d-Decay: timestamps außerhalb des Fensters werden beim Zugriff verworfen.
|
||||
self._routing_use_counter: Dict[str, Dict[str, Dict[str, Any]]] = {}
|
||||
# P-112: F5.3 Auto-Promotion-Cap — bereits promotete (keyword, room)-Paare.
|
||||
# Idempotenz: ein Paar wird nur EINMAL auto-promotet, danach nie wieder.
|
||||
self._promoted_pairs: set = set()
|
||||
self._loaded = False
|
||||
|
||||
def load(self) -> bool:
|
||||
@@ -154,6 +157,11 @@ class ArchivarState:
|
||||
# Stufe 5: Routing-Use-Counter laden (F5.2/F5.3)
|
||||
self._routing_use_counter = data.get("routing_use_counter", {})
|
||||
|
||||
# P-112: bereits promotete Paare laden (F5.3 Cap)
|
||||
self._promoted_pairs = set(
|
||||
tuple(p) for p in data.get("promoted_pairs", [])
|
||||
)
|
||||
|
||||
# ── P0-B: never_route v7 Migration ──────────────────────────
|
||||
# v6: never_route war ein Set von room_ids (nicht gespeichert)
|
||||
# v7: never_route ist Dict[room_id][topic] → {state, timestamp, ...}
|
||||
@@ -253,6 +261,7 @@ class ArchivarState:
|
||||
"never_route": self._never_route,
|
||||
"ring_state": self._ring_state, # V8.2 A2
|
||||
"routing_use_counter": self._routing_use_counter, # Stufe 5
|
||||
"promoted_pairs": [list(p) for p in self._promoted_pairs], # P-112
|
||||
}
|
||||
|
||||
def get_room_state(self, room_id: str) -> Optional[RoomState]:
|
||||
@@ -1490,11 +1499,23 @@ class ArchivarState:
|
||||
|
||||
Schwelle: 5 Uses innerhalb 30 Tagen → True (Auto-Promotion zu permanent).
|
||||
|
||||
P-112 (F5.3 Cap): Idempotent. Ein Paar wird nur EINMAL auto-promotet.
|
||||
Beim ersten Erreichen der Schwelle wird das Paar in ``_promoted_pairs``
|
||||
markiert; alle weiteren Aufrufe liefern ``False`` — der Counter steigt
|
||||
zwar weiter (für Telemetrie), aber es gibt keine erneute Promotion.
|
||||
|
||||
Args:
|
||||
keyword: Das Keyword/Thema.
|
||||
room_id: Der Raum.
|
||||
|
||||
Returns:
|
||||
True wenn der Use-Count >= 5 ist (Auto-Promotion fällig).
|
||||
True beim Übergang auf >= 5 Uses (einmalig), sonst False.
|
||||
"""
|
||||
return self.get_routing_use_count(keyword, room_id) >= 5
|
||||
pair = (keyword, room_id)
|
||||
if pair in self._promoted_pairs:
|
||||
return False
|
||||
if self.get_routing_use_count(keyword, room_id) >= 5:
|
||||
self._promoted_pairs.add(pair)
|
||||
self.save()
|
||||
return True
|
||||
return False
|
||||
Reference in New Issue
Block a user