The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui_gateway): a Bot Chat reply keeps its saved-row receipt when a closing marker is dropped
Teknium7ba6a66c3b84
diff --git a/tests/tui_gateway/test_bot_mode_silence_delivery.py b/tests/tui_gateway/test_bot_mode_silence_delivery.pyindex 97e45b962a4..a6ae636609b 100644--- a/tests/tui_gateway/test_bot_mode_silence_delivery.py+++ b/tests/tui_gateway/test_bot_mode_silence_delivery.py@@ -44,6 +44,28 @@ def test_live_bot_chat_completion_empties_marker_only_for_successful_turns(monkeassert payload["text"] == "NO_REPLY"+def test_bot_chat_receipt_still_names_the_saved_row_when_a_trailing_marker_is_dropped(monkeypatch):+ """The delivered copy drops the marker; the stored row keeps it, and the receipt must+ still bind this turn to that row."""+ from agent.context_compressor import _DB_PERSISTED_MARKER+ monkeypatch.setattr(srv, "_get_usage", lambda _agent: {})+ monkeypatch.setattr(srv, "render_message", lambda _text, _cols: None)+ monkeypatch.setattr(srv, "_clear_inflight_turn", lambda _session: None)+ session = {"pending_title": None, "session_key": "k", "history_lock": contextlib.nullcontext(),+ "agent": SimpleNamespace(_session_title_hint="Bot Chat")}+ raw = "Paris.\n\nNO_REPLY"+ rows = [{"role": "user", "content": "q", "_row_id": 7, _DB_PERSISTED_MARKER: True},+ {"role": "assistant", "content": raw, "_row_id": 8, _DB_PERSISTED_MARKER: True}]+ st = _turn({"final_response": raw, "messages": rows})+ st.agent._persist_user_message_idx = 0+ st.history, st.compression_count = [], None++ payload, _, _ = srv._complete_turn_payload(session, st, None, 80)++ assert payload["text"] == "Paris."+ assert payload["persisted_turn"]["final_assistant_row_id"] == 8++def test_live_bot_chat_stream_holds_back_partial_silence_marker(monkeypatch):"""Mirror of stream_consumer's hold-back: a marker never reaches message.delta, prose thatdiverges from every marker is flushed intact once it diverges."""diff --git a/tui_gateway/prompt_turn.py b/tui_gateway/prompt_turn.pyindex 094c1169ff2..c6f7a576c2f 100644--- a/tui_gateway/prompt_turn.py+++ b/tui_gateway/prompt_turn.py@@ -916,10 +916,13 @@ def _complete_turn_payload(session: dict, st: _TurnRun, status_note: str | None,except Exception:_error_surface = Noneraw, status, last_reasoning = _turn_outcome(result, _error_surface)+ # The receipt verifies the stored row's body, which keeps the model's text as written;+ # only the delivered copy drops a silence marker.+ receipt = _persisted_turn_receipt(st, raw, status)if _is_bot_mode_session(session):raw = _bot_mode_delivery_text(raw, successful=status == "complete")payload = {"text": raw, "usage": _get_usage(agent), "status": status}- if receipt := _persisted_turn_receipt(st, raw, status):+ if receipt:payload["persisted_turn"] = receiptif last_reasoning:payload["reasoning"] = last_reasoning