Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
fix: ensure consistent message order in chat runtime by improving sort logic and adding fallback for createdAt
Shine1ib83eeab60345
diff --git a/studio/frontend/src/features/chat/runtime-provider.tsx b/studio/frontend/src/features/chat/runtime-provider.tsxindex a94e25b67ac..a904a72e924 100644--- a/studio/frontend/src/features/chat/runtime-provider.tsx+++ b/studio/frontend/src/features/chat/runtime-provider.tsx@@ -287,10 +287,19 @@ function ThreadHistoryProvider({if (!remoteId) {return { messages: [] };}- const msgs = await db.messages- .where("threadId")- .equals(remoteId)- .sortBy("createdAt");+ const roleOrder: Record<string, number> = {+ system: 0,+ user: 1,+ assistant: 2,+ };+ const msgs = await db.messages.where("threadId").equals(remoteId).toArray();+ msgs.sort((a, b) => {+ if (a.createdAt !== b.createdAt) return a.createdAt - b.createdAt;+ const aOrder = roleOrder[a.role] ?? 99;+ const bOrder = roleOrder[b.role] ?? 99;+ if (aOrder !== bOrder) return aOrder - bOrder;+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;+ });return ExportedMessageRepository.fromArray(msgs.map(toThreadMessage));},@@ -301,13 +310,18 @@ function ThreadHistoryProvider({? JSON.parse(JSON.stringify(message.content)): [];const custom = message.metadata?.custom;+ const existing = await db.messages.get(message.id);+ const createdAt =+ existing?.createdAt ??+ message.createdAt?.getTime?.() ??+ Date.now();await db.messages.put({id: message.id,threadId: remoteId,role: message.role,content,...(custom && Object.keys(custom).length > 0 && { metadata: custom }),- createdAt: message.createdAt?.getTime() ?? Date.now(),+ createdAt,});},}),diff --git a/studio/frontend/src/features/chat/shared-composer.tsx b/studio/frontend/src/features/chat/shared-composer.tsxindex 185a6ac8239..f849d3f5b7a 100644--- a/studio/frontend/src/features/chat/shared-composer.tsx+++ b/studio/frontend/src/features/chat/shared-composer.tsx@@ -52,7 +52,9 @@ export function RegisterCompareHandle({}const currentHandles = handlesRef.current;currentHandles[name] = {- append: (content) => aui.thread().append({ role: "user", content }),+ // fixes occasional reorder on reload.+ append: (content) =>+ aui.thread().append({ role: "user", content, createdAt: new Date() } as never),cancel: () => aui.thread().cancelRun(),isRunning: () => aui.thread().getState().isRunning,};