fix(presence): Pulse-Engine Timeout-Hardening (Rainer Architects Review)

6 hardcoded Werte in PulseController geaendert:
- _await_timeout: 1.0 → 4.0s (DDP setDefaultStatus braucht mehr Zeit)
- _away_pulse_interval: 3.0 → 6.0s (seltener, vermeidet 429)
- _busy_pulse_interval: 1.5 → 4.0s (nicht zu aggressiv)
- _breaker_429_threshold: 1 → 3 (nicht sofort nach erstem 429 oeffnen)
- _backoff_intervals: (5,15,60) → (10,30,60) (sanftere Eskalation)
- _breaker_cooldown_s: 30.0 → 45.0s (laengere Erholungsphase)

Tests: threshold-abhaengige Tests dynamisch auf _breaker_429_threshold
umgestellt. 103/106 passed (3 pre-existing pgrep-mock Fehler).

ENV-Check: ROCKETCHAT_PRESENCE_PULSE_INTERVAL setzt nur initialen
_pulse_interval, set_pulse_target ueberschreibt mit mode-spezifischen
Werten — neue Defaults greifen korrekt.
This commit is contained in:
Bernd (Hermes)
2026-08-02 20:28:47 +02:00
parent b3d9a450e8
commit 52491d7972
2 changed files with 46 additions and 38 deletions
+12 -12
View File
@@ -844,7 +844,7 @@ class PulseController:
self._cancel_pending_event = threading.Event() # B6: thread-safe via Event statt bool
# P1-2 O-2: Async-await bridge
self._loop: Optional[asyncio.AbstractEventLoop] = None
self._await_timeout: float = 1.0 # V8.8: 1.0s statt 2.0s — schneller fail bei 429
self._await_timeout: float = 4.0 # V8.9: 4.0s — DDP setDefaultStatus braucht mehr Zeit
# Phase 5: pulse_target — "away" (default) oder "busy"
# "away": pulsiert online↔away (Subagent läuft, Hauptagent idle)
@@ -853,23 +853,23 @@ class PulseController:
self._mode_lock = threading.Lock() # Mode-Sentinel (Risiko #2)
self._tick_counter: int = 0 # für Message-only-every-2-ticks
# V8.8: Mode-abhängige Pulse-Intervalle
# away-pulse: 3.0s (weniger aggressiv, vermeidet 429)
# busy-pulse: 1.5s (schnelle Reaktion auf busy-Status)
self._away_pulse_interval: float = 3.0
self._busy_pulse_interval: float = 1.5
# V8.9: Mode-abhängige Pulse-Intervalle (Timeout-Hardening)
# away-pulse: 6.0s (seltener, vermeidet 429)
# busy-pulse: 4.0s (schnelle Reaktion, aber nicht zu aggressiv)
self._away_pulse_interval: float = 6.0
self._busy_pulse_interval: float = 4.0
# P1: Circuit-Breaker — verhindert 429-Endlosschleife im Gateway
# States: CLOSED (normal) → OPEN (nach N×429: Pause) → HALF_OPEN (Test-Ping)
self._breaker_state: str = "CLOSED"
self._consecutive_429s: int = 0
self._breaker_opened_at: float = 0.0
self._breaker_cooldown_s: float = 30.0
self._breaker_429_threshold: int = 1 # V8.8: 1 statt 3 — sofort nach erstem 429
self._breaker_cooldown_s: float = 45.0
self._breaker_429_threshold: int = 3 # V8.9: 3 statt 1 — nicht sofort nach erstem 429 öffnen
self._base_pulse_interval: float = self._pulse_interval
self._backoff_level: int = 0
# Adaptive Backoff: pulse_interval wird bei OPEN eskaliert
self._backoff_intervals: tuple = (5.0, 15.0, 60.0)
self._backoff_intervals: tuple = (10.0, 30.0, 60.0)
# ── Public API ───────────────────────────────────────────────────────
@@ -908,9 +908,9 @@ class PulseController:
def set_pulse_target(self, target: str) -> bool:
"""Phase 5: Set the pulse target mode with Mode-Sentinel.
V8.8: Mode-abhängige Pulse-Intervalle:
- "away": 3.0s (weniger aggressiv, vermeidet 429)
- "busy": 1.5s (schnelle Reaktion auf busy-Status)
V8.9: Mode-abhängige Pulse-Intervalle (Timeout-Hardening):
- "away": 6.0s (seltener, vermeidet 429)
- "busy": 4.0s (schnelle Reaktion, aber nicht zu aggressiv)
Args:
target: "away" (pulse online↔away) or "busy" (pulse message while busy).