Skip to content

Commit fd41aa6

Browse files
committed
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.
1 parent c429d99 commit fd41aa6

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

packages/claude-code-plugin/hooks/lib/hud_helpers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def on_mode_entry(
4848
"phase": phase,
4949
"focus": None,
5050
"blockerCount": 0,
51+
"activeAgent": None,
52+
"executionStrategy": None,
53+
"councilStatus": None,
54+
"lastHandoff": None,
5155
}
5256
if state_file:
5357
update_hud_state(state_file=state_file, **kwargs)

packages/claude-code-plugin/hooks/tests/test_hud_helpers.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,39 @@ def test_resets_focus_and_blockers(self, state_file):
113113
assert state["focus"] is None
114114
assert state["blockerCount"] == 0
115115

116+
@pytest.mark.parametrize("mode,expected_phase", [
117+
("PLAN", "planning"),
118+
("ACT", "executing"),
119+
("EVAL", "evaluating"),
120+
("AUTO", "cycling"),
121+
])
122+
def test_resets_all_stale_workflow_fields(self, state_file, mode, expected_phase):
123+
"""Seed ALL workflow fields with non-default values then verify full reset."""
124+
from hud_state import update_hud_state
125+
update_hud_state(
126+
state_file=state_file,
127+
currentMode="EVAL",
128+
phase="evaluating",
129+
focus="old-file.py",
130+
blockerCount=5,
131+
activeAgent="Security Specialist",
132+
executionStrategy="subagent",
133+
councilStatus="voting",
134+
lastHandoff="Frontend Developer",
135+
)
136+
137+
on_mode_entry(mode, state_file=state_file)
138+
state = _read(state_file)
139+
140+
assert state["currentMode"] == mode
141+
assert state["phase"] == expected_phase
142+
assert state["focus"] is None
143+
assert state["blockerCount"] == 0
144+
assert state["activeAgent"] is None
145+
assert state["executionStrategy"] is None
146+
assert state["councilStatus"] is None
147+
assert state["lastHandoff"] is None
148+
116149
def test_unknown_mode_defaults_to_ready(self, state_file):
117150
on_mode_entry("UNKNOWN", state_file=state_file)
118151
state = _read(state_file)

0 commit comments

Comments
 (0)