From 410ef98783b4fb1e9d099e6ac414dfec6fa79247 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 1 Apr 2026 20:17:30 +0000 Subject: [PATCH] fix: remove dead code, fix naming inconsistency, document migration - Remove unused AGENT_CHAT_RETRY_EVENT_NAME constant (dead code) - Rename agentStreamingService to agentChatStreamingService for consistency - Add comment explaining why migration down() deletes queued messages https://claude.ai/code/session_01NGv3c62sYGMww7iuVsWzcJ --- .../src/modules/ai/constants/AgentChatRetryEventName.ts | 1 - .../common/1774776000000-add-status-to-agent-message.ts | 2 ++ .../ai/ai-chat/controllers/agent-chat.controller.ts | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 packages/twenty-front/src/modules/ai/constants/AgentChatRetryEventName.ts diff --git a/packages/twenty-front/src/modules/ai/constants/AgentChatRetryEventName.ts b/packages/twenty-front/src/modules/ai/constants/AgentChatRetryEventName.ts deleted file mode 100644 index 1d908e2cb89..00000000000 --- a/packages/twenty-front/src/modules/ai/constants/AgentChatRetryEventName.ts +++ /dev/null @@ -1 +0,0 @@ -export const AGENT_CHAT_RETRY_EVENT_NAME = 'agent-chat-retry' as const; diff --git a/packages/twenty-server/src/database/typeorm/core/migrations/common/1774776000000-add-status-to-agent-message.ts b/packages/twenty-server/src/database/typeorm/core/migrations/common/1774776000000-add-status-to-agent-message.ts index 46fec66f8fd..5bb266b8bff 100644 --- a/packages/twenty-server/src/database/typeorm/core/migrations/common/1774776000000-add-status-to-agent-message.ts +++ b/packages/twenty-server/src/database/typeorm/core/migrations/common/1774776000000-add-status-to-agent-message.ts @@ -25,6 +25,8 @@ export class AddStatusToAgentMessage1774776000000 await queryRunner.query( `ALTER TABLE "core"."agentMessage" DROP COLUMN "processedAt"`, ); + // Queued messages have turnId=NULL. They must be deleted before + // restoring the NOT NULL constraint on turnId. await queryRunner.query( `DELETE FROM "core"."agentMessage" WHERE "turnId" IS NULL`, ); diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/controllers/agent-chat.controller.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/controllers/agent-chat.controller.ts index f437d74dbec..7c20aeb29d7 100644 --- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/controllers/agent-chat.controller.ts +++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/controllers/agent-chat.controller.ts @@ -52,7 +52,7 @@ import { AiModelRegistryService } from 'src/engine/metadata-modules/ai/ai-models ) export class AgentChatController { constructor( - private readonly agentStreamingService: AgentChatStreamingService, + private readonly agentChatStreamingService: AgentChatStreamingService, private readonly agentChatService: AgentChatService, private readonly eventPublisherService: AgentChatEventPublisherService, private readonly billingService: BillingService, @@ -132,7 +132,7 @@ export class AgentChatController { return { messageId: message.id, queued: true }; } - const result = await this.agentStreamingService.streamAgentChat({ + const result = await this.agentChatStreamingService.streamAgentChat({ threadId, browsingContext: body.browsingContext ?? null, modelId: body.modelId,