The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): detect pronounless action acknowledgements (#72692)
Brooklyn Nicholson3a009f97c108
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex a6065026d35..16a95fb3519 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -3251,15 +3251,142 @@ def looks_like_codex_intermediate_ack() -> bool:"""Detect a planning/ack message that should continue instead of ending the turn.``require_workspace=False`` (opt-in for all api_modes) drops the filesystem/repo reference- requirement; future-ack + short-content + no-prior-tools + action-verb checks always apply."""+ requirement; short-content + no-prior-tools guardrails always apply. A response must then+ contain either a first-person future acknowledgement with an action marker or a narrowly+ bounded pronounless action clause with an explicit transition cue; this keeps ordinary+ conversational replies such as "I'll help you brainstorm" from tripping it."""if any(isinstance(msg, dict) and msg.get("role") == "tool" for msg in messages):return Falseassistant_text = agent._strip_think_blocks(assistant_content or "").strip().lower()if not assistant_text or len(assistant_text) > 1200:return False- if not _ACK_FUTURE_RE.search(assistant_text):+ # Some tool-using providers narrate the next action in terse log style+ # rather than with a first-person lead-in: "Brief written. Creating the+ # session now." Bare gerunds are too ambiguous ("Reading the traceback+ # explains the failure" is a final answer), so this path also requires an+ # explicit transition cue such as "now", "via acpx", "actual log", or+ # "then launching". Completed reports and questions stay final.+ action_clause_pattern = re.compile(+ r"(?:^|[.!…—–]\s+|\n+\s*|,\s+then\s+)"+ r"(?:(?P<transition>then)\s+)?"+ r"(?P<action>(?:re)?launching|(?:re)?starting|creating|"+ r"checking|running|writing|opening|reading|inspecting|reviewing|"+ r"testing|debugging|searching|fixing)\b"+ )+ list_item_prefix_pattern = re.compile(r"(?:^|\n)\s*(?:[-*+]|\d+[.)])\s*$")+ numbered_item_pattern = re.compile(r"(?:^|\s)(\d+)[.)](?=\s)")+ status_number_pattern = re.compile(+ r"\b(?P<label>exit\s+code|attempt|step|retry)\s+"+ r"(?P<number>\d+)[.)](?=\s)"+ )+ question_pattern = re.compile(r"\?(?=\s|$|[\"'’”)\\]])")+ sentence_boundary_pattern = re.compile(+ r"(?:[.!…](?=\s|$)|\?(?=\s|$|[\"'’”)\\]])|\n+)"+ )+ allowed_trailing_action_pattern = re.compile(+ r"\s*(?:will\s+report\s+back|"+ r"then\s+(?:launching|relaunching|starting|restarting|creating)\s+"+ r"(?:it|(?:the\s+)?(?:session|worker|agent|job|process))|"+ r"(?:checking|reading|opening|inspecting)\s+(?:the\s+)?(?:log|output))"+ r"\s*[.!…]?\s*$"+ )+ launch_now_tail_pattern = re.compile(+ r"\s+(?:(?:it|(?:the\s+)?(?:session|worker|agent|job|process)|"+ r"(?:the\s+)?migration\s+file\s+in\s+the\s+repo)\s+)?"+ r"now(?:\s*\([^)]*\))?\s*$"+ )+ run_now_tail_pattern = re.compile(+ r"\s+(?:(?:it|(?:the\s+)?(?:(?:repo\s+)?suite|tests?|job|process|"+ r"server|service))\s+)?now(?:\s*\([^)]*\))?\s*$"+ )+ check_now_tail_pattern = re.compile(+ r"\s+(?:the\s+)?(?:log|output|status|service|session|job)\s+"+ r"now(?:\s*\([^)]*\))?\s*$"+ )+ launch_url_tail_pattern = re.compile(+ r"\s+now\s*[—–-]\s*see\s+https?://\S+"+ r"(?:\s+for\s+progress)?\s*$"+ )+ provider_tail_pattern = re.compile(+ r"\s+(?:it|(?:the\s+)?(?:session|worker|agent|job|process))\s+"+ r"on\s+copilot(?:\s+via\s+acpx)?\s*$"+ )+ actual_log_tail_pattern = re.compile(+ r"\s+(?:the\s+)?actual\s+(?:log|output)\s*$"+ )+ health_check_tail_pattern = re.compile(+ r"\s+whether\b.*\b(?:healthy|ready|running|available|reachable|working)\s*$"+ )+ launch_with_pattern = re.compile(+ r"\s+with\s+(?:(?:corrected|updated|new)\s+"+ r"(?:arguments?|args?|options?|flags?|parameters?)|"+ r"globals?\s+before\s+(?:the\s+)?agent\s+name)\s*$"+ )+ has_pronounless_action = False+ step_numbers = {+ status_match.group("number")+ for status_match in status_number_pattern.finditer(assistant_text)+ if status_match.group("label") == "step"+ }+ has_step_sequence = len(step_numbers) >= 2+ numbering_text = status_number_pattern.sub("", assistant_text)+ numbered_markers = {+ match.group(1) for match in numbered_item_pattern.finditer(numbering_text)+ }+ has_numbered_list = has_step_sequence or bool(numbered_markers)+ if not question_pattern.search(assistant_text):+ for action_match in action_clause_pattern.finditer(assistant_text):+ action_prefix = assistant_text[: action_match.start("action")]+ if has_numbered_list or list_item_prefix_pattern.search(action_prefix):+ continue+ raw_clause_tail = assistant_text[action_match.end() :]+ boundary_match = sentence_boundary_pattern.search(raw_clause_tail)+ if boundary_match:+ clause_tail = raw_clause_tail[: boundary_match.start()]+ remaining_text = raw_clause_tail[boundary_match.end() :]+ else:+ clause_tail = raw_clause_tail+ remaining_text = ""+ if remaining_text.strip() and not allowed_trailing_action_pattern.fullmatch(+ remaining_text+ ):+ continue+ action_word = action_match.group("action")+ is_launch_action = action_word in {+ "launching",+ "relaunching",+ "starting",+ "restarting",+ "creating",+ }+ has_transition_cue = bool(+ (is_launch_action and launch_now_tail_pattern.fullmatch(clause_tail))+ or (action_word == "running" and run_now_tail_pattern.fullmatch(clause_tail))+ or (+ action_word == "checking"+ and check_now_tail_pattern.fullmatch(clause_tail)+ )+ or (is_launch_action and launch_url_tail_pattern.fullmatch(clause_tail))+ or (is_launch_action and provider_tail_pattern.fullmatch(clause_tail))+ or (+ action_word in {"checking", "reading", "opening", "inspecting"}+ and actual_log_tail_pattern.fullmatch(clause_tail)+ )+ or (+ action_word == "checking"+ and health_check_tail_pattern.fullmatch(clause_tail)+ )+ or (is_launch_action and launch_with_pattern.fullmatch(clause_tail))+ )+ if not has_transition_cue:+ continue+ has_pronounless_action = True+ break+ if not (_ACK_FUTURE_RE.search(assistant_text) or has_pronounless_action):return False- if not any(marker in assistant_text for marker in _ACK_ACTION_MARKERS):+ if not has_pronounless_action and not any(+ marker in assistant_text for marker in _ACK_ACTION_MARKERS+ ):return False# Opted-in (all-api_mode) path: future-ack + action verb + no prior tool call suffices.if not require_workspace:diff --git a/tests/agent/test_intent_ack_continuation.py b/tests/agent/test_intent_ack_continuation.pyindex cee992866f0..5340d1c5c48 100644--- a/tests/agent/test_intent_ack_continuation.py+++ b/tests/agent/test_intent_ack_continuation.py@@ -70,12 +70,32 @@ def test_missing_attr_defaults_to_auto():bare_codex = SimpleNamespace(api_mode="codex_responses", model="x", _strip_think_blocks=lambda c: c)assert intent_ack_continuation_mode(bare_codex) == "codex_only"-# ── detector: workspace requirement ─────────────────────────────────────────+def test_codex_only_path_accepts_pronounless_workspace_announcement():+ """The default codex path keeps ACP-style action narration moving."""+ a = _agent("auto", "codex_responses")+ user = "add a migration"+ msgs = [{"role": "user", "content": user}]+ assert looks_like_codex_intermediate_ack(+ a,+ user,+ "Creating the migration file in the repo now.",+ msgs,+ require_workspace=True,+ )+ assert not looks_like_codex_intermediate_ack(+ a,+ user,+ "Testing complete. The repo is clean.",+ msgs,+ require_workspace=True,+ )++def test_multipart_user_message_does_not_crash_on_workspace_path():"""#9562: vision requests forward ``user_message`` as a multi-part list.@@ -108,9 +128,131 @@ def test_all_path_drops_workspace_requirement():)-# ── detector: guardrails that hold regardless of workspace ───────────────────+def test_pronounless_action_announcements_continue_when_opted_in():+ """#72692: Copilot ACP uses terse log-style action narration."""+ a = _agent(True, "chat_completions")+ user = "write the brief and launch the session"+ msgs = [{"role": "user", "content": user}]+ announcements = (+ "Launching it now.",+ "Launching it on Copilot via acpx.",+ "Writing the task brief, then launching it on Copilot via acpx.",+ "Brief written. Creating the session now.",+ "Brief written. Creating the session on Copilot.",+ "EXIT=1 — checking the actual log.",+ "Exited — checking the actual log.",+ "Relaunching with corrected arguments.",+ "Relaunching with globals before the agent name.",+ "Running now (pid 19441, no early exit). Checking the log…",+ "Brief written\nCreating the session now",+ "Checking whether the service is healthy.",+ "Launching now — see https://ci.example.com/run?id=5 for progress.",+ "Creating the session now. Then launching the worker.",+ "Checking the log now. Will report back.",+ "Exit code 1. Checking the actual log.",+ "Step 2. Creating the session now.",+ "Attempt 2. Relaunching with corrected arguments.",+ "Exit code 1. Attempt 2. Relaunching with corrected arguments.",+ "Exit code 1. Step 2. Checking the actual log.",+ "Attempt 1. Attempt 2. Relaunching with corrected arguments.",+ )+ for announcement in announcements:+ assert looks_like_codex_intermediate_ack(+ a, user, announcement, msgs, require_workspace=False+ ), announcement+++def test_pronounless_action_guardrails_reject_questions_and_finals():+ a = _agent(True, "chat_completions")+ user = "launch the session"+ msgs = [{"role": "user", "content": user}]+ final_answers = (+ "Should I launch it now?",+ "Nothing to do here.",+ "Interesting result; no action is needed.",+ "Done. The deployment succeeded.",+ "Testing completed successfully.",+ "Checking finished with no issues.",+ "Testing has completed successfully.",+ "Checking is complete.",+ "Running was successful.",+ "Testing complete.",+ "Checking done.",+ "Running successful.",+ "Testing the parser completed successfully.",+ "Checking the logs finished with no errors.",+ "Testing completed in 3.2 seconds.",+ "Checking finished at 10:42.",+ "Running the suite passed 42 of 42 assertions.",+ "Testing completed and everything looks good.",+ "Running the suite passed. 42 tests, 0 failures.",+ "Running the suite in parallel with pytest-xdist is the fastest win.",+ "Checking the CI logs would be the first step.",+ "Reading the traceback tells you which parser rule failed.",+ "Reading the traceback gives you the failing rule.",+ "Running the suite locally reproduces the failure.",+ "Checking the CI logs seems like the first step.",+ "Running the suite locally reproduced the failure.",+ "Checking the CI logs revealed a stale cache.",+ "Testing the parser found three bugs.",+ "Reviewing the diff surfaced two issues.",+ "Running the tests fails intermittently.",+ "Running the suite that ships with the repo reproduces the failure.",+ "Reading the traceback that pytest prints gives the failing rule.",+ "Testing the branch that CI builds found three bugs.",+ "Reading the traceback explains the failure.",+ "Checking the logs confirms the theory.",+ "Running the migration breaks the schema.",+ "Testing the parser produces a stack trace.",+ "Creating the migration that adds the users table.",+ "Checking the job that failed in CI.",+ "Running the migration via script improves speed.",+ "Running now — this improves reliability.",+ "Checking the actual log reveals the cause.",+ "Relaunching with corrected arguments improves reliability.",+ "Checking whether the service is healthy improves reliability.",+ "Then launching the worker improves reliability.",+ "Running the suite now. 42 passed, 0 failed.",+ "Checking the log now. Testing completed successfully.",+ "Checking the actual log. The job failed because the token expired.",+ "Running the suite locally works now.",+ "Creating the index speeds queries now.",+ "Running the suite works on Copilot.",+ "Testing happens via acpx.",+ "Checking the actual log. The error was a missing token.",+ "Checking the log now. The build is green.",+ "Launching it now. The deployment is live.",+ "Reviewing the diff. Everything looks fine.",+ "Testing the parser.\n\nAll 42 tests pass.",+ "Running the numbers. The total is 42.",+ "A few options:\n- Running the suite with a fixed seed\n- Pinning the dependency.",+ "Two ideas:\n* Checking the CI cache\n* Bumping the timeout.",+ "Options:\n1. Running the suite locally.",+ "Two options. 1. Running the suite locally. 2. Pinning the dependency.",+ "Two options. 1. Pinning the dependency. 2. Running the suite locally.",+ "Two options. 1. Checking the actual log. 2. Bumping the timeout.",+ "Two options. 1. Relaunching with corrected arguments. 2. Pinning the dep.",+ "Two approaches. 1. Checking the actual log. 2. Bumping the timeout.",+ "Two approaches. 1. Pinning the dependency. 2. Checking the actual log.",+ "Two ways. 1. Creating the session now. 2. Pinning the dep.",+ "Two options. Step 1. Pinning the dependency. Step 2. Relaunching with corrected arguments.",+ "Step 1. Pinning the dependency. Step 2. Relaunching with corrected arguments.",+ "Step 1. Pinning the dependency. Step 3. Relaunching with corrected arguments.",+ "Two options. 2. Pinning the dependency. 3. Checking the actual log.",+ "Possible fixes. 1. Checking the actual log. 2. Bumping the timeout.",+ "Two options: pinning the dep, checking the actual log.",+ "Two fixes: bumping the timeout, relaunching with corrected arguments.",+ "Option: 1. Launching it now.",+ "Options: 1. Creating the session now.",+ )+ for final in final_answers:+ assert not looks_like_codex_intermediate_ack(+ a, user, final, msgs, require_workspace=False+ ), final+# ── detector: guardrails that hold regardless of workspace ───────────────────+