-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat: resubmit overloaded errors #9082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,43 +8,63 @@ import { ThunkApiType } from "../store"; | |||||||
| import { cancelStream } from "./cancelStream"; | ||||||||
| import { saveCurrentSession } from "./session"; | ||||||||
|
|
||||||||
| const OVERLOADED_RETRIES = 3; | ||||||||
| const OVERLOADED_DELAY_MS = 1000; | ||||||||
|
|
||||||||
| function isOverloadedErrorMessage(message?: string | null): boolean { | ||||||||
| if (!message) return false; | ||||||||
| const lower = message.toLowerCase(); | ||||||||
| return lower.includes("overloaded") || lower.includes("malformed json"); | ||||||||
| } | ||||||||
|
|
||||||||
| export const streamThunkWrapper = createAsyncThunk< | ||||||||
| void, | ||||||||
| () => Promise<void>, | ||||||||
| ThunkApiType | ||||||||
| >("chat/streamWrapper", async (runStream, { dispatch, extra, getState }) => { | ||||||||
| try { | ||||||||
| await runStream(); | ||||||||
| const state = getState(); | ||||||||
| if (!state.session.isInEdit) { | ||||||||
| await dispatch( | ||||||||
| saveCurrentSession({ | ||||||||
| openNewSession: false, | ||||||||
| generateTitle: true, | ||||||||
| }), | ||||||||
| ); | ||||||||
| } | ||||||||
| } catch (e) { | ||||||||
| await dispatch(cancelStream()); | ||||||||
| dispatch(setDialogMessage(<StreamErrorDialog error={e} />)); | ||||||||
| dispatch(setShowDialog(true)); | ||||||||
| >("chat/streamWrapper", async (runStream, { dispatch, getState }) => { | ||||||||
| for (let attempt = 0; attempt <= OVERLOADED_RETRIES; attempt++) { | ||||||||
| try { | ||||||||
| await runStream(); | ||||||||
| const state = getState(); | ||||||||
| if (!state.session.isInEdit) { | ||||||||
| await dispatch( | ||||||||
| saveCurrentSession({ | ||||||||
| openNewSession: false, | ||||||||
| generateTitle: true, | ||||||||
| }), | ||||||||
| ); | ||||||||
| } | ||||||||
| return; | ||||||||
| } catch (e) { | ||||||||
| // Get the selected model from the state for error analysis | ||||||||
| const state = getState(); | ||||||||
| const selectedModel = selectSelectedChatModel(state); | ||||||||
| const { parsedError, statusCode, message, modelTitle, providerName } = | ||||||||
| analyzeError(e, selectedModel); | ||||||||
|
|
||||||||
| // Get the selected model from the state for error analysis | ||||||||
| const state = getState(); | ||||||||
| const selectedModel = selectSelectedChatModel(state); | ||||||||
| const shouldRetry = | ||||||||
| isOverloadedErrorMessage(message) && attempt < OVERLOADED_RETRIES; | ||||||||
|
|
||||||||
| const { parsedError, statusCode, modelTitle, providerName } = analyzeError( | ||||||||
| e, | ||||||||
| selectedModel, | ||||||||
| ); | ||||||||
| if (shouldRetry) { | ||||||||
| await dispatch(cancelStream()); | ||||||||
| const delayMs = OVERLOADED_DELAY_MS * 2 ** attempt; | ||||||||
| await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||||||||
| await dispatch(cancelStream()); | ||||||||
| } else { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Missing Prompt for AI agents
Suggested change
✅ Addressed in |
||||||||
| await dispatch(cancelStream()); | ||||||||
| dispatch(setDialogMessage(<StreamErrorDialog error={e} />)); | ||||||||
| dispatch(setShowDialog(true)); | ||||||||
|
|
||||||||
| const errorData = { | ||||||||
| error_type: statusCode ? `HTTP ${statusCode}` : "Unknown", | ||||||||
| error_message: parsedError, | ||||||||
| model_provider: providerName, | ||||||||
| model_title: modelTitle, | ||||||||
| }; | ||||||||
| const errorData = { | ||||||||
| error_type: statusCode ? `HTTP ${statusCode}` : "Unknown", | ||||||||
| error_message: parsedError, | ||||||||
| model_provider: providerName, | ||||||||
| model_title: modelTitle, | ||||||||
| }; | ||||||||
|
|
||||||||
| posthog.capture("gui_stream_error", errorData); | ||||||||
| posthog.capture("gui_stream_error", errorData); | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Missing Prompt for AI agents
Suggested change
✅ Addressed in |
||||||||
| return; | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
| }); | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think checking
attempt < OVERLOADED_RETRIEShere has 2 issuesLet's change to either use recursive stop at depth OVERLOADED_RETRIES approach or just the for loop