fix(presence): P-103 Folge-Bug — force=True Status-Send nach Clarify-Replay
Root Cause: clear_clarify_modal() hält _mediator_lock und rief
on_phase_transition() auf, das den nicht-reentranten threading.Lock erneut
akquiriert → Deadlock. Der Replay-Pfad (pending transition) hing für immer,
kein Status-Send folgte auf 'Replay pending transition'.
Zusätzlich: Der Replay-Pfad ging durch den normalen Phasen-Übergang ohne
force=True — der letzte gesendete Status war 'offline' (⬛) aus dem
Modal-Puls, der Cache hätte den korrekten Status (online/busy) unterdrückt.
Fix:
1. on_phase_transition() in _apply_phase_transition_locked() extrahiert
(lock-freie Variante, Caller hält _mediator_lock).
2. clear_clarify_modal() nutzt _apply_phase_transition_locked() statt
on_phase_transition() — kein Deadlock mehr.
3. Nach dem Replay wird _send_phase_status_locked(force=True) aufgerufen —
der korrekte Post-Clarify-Status wird sofort gesendet, unabhängig vom
Cache-Zustand.
Tests: 2 neue Tests (Replay zu RED_PULSE + GREEN_STATIC) in
TestClarifyModalCooldownReset. 1667 passed, 37 skipped, 11 xfailed.
This commit is contained in:
@@ -492,6 +492,72 @@ class TestClarifyModalCooldownReset:
|
||||
|
||||
assert rest_sender.call_count == 0
|
||||
|
||||
def test_clear_modal_replay_pending_transition_sends_force_status(self):
|
||||
"""P-103 Folge-Bug: Replay-Pfad (pending transition) darf nicht deadlocken
|
||||
und MUSS den finalen Status mit force=True senden.
|
||||
|
||||
Der ursprüngliche Bug: clear_clarify_modal() hält _mediator_lock und
|
||||
rief on_phase_transition() auf, das den Lock erneut akquiriert
|
||||
(nicht-reentrant) → Deadlock. Nach dem Replay wurde zudem kein
|
||||
force=True-Status gesendet, sodass der letzte Status 'offline' (⬛)
|
||||
aus dem Modal-Puls stehen blieb.
|
||||
"""
|
||||
rest_sender = MagicMock(return_value=True)
|
||||
mediator = _Mediator(rest_sender=rest_sender)
|
||||
# Modal aktiv, pending transition RED_STATIC → RED_PULSE gespeichert
|
||||
mediator.current_phase = Phase.RED_STATIC
|
||||
mediator._clarify_modal = True
|
||||
mediator._clarify_modal_message = "Hauptagent wartet auf Antwort"
|
||||
mediator._modal_pending_phase = Phase.RED_PULSE
|
||||
# Cooldown aktiv (durch Modal-Puls aufgebaut)
|
||||
mediator._rest_cooldown_until = time.monotonic() + 58.4
|
||||
mediator._consecutive_429s = 11
|
||||
# Letzter gesendeter Status war 'offline' (Modal-Puls)
|
||||
mediator._last_sent_phase = Phase.RED_STATIC
|
||||
mediator._last_sent_message = "Hauptagent wartet auf Antwort"
|
||||
mediator._last_sent_status = "offline"
|
||||
|
||||
# Darf NICHT deadlocken — muss sofort zurückkehren
|
||||
mediator.clear_clarify_modal()
|
||||
|
||||
# Phase muss auf RED_PULSE angewendet worden sein (Replay)
|
||||
assert mediator.current_phase == Phase.RED_PULSE, (
|
||||
"Replay hat die pending Transition nicht angewendet"
|
||||
)
|
||||
# Cooldown zurückgesetzt
|
||||
assert mediator._rest_cooldown_until == 0.0
|
||||
# force=True Status gesendet — nicht 'offline'
|
||||
assert rest_sender.call_count >= 1, (
|
||||
"Replay-Pfad hat keinen Status gesendet — Bot bleibt ⬛ away"
|
||||
)
|
||||
# Der letzte gesendete Status muss busy (RED_PULSE Primärseite) sein,
|
||||
# nicht 'offline' aus dem Modal-Puls.
|
||||
sent_status = rest_sender.call_args[0][0]
|
||||
assert sent_status in ("busy", "online"), (
|
||||
f"Falscher Status nach Replay: {sent_status} — erwartet busy/online, "
|
||||
f"nicht 'offline'"
|
||||
)
|
||||
|
||||
def test_clear_modal_replay_pending_to_green_static_sends_online(self):
|
||||
"""Replay zu GREEN_STATIC → Status 'online' (nicht 'offline')."""
|
||||
rest_sender = MagicMock(return_value=True)
|
||||
mediator = _Mediator(rest_sender=rest_sender)
|
||||
mediator.current_phase = Phase.RED_STATIC
|
||||
mediator._clarify_modal = True
|
||||
mediator._clarify_modal_message = "Hauptagent wartet auf Antwort"
|
||||
mediator._modal_pending_phase = Phase.GREEN_STATIC
|
||||
mediator._rest_cooldown_until = time.monotonic() + 58.4
|
||||
mediator._last_sent_status = "offline"
|
||||
|
||||
mediator.clear_clarify_modal()
|
||||
|
||||
assert mediator.current_phase == Phase.GREEN_STATIC
|
||||
assert rest_sender.call_count >= 1
|
||||
sent_status = rest_sender.call_args[0][0]
|
||||
assert sent_status == "online", (
|
||||
f"Falscher Status nach Replay zu GREEN_STATIC: {sent_status}"
|
||||
)
|
||||
|
||||
|
||||
class TestPulsePhaseCacheSkip:
|
||||
"""P-079b: Normaler Puls (GREEN_PULSE/RED_PULSE) muss den Cache überspringen."""
|
||||
|
||||
Reference in New Issue
Block a user