From 111c34c3b4077a7c38109a95195b82e361cf8335 Mon Sep 17 00:00:00 2001 From: Vikhyath Mondreti Date: Wed, 28 Jan 2026 19:31:58 -0800 Subject: [PATCH] fix few more inconsitencies --- .../workflow-selector/workflow-selector-input.tsx | 3 ++- .../components/preview-editor/preview-editor.tsx | 5 ++++- .../preview-workflow/components/block/block.tsx | 3 ++- apps/sim/lib/logs/events.ts | 2 ++ apps/sim/lib/logs/execution/logger.ts | 12 ++++++++++-- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-selector/workflow-selector-input.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-selector/workflow-selector-input.tsx index 5e65381d9..4b5abc8af 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-selector/workflow-selector-input.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-selector/workflow-selector-input.tsx @@ -1,6 +1,7 @@ 'use client' import { useMemo } from 'react' +import { DELETED_WORKFLOW_LABEL } from '@/app/workspace/[workspaceId]/logs/utils' import { SelectorCombobox } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/selector-combobox/selector-combobox' import type { SubBlockConfig } from '@/blocks/types' import type { SelectorContext } from '@/hooks/selectors/types' @@ -40,7 +41,7 @@ export function WorkflowSelectorInput({ isPreview={isPreview} previewValue={previewValue} placeholder={subBlock.placeholder || 'Select workflow...'} - missingOptionLabel='Deleted Workflow' + missingOptionLabel={DELETED_WORKFLOW_LABEL} /> ) } diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-editor/preview-editor.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-editor/preview-editor.tsx index bf5a44a76..b94e17de4 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-editor/preview-editor.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-editor/preview-editor.tsx @@ -34,6 +34,7 @@ import { isSubBlockFeatureEnabled, isSubBlockVisibleForMode, } from '@/lib/workflows/subblocks/visibility' +import { DELETED_WORKFLOW_LABEL } from '@/app/workspace/[workspaceId]/logs/utils' import { SubBlock } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components' import { PreviewContextMenu } from '@/app/workspace/[workspaceId]/w/components/preview/components/preview-context-menu' import { PreviewWorkflow } from '@/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow' @@ -1327,7 +1328,9 @@ function PreviewEditorContent({ ) : (
- {isMissingChildWorkflow ? 'Deleted Workflow' : 'Unable to load preview'} + {isMissingChildWorkflow + ? DELETED_WORKFLOW_LABEL + : 'Unable to load preview'}
)} diff --git a/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/block/block.tsx b/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/block/block.tsx index cc2fbcc9f..3317006f0 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/block/block.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/components/preview/components/preview-workflow/components/block/block.tsx @@ -9,6 +9,7 @@ import { isSubBlockFeatureEnabled, isSubBlockVisibleForMode, } from '@/lib/workflows/subblocks/visibility' +import { DELETED_WORKFLOW_LABEL } from '@/app/workspace/[workspaceId]/logs/utils' import { getDisplayValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block' import { getBlock } from '@/blocks' import { SELECTOR_TYPES_HYDRATION_REQUIRED, type SubBlockConfig } from '@/blocks/types' @@ -112,7 +113,7 @@ function resolveWorkflowName( if (!rawValue || typeof rawValue !== 'string') return null const workflowMap = useWorkflowRegistry.getState().workflows - return workflowMap[rawValue]?.name ?? 'Deleted Workflow' + return workflowMap[rawValue]?.name ?? DELETED_WORKFLOW_LABEL } /** diff --git a/apps/sim/lib/logs/events.ts b/apps/sim/lib/logs/events.ts index 767c4bd8a..8289919e1 100644 --- a/apps/sim/lib/logs/events.ts +++ b/apps/sim/lib/logs/events.ts @@ -50,6 +50,8 @@ function prepareLogData( export async function emitWorkflowExecutionCompleted(log: WorkflowExecutionLog): Promise { try { + if (!log.workflowId) return + const workflowData = await db .select({ workspaceId: workflow.workspaceId }) .from(workflow) diff --git a/apps/sim/lib/logs/execution/logger.ts b/apps/sim/lib/logs/execution/logger.ts index d8499b007..68cd9c22d 100644 --- a/apps/sim/lib/logs/execution/logger.ts +++ b/apps/sim/lib/logs/execution/logger.ts @@ -293,7 +293,10 @@ export class ExecutionLogger implements IExecutionLoggerService { } try { - const [wf] = await db.select().from(workflow).where(eq(workflow.id, updatedLog.workflowId)) + // Skip workflow lookup if workflow was deleted + const wf = updatedLog.workflowId + ? (await db.select().from(workflow).where(eq(workflow.id, updatedLog.workflowId)))[0] + : undefined if (wf) { const [usr] = await db .select({ id: userTable.id, email: userTable.email, name: userTable.name }) @@ -461,7 +464,7 @@ export class ExecutionLogger implements IExecutionLoggerService { * Maintains same logic as original execution logger for billing consistency */ private async updateUserStats( - workflowId: string, + workflowId: string | null, costSummary: { totalCost: number totalInputCost: number @@ -494,6 +497,11 @@ export class ExecutionLogger implements IExecutionLoggerService { return } + if (!workflowId) { + logger.debug('Workflow was deleted, skipping user stats update') + return + } + try { // Get the workflow record to get the userId const [workflowRecord] = await db