Fix #278: treat AGENT_CLARIFY as active only when it is the final marker#279
Conversation
is_clarification_request() previously matched AGENT_CLARIFY anywhere in the response, so literal examples in plan prose (e.g. describing the protocol) could trigger clarification handling even when the response ended with a valid AGENT_PLAN_STATE or AGENT_STATE footer. Now the function finds the last AGENT_CLARIFY occurrence and compares its position against the last AGENT_STATE / AGENT_PLAN_STATE marker: if a valid state marker appears after the last AGENT_CLARIFY, the state marker takes precedence and the response is not treated as a clarification request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix for #278: AGENT_CLARIFY should not override a valid final state markerRoot cause confirmed: Fix applied ( The function now finds the last def is_clarification_request(text: str) -> bool:
clarify_matches = list(CLARIFY_RE.finditer(text))
if not clarify_matches:
return False
last_clarify_pos = clarify_matches[-1].start()
# A valid AGENT_STATE or AGENT_PLAN_STATE marker appearing after the last
# AGENT_CLARIFY takes precedence.
state_matches = list(STATE_RE.finditer(text)) + list(PLAN_STATE_RE.finditer(text))
if state_matches and max(m.start() for m in state_matches) > last_clarify_pos:
return False
return TrueTests added (
All 708 existing tests continue to pass. PR: #279 -- Anthropic Claude |
|
Review verdict: Blocking The precedence fix covers the reported state-after-clarify path, and the targeted clarification tests pass locally under python3, but clarification is still detected from embedded/non-standalone examples when no later state marker exists. Blocking issues
-- OpenAI Codex |
|
Review verdict: Blocking The fix correctly addresses AGENT_PLAN_STATE and AGENT_STATE precedence, but misses AGENT_PR which is required by the acceptance criteria. Blocking issues
Same-PR follow-ups
-- Google Gemini |
…ast-match - is_clarification_request now uses a line-anchored standalone regex (_STANDALONE_CLARIFY_RE) so inline/embedded AGENT_CLARIFY examples in prose or code blocks never trigger clarification handling, even when no state marker is present (addresses Codex item-1). - AGENT_PR and GH_PR_URL_RE are now included in the set of final-state markers that take precedence over a preceding standalone AGENT_CLARIFY, matching the acceptance criteria in #278 (addresses Gemini item-2 and item-3). - parse_pr_number now uses the final (last) AGENT_PR marker / PR URL, consistent with parse_agent_state and the "final marker is authoritative" principle (addresses Gemini item-4). - Tests updated: inline-only clarify without state marker now asserts False; new tests cover AGENT_PR precedence, GH_PR_URL precedence, and parse_pr_number last-match behavior. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coder follow-upAddressed all four review items: standalone-only clarify detection, AGENT_PR and GH_PR_URL_RE precedence, and parse_pr_number last-match. All 710 tests pass. Addressed items
Remaining items
Tests run
-- Anthropic Claude |
|
Review verdict: Blocking The PR resolves the AGENT_PR, PR URL, and final PR-number items, but still treats a fenced-code AGENT_CLARIFY example as an active clarification request. Blocking issues
Prior unresolved item dispositions
-- OpenAI Codex |
|
Review verdict: Approved Fixes are correct and appropriately prioritize final markers and explicit PR markers over standalone clarification requests. All prior unresolved items have been addressed successfully. Prior unresolved item dispositions
-- Google Gemini |
AGENT_CLARIFY on its own line inside a markdown fenced code block was matched by _STANDALONE_CLARIFY_RE, causing false-positive clarification detection when the code block appeared with no later state marker or when it appeared after the state marker (breaking the positional suppression). Add _FENCE_RE and _fenced_code_block_ranges() to identify fenced code block ranges, then filter out any standalone AGENT_CLARIFY match whose position falls within a code block before applying the precedence check. Tests added in test_is_clarification_request_ignores_fenced_code_block_examples: - backtick-fenced example with no state marker -> not clarification - backtick-fenced example with AGENT_PLAN_STATE after -> not clarification - AGENT_PLAN_STATE before fenced example -> not clarification (item-5 shape) - tilde-fenced example -> not clarification - AGENT_CLARIFY outside a fence -> still detected - AGENT_CLARIFY both inside and outside a fence -> outside occurrence active Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coder follow-upExcluded fenced code block content from clarification detection by adding _fenced_code_block_ranges() and filtering AGENT_CLARIFY matches that fall within code blocks. All 711 tests pass. Addressed items
Remaining items
Tests run
-- Anthropic Claude |
|
Review verdict: Blocking Round 3 fixes inline and fenced clarification examples, but AGENT_CLARIFY is still accepted when it is not the final response marker. Blocking issues
Prior unresolved item dispositions
-- OpenAI Codex |
|
Review verdict: Approved The PR correctly addresses issue #278 by refining how Prior unresolved item dispositions
-- Google Gemini |
…ast-match Use standalone-only regexes for AGENT_STATE, AGENT_PLAN_STATE, and AGENT_PR so that inline (prose) occurrences of these markers no longer suppress AGENT_CLARIFY, while still ensuring that any standalone (own-line, not in a code block) state/PR marker takes precedence regardless of its position in the text. Previously the precedence check was purely positional (state marker after clarify → suppress). This missed the case where a real AGENT_PLAN_STATE footer appeared before a standalone AGENT_CLARIFY example in an appendix — the clarify marker was incorrectly treated as active. New rule: - AGENT_CLARIFY is active only when it is standalone, not in a fenced code block, AND no standalone AGENT_STATE / AGENT_PLAN_STATE / AGENT_PR marker (outside a code block) exists anywhere in the response. - Inline markers in prose are ignored so quoted references to earlier rounds do not suppress a real clarification request. - GH_PR_URL_RE is still checked positionally (after AGENT_CLARIFY → suppress). Added _STANDALONE_STATE_RE, _STANDALONE_PLAN_STATE_RE, _STANDALONE_PR_RE. Added test_is_clarification_request_standalone_state_suppresses_regardless_of_position and extended test_is_clarification_request_pr_marker_takes_precedence. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coder follow-upSwitched to standalone-only regexes for state/PR markers and changed the precedence rule from positional to presence-based: any standalone (own-line, not in code block) AGENT_STATE/AGENT_PLAN_STATE/AGENT_PR marker anywhere in the response suppresses AGENT_CLARIFY, regardless of position. All 712 tests pass. Addressed items
Remaining items
Tests run
-- Anthropic Claude |
|
Review verdict: Blocking Blocking: targeted tests pass locally under python3, but AGENT_CLARIFY is still accepted when it is standalone but not the final response marker. Blocking issues
Prior unresolved item dispositions
-- OpenAI Codex |
|
Review verdict: Approved The PR successfully addresses issue #278 by refining the clarification marker detection and precedence rules. It ensures that Prior unresolved item dispositions
-- Google Gemini |
Add trailing-content check to is_clarification_request(): after the last active AGENT_CLARIFY, only blank lines and signature lines (-- Name) may follow. Any non-blank, non-signature line means the marker is embedded in plan/prose body rather than being the terminal response marker. Closes #278
Coder follow-upAdded trailing-content check: AGENT_CLARIFY is now only active when only blank lines and/or signature lines follow the last active marker. Addressed items
Remaining items
-- Anthropic Claude |
|
Review verdict: Blocking The main embedded-marker cases are fixed, but a final clarification marker can still be ignored when an earlier standalone state or PR marker appears in the response. Blocking issues
Prior unresolved item dispositions
-- OpenAI Codex |
|
Review verdict: Approved The PR correctly addresses issue #278 by requiring Prior unresolved item dispositions
-- Google Gemini |
…sses it The standalone STATE/PR check in is_clarification_request was position- agnostic — any such marker anywhere in the text would suppress AGENT_CLARIFY even when CLARIFY was the final content marker. Apply the same positional logic already used for GH_PR_URL: only suppress AGENT_CLARIFY when a standalone STATE/PLAN_STATE/PR marker appears AFTER the last active AGENT_CLARIFY position. Markers preceding the final CLARIFY (e.g. a plan footer from an earlier section, or a prior-round state reference) now correctly yield to the final AGENT_CLARIFY. Update test_is_clarification_request_standalone_state_suppresses_regardless_of_position → renamed to test_is_clarification_request_standalone_marker_positional_semantics with updated assertions reflecting the positional rule. Also update test_is_clarification_request_pr_marker_takes_precedence: a PR marker before the final CLARIFY no longer suppresses it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coder follow-upFixed item-8: made the standalone STATE/PR suppression check positional so a final AGENT_CLARIFY marker wins over earlier standalone state or PR markers. Addressed items
Remaining items
Tests run
-- Anthropic Claude |
|
Review verdict: Approved The positional clarification-marker fix covers the carried item, and the targeted test module passes locally; GitHub checks were still pending in the supplied PR context. Prior unresolved item dispositions
-- OpenAI Codex |
|
Review verdict: Approved The PR correctly implements positional semantics for AGENT_STATE, AGENT_PLAN_STATE, and AGENT_PR markers, ensuring they only suppress AGENT_CLARIFY if they appear after the last active clarification marker. This fixes the reported issue where embedded markers or footers from previous rounds could incorrectly suppress a genuine clarification request. Tests have been updated and verified to cover these scenarios. Prior unresolved item dispositions
-- Google Gemini |
|
GitHub PR checks are still pending for PR #279. Reviewer approvals do not make this PR merge-ready until GitHub PR checks are green, or the PR explicitly states that only a local subset passed.
-- coding-review-agent-loop |
Summary
is_clarification_request()previously matched<!-- AGENT_CLARIFY -->anywhere in the response text, so embedded examples in plan prose (e.g. Claude describing the protocol) could override a valid finalAGENT_PLAN_STATEorAGENT_STATEfooter and abort the loop as if clarification was requested.AGENT_CLARIFYoccurrence and compare its position against the lastAGENT_STATE/AGENT_PLAN_STATEmarker. If a valid state marker appears after the lastAGENT_CLARIFY, it takes precedence and the response is not treated as a clarification request.AGENT_PLAN_STATE: blocking), the PR/coder shape (AGENT_STATEafter embedded example), and the reverse (clarify is genuinely last).Fixes #278
Test plan
test_is_clarification_request_detects_marker— existing baseline still passestest_is_clarification_request_state_marker_after_clarify_takes_precedence— new test covering all acceptance criteria from Treat clarification markers as active only when they are final response markers #278🤖 Generated with Claude Code