From 029ac213d0325ea97550ef8fac9c1e1930841908 Mon Sep 17 00:00:00 2001 From: Ayush7614 Date: Fri, 4 Sep 2026 14:13:49 +0530 Subject: [PATCH] fix(chat): drop malformed user content instead of throwing --- app/src/components/channels/chat-messages.ts | 6 ++++++ app/tests/chat-messages.test.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/src/components/channels/chat-messages.ts b/app/src/components/channels/chat-messages.ts index 7dce9acf8..c12273bbb 100644 --- a/app/src/components/channels/chat-messages.ts +++ b/app/src/components/channels/chat-messages.ts @@ -98,6 +98,12 @@ export function toVisibleChatItems( if (message.role !== "user") return []; + if ( + typeof message.content !== "string" && + !Array.isArray(message.content) + ) { + return []; + } const text = typeof message.content === "string" ? message.content diff --git a/app/tests/chat-messages.test.ts b/app/tests/chat-messages.test.ts index b637c3ecf..028c18a7b 100644 --- a/app/tests/chat-messages.test.ts +++ b/app/tests/chat-messages.test.ts @@ -154,4 +154,16 @@ describe("toVisibleChatItems", () => { expect(toVisibleChatItems([thinking])).toEqual([]); }); + + test("drops a malformed live user turn instead of throwing", () => { + // Live turns bypass schema validation; one bad turn must not unmount the transcript. + for (const content of [undefined, null, 42] as unknown[]) { + const bad = { + id: "user-bad", + role: "user", + content, + } as unknown as Message; + expect(toVisibleChatItems([bad])).toEqual([]); + } + }); });