Skip to content

The agent that grows with you

fix(compression): recognize normalized legacy headless notices

unsupportedpastelsbb873ade2533
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index 3b29d3ca1c0..6937cf418a5 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -1726,7 +1726,6 @@ _CLARIFY_NON_RESPONSE_PREFIXES = (
"[user did not respond", # gateway clarify delivery timeout
"[clarify prompt could not be delivered", # gateway UNDELIVERED*
"[oneshot mode:", # hermes_cli/oneshot.py
- "[single-query mode: no user available", # hermes chat -q headless callback
)
# Matched whole: as a prefix these would also swallow real answers that start the same way.
_CLARIFY_NON_RESPONSE_TEXTS = (
@@ -1734,11 +1733,24 @@ _CLARIFY_NON_RESPONSE_TEXTS = (
)
+# Complete historical headless callback envelopes. A prefix alone can also be
+# user-entered text; the suffix distinguishes the runtime's instruction to proceed.
+_CLARIFY_HEADLESS_NOTICE = re.compile(
+ r"\[(?:oneshot mode: no user available\. |"
+ r"single-query mode: no user available to answer .+\. )"
+ r"(?:Make the most reasonable assumption you can and continue\.|"
+ r"Pick the best (?:option|subset) from \[.*\] using your own judgment and continue\.)\]",
+ re.DOTALL,
+)
+
+
def _is_clarify_non_response(item) -> bool:
if not isinstance(item, str):
return False
text = item.strip()
- return text in _CLARIFY_NON_RESPONSE_TEXTS or text.startswith(_CLARIFY_NON_RESPONSE_PREFIXES)
+ return (text in _CLARIFY_NON_RESPONSE_TEXTS
+ or text.startswith(_CLARIFY_NON_RESPONSE_PREFIXES)
+ or _CLARIFY_HEADLESS_NOTICE.fullmatch(text) is not None)
def _sum_clarify(name, args, content, content_len, line_count):
@@ -1764,6 +1776,12 @@ def _sum_clarify(name, args, content, content_len, line_count):
# Only those legacy records need the old sentinel check; explicit status wins.
# Drop just the notice items so other selections in the same entry survive.
if "status" not in entry:
+ # The old multi-select normalizer split non-JSON callback text on
+ # commas. Recognize the complete envelope before filtering items,
+ # or its prefix-less trailing fragments become alleged answers.
+ if (isinstance(value, list) and all(isinstance(item, str) for item in values)
+ and _CLARIFY_HEADLESS_NOTICE.fullmatch(",".join(item.strip() for item in values))):
+ continue
values = [item for item in values if not _is_clarify_non_response(item)]
answers.extend(values)
answers = [answer for answer in answers if isinstance(answer, str) and answer]
diff --git a/tests/agent/test_context_compressor.py b/tests/agent/test_context_compressor.py
index ad371dd180b..b19f43a0365 100644
--- a/tests/agent/test_context_compressor.py
+++ b/tests/agent/test_context_compressor.py
@@ -54,7 +54,8 @@ class TestLegacyClarifyResults:
@pytest.mark.parametrize("shape", ["single", "batch", "current"])
@pytest.mark.parametrize("question_size", [300, 4500])
@pytest.mark.parametrize("answer", ["production, but only after 18:00 UTC", ["staging", "production"],
- "The user cancelled the production rollout; do not restart it."])
+ "The user cancelled the production rollout; do not restart it.",
+ "[single-query mode: no user available to answer 'Deploy?'. STOP production rollout now."])
def test_answers_reach_summary_after_repeated_pruning(self, monkeypatch, shape, question_size, answer):
import agent.context_compressor as module
@@ -105,6 +106,16 @@ class TestLegacyClarifyResults:
"Make the most reasonable assumption you can and continue.]",
])
def test_legacy_sentinels_are_not_answers_but_explicit_status_is_authoritative(self, sentinel):
+ # Persisted pre-#127760 headless multi-select results: the producer split its
+ # callback's non-JSON string at commas, including commas in the question.
+ for mode in ("oneshot", "single-query"):
+ prefix = ("[oneshot mode: no user available. " if mode == "oneshot" else
+ "[single-query mode: no user available to answer 'Deploy, really?'. ")
+ notice = prefix + "Pick the best subset from ['staging (Recommended)', 'production'] using your own judgment and continue.]"
+ fragments = [part.strip() for part in notice.split(",")]
+ for payload in ({"user_response": fragments}, {"responses": [{"user_response": fragments}]}):
+ content = json.dumps(payload)
+ assert _sum_clarify("clarify", {}, content, len(content), 1) == "[clarify] asked user a question"
for value, kept in ((sentinel, None), (["production", " " + sentinel], "production")):
for payload in ({"user_response": value}, {"responses": [{"user_response": value}]}):
content = json.dumps(payload)