From c1c149855a6f7fbd1a2719deecf74a9acb7d99e4 Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Tue, 26 May 2026 00:59:32 +0700 Subject: [PATCH] feat: enforce strict AI env validation and force close --- src/app/bootstrap.ts | 5 +++++ src/moderation/aiAnalysisWorker.ts | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/app/bootstrap.ts b/src/app/bootstrap.ts index 01cfe6f..713377d 100644 --- a/src/app/bootstrap.ts +++ b/src/app/bootstrap.ts @@ -14,6 +14,11 @@ import { createGracefulShutdown } from "./shutdown.js"; export async function initializeApp() { const logger = createChildLogger("bot"); + if (!config.AI_LLM_API_KEY) { + logger.error("AI_LLM_API_KEY is missing from environment. Force closing application as AI environment is required."); + process.exit(1); + } + const token = config.DISCORD_TOKEN; logger.info( { hasToken: token.length > 0, tokenLength: token.length }, diff --git a/src/moderation/aiAnalysisWorker.ts b/src/moderation/aiAnalysisWorker.ts index 3e83561..4de4843 100644 --- a/src/moderation/aiAnalysisWorker.ts +++ b/src/moderation/aiAnalysisWorker.ts @@ -44,6 +44,16 @@ export default async function processAnalysisRequest({ conversationKey, messages, }: AnalysisWorkerRequest): Promise { + if (!config.AI_LLM_API_KEY) { + console.error(JSON.stringify({ + level: "FATAL", + context: "aiAnalysisWorker", + error: "AI_LLM_API_KEY is missing from environment. Force closing worker operation.", + timestamp: new Date().toISOString(), + })); + process.exit(1); + } + try { try { await ensureDb();