fix(agent): clear stale intermediate acknowledgments

Treat intent-ack continuation text as non-final so last-turn exhaustion requests a real summary instead of surfacing a premature promise. Keep iteration-limit fallback text free of the abnormal-fragment explainer.
This commit is contained in:
kshitijk4poor 2026-07-10 11:31:42 +05:30 committed by kshitij
parent 1453431881
commit f46e7647eb
3 changed files with 24 additions and 1 deletions

View file

@ -5104,6 +5104,10 @@ def run_conversation(
}
messages.append(continue_msg)
agent._session_messages = messages
# An acknowledgment is explicitly non-final. Do not let its
# text suppress iteration-limit summarization if this
# continuation consumes the remaining budget.
final_response = None
continue
codex_ack_continuations = 0

View file

@ -320,7 +320,7 @@ def finalize_turn(
# truncated partial (the "The" case from #34452).
_is_partial_fragment = (
not _is_empty_terminal
and not continuation_budget_exhausted
and not iteration_limit_fallback
and not str(_turn_exit_reason).startswith("text_response")
and len(_stripped) <= 24
and _stripped[-1:] not in {".", "!", "?", "", "", "", "`", ")"}

View file

@ -102,3 +102,22 @@ def test_pre_verify_preserves_composed_report_at_budget_limit(agent, monkeypatch
_assert_pending_response_survives(agent, result)
assert result["messages"][1]["_pre_verify_synthetic"] is True
assert result["messages"][2]["_pre_verify_synthetic"] is True
def test_intermediate_ack_uses_summary_instead_of_premature_text(agent, monkeypatch):
agent.valid_tool_names = ["web_search"]
agent._intent_ack_continuation = True
agent._looks_like_codex_intermediate_ack = MagicMock(return_value=True)
agent._interruptible_api_call = lambda _kwargs: _response("I'll inspect the files now")
agent._handle_max_iterations = MagicMock(return_value="verified summary")
monkeypatch.setenv("HERMES_VERIFY_ON_STOP", "0")
with (
patch("hermes_cli.plugins.has_hook", return_value=False),
patch("hermes_cli.plugins.invoke_hook", return_value=[]),
):
result = agent.run_conversation("inspect /tmp/project")
assert result["final_response"] == "verified summary"
assert result["turn_exit_reason"] == "max_iterations_reached(1/1)"
agent._handle_max_iterations.assert_called_once()