{"record":{"id":"f190eca95a802674","repo":"Budibase/budibase","slug":"knowledge-base-file-is-not-in-failed-state","errorCode":null,"errorMessage":"Knowledge base file is not in failed state","messagePattern":"Knowledge base file is not in failed state","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts","lineNumber":228,"sourceCode":"        workspaceId,\n        knowledgeBaseId,\n        fileId: file._id,\n        error,\n      })\n    }\n  }\n}\n\nexport const retryKnowledgeBaseFileIngestion = async (fileId: string) => {\n  const workspaceId = context.getOrThrowWorkspaceId()\n  const file = await getKnowledgeBaseFileOrThrow(fileId)\n  const startedAtMs = Date.now()\n\n  if (!file.objectStoreKey) {\n    throw new HTTPError(\"Knowledge base file does not have an object key\", 400)\n  }\n  if (file.status !== KnowledgeBaseFileStatus.FAILED) {\n    throw new HTTPError(\"Knowledge base file is not in failed state\", 400)\n  }\n\n  file.status = KnowledgeBaseFileStatus.PROCESSING\n  file.errorMessage = undefined\n  file.processedAt = undefined\n  await updateKnowledgeBaseFile(file)\n  console.log(\"Retrying knowledge base file ingestion\", {\n    workspaceId,\n    knowledgeBaseId: file.knowledgeBaseId,\n    fileId,\n    objectStoreKey: file.objectStoreKey,\n  })\n\n  try {\n    await enqueueRagFileIngestion({\n      workspaceId,\n      knowledgeBaseId: file.knowledgeBaseId,\n      fileId,","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts#L210-L246","documentation":"retryKnowledgeBaseFileIngestion is only valid for files whose status is KnowledgeBaseFileStatus.FAILED. Files that are PROCESSING, PENDING/SUCCEEDED etc. are either already in flight or already done, so retrying them would corrupt state; a 400 HTTPError is thrown to reject the request.","triggerScenarios":"Calling retryKnowledgeBaseFileIngestion(fileId) for a file whose current status is anything other than FAILED — typically the file is still PROCESSING, has already succeeded, or has not started.","commonSituations":"Double-clicking a 'retry' button in the UI, a user retrying while the original ingestion job is still running, retrying a successfully processed file, or stale UI state showing FAILED after the file has since succeeded.","solutions":["Check file.status === KnowledgeBaseFileStatus.FAILED before calling retry and surface a friendly message otherwise.","Refresh the file status from the API before showing the retry action to avoid stale UI state.","If the file is stuck in PROCESSING forever, fix/reset the stuck job rather than using the retry endpoint."],"exampleFix":"// before\nawait retryKnowledgeBaseFileIngestion(fileId)\n// after\nconst file = await getKnowledgeBaseFileOrThrow(fileId)\nif (file.status === KnowledgeBaseFileStatus.FAILED) {\n  await retryKnowledgeBaseFileIngestion(fileId)\n}","handlingStrategy":"validation","validationCode":"const file = await getKnowledgeBaseFileOrThrow(fileId)\nif (file.status !== KnowledgeBaseFileStatus.FAILED) {\n  return // nothing to retry; show current status to the user\n}\nawait retryKnowledgeBaseFileIngestion(fileId)","typeGuard":"const isFailedKnowledgeBaseFile = (\n  f: KnowledgeBaseFile,\n  status: typeof KnowledgeBaseFileStatus\n): boolean => f.status === status.FAILED","tryCatchPattern":"try {\n  await retryKnowledgeBaseFileIngestion(fileId)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 400) {\n    // refresh file status in UI; retry is not applicable\n  }\n  throw err\n}","preventionTips":["Refresh the file's status from the server before rendering the retry button.","Disable retry for files in PROCESSING or SUCCEEDED state.","Debounce/deduplicate retry clicks to avoid racing an in-flight job."],"tags":["validation","state-machine","knowledge-base","http-400"],"backgroundTag":"invalid-state-transition","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}