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
- Check logs for '[ChatService] Failed to delete all sessions: <cause>'
- Ensure FKs are ON DELETE CASCADE, or wrap in a transaction that deletes chat_messages first
- Retry when the system is idle to avoid lock contention
- 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
- Require explicit confirmation for destructive wipes and run them at low-traffic times
- Delete child tables in a transaction before the parent wipe
- Verify FK cascade behavior in a staging DB before enabling the feature
- Check DB connectivity and lock activity before issuing bulk deletes
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
- Failed to add message
- Failed to create chat session
- Failed to update chat session
- Failed to delete chat session
- Failed to delete all sessions
AI-assisted analysis of Crosstalk-Solutions/project-nomad@0bd1c6f4f9 (2026-08-27).
Data as JSON: /api/errors/8906adb137032742.
Report an issue: GitHub.