feat(F169): Reset-Endpoint für adaptiven LLM-Timeout (Voraussetzung F172 Pacing)

@implements F-169

Reset der Welford-Kalibrierung auf Baseline, damit ein Test nicht auf
Bot-Tempo statt Mensch-Tempo kalibriert (Rainers Veto für F172).

- adaptive_timeout.py: reset_timeout(agent_name) — setzt n/mean/m2/streak/
  escalated/accepted/rejected zurück; in-flight-Zähler (begin_call/end_call)
  für Race-Condition-Erkennung; in_flight-Property.
- classifier.py: begin_call()/end_call() um den LLM-Call verdrahtet
  (finally garantiert Dekrement auch bei Exception).
- adapter.py: ::reset-timeout Inline-Command (manueller Reset durch Andreas).
- rc_tools.py: rocketchat_reset_timeout Tool (programmatischer Reset).
- tests: test_f169_reset_timeout.py — 10 A1c-Tests (Reset setzt Statistik
  zurück, Reset während in-flight Call ist safe, in-flight nicht persistiert).

Race-Condition-Schutz: Reset läuft unter self._lock (atomar gegenüber
record/current_timeout). Laufender Call wird nicht blockiert, zählt als
erste Messung der Neukalibrierung. Nach Reset: Failsafe 30s bis genug Samples.
This commit is contained in:
Bernd (Hermes)
2026-09-05 12:16:57 +02:00
parent b957a35402
commit 44b2ada193
5 changed files with 339 additions and 0 deletions
+57
View File
@@ -1050,6 +1050,62 @@ ROCKETCHAT_BROADCAST_SCHEMA = {
}
# ---------------------------------------------------------------------------
# F169: rocketchat_reset_timeout — adaptiven LLM-Timeout auf Baseline zurücksetzen
# ---------------------------------------------------------------------------
def _handle_rocketchat_reset_timeout(args: dict, **kw) -> str:
"""F169: Setzt die adaptive LLM-Timeout-Kalibrierung auf Baseline zurück.
@implements F-169
Setzt Welford-Statistik (Mittelwert + Varianz), Call-Counter und
Eskalations-Stufe zurück. Der erste Call nach dem Reset kalibriert neu;
bis genug Samples vorliegen, gilt wieder der Failsafe (30s).
Nützlich vor Tests (z.B. F172 Human-Tempo-Pacing), damit die Kalibrierung
nicht auf Bot-Tempo statt Mensch-Tempo läuft.
"""
try:
from archivar.adaptive_timeout import adaptive_timeout
except Exception as exc:
return tool_error(f"adaptive_timeout nicht verfügbar: {type(exc).__name__}: {exc}")
agent_name = str(args.get("agent_name") or "rocketchat_reset_timeout").strip()
result = adaptive_timeout.reset_timeout(agent_name=agent_name)
return tool_result({
"success": True,
"message": "Adaptive timeout reset to baseline",
"calls": result["calls"],
"mean": result["mean"],
"stddev": result["stddev"],
"in_flight": result["in_flight"],
})
ROCKETCHAT_RESET_TIMEOUT_SCHEMA = {
"name": "rocketchat_reset_timeout",
"description": (
"Reset the adaptive LLM timeout calibration to baseline (F169). "
"Clears the Welford statistics (mean + variance), the call counter, "
"and the escalation level. The first call after the reset recalibrates; "
"until enough samples are collected, the failsafe (30s) applies. "
"Use this before starting a test so the calibration reflects human "
"tempo instead of bot tempo."
),
"parameters": {
"type": "object",
"properties": {
"agent_name": {
"type": "string",
"description": "Name of the agent triggering the reset (for logging).",
},
},
"required": [],
},
}
# ---------------------------------------------------------------------------
# Registration helpers for the plugin register() function
# ---------------------------------------------------------------------------
@@ -1063,6 +1119,7 @@ _TOOLS = (
("rocketchat_download", ROCKETCHAT_DOWNLOAD_SCHEMA, _handle_rocketchat_download, "📥"),
("rocketchat_files", ROCKETCHAT_FILES_SCHEMA, _handle_rocketchat_files, "📁"),
("rocketchat_broadcast", ROCKETCHAT_BROADCAST_SCHEMA, _handle_rocketchat_broadcast, "📢"),
("rocketchat_reset_timeout", ROCKETCHAT_RESET_TIMEOUT_SCHEMA, _handle_rocketchat_reset_timeout, "⏱️"),
)