The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: pin the stopped mark on the interrupt close and the authority turn's reply stamps
Tekniumf29772123f0b
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.pyindex 0d64fefded2..7018127af62 100644--- a/agent/message_sanitization.py+++ b/agent/message_sanitization.py@@ -299,9 +299,10 @@ def close_interrupted_tool_sequence(messages: list, final_response: Any = None,(truncation notices, partial-delivery text) stays visible: it is the turn's onlyuser-facing explanation.- ``stopped`` (a user stop, not a truncation or overflow exit) puts the stopped mark on the- closing row, as ``turn_api_call.py`` does on a partial reply: it is the turn's last stored- row, so a reopened transcript still says the turn was stopped."""+ ``stopped`` (an interrupted turn: a user stop or any other interrupt, not a truncation or+ overflow exit) puts the stopped mark on the closing row, as ``turn_api_call.py`` does on every+ interrupted partial reply: it is the turn's last stored row, so a reopened transcript still says+ the turn was stopped."""last = messages[-1] if messages else Noneif not isinstance(last, dict) or last.get("role") != "tool":return Falsediff --git a/tests/agent/test_close_interrupted_tool_sequence.py b/tests/agent/test_close_interrupted_tool_sequence.pyindex ecf5aa59907..63d23c517ae 100644--- a/tests/agent/test_close_interrupted_tool_sequence.py+++ b/tests/agent/test_close_interrupted_tool_sequence.py@@ -71,3 +71,13 @@ def test_user_tail_is_left_untouched():assert close_interrupted_tool_sequence(messages, None) is Falseassert len(messages) == 1+++def test_only_an_interrupted_close_carries_the_stopped_mark():+ """The closing row is the turn's last stored row: it alone tells a reopened transcript the turn was stopped."""+ stopped = _tool_tail()+ assert close_interrupted_tool_sequence(stopped, None, stopped=True) is True+ assert stopped[-1]["display_metadata"] == {"interrupted": True}+ truncated = _tool_tail()+ assert close_interrupted_tool_sequence(truncated, "Response truncated.") is True+ assert "display_metadata" not in truncated[-1]diff --git a/tests/gateway/test_turn_runner_reply_identity.py b/tests/gateway/test_turn_runner_reply_identity.pynew file mode 100644index 00000000000..d46ab102370--- /dev/null+++ b/tests/gateway/test_turn_runner_reply_identity.py@@ -0,0 +1,37 @@+"""The session-authority turn stamps its reply frames with the same wire identity as tui_gateway's ``_emit``.++A viewer upserts a re-sent delta or seal by ``turn_id``/``segment``/``offset`` instead of painting a second copy.+"""+from gateway.run_turn_runner import TurnRunner+++class _Authority:+ def __init__(self):+ self.frames = []++ def publish_execution(self, session_id, generation, event_type, payload):+ self.frames.append((generation, event_type, payload))+ return True+++def test_reply_frames_carry_one_cursor_per_execution_generation():+ authority = _Authority()+ runner = TurnRunner.__new__(TurnRunner)+ runner._approval_owner = (authority, 's', 1)+ for event_type, payload in (('message.delta', {'text': 'a\U0001F440'}), ('message.delta', {'text': 'b'}),+ ('message.interim', {'text': 'a\U0001F440b'}), ('message.delta', {'text': 'c'}),+ ('tool.start', {'name': 'terminal'})):+ runner._publish_execution(event_type, payload)+ runner._approval_owner = (authority, 's', 2)+ runner._publish_execution('message.delta', {'text': 'next'})++ stamps = [{k: p.get(k) for k in ('turn_id', 'segment', 'offset') if k in p} for _, _, p in authority.frames]+ first, second = stamps[0]['turn_id'], stamps[-1]['turn_id']+ assert stamps[:5] == [+ {'turn_id': first, 'segment': 0, 'offset': 0},+ {'turn_id': first, 'segment': 0, 'offset': 3}, # the emoji is two UTF-16 code units+ {'turn_id': first, 'segment': 0},+ {'turn_id': first, 'segment': 1, 'offset': 0},+ {}, # not a reply frame: unchanged+ ]+ assert stamps[5] == {'turn_id': second, 'segment': 0, 'offset': 0} and second != first