fix(presence): pgrep False-Positive + DDP 429-Verbesserung (V8.8)
Bug 1 — pgrep argv-basierter Scanner: - _pgrep_hermes_subagents() nutzt jetzt argv-basierte Erkennung statt Substring-Suche in der kompletten cmdline - 'chat' und '--profile' muessen eigene argv-Elemente sein - argv[0] basename pruefen: 'hermes', 'python', 'python3' - python: '-m hermes_cli.main' oder hermes-Skript-Pfad in argv - Gateway-PID aus gateway_state.json ausschliessen - Neue _read_gateway_pid() Hilfsmethode - 6 neue False-Positive-Tests (bash grep, snap-path, gateway) Bug 2 — DDP 429 Circuit-Breaker + Pulse-Interval: - Circuit-Breaker threshold: 3 → 1 (sofort nach erstem 429) - DDP-Timeout: 2.0s → 1.0s (schneller fail) - Mode-abhaengige Pulse-Intervalle: away=3.0s, busy=1.5s - set_pulse_target() passt dynamisch das Interval an Tests: 144/144 passed
This commit is contained in:
@@ -2263,8 +2263,8 @@ class TestCircuitBreakerStateTransitions:
|
||||
assert pc.get_breaker_state() == "CLOSED"
|
||||
assert pc.get_consecutive_429s() == 0
|
||||
|
||||
def test_three_consecutive_429s_open_breaker(self):
|
||||
"""3 aufeinanderfolgende 429 → CLOSED→OPEN, pulse_interval steigt."""
|
||||
def test_one_429_opens_breaker(self):
|
||||
"""V8.8: 1×429 → CLOSED→OPEN sofort (threshold=1)."""
|
||||
from plugin.archivar.presence_engine import PulseController
|
||||
|
||||
mock_ddp = MagicMock()
|
||||
@@ -2277,20 +2277,10 @@ class TestCircuitBreakerStateTransitions:
|
||||
|
||||
base_interval = pc.get_effective_pulse_interval()
|
||||
|
||||
# Tick 1: 429 #1
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "CLOSED"
|
||||
assert pc.get_consecutive_429s() == 1
|
||||
|
||||
# Tick 2: 429 #2
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "CLOSED"
|
||||
assert pc.get_consecutive_429s() == 2
|
||||
|
||||
# Tick 3: 429 #3 → OPEN
|
||||
# Tick 1: 429 #1 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
assert pc.get_consecutive_429s() == 3
|
||||
assert pc.get_consecutive_429s() == 1
|
||||
# pulse_interval sollte auf backoff_level=0 → 5.0s gestiegen sein
|
||||
assert pc.get_effective_pulse_interval() > base_interval
|
||||
|
||||
@@ -2305,9 +2295,8 @@ class TestCircuitBreakerStateTransitions:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 3×429 → OPEN
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
|
||||
# Weitere Ticks werden geblockt (kein DDP-Call mehr)
|
||||
@@ -2325,12 +2314,12 @@ class TestCircuitBreakerHalfOpen:
|
||||
"""HALF_OPEN Test-Ping success → CLOSED, pulse_interval reset."""
|
||||
from plugin.archivar.presence_engine import PulseController
|
||||
|
||||
# DDP wirft 3×429, dann success
|
||||
# DDP wirft 1×429, dann success (threshold=1)
|
||||
call_count = [0]
|
||||
|
||||
def ddp_side_effect(status):
|
||||
call_count[0] += 1
|
||||
if call_count[0] <= 3:
|
||||
if call_count[0] <= 1:
|
||||
raise Exception("HTTP 429 Too Many Requests")
|
||||
return True
|
||||
|
||||
@@ -2341,9 +2330,8 @@ class TestCircuitBreakerHalfOpen:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 3×429 → OPEN
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
|
||||
# Simuliere Cooldown-Ablauf: setze _breaker_opened_at in die Vergangenheit
|
||||
@@ -2368,9 +2356,8 @@ class TestCircuitBreakerHalfOpen:
|
||||
pc = PulseController(pulse_interval=0.05, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 3×429 → OPEN (backoff_level=0, pulse_interval=5.0)
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 → OPEN (threshold=1, backoff_level=0, pulse_interval=5.0)
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
first_open_interval = pc.get_effective_pulse_interval()
|
||||
|
||||
@@ -2399,9 +2386,8 @@ class TestCircuitBreakerSustained429:
|
||||
|
||||
intervals_seen = [pc.get_effective_pulse_interval()]
|
||||
|
||||
# Zyklus 1: 3×429 → OPEN (backoff 0: 5.0s)
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# Zyklus 1: 1×429 → OPEN (threshold=1, backoff 0: 5.0s)
|
||||
pc._pulse_tick()
|
||||
intervals_seen.append(pc.get_effective_pulse_interval())
|
||||
|
||||
# Cooldown ablaufen lassen → HALF_OPEN → 429 → OPEN (backoff 1: 15.0s)
|
||||
@@ -2438,9 +2424,8 @@ class TestCircuitBreakerSustained429:
|
||||
|
||||
# 5 Zyklen OPEN→HALF_OPEN→OPEN (mehr als backoff_intervals Länge)
|
||||
for cycle in range(5):
|
||||
# 3×429 → OPEN
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 → OPEN (threshold=1)
|
||||
pc._pulse_tick()
|
||||
# Cooldown ablaufen → HALF_OPEN → 429 → OPEN
|
||||
pc._breaker_opened_at = time.monotonic() - pc._breaker_cooldown_s - 1.0
|
||||
pc._pulse_tick()
|
||||
@@ -2521,9 +2506,8 @@ class TestCircuitBreakerDdpErrorClassification:
|
||||
pc.bind_ddp(mock_ddp)
|
||||
pc.bind_rest(mock_rest)
|
||||
|
||||
# 3×429 DDP → OPEN, REST wurde NIE aufgerufen
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 DDP → OPEN (threshold=1), REST wurde NIE aufgerufen
|
||||
pc._pulse_tick()
|
||||
|
||||
# REST wurde NICHT aufgerufen (429 blockiert Fallback)
|
||||
mock_rest._request.assert_not_called()
|
||||
@@ -2559,7 +2543,7 @@ class TestCircuitBreakerRecordSuccess:
|
||||
|
||||
def ddp_side_effect(status):
|
||||
call_count[0] += 1
|
||||
if call_count[0] <= 3:
|
||||
if call_count[0] <= 1:
|
||||
raise Exception("HTTP 429 Too Many Requests")
|
||||
return True
|
||||
|
||||
@@ -2570,9 +2554,8 @@ class TestCircuitBreakerRecordSuccess:
|
||||
pc = PulseController(pulse_interval=1.5, _clamp_pulse=False)
|
||||
pc.bind_ddp(mock_ddp)
|
||||
|
||||
# 3×429 → OPEN (pulse_interval=5.0)
|
||||
for _ in range(3):
|
||||
pc._pulse_tick()
|
||||
# 1×429 → OPEN (threshold=1, pulse_interval=5.0)
|
||||
pc._pulse_tick()
|
||||
assert pc.get_breaker_state() == "OPEN"
|
||||
assert pc.get_effective_pulse_interval() == 5.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user