chatboxai/chatbox · error · Error

Knowledge base ${kbId} not found

Error message

Knowledge base ${kbId} not found

What it means

Thrown by authenticatedAfetch() before any network call when `getTokens()` resolves to null — i.e. the user is not logged in / has no stored access+refresh token pair. This is the entry guard for Chatbox AI authenticated endpoints: every authenticated request requires a valid token pair, so a null token short-circuits immediately.

Source

Thrown at src/main/knowledge-base/ipc-handlers.ts:222

    }
  )

  ipcMain.handle('kb:delete', async (_event, kbId: number): Promise<{ success: boolean; error?: string }> => {
    try {
      log.info(`ipcMain: kb:delete, kbId=${kbId}`)

      if (!kbId || kbId <= 0) {
        throw new Error('Invalid knowledge base ID')
      }

      await withTransaction(async () => {
        const db = getDatabase()
        const vectorStore = getVectorStore()

        // Verify knowledge base exists before deletion
        const kbExists = await db.execute('SELECT id FROM knowledge_base WHERE id = ?', [kbId])
        if (!kbExists.rows[0]) {
          throw new Error(`Knowledge base ${kbId} not found`)
        }

        // 1. Delete associated files from kb_file
        await db.execute({
          sql: 'DELETE FROM kb_file WHERE kb_id = ?',
          args: [kbId],
        })
        log.info(`[IPC] Deleted file records for kbId=${kbId}`)

        // 2. Delete the knowledge base entry
        await db.execute({
          sql: 'DELETE FROM knowledge_base WHERE id = ?',
          args: [kbId],
        })
        log.info(`[IPC] Deleted knowledge base record for kbId=${kbId}`)

        // 3. Delete vector index
        await vectorStore.deleteIndex({ indexName: `kb_${kbId}` })

View on GitHub (pinned to 81571269ad)

Solutions

  1. Before calling authenticated endpoints, check the login state and prompt the user to sign in if no tokens are present.
  2. Coordinate logout so in-flight/queued authenticated requests are cancelled rather than allowed to hit this guard.
  3. Verify token storage permissions (keychain access on mobile, IndexedDB/localStorage on web) so getTokens() does not silently return null.
  4. On app start, if a feature expects auth, run a login-status check and route to the login screen when tokens are absent.

Example fix

// before
const res = await authedAfetch(url, init)  // throws 'No authentication tokens available'

// after
const tokens = await getTokens()
if (!tokens) { routeToLogin(); return }
const res = await authedAfetch(url, init)
Defensive patterns

Strategy: validation

Validate before calling

const tokens = await getTokens()
if (!tokens) { routeToLogin(); throw new Error('Login required') }

Type guard

function hasTokens(t: { accessToken?: string; refreshToken?: string } | null): t is { accessToken: string; refreshToken: string } {
  return !!t && typeof t.accessToken === 'string' && typeof t.refreshToken === 'string'
}

Try / catch

try { return await authedAfetch(url, init) }
catch (e) {
  if (e instanceof ApiError && e.message.includes('No authentication tokens available')) routeToLogin()
  throw e
}

Prevention

When it happens

Trigger: User opened a feature requiring Chatbox AI authentication without completing login; tokens were cleared by a prior refresh failure (clearTokens runs on refresh error); fresh install / new device profile with no stored session; logout just completed but a background task still tried an authenticated call; token storage (e.g. keychain) returned null due to a permission/IO error.

Common situations: Background sync, license check, or chat retry runs after the user signed out; mobile app reinstall lost the keychain entry; OS keychain access denied so getTokens() yields null even though the user 'is logged in' from the UI's perspective; race between logout and an in-flight queued request.

Related errors


AI-assisted analysis of chatboxai/chatbox@81571269ad (2026-08-12). Data as JSON: /api/errors/0f509e5ecbca48d8. Report an issue: GitHub.