From fd41aa6a64f88f3e9a6e24a6eefd85fb2140a260 Mon Sep 17 00:00:00 2001 From: JeremyDev87 Date: Sun, 5 Apr 2026 00:38:08 +0900 Subject: [PATCH] fix(plugin): clear stale workflow state when entering a new mode (#1334) on_mode_entry() now resets activeAgent, executionStrategy, councilStatus, and lastHandoff to None alongside the existing field resets, preventing stale workflow state from leaking across mode transitions. --- .../hooks/lib/hud_helpers.py | 4 +++ .../hooks/tests/test_hud_helpers.py | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/claude-code-plugin/hooks/lib/hud_helpers.py b/packages/claude-code-plugin/hooks/lib/hud_helpers.py index 556c2bbd..12a04d1f 100644 --- a/packages/claude-code-plugin/hooks/lib/hud_helpers.py +++ b/packages/claude-code-plugin/hooks/lib/hud_helpers.py @@ -48,6 +48,10 @@ def on_mode_entry( "phase": phase, "focus": None, "blockerCount": 0, + "activeAgent": None, + "executionStrategy": None, + "councilStatus": None, + "lastHandoff": None, } if state_file: update_hud_state(state_file=state_file, **kwargs) diff --git a/packages/claude-code-plugin/hooks/tests/test_hud_helpers.py b/packages/claude-code-plugin/hooks/tests/test_hud_helpers.py index 4a7a26a5..6d26ca77 100644 --- a/packages/claude-code-plugin/hooks/tests/test_hud_helpers.py +++ b/packages/claude-code-plugin/hooks/tests/test_hud_helpers.py @@ -113,6 +113,39 @@ def test_resets_focus_and_blockers(self, state_file): assert state["focus"] is None assert state["blockerCount"] == 0 + @pytest.mark.parametrize("mode,expected_phase", [ + ("PLAN", "planning"), + ("ACT", "executing"), + ("EVAL", "evaluating"), + ("AUTO", "cycling"), + ]) + def test_resets_all_stale_workflow_fields(self, state_file, mode, expected_phase): + """Seed ALL workflow fields with non-default values then verify full reset.""" + from hud_state import update_hud_state + update_hud_state( + state_file=state_file, + currentMode="EVAL", + phase="evaluating", + focus="old-file.py", + blockerCount=5, + activeAgent="Security Specialist", + executionStrategy="subagent", + councilStatus="voting", + lastHandoff="Frontend Developer", + ) + + on_mode_entry(mode, state_file=state_file) + state = _read(state_file) + + assert state["currentMode"] == mode + assert state["phase"] == expected_phase + assert state["focus"] is None + assert state["blockerCount"] == 0 + assert state["activeAgent"] is None + assert state["executionStrategy"] is None + assert state["councilStatus"] is None + assert state["lastHandoff"] is None + def test_unknown_mode_defaults_to_ready(self, state_file): on_mode_entry("UNKNOWN", state_file=state_file) state = _read(state_file)