fix: prevent 'active request' error from showing blocking error screen (#8398)
Signed-off-by: Michael Neale <michael.neale@gmail.com> Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -130,6 +130,7 @@ impl SessionEventBus {
|
||||
request_id: String,
|
||||
) -> Result<CancellationToken, String> {
|
||||
let mut requests = self.active_requests.lock().await;
|
||||
requests.retain(|_id, token| !token.is_cancelled());
|
||||
if !requests.is_empty() {
|
||||
return Err("Session already has an active request".into());
|
||||
}
|
||||
|
||||
@@ -643,7 +643,12 @@ export function useChatStream({
|
||||
activeRequestSessionIdRef.current = null;
|
||||
activeAbortRef.current = null;
|
||||
}
|
||||
onFinish('Submit error: ' + errorMessage(error));
|
||||
const msg = errorMessage(error);
|
||||
if (msg.includes('already has an active request')) {
|
||||
dispatch({ type: 'SET_CHAT_STATE', payload: ChatState.Idle });
|
||||
} else {
|
||||
onFinish('Submit error: ' + msg);
|
||||
}
|
||||
}
|
||||
},
|
||||
[addListener, onFinish, reloadConversation]
|
||||
@@ -783,7 +788,13 @@ export function useChatStream({
|
||||
const { msg: userMessage, images } = input;
|
||||
const currentState = stateRef.current;
|
||||
|
||||
if (!currentState.session || currentState.chatState === ChatState.LoadingConversation) {
|
||||
if (
|
||||
!currentState.session ||
|
||||
currentState.chatState === ChatState.LoadingConversation ||
|
||||
currentState.chatState === ChatState.Streaming ||
|
||||
currentState.chatState === ChatState.Thinking ||
|
||||
currentState.chatState === ChatState.Compacting
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user