The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep the context-overflow error reply free of the partial-effect notice
kshitijk4poor241752ac9793
diff --git a/gateway/run_turn.py b/gateway/run_turn.pyindex 8219757592c..ae26dcb4403 100644--- a/gateway/run_turn.py+++ b/gateway/run_turn.py@@ -1843,10 +1843,11 @@ class GatewayTurnMixin:elif status_code in {400, 500}:# 400/500 on a large session: context overflow / payload too large.if len(prepared.history) > 50:- return self._hmwa_add_failed_turn_notice(+ # Overflow is a deterministic request rejection, not an indeterminate-effect+ # failure (#107567): keep the reply to the /compact / /reset guidance only.+ return ("⚠️ Session too large for the model's context window.\nUse /compact to "- "compress the conversation, or /reset to start fresh.",- self._PARTIAL_FAILED_TURN_NOTICE,+ "compress the conversation, or /reset to start fresh.")elif status_code == 400:status_hint = " The request was rejected by the API."diff --git a/tests/gateway/test_failure_writer_ownership.py b/tests/gateway/test_failure_writer_ownership.pyindex 1a2ea204da5..eb1cd5b10bf 100644--- a/tests/gateway/test_failure_writer_ownership.py+++ b/tests/gateway/test_failure_writer_ownership.py@@ -115,3 +115,32 @@ def test_failure_owner_follows_only_live_lineage_markers(tmp_path):db.close()asyncio.run(check())+++def test_context_overflow_error_reply_carries_no_partial_effect_notice():+ """Overflow is a deterministic rejection (#107567); the reply must stay the /compact+ guidance alone rather than inherit the indeterminate "actions may have run" warning."""+ import asyncio+ from gateway.config import Platform+ from gateway.platforms.event import MessageEvent+ from gateway.run import GatewayRunner+ from gateway.session import SessionSource++ runner = object.__new__(GatewayRunner)++ async def stop_typing(event, source):+ return None++ runner._hmwa_stop_typing_for_turn = stop_typing+ source = SessionSource(platform=Platform.TELEGRAM, chat_id="c", user_id="u")+ prepared = runner._PreparedTurn([{"role": "user", "content": "x"}] * 51, "", None, None, None, None)+ err = RuntimeError("payload too large")+ err.status_code = 400++ reply = asyncio.run(runner._hmwa_agent_error_reply(+ err, MessageEvent(text="x", source=source), source, None, "k", prepared,+ ))++ assert reply.startswith("⚠️ Session too large for the model's context window.")+ assert reply.endswith("or /reset to start fresh.")+ assert runner._PARTIAL_FAILED_TURN_NOTICE not in reply