Skip to content

The agent that grows with you

fix(tui_gateway): strip a persisted Discord triggering note from user rows on resume

teknium13569a135feb0
diff --git a/tests/tui_gateway/test_tui_gateway_server.py b/tests/tui_gateway/test_tui_gateway_server.py
index af16c4cf30a..70f2e32facb 100644
--- a/tests/tui_gateway/test_tui_gateway_server.py
+++ b/tests/tui_gateway/test_tui_gateway_server.py
@@ -2947,6 +2947,24 @@ def test_history_to_messages_renders_multimodal_content():
]
+def test_history_to_messages_strips_legacy_discord_triggering_note():
+ # Rows written before the gateway persisted the authored text carry the model-facing
+ # routing note in user ``content``; this projection heals them for TUI/web resume
+ # (the desktop hydration strip is the same rule). Reply pointer and assistant rows are kept.
+ from gateway.run_inbound import discord_triggering_note
+
+ note = discord_triggering_note("123")
+ history = [
+ {"role": "user", "content": f"{note}\n\n[Replying to: hi]\nwhat is up"},
+ {"role": "assistant", "content": f"echo: {note}"},
+ ]
+
+ assert server._history_to_messages(history) == [
+ {"role": "user", "text": "[Replying to: hi]\nwhat is up"},
+ {"role": "assistant", "text": f"echo: {note}"},
+ ]
+
+
def test_history_to_messages_hides_gateway_system_markers():
# Model-switch / personality notices are persisted as role=user [System: …]
# rows so strict providers accept them mid-history, but they are model-facing
diff --git a/tui_gateway/session_history.py b/tui_gateway/session_history.py
index f58f6ce36aa..9c71e76a1d3 100644
--- a/tui_gateway/session_history.py
+++ b/tui_gateway/session_history.py
@@ -3,9 +3,17 @@ turn tracking and turn-failure detail. Bodies are rebound onto server.py's globa
from __future__ import annotations
+import re
+
from .method_ctx import bind_module
from agent.prompt_builder import STEER_DISPLAY_KIND
+# Discord routing note (gateway/run_inbound.py::discord_triggering_note) persisted as user
+# ``content`` by gateways before the authored-text fix; presentation-only heal for those rows.
+_DISCORD_TRIGGERING_NOTE_RE = re.compile(
+ r"(^|\n)\[Triggering message id: `[^`\n]*` — use as `message_id` for reply/react/pin via the discord tools\.\]\n*"
+)
+
def _active_image_routing_identity(agent: Any) -> tuple[str, str]:
"""Return the live provider/model, falling back before agent startup."""
@@ -194,6 +202,8 @@ def _history_to_messages(history: list[dict]) -> list[dict]:
content_text = _coerce_message_text(m.get("content"))
if _is_display_hidden_marker(role, content_text):
continue
+ if role == "user":
+ content_text = _DISCORD_TRIGGERING_NOTE_RE.sub(r"\1", content_text)
if role == "assistant" and m.get("tool_calls"):
for tc in m["tool_calls"]:
fn, tc_id = tc.get("function", {}), tc.get("id", "")