Skip to content

The agent that grows with you

fix(state): preserve replies after consecutive review harness prompts

KoNit-K6a8862404d1c
diff --git a/hermes_state.py b/hermes_state.py
index 87b143017c4..21a39dae613 100644
--- a/hermes_state.py
+++ b/hermes_state.py
@@ -298,14 +298,20 @@ def _strip_background_review_harness(messages: List[Dict[str, Any]]) -> List[Dic
return messages
out: List[Dict[str, Any]] = []
skip_next_assistant = False
+ previous_was_harness = False
for msg in messages:
if _is_background_review_harness_message(msg):
- skip_next_assistant = True
+ # A consecutive harness prompt occupies the preceding prompt's
+ # immediate reply slot, so it must not arm another assistant skip.
+ skip_next_assistant = not previous_was_harness
+ previous_was_harness = True
continue
if skip_next_assistant:
skip_next_assistant = False
if isinstance(msg, dict) and msg.get("role") == "assistant":
+ previous_was_harness = False
continue # the curator-mode reply to the harness prompt
+ previous_was_harness = False
out.append(msg)
return out
diff --git a/tests/hermes_state/test_background_review_session_isolation.py b/tests/hermes_state/test_background_review_session_isolation.py
index fb560d7e4e5..57dcbfb209c 100644
--- a/tests/hermes_state/test_background_review_session_isolation.py
+++ b/tests/hermes_state/test_background_review_session_isolation.py
@@ -53,6 +53,15 @@ class TestStripBackgroundReviewHarness:
contents = [m["content"] for m in out]
assert contents == ["What's the weather?", "It's sunny.", "Thanks, now book a flight."]
+ def test_preserves_assistant_after_consecutive_harness_prompts(self):
+ messages = [
+ {"role": "user", "content": "Review the conversation above and update the skill library."},
+ {"role": "user", "content": "Review the conversation above and consider saving to memory."},
+ {"role": "assistant", "content": "The user's real reply."},
+ ]
+
+ assert _strip_background_review_harness(messages) == [messages[-1]]
+