From 56f085bae40b53aa52cea6e25395d0f7dba3ad32 Mon Sep 17 00:00:00 2001 From: Molecule AI Frontend Engineer Date: Fri, 17 Apr 2026 20:34:48 +0000 Subject: [PATCH] fix(canvas): expose loadMessagesFromDB failures with error banner + Retry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously loadMessagesFromDB swallowed all errors and returned [] — a network failure was indistinguishable from an empty history, so the user had no way to know loading failed. Now the function returns { messages, error } and the MyChatPanel renders a role="alert" banner with the error message and a Retry button when messages are empty and a load error occurred. Co-Authored-By: Claude Sonnet 4.6 --- canvas/src/components/tabs/ChatTab.tsx | 42 ++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/canvas/src/components/tabs/ChatTab.tsx b/canvas/src/components/tabs/ChatTab.tsx index f1b8bbb0..f3063baa 100644 --- a/canvas/src/components/tabs/ChatTab.tsx +++ b/canvas/src/components/tabs/ChatTab.tsx @@ -55,7 +55,7 @@ function extractReplyText(resp: A2AResponse): string { * Load chat history from the activity_logs database via the platform API. * Uses source=canvas to only get user-initiated messages (not agent-to-agent). */ -async function loadMessagesFromDB(workspaceId: string): Promise { +async function loadMessagesFromDB(workspaceId: string): Promise<{ messages: ChatMessage[]; error: string | null }> { try { const activities = await api.get { } } } - return messages; - } catch { - return []; + return { messages, error: null }; + } catch (err) { + return { + messages: [], + error: err instanceof Error ? err.message : "Failed to load chat history", + }; } } @@ -162,6 +165,7 @@ function MyChatPanel({ workspaceId, data }: Props) { const [thinkingElapsed, setThinkingElapsed] = useState(0); const [activityLog, setActivityLog] = useState([]); const [loading, setLoading] = useState(true); + const [loadError, setLoadError] = useState(null); const currentTaskRef = useRef(data.currentTask); const sendingFromAPIRef = useRef(false); const [agentReachable, setAgentReachable] = useState(false); @@ -172,8 +176,10 @@ function MyChatPanel({ workspaceId, data }: Props) { // Load chat history from database on mount useEffect(() => { setLoading(true); - loadMessagesFromDB(workspaceId).then((msgs) => { + setLoadError(null); + loadMessagesFromDB(workspaceId).then(({ messages: msgs, error: fetchErr }) => { setMessages(msgs); + setLoadError(fetchErr); setLoading(false); }); }, [workspaceId]); @@ -355,7 +361,31 @@ function MyChatPanel({ workspaceId, data }: Props) { {loading && (
Loading chat history...
)} - {!loading && messages.length === 0 && ( + {!loading && loadError !== null && messages.length === 0 && ( +
+

+ Failed to load chat history: {loadError} +

+ +
+ )} + {!loading && loadError === null && messages.length === 0 && (
No messages yet. Send a message to start chatting with this agent.