Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(web): stop aborting new RAG document uploads after 30s (#44965)

Stephen Zhoubf38ee592288
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index 60f501ea190..fa6a0757a38 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -6814,11 +6814,6 @@
"count": 10
}
},
- "web/features/new-rag/quality/golden-question-dialog.tsx": {
- "better-tailwindcss/enforce-logical-properties": {
- "count": 1
- }
- },
"web/features/new-rag/quality/golden-questions-panel.tsx": {
"better-tailwindcss/enforce-logical-properties": {
"count": 16
diff --git a/web/features/new-rag/documents/__tests__/page.spec.tsx b/web/features/new-rag/documents/__tests__/page.spec.tsx
index fcd35ff131a..d4b0040e701 100644
--- a/web/features/new-rag/documents/__tests__/page.spec.tsx
+++ b/web/features/new-rag/documents/__tests__/page.spec.tsx
@@ -2868,7 +2868,7 @@ describe('DocumentsPage', () => {
expect(screen.queryByLabelText('knowledgeCreate.uploadDocuments')).not.toBeInTheDocument()
})
- it('times out an exact 15 MiB staging request and discards a late success', async () => {
+ it('keeps a slow exact 15 MiB staging request alive until it settles', async () => {
vi.useFakeTimers()
let resolveStaging!: (value: { id: string }) => void
let stagingSignal: AbortSignal | undefined
@@ -2891,30 +2891,24 @@ describe('DocumentsPage', () => {
})
expect(stageUploadMutation).toHaveBeenCalledOnce()
- expect(stagingSignal?.aborted).toBe(false)
await act(async () => {
- vi.advanceTimersByTime(30_000)
+ vi.advanceTimersByTime(5 * 60_000)
await Promise.resolve()
await Promise.resolve()
})
- expect(stagingSignal?.aborted).toBe(true)
- expect(toastMock.error).toHaveBeenCalledOnce()
- expect(toastMock.error).toHaveBeenCalledWith('knowledgeSpace.documentUploadFailed')
- expect(screen.getByRole('button', { name: 'knowledgeCreate.addAndProcess' })).toBeEnabled()
- expect(screen.getByRole('listitem')).not.toHaveAttribute('aria-busy')
+ expect(stagingSignal?.aborted).toBe(false)
+ expect(toastMock.error).not.toHaveBeenCalled()
await act(async () => {
- resolveStaging({ id: 'late-boundary-upload' })
+ resolveStaging({ id: 'slow-boundary-upload' })
await Promise.resolve()
await Promise.resolve()
})
- expect(discardStagedUploadMutation).toHaveBeenCalledOnce()
- expect(discardStagedUploadMutation).toHaveBeenCalledWith('late-boundary-upload')
- expect(toastMock.error).toHaveBeenCalledOnce()
- expect(uploadMutation.mutateAsync).not.toHaveBeenCalled()
+ expect(discardStagedUploadMutation).not.toHaveBeenCalled()
+ expect(toastMock.error).not.toHaveBeenCalled()
} finally {
rendered.unmount()
vi.useRealTimers()
diff --git a/web/features/new-rag/documents/upload/model.ts b/web/features/new-rag/documents/upload/model.ts
index 6a42c06a560..b871ed6a555 100644
--- a/web/features/new-rag/documents/upload/model.ts
+++ b/web/features/new-rag/documents/upload/model.ts
@@ -1,7 +1,5 @@
import type { DocumentUploadIssue } from '../../upload/policy'
-export const DOCUMENT_STAGING_REQUEST_TIMEOUT = 30_000
-
export class DocumentStagingCanceledError extends Error {
constructor() {
super('Document staging was canceled')
@@ -9,13 +7,6 @@ export class DocumentStagingCanceledError extends Error {
}
}
-export class DocumentStagingTimeoutError extends Error {
- constructor() {
- super('Document staging timed out')
- this.name = 'DocumentStagingTimeoutError'
- }
-}
-
type UploadApiExclusionReason =
| 'batchLimit'
| 'countLimit'
diff --git a/web/features/new-rag/documents/upload/use-document-upload-session.ts b/web/features/new-rag/documents/upload/use-document-upload-session.ts
index 7ce10bcdec3..a4bc5585aa2 100644
--- a/web/features/new-rag/documents/upload/use-document-upload-session.ts
+++ b/web/features/new-rag/documents/upload/use-document-upload-session.ts
@@ -15,11 +15,7 @@ import {
import { documentUploadFingerprint } from '../../upload/policy'
import { documentsKnowledgeSpaceIdAtom } from '../state/inputs'
import { documentUploadingAtom } from '../state/upload'
-import {
- DOCUMENT_STAGING_REQUEST_TIMEOUT,
- DocumentStagingCanceledError,
- DocumentStagingTimeoutError,
-} from './model'
+import { DocumentStagingCanceledError } from './model'
export function useDocumentUploadSession() {
const knowledgeSpaceId = useAtomValue(documentsKnowledgeSpaceIdAtom)
@@ -48,10 +44,8 @@ export function useDocumentUploadSession() {
const controller = new AbortController()
controllers.push(controller)
let settled = false
- let timeout: number | undefined
const promise = new Promise<string>((resolve, reject) => {
function cleanup() {
- if (timeout !== undefined) window.clearTimeout(timeout)
controller.signal.removeEventListener('abort', handleAbort)
if (stagingControllersRef.current.get(file) === controller) {
stagingPromisesRef.current.delete(file)
@@ -74,10 +68,6 @@ export function useDocumentUploadSession() {
controller.signal.addEventListener('abort', handleAbort, { once: true })
function stage() {
if (controller.signal.aborted) return
- timeout = window.setTimeout(
- () => controller.abort(new DocumentStagingTimeoutError()),
- DOCUMENT_STAGING_REQUEST_TIMEOUT,
- )
void stageKnowledgeFsDocument(file, controller.signal).then((uploadId) => {
if (settled) {
void discardKnowledgeFsStagedUpload(uploadId).catch(() => undefined)
diff --git a/web/features/new-rag/quality/golden-question-dialog.tsx b/web/features/new-rag/quality/golden-question-dialog.tsx
index 23566420099..7fdd420281e 100644
--- a/web/features/new-rag/quality/golden-question-dialog.tsx
+++ b/web/features/new-rag/quality/golden-question-dialog.tsx
@@ -189,13 +189,13 @@ function GoldenQuestionDialogSession({
/>
</div>
<form
- className="flex min-h-0 flex-col gap-5 overflow-y-auto overscroll-contain px-6 pb-6"
+ className="relative flex min-h-0 flex-col gap-5 overflow-y-auto overscroll-contain px-6 pb-6"
onSubmit={handleSubmit}
>
<Field name="question" disabled={pending} invalid={questionInvalid}>
<FieldLabel>
{t(($) => $['qualityPage.question'], { ns: 'knowledgeSpace' })}
- <span className="ml-0.5 text-text-destructive">*</span>
+ <span className="ms-0.5 text-text-destructive">*</span>
</FieldLabel>
<Textarea
aria-invalid={questionInvalid}
@@ -338,7 +338,7 @@ function GoldenQuestionDialogSession({
{searchCandidates.length > 0 && (
<Field name="evidenceSearchResults" disabled={pending}>
<Fieldset
- className="flex max-h-52 flex-col gap-2 overflow-y-auto rounded-lg border border-divider-subtle p-2"
+ className="relative flex max-h-52 flex-col gap-2 overflow-y-auto rounded-lg border border-divider-subtle p-2"
render={
<CheckboxGroup
disabled={pending}