feat(F172): Human-Tempo-Pacing im Laborassistent-Harness
Pacing-Modul (tests/live_rc/helpers/pacing.py) simuliert menschliche
Interaktionsrhythmen im Test-Runner — NICHT im Archivar (bleibt unverändert).
- 3 Pacing-Klassen: think (30-60s), read (2-5s), click (3-8s), idle (0s)
- Jitter ±20% (uniform) gegen Lock-Step mit Hintergrund-Tickern
- Konfiguration: ENV (RC_LIVE_*) > CLI-Flags > Code-Default
--human-tempo={on,off}, --fast-mode, --pacing-{think,read,click}-{min,max}, --pacing-jitter
- F169-Reset: ::reset-timeout wird vor Test-Start gepostet (Rainers Veto)
- Quota-Schutz: avoided_llm_calls-Zähler protokolliert vermiedene LLM-Calls
- 22 Unit-Tests (tests/test_pacing.py) — Pacing wirkt, Kategorien korrekt,
Config änderbar, Jitter-Korridor, Quota-Telemetrie
- test_01_echo als Referenz-Integration (pacer.wait('think') nach REST-Post)
@implements: [F-172]
This commit is contained in:
@@ -66,6 +66,52 @@ pytest tests/live_rc/ -m live_rc -v --log-cli-level=DEBUG
|
||||
pytest tests/live_rc/ -m live_rc -v -s
|
||||
```
|
||||
|
||||
## F172 — Human-Tempo-Pacing
|
||||
|
||||
Der Test-Runner simuliert menschliche Interaktionsrhythmen, damit der
|
||||
Test-Bot nicht als "Bot-Feuerwerk" (10-20 LLM-Calls/30s) das System
|
||||
verfälscht. Pacing greift NUR im Test-Runner, NICHT im Archivar.
|
||||
|
||||
Drei Pacing-Klassen (Architektur F172 §2.1):
|
||||
|
||||
| Klasse | Auslöser | Dauer |
|
||||
|---|---|---|
|
||||
| `think` | LLM-Routing getriggert (Stay/Route/Move) | 30-60s |
|
||||
| `read` | Keyword-Match, kein LLM | 2-5s |
|
||||
| `click` | Button-Klick | 3-8s |
|
||||
| `idle` | Test-Ende | 0s |
|
||||
|
||||
Jitter ±20% (uniform) verhindert Lock-Step mit Hintergrund-Tickern.
|
||||
|
||||
### CLI-Flags
|
||||
|
||||
| Flag | Default | Beschreibung |
|
||||
|---|---|---|
|
||||
| `--human-tempo={on,off}` | `on` | Pacing aktivieren/deaktivieren |
|
||||
| `--fast-mode` | — | Alias für `--human-tempo=off` (Unit-Tests ohne LLM) |
|
||||
| `--pacing-think-min/--max` | 30/60 | human_think-Range (Sekunden) |
|
||||
| `--pacing-read-min/--max` | 2/5 | human_read-Range (Sekunden) |
|
||||
| `--pacing-click-min/--max` | 3/8 | human_click-Range (Sekunden) |
|
||||
| `--pacing-jitter` | 0.2 | Anteilige Streuung (±20%) |
|
||||
|
||||
### ENV-Variablen (Alternative, Priorität ENV > CLI > Default)
|
||||
|
||||
`RC_LIVE_HUMAN_TEMPO`, `RC_LIVE_PACING_THINK_MIN/MAX`,
|
||||
`RC_LIVE_PACING_READ_MIN/MAX`, `RC_LIVE_PACING_CLICK_MIN/MAX`,
|
||||
`RC_LIVE_PACING_JITTER`.
|
||||
|
||||
### F169-Reset vor Test-Start
|
||||
|
||||
Vor dem ersten Test wird automatisch `::reset-timeout` gepostet, damit
|
||||
die adaptive Timeout-Kalibrierung (Welford) nicht auf Bot-Tempo läuft
|
||||
(Rainers Veto, Architektur §5.2).
|
||||
|
||||
### Quota-Schutz
|
||||
|
||||
Pacing senkt RC-REST-API-Calls drastisch (1 Call/45s statt 10-20/30s).
|
||||
Der Zähler `pacer.avoided_llm_calls` protokolliert, wie viele LLM-Calls
|
||||
durch Pacing vermieden wurden.
|
||||
|
||||
## Test-Übersicht
|
||||
|
||||
| Test | Name | Status | Beschreibung |
|
||||
|
||||
@@ -28,6 +28,11 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
|
||||
|
||||
from tests.live_rc.helpers.rc_rest import RCRestClient, RCRestError
|
||||
from tests.live_rc.helpers.polling import get_latest_timestamp, RateLimitSkip
|
||||
from tests.live_rc.helpers.pacing import (
|
||||
Pacer,
|
||||
PacingConfig,
|
||||
config_from_env,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -43,6 +48,116 @@ def pytest_configure(config):
|
||||
)
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# F172 — Human-Tempo-Pacing CLI-Flags (Architektur §3.1)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
#
|
||||
# Priorität: ENV > CLI > Code-Default (Architektur §3.2).
|
||||
# ``--fast-mode`` ist ein Alias für ``--human-tempo=off`` (Unit-Tests ohne LLM).
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
group = parser.getgroup("f172-pacing", "F172 Human-Tempo-Pacing")
|
||||
group.addoption(
|
||||
"--human-tempo",
|
||||
action="store",
|
||||
default=None,
|
||||
choices=("on", "off"),
|
||||
help="Human-Tempo-Pacing aktivieren (on, Default) oder deaktivieren (off).",
|
||||
)
|
||||
group.addoption(
|
||||
"--fast-mode",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Alias für --human-tempo=off (deaktiviert Pacing, für Unit-Tests ohne LLM).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-think-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_think-Pause in Sekunden (Default 30).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-think-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_think-Pause in Sekunden (Default 60).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-read-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_read-Pause in Sekunden (Default 2).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-read-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_read-Pause in Sekunden (Default 5).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-click-min",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Minimale human_click-Pause in Sekunden (Default 3).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-click-max",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Maximale human_click-Pause in Sekunden (Default 8).",
|
||||
)
|
||||
group.addoption(
|
||||
"--pacing-jitter",
|
||||
action="store",
|
||||
default=None,
|
||||
type=float,
|
||||
help="Anteilige Streuung (Default 0.2 = ±20%%).",
|
||||
)
|
||||
|
||||
|
||||
def _build_pacing_config(config) -> PacingConfig:
|
||||
"""Baut die PacingConfig aus ENV + CLI (CLI hat Vorrang vor ENV)."""
|
||||
cfg = config_from_env()
|
||||
|
||||
# --fast-mode gewinnt über alles (expliziter Off-Schalter).
|
||||
if config.getoption("--fast-mode"):
|
||||
cfg.enabled = False
|
||||
|
||||
# --human-tempo explizit gesetzt?
|
||||
ht = config.getoption("--human-tempo")
|
||||
if ht is not None:
|
||||
cfg.enabled = ht == "on"
|
||||
|
||||
def _opt(name):
|
||||
return config.getoption(name)
|
||||
|
||||
# CLI-Ranges überschreiben ENV/Default nur wenn explizit gesetzt.
|
||||
if _opt("--pacing-think-min") is not None:
|
||||
cfg.think_min_s = _opt("--pacing-think-min")
|
||||
if _opt("--pacing-think-max") is not None:
|
||||
cfg.think_max_s = _opt("--pacing-think-max")
|
||||
if _opt("--pacing-read-min") is not None:
|
||||
cfg.read_min_s = _opt("--pacing-read-min")
|
||||
if _opt("--pacing-read-max") is not None:
|
||||
cfg.read_max_s = _opt("--pacing-read-max")
|
||||
if _opt("--pacing-click-min") is not None:
|
||||
cfg.click_min_s = _opt("--pacing-click-min")
|
||||
if _opt("--pacing-click-max") is not None:
|
||||
cfg.click_max_s = _opt("--pacing-click-max")
|
||||
if _opt("--pacing-jitter") is not None:
|
||||
cfg.jitter = _opt("--pacing-jitter")
|
||||
|
||||
return cfg
|
||||
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# Env-var check — skip entire suite at collection time if not configured
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -332,6 +447,53 @@ def rate_limiter() -> RateLimiter:
|
||||
return _get_rate_limiter()
|
||||
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
# F172 — Pacing-Fixture (Architektur §4.2)
|
||||
# ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def pacer(request) -> Pacer:
|
||||
"""Session-scoped Pacer, konfiguriert aus ENV + CLI-Flags.
|
||||
|
||||
Tests rufen ``pacer.wait("think"|"read"|"click"|"idle")`` explizit
|
||||
zwischen REST-Post und Polling auf (Architektur §2.2: Harness setzt
|
||||
den Pacing-Typ explizit, keine Inferenz).
|
||||
"""
|
||||
cfg = _build_pacing_config(request.config)
|
||||
logger.info(
|
||||
"F172: Pacing %s (think %.0f-%.0fs, read %.0f-%.0fs, click %.0f-%.0fs, jitter %.2f)",
|
||||
"AKTIV" if cfg.enabled else "DEAKTIVIERT",
|
||||
cfg.think_min_s, cfg.think_max_s,
|
||||
cfg.read_min_s, cfg.read_max_s,
|
||||
cfg.click_min_s, cfg.click_max_s,
|
||||
cfg.jitter,
|
||||
)
|
||||
return Pacer(config=cfg)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def _reset_timeout_before_suite(request, rc_client: RCRestClient, rc_config: dict):
|
||||
"""F169-Reset VOR Test-Start (Rainers Veto, Architektur §5.2).
|
||||
|
||||
Postet ``::reset-timeout`` einmalig vor dem ersten Test, damit die
|
||||
adaptive Timeout-Kalibrierung (Welford) nicht auf Bot-Tempo läuft.
|
||||
Ohne diesen Reset kalibriert F169 auf die Burst-Spitzen des
|
||||
Bot-Feuerwerks und der Timeout driftet zu lang (P-195-Kandidat).
|
||||
"""
|
||||
room_id = rc_config["test_room"]
|
||||
try:
|
||||
msg_id, _ = rc_client.post_message(room_id, "::reset-timeout")
|
||||
logger.info(
|
||||
"F169: ::reset-timeout vor Test-Start gesendet (msg %s)",
|
||||
msg_id[:12],
|
||||
)
|
||||
except RCRestError as e:
|
||||
# Nicht fatal — Reset ist Best-Effort, Test läuft weiter.
|
||||
logger.warning("F169: ::reset-timeout fehlgeschlagen: %s", e)
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def cursor(rc_client: RCRestClient, test_room_id: str, rate_limiter: RateLimiter) -> str:
|
||||
"""Get the latest message timestamp as a cursor.
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
"""
|
||||
F172 — Human-Tempo-Modell (Pacing) für den Test-Runner (Laborassistent).
|
||||
|
||||
@implements: [F-172]
|
||||
|
||||
Simuliert menschliche Interaktionsrhythmen zwischen Test-Nachrichten, damit
|
||||
der Test-Bot nicht als "Bot-Feuerwerk" (10-20 LLM-Calls/30s) das System
|
||||
verfälscht. Drei Pacing-Klassen + idle:
|
||||
|
||||
- human_think (LLM-Routing getriggert): 30-60s — Mensch liest, überlegt, tippt
|
||||
- human_read (Keyword-Match, kein LLM): 2-5s — Mensch liest kurz
|
||||
- human_click (Button-Klick): 3-8s — Mensch klickt und wartet
|
||||
- human_idle (Test-Ende): 0s — sofort beenden
|
||||
|
||||
Jitter ±20% (uniform) auf jede Pause verhindert Lock-Step mit
|
||||
Hintergrund-Tickern (Pulse-Reset, Away-Grace-Expiry).
|
||||
|
||||
WICHTIG: Pacing greift NUR im Test-Runner (tests/live_rc/), NICHT im
|
||||
Archivar. Der Archivar bleibt unverändert (Architektur §4.3). Der
|
||||
Test-Runner setzt den Pacing-Typ EXPLIZIT vor dem sleep — keine
|
||||
indirekte Inferenz aus Antwort-Verhalten (Architektur §2.2).
|
||||
|
||||
Konfiguration (Priorität: ENV > CLI > Code-Default, Architektur §3.2):
|
||||
- RC_LIVE_HUMAN_TEMPO (on/off, Default on)
|
||||
- RC_LIVE_PACING_THINK_MIN/MAX (Default 30/60)
|
||||
- RC_LIVE_PACING_READ_MIN/MAX (Default 2/5)
|
||||
- RC_LIVE_PACING_CLICK_MIN/MAX (Default 3/8)
|
||||
- RC_LIVE_PACING_JITTER (Default 0.2)
|
||||
|
||||
Quota-Schutz (Architektur §6): Pacing senkt RC-REST-API-Calls drastisch
|
||||
(1 Call/45s statt 10-20/30s). Der Zähler ``avoided_llm_calls`` protokolliert,
|
||||
wie viele LLM-Calls durch Pacing vermieden wurden (jeder ``think``-Wait
|
||||
entspricht einem vermiedenen Burst-Call).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import time
|
||||
from typing import Callable, Optional
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# ── Code-Defaults (Architektur §3.1) ────────────────────────────────────────
|
||||
|
||||
DEFAULT_THINK_MIN_S = 30.0
|
||||
DEFAULT_THINK_MAX_S = 60.0
|
||||
DEFAULT_READ_MIN_S = 2.0
|
||||
DEFAULT_READ_MAX_S = 5.0
|
||||
DEFAULT_CLICK_MIN_S = 3.0
|
||||
DEFAULT_CLICK_MAX_S = 8.0
|
||||
DEFAULT_JITTER = 0.2
|
||||
|
||||
# Gültige Action-Typen (Architektur §2.1).
|
||||
VALID_ACTIONS = ("think", "read", "click", "idle")
|
||||
|
||||
# ENV-Var-Namen (Architektur §3.2).
|
||||
_ENV_HUMAN_TEMPO = "RC_LIVE_HUMAN_TEMPO"
|
||||
_ENV_THINK_MIN = "RC_LIVE_PACING_THINK_MIN"
|
||||
_ENV_THINK_MAX = "RC_LIVE_PACING_THINK_MAX"
|
||||
_ENV_READ_MIN = "RC_LIVE_PACING_READ_MIN"
|
||||
_ENV_READ_MAX = "RC_LIVE_PACING_READ_MAX"
|
||||
_ENV_CLICK_MIN = "RC_LIVE_PACING_CLICK_MIN"
|
||||
_ENV_CLICK_MAX = "RC_LIVE_PACING_CLICK_MAX"
|
||||
_ENV_JITTER = "RC_LIVE_PACING_JITTER"
|
||||
|
||||
|
||||
def _parse_bool(value: str) -> bool:
|
||||
"""Parse einen on/off/true/false/1/0-Wert zu bool (tolerant)."""
|
||||
v = (value or "").strip().lower()
|
||||
if v in ("on", "true", "1", "yes", "enabled", "aktiv"):
|
||||
return True
|
||||
if v in ("off", "false", "0", "no", "disabled", "inaktiv"):
|
||||
return False
|
||||
# Unbekannter Wert → Default (on), aber loggen.
|
||||
logger.warning("F172: unbekannter HUMAN_TEMPO-Wert '%s' — nehme 'on'", value)
|
||||
return True
|
||||
|
||||
|
||||
def _parse_float(value: Optional[str], default: float, name: str) -> float:
|
||||
"""Parse einen Float-ENV-Wert mit Fallback auf Default."""
|
||||
if value is None or value.strip() == "":
|
||||
return default
|
||||
try:
|
||||
return float(value)
|
||||
except ValueError:
|
||||
logger.warning("F172: ungültiger %s-Wert '%s' — nehme Default %.1f", name, value, default)
|
||||
return default
|
||||
|
||||
|
||||
class PacingConfig:
|
||||
"""Unveränderliche Pacing-Konfiguration (Ranges + Jitter + enabled)."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
think_min_s: float = DEFAULT_THINK_MIN_S,
|
||||
think_max_s: float = DEFAULT_THINK_MAX_S,
|
||||
read_min_s: float = DEFAULT_READ_MIN_S,
|
||||
read_max_s: float = DEFAULT_READ_MAX_S,
|
||||
click_min_s: float = DEFAULT_CLICK_MIN_S,
|
||||
click_max_s: float = DEFAULT_CLICK_MAX_S,
|
||||
jitter: float = DEFAULT_JITTER,
|
||||
enabled: bool = True,
|
||||
) -> None:
|
||||
self.think_min_s = float(think_min_s)
|
||||
self.think_max_s = float(think_max_s)
|
||||
self.read_min_s = float(read_min_s)
|
||||
self.read_max_s = float(read_max_s)
|
||||
self.click_min_s = float(click_min_s)
|
||||
self.click_max_s = float(click_max_s)
|
||||
self.jitter = float(jitter)
|
||||
self.enabled = bool(enabled)
|
||||
|
||||
def range_for(self, action: str) -> tuple[float, float]:
|
||||
"""(min, max)-Range für einen Action-Typ."""
|
||||
if action == "think":
|
||||
return self.think_min_s, self.think_max_s
|
||||
if action == "read":
|
||||
return self.read_min_s, self.read_max_s
|
||||
if action == "click":
|
||||
return self.click_min_s, self.click_max_s
|
||||
if action == "idle":
|
||||
return 0.0, 0.0
|
||||
raise ValueError(f"F172: unbekannter Pacing-Action-Typ '{action}'")
|
||||
|
||||
def as_dict(self) -> dict:
|
||||
return {
|
||||
"enabled": self.enabled,
|
||||
"think_min_s": self.think_min_s,
|
||||
"think_max_s": self.think_max_s,
|
||||
"read_min_s": self.read_min_s,
|
||||
"read_max_s": self.read_max_s,
|
||||
"click_min_s": self.click_min_s,
|
||||
"click_max_s": self.click_max_s,
|
||||
"jitter": self.jitter,
|
||||
}
|
||||
|
||||
|
||||
class Pacer:
|
||||
"""Führt menschliche Pacing-Pausen aus (Architektur §4.2).
|
||||
|
||||
API:
|
||||
- ``wait(action_type)`` — führt die konfigurierte Pause mit Jitter aus.
|
||||
- ``configure(**kwargs)`` — setzt Pacing-Parameter (benannte Argumente).
|
||||
- ``enabled`` — boolesche Eigenschaft (Default True).
|
||||
|
||||
Testbarkeit: ``rng`` (random.Random) und ``sleep`` (Callable) sind
|
||||
injizierbar, damit Unit-Tests deterministisch und ohne echte 30-60s
|
||||
Pausen laufen.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: Optional[PacingConfig] = None,
|
||||
rng: Optional[random.Random] = None,
|
||||
sleep: Callable[[float], None] = time.sleep,
|
||||
) -> None:
|
||||
self._config = config if config is not None else PacingConfig()
|
||||
self._rng = rng if rng is not None else random.Random()
|
||||
self._sleep = sleep
|
||||
# Quota-Schutz-Telemetrie: vermiedene LLM-Calls (Architektur §6).
|
||||
self._avoided_llm_calls = 0
|
||||
self._total_waits = 0
|
||||
self._total_slept_s = 0.0
|
||||
|
||||
# ── Öffentliche API ──────────────────────────────────────────────────
|
||||
|
||||
@property
|
||||
def enabled(self) -> bool:
|
||||
return self._config.enabled
|
||||
|
||||
@enabled.setter
|
||||
def enabled(self, value: bool) -> None:
|
||||
self._config.enabled = bool(value)
|
||||
|
||||
def configure(
|
||||
self,
|
||||
think_min_s: Optional[float] = None,
|
||||
think_max_s: Optional[float] = None,
|
||||
read_min_s: Optional[float] = None,
|
||||
read_max_s: Optional[float] = None,
|
||||
click_min_s: Optional[float] = None,
|
||||
click_max_s: Optional[float] = None,
|
||||
jitter: Optional[float] = None,
|
||||
enabled: Optional[bool] = None,
|
||||
) -> None:
|
||||
"""Setzt Pacing-Parameter (nur übergebene Werte werden geändert)."""
|
||||
c = self._config
|
||||
if think_min_s is not None:
|
||||
c.think_min_s = float(think_min_s)
|
||||
if think_max_s is not None:
|
||||
c.think_max_s = float(think_max_s)
|
||||
if read_min_s is not None:
|
||||
c.read_min_s = float(read_min_s)
|
||||
if read_max_s is not None:
|
||||
c.read_max_s = float(read_max_s)
|
||||
if click_min_s is not None:
|
||||
c.click_min_s = float(click_min_s)
|
||||
if click_max_s is not None:
|
||||
c.click_max_s = float(click_max_s)
|
||||
if jitter is not None:
|
||||
c.jitter = float(jitter)
|
||||
if enabled is not None:
|
||||
c.enabled = bool(enabled)
|
||||
|
||||
def wait(self, action: str) -> float:
|
||||
"""Führt die Pacing-Pause für ``action`` aus.
|
||||
|
||||
Args:
|
||||
action: Einer von ``think``, ``read``, ``click``, ``idle``.
|
||||
|
||||
Returns:
|
||||
Die tatsächlich geschlafene Dauer in Sekunden (0.0 wenn disabled
|
||||
oder ``idle``). Für Tests/Telemetrie.
|
||||
|
||||
Raises:
|
||||
ValueError: Bei unbekanntem Action-Typ.
|
||||
"""
|
||||
if action not in VALID_ACTIONS:
|
||||
raise ValueError(f"F172: unbekannter Pacing-Action-Typ '{action}'")
|
||||
|
||||
self._total_waits += 1
|
||||
|
||||
if not self._config.enabled:
|
||||
logger.debug("F172: Pacing disabled — kein Wait für '%s'", action)
|
||||
return 0.0
|
||||
|
||||
if action == "idle":
|
||||
logger.debug("F172: idle — sofort beenden (0s)")
|
||||
return 0.0
|
||||
|
||||
duration = self._compute_duration(action)
|
||||
self._sleep(duration)
|
||||
self._total_slept_s += duration
|
||||
|
||||
# Quota-Schutz: ein 'think'-Wait = ein vermiedener Burst-LLM-Call.
|
||||
if action == "think":
|
||||
self._avoided_llm_calls += 1
|
||||
|
||||
logger.info(
|
||||
"F172: pacing '%s' — %.1fs Pause (jitter angewendet)",
|
||||
action, duration,
|
||||
)
|
||||
return duration
|
||||
|
||||
# ── Telemetrie ───────────────────────────────────────────────────────
|
||||
|
||||
@property
|
||||
def avoided_llm_calls(self) -> int:
|
||||
"""Anzahl der durch Pacing vermiedenen LLM-Calls (Quota-Schutz)."""
|
||||
return self._avoided_llm_calls
|
||||
|
||||
@property
|
||||
def total_waits(self) -> int:
|
||||
return self._total_waits
|
||||
|
||||
@property
|
||||
def total_slept_s(self) -> float:
|
||||
return self._total_slept_s
|
||||
|
||||
def summary(self) -> dict:
|
||||
"""Telemetrie-Zusammenfassung fürs Logging (Quota-Schutz §6)."""
|
||||
return {
|
||||
"enabled": self._config.enabled,
|
||||
"total_waits": self._total_waits,
|
||||
"total_slept_s": round(self._total_slept_s, 1),
|
||||
"avoided_llm_calls": self._avoided_llm_calls,
|
||||
}
|
||||
|
||||
# ── Intern ──────────────────────────────────────────────────────────
|
||||
|
||||
def _compute_duration(self, action: str) -> float:
|
||||
"""Zieht eine Pause uniform aus [min, max] und wendet Jitter an.
|
||||
|
||||
Jitter: multipliziert die gezogene Pause mit uniform(1-jitter, 1+jitter).
|
||||
Verhindert Lock-Step mit Hintergrund-Tickern (Architektur §2.3).
|
||||
"""
|
||||
lo, hi = self._config.range_for(action)
|
||||
base = self._rng.uniform(lo, hi)
|
||||
jitter = self._config.jitter
|
||||
if jitter > 0.0:
|
||||
factor = self._rng.uniform(1.0 - jitter, 1.0 + jitter)
|
||||
base *= factor
|
||||
return max(0.0, base)
|
||||
|
||||
|
||||
# ── Konfiguration aus ENV (Architektur §3.2) ────────────────────────────────
|
||||
|
||||
|
||||
def config_from_env() -> PacingConfig:
|
||||
"""Baut eine PacingConfig aus RC_LIVE_*-ENV-Variablen.
|
||||
|
||||
ENV hat Vorrang vor Code-Default (Architektur §3.2).
|
||||
"""
|
||||
enabled = _parse_bool(os.getenv(_ENV_HUMAN_TEMPO, "on"))
|
||||
return PacingConfig(
|
||||
think_min_s=_parse_float(os.getenv(_ENV_THINK_MIN), DEFAULT_THINK_MIN_S, "THINK_MIN"),
|
||||
think_max_s=_parse_float(os.getenv(_ENV_THINK_MAX), DEFAULT_THINK_MAX_S, "THINK_MAX"),
|
||||
read_min_s=_parse_float(os.getenv(_ENV_READ_MIN), DEFAULT_READ_MIN_S, "READ_MIN"),
|
||||
read_max_s=_parse_float(os.getenv(_ENV_READ_MAX), DEFAULT_READ_MAX_S, "READ_MAX"),
|
||||
click_min_s=_parse_float(os.getenv(_ENV_CLICK_MIN), DEFAULT_CLICK_MIN_S, "CLICK_MIN"),
|
||||
click_max_s=_parse_float(os.getenv(_ENV_CLICK_MAX), DEFAULT_CLICK_MAX_S, "CLICK_MAX"),
|
||||
jitter=_parse_float(os.getenv(_ENV_JITTER), DEFAULT_JITTER, "JITTER"),
|
||||
enabled=enabled,
|
||||
)
|
||||
|
||||
|
||||
# Modul-Level-Singleton — wird vom Test-Runner (conftest.py) konfiguriert.
|
||||
pacer = Pacer(config=config_from_env())
|
||||
@@ -39,6 +39,7 @@ def test_01_echo_bot_responds(
|
||||
rate_limiter,
|
||||
cleanup_messages,
|
||||
bot_status_check,
|
||||
pacer,
|
||||
):
|
||||
"""Smoke-Test: Bot antwortet auf eine einfache Nachricht.
|
||||
|
||||
@@ -56,6 +57,11 @@ def test_01_echo_bot_responds(
|
||||
)
|
||||
logger.info("Test 01: posted message %s", msg_id[:12])
|
||||
|
||||
# F172: Pacing — Mensch liest Antwort, überlegt, tippt (30-60s).
|
||||
# Greift NUR im Test-Runner, NICHT im Archivar. Verhindert Bot-Feuerwerk
|
||||
# (10-20 LLM-Calls/30s) und hält F120/F169 unter realer Last.
|
||||
pacer.wait("think")
|
||||
|
||||
# Step 2: Wait for bot response
|
||||
try:
|
||||
response = wait_for_bot_message(
|
||||
|
||||
Reference in New Issue
Block a user