Fix llm errors not propagating to the ui and auto summarize not starting (#3490)

This commit is contained in:
Zane
2025-07-17 15:33:44 -07:00
committed by GitHub
parent 759cc6830e
commit ca13eca7bd
3 changed files with 118 additions and 26 deletions
+47 -3
View File
@@ -323,8 +323,45 @@ export function useMessageStream({
break;
}
case 'Error':
throw new Error(parsedEvent.error);
case 'Error': {
// Check if this is a token limit error (more specific detection)
const errorMessage = parsedEvent.error;
const isTokenLimitError =
errorMessage &&
((errorMessage.toLowerCase().includes('token') &&
errorMessage.toLowerCase().includes('limit')) ||
(errorMessage.toLowerCase().includes('context') &&
errorMessage.toLowerCase().includes('length') &&
errorMessage.toLowerCase().includes('exceeded')));
// If this is a token limit error, create a contextLengthExceeded message instead of throwing
if (isTokenLimitError) {
const contextMessage: Message = {
id: `context-${Date.now()}`,
role: 'assistant',
created: Math.floor(Date.now() / 1000),
content: [
{
type: 'contextLengthExceeded',
msg: errorMessage,
},
],
display: true,
sendToLLM: false,
};
currentMessages = [...currentMessages, contextMessage];
mutate(currentMessages, false);
// Clear any existing error state since we handled this as a context message
setError(undefined);
break; // Don't throw error, just add the message
}
// For non-token-limit errors, still throw the error
const error = new Error(parsedEvent.error);
throw error;
}
case 'Finish': {
// Call onFinish with the last message if available
@@ -371,6 +408,11 @@ export function useMessageStream({
if (onError && e instanceof Error) {
onError(e);
}
// Don't re-throw here, let the error be handled by the outer catch
// Instead, set the error state directly
if (e instanceof Error) {
setError(e);
}
}
}
}
@@ -381,6 +423,8 @@ export function useMessageStream({
if (onError) {
onError(e);
}
// Re-throw the error so it gets caught by sendRequest and sets the error state
throw e;
}
} finally {
reader.releaseLock();
@@ -388,7 +432,7 @@ export function useMessageStream({
return currentMessages;
},
[mutate, onFinish, onError, forceUpdate]
[mutate, onFinish, onError, forceUpdate, setError]
);
// Send a request to the server