-
Notifications
You must be signed in to change notification settings - Fork 137
Improve loading spinner response #153
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: develop
Are you sure you want to change the base?
Changes from all commits
35fe0a4
dd5f2e5
cea4249
825cfdd
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 |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { useEffect, useRef, useCallback, useState } from 'react' | |
| import { | ||
| createDeepResearchClient, | ||
| cancelJob, | ||
| getJobReport, | ||
| type DeepResearchClient, | ||
| type DeepResearchJobStatus, | ||
| type TodoItem, | ||
|
|
@@ -248,7 +249,7 @@ export const useDeepResearch = (): UseDeepResearchReturn => { | |
| } | ||
| }, | ||
|
|
||
| onJobStatus: (status, error) => { | ||
| onJobStatus: async (status, error) => { | ||
| if (buf.active) flushBuffer() | ||
| if (!isOwnerActive()) return | ||
| resetTimeout() | ||
|
|
@@ -266,10 +267,23 @@ export const useDeepResearch = (): UseDeepResearchReturn => { | |
|
|
||
| if (status === 'success') { | ||
| setCurrentStatus('complete') | ||
| const { reportContent: currentReport, deepResearchLLMSteps, deepResearchToolCalls } = state | ||
| let resolvedReport = state.reportContent | ||
| if (!resolvedReport?.trim()) { | ||
| try { | ||
| const response = await getJobReport(jobId, idToken || undefined) | ||
| if (response.has_report && response.report?.trim()) { | ||
| resolvedReport = response.report | ||
| setReportContent(response.report) | ||
| } | ||
| } catch (reportError) { | ||
| console.warn('Failed to backfill final report after deep research success:', reportError) | ||
| } | ||
| } | ||
|
|
||
| const { deepResearchLLMSteps, deepResearchToolCalls } = state | ||
| const totalTokens = deepResearchLLMSteps.reduce((sum, step) => sum + (step.usage?.input_tokens || 0) + (step.usage?.output_tokens || 0), 0) | ||
| const toolCallCount = deepResearchToolCalls.length | ||
|
Comment on lines
+283
to
285
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. State snapshot read before
const freshState = useChatStore.getState()
const { deepResearchLLMSteps, deepResearchToolCalls } = freshState |
||
| const hasReport = Boolean(currentReport?.trim()) | ||
| const hasReport = Boolean(resolvedReport?.trim()) | ||
|
|
||
| if (ownerConvId && messageId) { | ||
| patchConversationMessage(ownerConvId, messageId, { | ||
|
|
||
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.
Ownership not re-validated after
await getJobReportisOwnerActive()is called once at the top of the callback (line 254), but the code makes multiple store mutations after theawait getJobReport(...)call. If the user switches conversations during the async fetch (a few hundred ms window),ownerConvIdandmessageIdwere captured from the pre-await state snapshot and are now stale. The subsequentpatchConversationMessage,stopAllDeepResearchSpinners,completeDeepResearch, andsetStreaming(false)calls will mutate state for the old session, potentially corrupting the current view.Adding a guard after the await prevents this: