From 3bcb541560747df2b15e1bf30442b8c191de2e47 Mon Sep 17 00:00:00 2001 From: Haileyesus <118998054+blackmammoth@users.noreply.github.com> Date: Sun, 28 Jun 2026 18:45:22 +0300 Subject: [PATCH] fix(chat): stop orphaned tool results rendering as raw text during pagination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sessions load in pages from the bottom up, so a loaded page often contains a tool_result whose tool_use sits in an older, not-yet-loaded page. That result wasn't recognized as attached, so it was pushed as a standalone assistant message and its raw output rendered as unstyled Markdown. It only "fixed itself" once the user scrolled up far enough to load the page with the matching tool_use. Skip results that have a toolId but no matching tool_use in the loaded set — they attach and render correctly (inside their command row/group) once the older page loads. Results with no toolId still render as before. --- src/components/chat/hooks/useChatMessages.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/components/chat/hooks/useChatMessages.ts b/src/components/chat/hooks/useChatMessages.ts index 82e7d9e1..a9dd1923 100644 --- a/src/components/chat/hooks/useChatMessages.ts +++ b/src/components/chat/hooks/useChatMessages.ts @@ -207,6 +207,15 @@ export function normalizedToChatMessages(messages: NormalizedMessage[]): ChatMes break; } + // A result with a toolId but no matching tool_use in the loaded set is + // almost always a tool_use/tool_result pair split across a pagination + // boundary (older page not loaded yet). Rendering its raw content here + // produces an unstyled dump that "fixes itself" once the older page + // loads; skip it and let it attach to its tool_use when that arrives. + if (msg.toolId) { + break; + } + const content = formatToolResultContent(msg.content || ''); if (!content.trim()) { break;