1c93c8f79f
## RoutingCounter (routing_counter.py)
- Thread-safe In-Memory-Counter für JEDE Routing-Entscheidung
- 17 Counter-Gründe: self_message_filtered, is_auftrag_bypass,
dm_auftrag_bypass, onboarding_active_skip, excluded_room_skip,
catch_all_origin_bypass, move_request_pending_guard, meta_check_stay,
never_route_stay, keyword_100_auto_route, keyword_context_butler,
faiss_auto_route, faiss_butler, llm_route, llm_stay,
recursive_restore, no_match_stay
- routing_counter.log_counts() für Log-Ausgabe
- Inkremente an ALLEN Bypass- und Entscheidungspunkten in adapter.py
und router.py
## ROUTING DECISION / ROUTING BYPASS Logging
- JEDE Routing-Entscheidung: logger.info('ROUTING DECISION:
reason=X, origin_room=Y, target_room=Z, stay=B, butler_mode=B')
- JEDER Bypass: logger.info('ROUTING BYPASS: reason=X, origin_room=Y')
- Macht Routing-Entscheidungen im Log nachvollziehbar
## is_auftrag Tests (test_is_auftrag.py)
- 129 Tests dokumentieren das AKTUELLE Verhalten
- TestIsAuftragKeywords: 54 Tests (jedes Keyword isoliert + im Satz)
- TestIsAuftragTruePositives: 25 echte Aufträge
- TestIsAuftragFalsePositives: 27 dokumentierte False-Positives
(Substring-Matching: 'mach' matcht 'gemacht', 'test' matcht 'Könntest')
- TestIsAuftragFalseNegatives: 5 dokumentierte False-Negatives
- TestIsAuftragTrueNegatives: 7 echte Nicht-Aufträge
- TestIsAuftragEdgeCases: 7 Grenzfälle
- TestIsAuftragStatistics: 3 statistische Tests
## Wichtig
- KEIN Verhaltenswechsel — nur Counter + Tests + Logging
- is_auftrag-Refactoring kommt in V8
- 321/322 bestehende Tests bestehen (1 pre-existing failure)
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""
|
|
Routing-Counter für Archivar v7 — empirische Daten für V8-Refactoring.
|
|
|
|
Zählt JEDE Routing-Entscheidung und JEDEN Bypass.
|
|
In-Memory (nicht persistent). Nach Neustart beginnt Zählung neu.
|
|
|
|
Usage::
|
|
|
|
from archivar.routing_counter import routing_counter
|
|
routing_counter.increment('is_auftrag_bypass')
|
|
routing_counter.log_counts()
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import threading
|
|
from typing import Dict
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RoutingCounter:
|
|
"""Thread-safe In-Memory-Counter für Routing-Entscheidungen."""
|
|
|
|
def __init__(self) -> None:
|
|
self._lock = threading.Lock()
|
|
self._counts: Dict[str, int] = {}
|
|
|
|
def increment(self, reason: str) -> None:
|
|
"""Inkrementiere den Zähler für einen Grund (thread-safe)."""
|
|
with self._lock:
|
|
self._counts[reason] = self._counts.get(reason, 0) + 1
|
|
|
|
def get_counts(self) -> Dict[str, int]:
|
|
"""Gibt eine Kopie aller Zählerstände zurück."""
|
|
with self._lock:
|
|
return dict(self._counts)
|
|
|
|
def log_counts(self) -> None:
|
|
"""Logge alle Zählerstände auf INFO-Level."""
|
|
counts = self.get_counts()
|
|
total = sum(counts.values())
|
|
logger.info(
|
|
"Routing counter (total=%d): %s",
|
|
total,
|
|
", ".join(f"{k}={v}" for k, v in sorted(counts.items())),
|
|
)
|
|
|
|
def reset(self) -> None:
|
|
"""Setze alle Zähler zurück."""
|
|
with self._lock:
|
|
self._counts.clear()
|
|
|
|
|
|
# Modul-Level-Singleton — wird von adapter.py und router.py importiert
|
|
routing_counter = RoutingCounter()
|