fix: V9.2.2 — False-Positive Puls-Bug: Puls-Timer nur bei delegate_subagent > 0

Root Cause: _apply_counter_delta prüfte subagent_active über alle drei
Counter (delegate_subagent, chat_profile, background_term). on_session_start
feuert bei JEDEM Turn und inkrementiert chat_profile → Puls startete ohne
echten Subagenten.

Fix:
- Puls-Trigger (pulse_counters) prüft NUR delegate_subagent
- chat_profile und background_term zeigen weiterhin AWAY (statisch, ohne Puls)
- _on_pulse_tick und _on_circuit_breaker_expired ebenfalls auf delegate_subagent-only umgestellt

Tests (5 neue):
- test_no_pulse_on_session_start: on_session_start → kein Puls
- test_no_pulse_on_background_term: terminal(bg=true) → kein Puls
- test_pulse_only_on_delegate_subagent: nur delegate_subagent triggert Puls
- test_pulse_stops_when_delegate_done_others_stay: delegate→0 stoppt Puls trotz chat_profile>0
- test_chat_profile_away_no_pulse: chat_profile → AWAY statisch, kein Puls

Alle 77 V9-Tests PASSED, keine Regression.
This commit is contained in:
Bernd (Hermes)
2026-08-04 20:54:53 +02:00
parent fcfbc29284
commit 9a085dc494
2 changed files with 107 additions and 21 deletions
@@ -756,6 +756,91 @@ class TestPulseRotGelb:
assert not engine.is_pulse_active()
assert engine._pulse_timer is None
# ── V9.2.2: False-Positive Puls-Bug Tests ──────────────────────────
def test_no_pulse_on_session_start(self):
"""V9.2.2: on_session_start feuert → KEIN Puls (chat_profile ist kein Subagent)."""
engine = _make_engine()
assert not engine.is_pulse_active()
engine.on_session_start()
counters = engine.get_counters()
assert counters["chat_profile"] == 1
assert engine.get_status() == "AWAY" # statisches AWAY, kein Puls
assert not engine.is_pulse_active() # ← DER FIX: kein Puls!
def test_no_pulse_on_background_term(self):
"""V9.2.2: terminal(background=true) → KEIN Puls (background_term ist kein Subagent)."""
engine = _make_engine()
assert not engine.is_pulse_active()
engine.on_pre_tool_call(
tool_name="terminal",
args={"background": True, "command": "sleep 10"},
)
counters = engine.get_counters()
assert counters["background_term"] == 1
assert engine.get_status() == "AWAY" # statisches AWAY, kein Puls
assert not engine.is_pulse_active() # ← DER FIX: kein Puls!
def test_pulse_only_on_delegate_subagent(self):
"""V9.2.2: Nur delegate_subagent > 0 startet den Puls."""
engine = _make_engine()
assert not engine.is_pulse_active()
# chat_profile allein → kein Puls
engine.on_session_start()
assert not engine.is_pulse_active()
# background_term allein → kein Puls
engine.on_pre_tool_call(
tool_name="terminal",
args={"background": True, "command": "sleep 10"},
)
assert not engine.is_pulse_active()
# delegate_subagent → Puls startet
engine.on_subagent_start()
assert engine.is_pulse_active()
def test_pulse_stops_when_delegate_done_others_stay(self):
"""V9.2.2: delegate_subagent → 0 stoppt Puls, auch wenn chat_profile/background_term > 0."""
engine = _make_engine()
engine.on_subagent_start()
assert engine.is_pulse_active()
# chat_profile und background_term werden aktiv — Puls läuft weiter
engine.on_session_start()
engine.on_pre_tool_call(
tool_name="terminal",
args={"background": True, "command": "sleep 10"},
)
assert engine.is_pulse_active()
# delegate_subagent stoppt → Puls muss stoppen, obwohl andere Counter > 0
engine.on_subagent_stop()
assert not engine.is_pulse_active() # ← DER FIX: Puls stoppt!
# chat_profile und background_term sind noch aktiv → AWAY (statisch)
assert engine.get_status() == "AWAY"
def test_chat_profile_away_no_pulse(self):
"""V9.2.2: chat_profile > 0 → AWAY (statisch), kein Puls."""
engine = _make_engine()
engine.on_session_start()
assert engine.get_status() == "AWAY"
assert not engine.is_pulse_active()
# main_agent wird aktiv → bleibt AWAY (chat_profile hat Vorrang), kein Puls
engine.on_pre_gateway_dispatch()
assert engine.get_status() == "AWAY" # chat_profile > 0 → AWAY
assert not engine.is_pulse_active()
# main_agent fertig → immer noch AWAY (chat_profile noch aktiv)
engine.on_post_llm_call()
assert engine.get_status() == "AWAY"
assert not engine.is_pulse_active()
# ═══════════════════════════════════════════════════════════════════════════
# V9.2.1 Tests — 429-Circuit-Breaker + 5s-Intervall + REST-Throttling