From fabd5ad5e140d56f9e269c6155b9b01e53c15e44 Mon Sep 17 00:00:00 2001 From: Val Alexander Date: Fri, 13 Mar 2026 19:19:06 -0500 Subject: [PATCH] UI: reload history after terminal tool runs --- ui/src/ui/app-gateway.node.test.ts | 36 ++++++++++++++++++++++++++++++ ui/src/ui/app-gateway.ts | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ui/src/ui/app-gateway.node.test.ts b/ui/src/ui/app-gateway.node.test.ts index bcef1be3ed3..15ebb0a2fe4 100644 --- a/ui/src/ui/app-gateway.node.test.ts +++ b/ui/src/ui/app-gateway.node.test.ts @@ -380,6 +380,42 @@ describe("connectGateway", () => { expect(loadChatHistoryMock).toHaveBeenCalledTimes(1); }); + + it("reloads chat history after an error chat event when tool output was used", () => { + const host = createHost(); + + connectGateway(host); + const client = gatewayClientInstances[0]; + expect(client).toBeDefined(); + + client.emitEvent({ + event: "agent", + payload: { + runId: "engine-run-1", + seq: 1, + stream: "tool", + ts: 1, + sessionKey: "main", + data: { + toolCallId: "tool-1", + name: "fetch", + phase: "result", + result: { text: "ok" }, + }, + }, + }); + + client.emitEvent({ + event: "chat", + payload: { + runId: "engine-run-1", + sessionKey: "main", + state: "error", + }, + }); + + expect(loadChatHistoryMock).toHaveBeenCalledTimes(1); + }); }); describe("resolveControlUiClientVersion", () => { diff --git a/ui/src/ui/app-gateway.ts b/ui/src/ui/app-gateway.ts index 0cf39df0bc4..1896a3bed31 100644 --- a/ui/src/ui/app-gateway.ts +++ b/ui/src/ui/app-gateway.ts @@ -301,7 +301,7 @@ function handleTerminalChatEvent( } // Reload history when tools were used so the persisted tool results // replace the now-cleared streaming state. - if (hadToolEvents && state === "final") { + if (hadToolEvents) { void loadChatHistory(host as unknown as OpenClawApp); return true; }