Crosstalk-Solutions/project-nomad · error · Error

Failed to delete all chat sessions

Error message

Failed to delete all chat sessions

What it means

ChatService.deleteAllSessions rethrows this after logging when the bulk deletion of every chat session (and their messages) fails at the database level. This is a destructive admin operation, so any DB error — connection loss, lock timeout, FK restriction — aborts the whole wipe.

Source

Thrown at admin/app/services/chat_service.ts:286

        const fallbackTitle = userMessage.slice(0, 57) + (userMessage.length > 57 ? '...' : '')
        await this.updateSession(sessionId, { title: fallbackTitle })
      } catch {
        // Silently fail - session keeps "New Chat" title
      }
    }
  }

  async deleteAllSessions() {
    try {
      await ChatSession.query().delete()
      return { success: true, message: 'All chat sessions deleted' }
    } catch (error) {
      logger.error(
        `[ChatService] Failed to delete all sessions: ${
          error instanceof Error ? error.message : error
        }`
      )
      throw new Error('Failed to delete all chat sessions')
    }
  }
}

View on GitHub (pinned to 0bd1c6f4f9)

Solutions

  1. Check logs for '[ChatService] Failed to delete all sessions: <cause>'
  2. Ensure FKs are ON DELETE CASCADE, or wrap in a transaction that deletes chat_messages first
  3. Retry when the system is idle to avoid lock contention
  4. Verify DB health/connectivity before the admin wipe action

Example fix

// before
await ChatSession.truncate(true) // or bulk delete that hits FK restrictions

// after
await db.transaction(async (trx) => {
  await ChatMessage.query({ client: trx }).del()
  await ChatSession.query({ client: trx }).del()
})
Defensive patterns

Strategy: try-catch

Validate before calling

if ((await ChatSession.query().count('* as total'))[0].total === 0) return // nothing to wipe

Try / catch

try { await chat.deleteAllSessions() } catch (e) { if (e.message === 'Failed to delete all chat sessions') { confirmAndRetryOnce(); return } throw e }

Prevention

When it happens

Trigger: Invoking 'delete all sessions' while the DB rejects the bulk delete: FK constraints without CASCADE, lock contention from active chat transactions, or the DB going away mid-statement.

Common situations: A schema where chat_messages references chat_sessions with ON DELETE RESTRICT/NO ACTION, long-running chat requests holding row locks during the wipe, or a DB restart/failover during the operation.

Related errors


AI-assisted analysis of Crosstalk-Solutions/project-nomad@0bd1c6f4f9 (2026-08-27). Data as JSON: /api/errors/8906adb137032742. Report an issue: GitHub.