From 755e0c0ff71ae3fc3cbd30b8ffe2ac283ac22b2f Mon Sep 17 00:00:00 2001 From: Pascal Date: Sat, 4 Oct 2025 05:35:17 +0200 Subject: [PATCH 1/8] fix: make SSE client robust to premature [DONE] in agentic proxy chains --- tools/server/webui/src/lib/services/chat.ts | 33 +++++++++------------ 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/tools/server/webui/src/lib/services/chat.ts b/tools/server/webui/src/lib/services/chat.ts index 8d9dcf75801c6..f2875a9057c45 100644 --- a/tools/server/webui/src/lib/services/chat.ts +++ b/tools/server/webui/src/lib/services/chat.ts @@ -262,6 +262,7 @@ export class ChatService { let fullReasoningContent = ''; let hasReceivedData = false; let lastTimings: ChatMessageTimings | undefined; + let streamFinished = false; try { let chunk = ''; @@ -277,18 +278,8 @@ export class ChatService { if (line.startsWith('data: ')) { const data = line.slice(6); if (data === '[DONE]') { - if (!hasReceivedData && aggregatedContent.length === 0) { - const contextError = new Error( - 'The request exceeds the available context size. Try increasing the context size or enable context shift.' - ); - contextError.name = 'ContextError'; - onError?.(contextError); - return; - } - - onComplete?.(aggregatedContent, fullReasoningContent || undefined, lastTimings); - - return; + streamFinished = true; + continue; } try { @@ -326,13 +317,17 @@ export class ChatService { } } - if (!hasReceivedData && aggregatedContent.length === 0) { - const contextError = new Error( - 'The request exceeds the available context size. Try increasing the context size or enable context shift.' - ); - contextError.name = 'ContextError'; - onError?.(contextError); - return; + if (streamFinished) { + if (!hasReceivedData && aggregatedContent.length === 0) { + const contextError = new Error( + 'The request exceeds the available context size. Try increasing the context size or enable context shift.' + ); + contextError.name = 'ContextError'; + onError?.(contextError); + return; + } + + onComplete?.(aggregatedContent, fullReasoningContent || undefined, lastTimings); } } catch (error) { const err = error instanceof Error ? error : new Error('Stream error'); From 8b07327c0c270ce725e49646f1dcd89f1d1fc260 Mon Sep 17 00:00:00 2001 From: Pascal Date: Sat, 11 Oct 2025 00:15:46 +0200 Subject: [PATCH 2/8] webui: remove client-side context pre-check and rely on backend for limits Removed the client-side context window pre-check and now simply sends messages while keeping the dialog imports limited to core components, eliminating the maximum context alert path Simplified streaming and non-streaming chat error handling to surface a generic 'No response received from server' error whenever the backend returns no content Removed the obsolete maxContextError plumbing from the chat store so state management now focuses on the core message flow without special context-limit cases --- .../app/chat/ChatScreen/ChatScreen.svelte | 36 ++--- .../app/dialogs/ChatErrorDialog.svelte | 60 ++++++++ .../dialogs/MaximumContextAlertDialog.svelte | 66 --------- .../webui/src/lib/components/app/index.ts | 3 +- tools/server/webui/src/lib/services/chat.ts | 68 +++------ .../server/webui/src/lib/services/context.ts | 102 ------------- tools/server/webui/src/lib/services/index.ts | 1 - .../webui/src/lib/stores/chat.svelte.ts | 138 ++++-------------- tools/server/webui/src/routes/+layout.svelte | 8 +- 9 files changed, 130 insertions(+), 352 deletions(-) create mode 100644 tools/server/webui/src/lib/components/app/dialogs/ChatErrorDialog.svelte delete mode 100644 tools/server/webui/src/lib/components/app/dialogs/MaximumContextAlertDialog.svelte delete mode 100644 tools/server/webui/src/lib/services/context.ts diff --git a/tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte b/tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte index 666febf0d28d6..abda2aaa354c9 100644 --- a/tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte +++ b/tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte @@ -7,6 +7,7 @@ ChatMessages, ChatProcessingInfo, EmptyFileAlertDialog, + ChatErrorDialog, ServerErrorSplash, ServerInfo, ServerLoadingSplash, @@ -22,10 +23,11 @@ activeMessages, activeConversation, deleteConversation, + dismissErrorDialog, + errorDialog, isLoading, sendMessage, - stopGeneration, - setMaxContextError + stopGeneration } from '$lib/stores/chat.svelte'; import { supportsVision, @@ -34,7 +36,6 @@ serverWarning, serverStore } from '$lib/stores/server.svelte'; - import { contextService } from '$lib/services'; import { parseFilesToMessageExtras } from '$lib/utils/convert-files-to-extra'; import { isFileTypeSupported } from '$lib/utils/file-type'; import { filterFilesByModalities } from '$lib/utils/modality-file-validation'; @@ -80,6 +81,7 @@ ); let isServerLoading = $derived(serverLoading()); + let activeErrorDialog = $derived(errorDialog()); async function handleDeleteConfirm() { const conversation = activeConversation(); @@ -105,6 +107,12 @@ } } + function handleErrorDialogOpenChange(open: boolean) { + if (!open) { + dismissErrorDialog(); + } + } + function handleDragOver(event: DragEvent) { event.preventDefault(); } @@ -183,21 +191,6 @@ const extras = result?.extras; - // Check context limit using real-time slots data - const contextCheck = await contextService.checkContextLimit(); - - if (contextCheck && contextCheck.wouldExceed) { - const errorMessage = contextService.getContextErrorMessage(contextCheck); - - setMaxContextError({ - message: errorMessage, - estimatedTokens: contextCheck.currentUsage, - maxContext: contextCheck.maxContext - }); - - return false; - } - // Enable autoscroll for user-initiated message sending userScrolledUp = false; autoScrollEnabled = true; @@ -461,6 +454,13 @@ }} /> + +