chore(discord-gateway): remove stale eslint-disable comment for sticker cache stats
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
import { Client } from "discord.js-selfbot-v13";
|
import { Client } from "discord.js-selfbot-v13";
|
||||||
import { startPendingAIAnalysisWorker } from "../modules/ai-moderation/aiAnalyzer.js";
|
import { startPendingAIAnalysisWorker } from "../modules/ai-moderation/aiAnalyzer.js";
|
||||||
import { CommandHandler } from "../modules/command-handler/commandHandler.js";
|
import { CommandHandler } from "../modules/command-handler/commandHandler.js";
|
||||||
@@ -17,7 +18,6 @@ import {
|
|||||||
} from "../shared/database/drizzle.js";
|
} from "../shared/database/drizzle.js";
|
||||||
import { runMigrations } from "../shared/database/migrate.js";
|
import { runMigrations } from "../shared/database/migrate.js";
|
||||||
import { createDiscordClientOptions } from "../shared/discord/clientOptions.js";
|
import { createDiscordClientOptions } from "../shared/discord/clientOptions.js";
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
|
||||||
import { createGracefulShutdown } from "./shutdown.js";
|
import { createGracefulShutdown } from "./shutdown.js";
|
||||||
|
|
||||||
const logger = createChildLogger("discord-gateway");
|
const logger = createChildLogger("discord-gateway");
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import { existsSync } from "node:fs";
|
import { existsSync } from "node:fs";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
|
import { retryWithBackoff } from "@bete/shared/utils";
|
||||||
import type { Client } from "discord.js-selfbot-v13";
|
import type { Client } from "discord.js-selfbot-v13";
|
||||||
import { AbortError } from "p-retry";
|
import { AbortError } from "p-retry";
|
||||||
import { Piscina } from "piscina";
|
import { Piscina } from "piscina";
|
||||||
import { config } from "../../shared/config/config.js";
|
import { config } from "../../shared/config/config.js";
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
|
||||||
import { retryWithBackoff } from "@bete/shared/utils";
|
|
||||||
import type { EventBroadcaster } from "../event-broadcaster/index.js";
|
import type { EventBroadcaster } from "../event-broadcaster/index.js";
|
||||||
import { invalidateAnalyticsCache } from "../message-capture/analyticsStore.js";
|
import { invalidateAnalyticsCache } from "../message-capture/analyticsStore.js";
|
||||||
import { isAgeRestrictedMetadata } from "../message-capture/messageMetadata.js";
|
import { isAgeRestrictedMetadata } from "../message-capture/messageMetadata.js";
|
||||||
@@ -28,9 +28,7 @@ import type {
|
|||||||
import { attemptAutoDeleteFlaggedMessage } from "./autoDeleteManager.js";
|
import { attemptAutoDeleteFlaggedMessage } from "./autoDeleteManager.js";
|
||||||
import { buildConversationContext } from "./conversationContext.js";
|
import { buildConversationContext } from "./conversationContext.js";
|
||||||
import { runModerationAnalysis } from "./llmModerationClient.js";
|
import { runModerationAnalysis } from "./llmModerationClient.js";
|
||||||
import {
|
import { logModerationError } from "./responseLogger.js";
|
||||||
logModerationError,
|
|
||||||
} from "./responseLogger.js";
|
|
||||||
|
|
||||||
const logger = createChildLogger("ai-analyzer");
|
const logger = createChildLogger("ai-analyzer");
|
||||||
|
|
||||||
@@ -163,7 +161,8 @@ const MAX_CONSECUTIVE_ERRORS = 5;
|
|||||||
const CONVERSATION_CB_COOLDOWN_MS = 60000;
|
const CONVERSATION_CB_COOLDOWN_MS = 60000;
|
||||||
|
|
||||||
function recordConversationBatchFailure(conversationKey: string): void {
|
function recordConversationBatchFailure(conversationKey: string): void {
|
||||||
const nextCount = (conversationConsecutiveErrors.get(conversationKey) ?? 0) + 1;
|
const nextCount =
|
||||||
|
(conversationConsecutiveErrors.get(conversationKey) ?? 0) + 1;
|
||||||
conversationConsecutiveErrors.set(conversationKey, nextCount);
|
conversationConsecutiveErrors.set(conversationKey, nextCount);
|
||||||
|
|
||||||
if (nextCount >= MAX_CONSECUTIVE_ERRORS) {
|
if (nextCount >= MAX_CONSECUTIVE_ERRORS) {
|
||||||
@@ -471,11 +470,16 @@ async function processIndividualFallback(
|
|||||||
lastError = error instanceof Error ? error.message : String(error);
|
lastError = error instanceof Error ? error.message : String(error);
|
||||||
|
|
||||||
// Log error with responseLogger
|
// Log error with responseLogger
|
||||||
logModerationError([messageId], config.AI_LLM_MODEL, error as Error | string, {
|
logModerationError(
|
||||||
phase: "individual_fallback",
|
[messageId],
|
||||||
conversationKey,
|
config.AI_LLM_MODEL,
|
||||||
exhaustedOnIncomplete,
|
error as Error | string,
|
||||||
});
|
{
|
||||||
|
phase: "individual_fallback",
|
||||||
|
conversationKey,
|
||||||
|
exhaustedOnIncomplete,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Infinite-loop prevention: if all retries were exhausted because the LLM
|
// Infinite-loop prevention: if all retries were exhausted because the LLM
|
||||||
// consistently dropped this specific message (not a transient error),
|
// consistently dropped this specific message (not a transient error),
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
|
import { retryWithBackoff } from "@bete/shared/utils";
|
||||||
import type { ChatCompletion } from "openai/resources/chat/completions";
|
import type { ChatCompletion } from "openai/resources/chat/completions";
|
||||||
import { AbortError } from "p-retry";
|
import { AbortError } from "p-retry";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { config } from "../../shared/config/config.js";
|
import { config } from "../../shared/config/config.js";
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
|
||||||
import { retryWithBackoff } from "@bete/shared/utils";
|
|
||||||
import { resizeImageForVision } from "../attachment-upload/imageResizer.js";
|
import { resizeImageForVision } from "../attachment-upload/imageResizer.js";
|
||||||
import { extractMessageMediaEvidence } from "../message-capture/messageMetadata.js";
|
import { extractMessageMediaEvidence } from "../message-capture/messageMetadata.js";
|
||||||
import type {
|
import type {
|
||||||
@@ -532,7 +532,10 @@ const analyzeSingleMediaImage = async (
|
|||||||
// processing this exact image, wait for it instead of starting a duplicate.
|
// processing this exact image, wait for it instead of starting a duplicate.
|
||||||
const existing = inFlightVisionCalls.get(cacheKey);
|
const existing = inFlightVisionCalls.get(cacheKey);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
log.debug({ cacheKey }, "Media analysis in-flight dedupe — waiting for existing call");
|
log.debug(
|
||||||
|
{ cacheKey },
|
||||||
|
"Media analysis in-flight dedupe — waiting for existing call",
|
||||||
|
);
|
||||||
const result = await existing;
|
const result = await existing;
|
||||||
if (!result) return null;
|
if (!result) return null;
|
||||||
return `[Media analysis for message ${messageId}] ${image.sourceLabel}: ${result}`;
|
return `[Media analysis for message ${messageId}] ${image.sourceLabel}: ${result}`;
|
||||||
@@ -910,7 +913,15 @@ async function runTextOnlyBatch(
|
|||||||
}),
|
}),
|
||||||
])) as { results: AnalysisResult[]; raw: unknown };
|
])) as { results: AnalysisResult[]; raw: unknown };
|
||||||
|
|
||||||
const rawUsage = (batchResult.raw as { usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number } })?.usage;
|
const rawUsage = (
|
||||||
|
batchResult.raw as {
|
||||||
|
usage?: {
|
||||||
|
prompt_tokens: number;
|
||||||
|
completion_tokens: number;
|
||||||
|
total_tokens: number;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)?.usage;
|
||||||
allResults.push(...batchResult.results);
|
allResults.push(...batchResult.results);
|
||||||
if (batchResult.raw) lastRaw = batchResult.raw;
|
if (batchResult.raw) lastRaw = batchResult.raw;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
|
|
||||||
import { createChildLogger } from "@bete/shared/logger";
|
import { createChildLogger } from "@bete/shared/logger";
|
||||||
|
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
|
||||||
|
|
||||||
const logger = createChildLogger("sticker-cache");
|
const logger = createChildLogger("sticker-cache");
|
||||||
|
|
||||||
@@ -42,10 +42,9 @@ export async function initStickerCache(): Promise<void> {
|
|||||||
`CREATE INDEX IF NOT EXISTS "idx_sticker_cache_fetched_at" ON "sticker_cache" USING btree ("fetched_at")`,
|
`CREATE INDEX IF NOT EXISTS "idx_sticker_cache_fetched_at" ON "sticker_cache" USING btree ("fetched_at")`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await executeAll(
|
await executeAll("DELETE FROM sticker_cache WHERE fetched_at < $1", [
|
||||||
"DELETE FROM sticker_cache WHERE fetched_at < $1",
|
Date.now() - TTL_MS,
|
||||||
[Date.now() - TTL_MS],
|
]);
|
||||||
);
|
|
||||||
const row = await executeGet(
|
const row = await executeGet(
|
||||||
"SELECT count(*) as cnt, COALESCE(SUM(size), 0) as total FROM sticker_cache",
|
"SELECT count(*) as cnt, COALESCE(SUM(size), 0) as total FROM sticker_cache",
|
||||||
[],
|
[],
|
||||||
@@ -149,10 +148,9 @@ async function evictIfNeeded(newSize: number): Promise<void> {
|
|||||||
if (freed >= targetToFree) break;
|
if (freed >= targetToFree) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await executeAll(
|
await executeAll(`DELETE FROM sticker_cache WHERE name = ANY($1)`, [
|
||||||
`DELETE FROM sticker_cache WHERE name = ANY($1)`,
|
namesToDelete,
|
||||||
[namesToDelete],
|
]);
|
||||||
);
|
|
||||||
statsCache.totalSizeBytes -= freed;
|
statsCache.totalSizeBytes -= freed;
|
||||||
statsCache.entryCount -= namesToDelete.length;
|
statsCache.entryCount -= namesToDelete.length;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user