From 57e8d44af8d7e6db6eb26dec6f8c0c1d27746d4b Mon Sep 17 00:00:00 2001 From: jonny Date: Sat, 11 Apr 2026 05:23:44 +0000 Subject: [PATCH] fix(tui): preserve tool metadata in resumed session history session.resume was building conversation history with only role and content, stripping tool_call_id, tool_calls, and tool_name. The API requires tool messages to reference their parent tool_call, so resumed sessions with tool history would fail with HTTP 500. Use get_messages_as_conversation() which already preserves the full message structure including tool metadata and reasoning fields. --- tui_gateway/server.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tui_gateway/server.py b/tui_gateway/server.py index e53694d1d..3c9120113 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -483,14 +483,13 @@ def _(rid, params: dict) -> dict: os.environ["HERMES_INTERACTIVE"] = "1" try: db.reopen_session(target) + history = db.get_messages_as_conversation(target) messages = [ - {"role": m["role"], "text": m["content"] or ""} - for m in db.get_messages(target) + {"role": m["role"], "text": m.get("content") or ""} + for m in history if m.get("role") in ("user", "assistant", "tool", "system") - and isinstance(m.get("content"), str) and (m.get("content") or "").strip() ] - history = [{"role": m["role"], "content": m["text"]} for m in messages] agent = _make_agent(sid, target, session_id=target) _init_session(sid, target, agent, history, cols=int(params.get("cols", 80))) except Exception as e: