The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): read the failed-turn notice module constants directly; drop the class aliases
teknium18eeed0a11a84
diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 819376a603e..b9dd88fe169 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -1607,10 +1607,8 @@ class GatewayTurnMixin:except Exception as e:logger.debug("Watch queue drain error: %s", e)- # One owner for the boundary copy: the core closer (agent/conversation_loop.py) writes the- # same row on the paths that never reach this layer; alias rather than keep a second copy.- _FAILED_TURN_NOTICE = FAILED_TURN_NOTICE- _PARTIAL_FAILED_TURN_NOTICE = PARTIAL_FAILED_TURN_NOTICE+ # One owner for the boundary copy (agent/turn_failure_copy.py): the core closer in+ # agent/conversation_loop.py writes the same row on the paths that never reach this layer.def _hmwa_add_failed_turn_notice(self, response, notice):"""Make failed-turn delivery explicit without replacing the provider-specific guidance."""@@ -1630,8 +1628,8 @@ class GatewayTurnMixin:or (message.get("role") == "assistant" and message.get("tool_calls"))for message in turn_messages):- return self._PARTIAL_FAILED_TURN_NOTICE- return self._FAILED_TURN_NOTICE+ return PARTIAL_FAILED_TURN_NOTICE+ return FAILED_TURN_NOTICEasync def _hmwa_close_failed_turn(self, session_id, notice):"""Append the gateway-owned assistant boundary iff the durable tail is an open user row.@@ -1916,7 +1914,7 @@ class GatewayTurnMixin:session_entry.session_id, self._hmwa_user_transcript_entry(event, prepared, time.time()),)# Tool effects are unknown after an exception.- await self._hmwa_close_failed_turn(session_entry.session_id, self._PARTIAL_FAILED_TURN_NOTICE)+ await self._hmwa_close_failed_turn(session_entry.session_id, PARTIAL_FAILED_TURN_NOTICE)except Exception:logger.debug("Failed to persist inbound user message after agent exception", exc_info=True)# Never expose raw exception types/messages to end users (info-leakage risk).@@ -1947,7 +1945,7 @@ class GatewayTurnMixin:f"⚠️ Something went wrong and I couldn't finish this reply.{status_hint}\n""Use /retry to try again, or /new to start a fresh conversation. ""Technical details are in the gateway log (`hermes logs`).",- self._PARTIAL_FAILED_TURN_NOTICE,+ PARTIAL_FAILED_TURN_NOTICE,)def _hmwa_discard_stale_result(self, source, _quick_key, run_generation):diff --git a/tests/gateway/test_duplicate_user_message.py b/tests/gateway/test_duplicate_user_message.pyindex 3d7d00a2e4f..c106af2c81e 100644--- a/tests/gateway/test_duplicate_user_message.py+++ b/tests/gateway/test_duplicate_user_message.py@@ -21,6 +21,7 @@ from unittest.mock import AsyncMock, MagicMockimport pytest+from agent.turn_failure_copy import FAILED_TURN_NOTICE, PARTIAL_FAILED_TURN_NOTICEimport gateway.run as gateway_runfrom gateway.config import GatewayConfig, Platformfrom gateway.platforms.event import MessageEvent@@ -154,7 +155,7 @@ async def test_agent_failed_early_skip_db_when_agent_has_session_db(_assert_user_call_has_skip_db(runner.session_store.append_to_transcript.call_args_list, True)- assert runner._FAILED_TURN_NOTICE in response+ assert FAILED_TURN_NOTICE in responsetranscript_rows = [call.args[1]@@ -162,7 +163,7 @@ async def test_agent_failed_early_skip_db_when_agent_has_session_db(if len(call.args) >= 2 and call.args[1].get("role") in {"user", "assistant"}]assert [row["role"] for row in transcript_rows] == ["user", "assistant"]- assert transcript_rows[-1]["content"] == runner._FAILED_TURN_NOTICE+ assert transcript_rows[-1]["content"] == FAILED_TURN_NOTICE# The next unrelated input remains its own turn instead of alternation repair# merging the failed mutating request into it.@@ -207,7 +208,7 @@ async def test_boundary_keyed_on_durable_tail_when_user_row_is_deduped(if len(call.args) >= 2 and call.args[1].get("role") in {"user", "assistant"}]assert [row["role"] for row in rows] == expected_roles- assert all(row["content"] == runner._FAILED_TURN_NOTICE for row in rows)+ assert all(row["content"] == FAILED_TURN_NOTICE for row in rows)@pytest.mark.asyncio@@ -249,8 +250,8 @@ async def test_failed_turn_with_tool_activity_does_not_recommend_blind_retry(if len(call.args) >= 2 and call.args[1].get("role") == "assistant"]assert len(assistant_rows) == 1- assert assistant_rows[0]["content"] == runner._PARTIAL_FAILED_TURN_NOTICE- assert runner._PARTIAL_FAILED_TURN_NOTICE in response+ assert assistant_rows[0]["content"] == PARTIAL_FAILED_TURN_NOTICE+ assert PARTIAL_FAILED_TURN_NOTICE in responseassert "not processed" not in responseassert "Send it again" not in responsediff --git a/tests/gateway/test_failure_writer_ownership.py b/tests/gateway/test_failure_writer_ownership.pyindex 24a235654ae..86839736a4b 100644--- a/tests/gateway/test_failure_writer_ownership.py+++ b/tests/gateway/test_failure_writer_ownership.py@@ -5,6 +5,8 @@ import subprocessimport sysfrom pathlib import Path+from agent.turn_failure_copy import PARTIAL_FAILED_TURN_NOTICE+def test_gateway_failure_writer_preserves_accepted_turn_identity(tmp_path):root = Path(__file__).resolve().parents[2]@@ -103,12 +105,12 @@ def test_failure_owner_follows_only_live_lineage_markers(tmp_path):# leaves an open user tail on the live route — never anything else.assert db.message_count() == before + (not owned) + ((not owned) or open_tail), locationassert store.has_input_owner(sid, owner), location- assert runner._PARTIAL_FAILED_TURN_NOTICE in reply+ assert PARTIAL_FAILED_TURN_NOTICE in replylive_messages = db.get_messages(child)assert not live_messages or live_messages[-1]["role"] != "user", locationassert sum(m["role"] == "assistant" for m in live_messages) <= 1, locationif not owned:- assert live_messages[-1]["content"] == runner._PARTIAL_FAILED_TURN_NOTICE+ assert live_messages[-1]["content"] == PARTIAL_FAILED_TURN_NOTICEpersisted_user = live_messages[-2]assert persisted_user["content"] == prepared.persist_user_messageassert persisted_user["display_metadata"]["gateway_input_owner"] == owner@@ -187,7 +189,7 @@ def test_context_overflow_error_reply_carries_no_partial_effect_notice():from gateway.run import _CONTEXT_OVERFLOW_REPLYassert reply == _CONTEXT_OVERFLOW_REPLY- assert runner._PARTIAL_FAILED_TURN_NOTICE not in reply+ assert PARTIAL_FAILED_TURN_NOTICE not in replydef test_fresh_session_agent_flushed_failed_turn_is_closed(tmp_path):diff --git a/tests/gateway/test_incomplete_gateway_turns.py b/tests/gateway/test_incomplete_gateway_turns.pyindex 311de514217..37c2fb8d5c2 100644--- a/tests/gateway/test_incomplete_gateway_turns.py+++ b/tests/gateway/test_incomplete_gateway_turns.py@@ -7,6 +7,7 @@ from unittest.mock import AsyncMock, MagicMockimport pytest+from agent.turn_failure_copy import FAILED_TURN_NOTICEimport gateway.run as gateway_runfrom gateway.config import GatewayConfig, Platform, PlatformConfigfrom gateway.platforms.base import BasePlatformAdapter, SendResult@@ -152,7 +153,7 @@ async def test_incomplete_codex_turn_closes_transcript_without_slack_delivery(moassert transcript_roles == ["session_meta", "user", "assistant"]assert runner.session_store.append_to_transcript.call_args_list[1].args[1]["content"] == "hello"boundary = runner.session_store.append_to_transcript.call_args_list[2].args[1]["content"]- assert boundary == runner._FAILED_TURN_NOTICE+ assert boundary == FAILED_TURN_NOTICEassert adapter.processing_hooks == [("start", "m-1"),("complete", "m-1", ProcessingOutcome.SUCCESS),