Budibase/budibase · error · HTTPError

Knowledge base file is not in failed state

Error message

Knowledge base file is not in failed state

What it means

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.

Source

Thrown at packages/server/src/sdk/workspace/ai/knowledgeBase/uploads.ts:228

        workspaceId,
        knowledgeBaseId,
        fileId: file._id,
        error,
      })
    }
  }
}

export const retryKnowledgeBaseFileIngestion = async (fileId: string) => {
  const workspaceId = context.getOrThrowWorkspaceId()
  const file = await getKnowledgeBaseFileOrThrow(fileId)
  const startedAtMs = Date.now()

  if (!file.objectStoreKey) {
    throw new HTTPError("Knowledge base file does not have an object key", 400)
  }
  if (file.status !== KnowledgeBaseFileStatus.FAILED) {
    throw new HTTPError("Knowledge base file is not in failed state", 400)
  }

  file.status = KnowledgeBaseFileStatus.PROCESSING
  file.errorMessage = undefined
  file.processedAt = undefined
  await updateKnowledgeBaseFile(file)
  console.log("Retrying knowledge base file ingestion", {
    workspaceId,
    knowledgeBaseId: file.knowledgeBaseId,
    fileId,
    objectStoreKey: file.objectStoreKey,
  })

  try {
    await enqueueRagFileIngestion({
      workspaceId,
      knowledgeBaseId: file.knowledgeBaseId,
      fileId,

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Check file.status === KnowledgeBaseFileStatus.FAILED before calling retry and surface a friendly message otherwise.
  2. Refresh the file status from the API before showing the retry action to avoid stale UI state.
  3. If the file is stuck in PROCESSING forever, fix/reset the stuck job rather than using the retry endpoint.

Example fix

// before
await retryKnowledgeBaseFileIngestion(fileId)
// after
const file = await getKnowledgeBaseFileOrThrow(fileId)
if (file.status === KnowledgeBaseFileStatus.FAILED) {
  await retryKnowledgeBaseFileIngestion(fileId)
}
Defensive patterns

Strategy: validation

Validate before calling

const file = await getKnowledgeBaseFileOrThrow(fileId)
if (file.status !== KnowledgeBaseFileStatus.FAILED) {
  return // nothing to retry; show current status to the user
}
await retryKnowledgeBaseFileIngestion(fileId)

Type guard

const isFailedKnowledgeBaseFile = (
  f: KnowledgeBaseFile,
  status: typeof KnowledgeBaseFileStatus
): boolean => f.status === status.FAILED

Try / catch

try {
  await retryKnowledgeBaseFileIngestion(fileId)
} catch (err) {
  if (err instanceof HTTPError && err.status === 400) {
    // refresh file status in UI; retry is not applicable
  }
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/f190eca95a802674. Report an issue: GitHub.