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

This commit is contained in:
KoNit-K
2026-09-14 13:55:18 +08:00
committed by Teknium
parent 7b44106174
commit 6a8862404d
2 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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]]