Skip to content

Commit b146728

Browse files
fix(sockets): webhooks logic removal from copilot ops (#2862)
* fix(sockets): dying on deployed webhooks * fix edit workflow
1 parent d024c1e commit b146728

File tree

3 files changed

+3
-86
lines changed

3 files changed

+3
-86
lines changed

apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,9 @@ export const editWorkflowServerTool: BaseServerTool<EditWorkflowParams, any> = {
24992499
async execute(params: EditWorkflowParams, context?: { userId: string }): Promise<any> {
25002500
const logger = createLogger('EditWorkflowServerTool')
25012501
const { operations, workflowId, currentUserWorkflow } = params
2502-
if (!operations || operations.length === 0) throw new Error('operations are required')
2502+
if (!Array.isArray(operations) || operations.length === 0) {
2503+
throw new Error('operations are required and must be an array')
2504+
}
25032505
if (!workflowId) throw new Error('workflowId is required')
25042506

25052507
logger.info('Executing edit_workflow', {

apps/sim/lib/workflows/persistence/utils.ts

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import crypto from 'crypto'
22
import {
33
db,
4-
webhook,
54
workflow,
65
workflowBlocks,
76
workflowDeploymentVersion,
@@ -22,7 +21,6 @@ import { generateLoopBlocks, generateParallelBlocks } from '@/stores/workflows/w
2221
const logger = createLogger('WorkflowDBHelpers')
2322

2423
export type WorkflowDeploymentVersion = InferSelectModel<typeof workflowDeploymentVersion>
25-
type WebhookRecord = InferSelectModel<typeof webhook>
2624
type SubflowInsert = InferInsertModel<typeof workflowSubflows>
2725

2826
export interface WorkflowDeploymentVersionResponse {
@@ -337,18 +335,6 @@ export async function saveWorkflowToNormalizedTables(
337335

338336
// Start a transaction
339337
await db.transaction(async (tx) => {
340-
// Snapshot existing webhooks before deletion to preserve them through the cycle
341-
let existingWebhooks: WebhookRecord[] = []
342-
try {
343-
existingWebhooks = await tx.select().from(webhook).where(eq(webhook.workflowId, workflowId))
344-
} catch (webhookError) {
345-
// Webhook table might not be available in test environments
346-
logger.debug('Could not load webhooks before save, skipping preservation', {
347-
error: webhookError instanceof Error ? webhookError.message : String(webhookError),
348-
})
349-
}
350-
351-
// Clear existing data for this workflow
352338
await Promise.all([
353339
tx.delete(workflowBlocks).where(eq(workflowBlocks.workflowId, workflowId)),
354340
tx.delete(workflowEdges).where(eq(workflowEdges.workflowId, workflowId)),
@@ -419,42 +405,6 @@ export async function saveWorkflowToNormalizedTables(
419405
if (subflowInserts.length > 0) {
420406
await tx.insert(workflowSubflows).values(subflowInserts)
421407
}
422-
423-
// Re-insert preserved webhooks if any exist and their blocks still exist
424-
if (existingWebhooks.length > 0) {
425-
try {
426-
const webhookInserts = existingWebhooks
427-
.filter((wh) => !!state.blocks?.[wh.blockId ?? ''])
428-
.map((wh) => ({
429-
id: wh.id,
430-
workflowId: wh.workflowId,
431-
blockId: wh.blockId,
432-
path: wh.path,
433-
provider: wh.provider,
434-
providerConfig: wh.providerConfig,
435-
credentialSetId: wh.credentialSetId,
436-
isActive: wh.isActive,
437-
createdAt: wh.createdAt,
438-
updatedAt: new Date(),
439-
}))
440-
441-
if (webhookInserts.length > 0) {
442-
await tx.insert(webhook).values(webhookInserts)
443-
logger.debug(`Preserved ${webhookInserts.length} webhook(s) through workflow save`, {
444-
workflowId,
445-
})
446-
}
447-
} catch (webhookInsertError) {
448-
// Webhook preservation is optional - don't fail the entire save if it errors
449-
logger.warn('Could not preserve webhooks during save', {
450-
error:
451-
webhookInsertError instanceof Error
452-
? webhookInsertError.message
453-
: String(webhookInsertError),
454-
workflowId,
455-
})
456-
}
457-
}
458408
})
459409

460410
return { success: true }

apps/sim/socket/database/operations.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as schema from '@sim/db'
22
import { webhook, workflow, workflowBlocks, workflowEdges, workflowSubflows } from '@sim/db'
33
import { createLogger } from '@sim/logger'
4-
import type { InferSelectModel } from 'drizzle-orm'
54
import { and, eq, inArray, or, sql } from 'drizzle-orm'
65
import { drizzle } from 'drizzle-orm/postgres-js'
76
import postgres from 'postgres'
@@ -1175,14 +1174,6 @@ async function handleWorkflowOperationTx(
11751174
parallelCount: Object.keys(parallels || {}).length,
11761175
})
11771176

1178-
// Snapshot existing webhooks before deletion to preserve them through the cycle
1179-
// (workflowBlocks has CASCADE DELETE to webhook table)
1180-
const existingWebhooks = await tx
1181-
.select()
1182-
.from(webhook)
1183-
.where(eq(webhook.workflowId, workflowId))
1184-
1185-
// Delete all existing blocks (this will cascade delete edges and webhooks via ON DELETE CASCADE)
11861177
await tx.delete(workflowBlocks).where(eq(workflowBlocks.workflowId, workflowId))
11871178

11881179
// Delete all existing subflows
@@ -1248,32 +1239,6 @@ async function handleWorkflowOperationTx(
12481239
await tx.insert(workflowSubflows).values(parallelValues)
12491240
}
12501241

1251-
// Re-insert preserved webhooks if any exist and their blocks still exist
1252-
type WebhookRecord = InferSelectModel<typeof webhook>
1253-
if (existingWebhooks.length > 0) {
1254-
const webhookInserts = existingWebhooks
1255-
.filter((wh: WebhookRecord) => !!blocks?.[wh.blockId ?? ''])
1256-
.map((wh: WebhookRecord) => ({
1257-
id: wh.id,
1258-
workflowId: wh.workflowId,
1259-
blockId: wh.blockId,
1260-
path: wh.path,
1261-
provider: wh.provider,
1262-
providerConfig: wh.providerConfig,
1263-
credentialSetId: wh.credentialSetId,
1264-
isActive: wh.isActive,
1265-
createdAt: wh.createdAt,
1266-
updatedAt: new Date(),
1267-
}))
1268-
1269-
if (webhookInserts.length > 0) {
1270-
await tx.insert(webhook).values(webhookInserts)
1271-
logger.debug(`Preserved ${webhookInserts.length} webhook(s) through state replacement`, {
1272-
workflowId,
1273-
})
1274-
}
1275-
}
1276-
12771242
logger.info(`Successfully replaced workflow state for ${workflowId}`)
12781243
break
12791244
}

0 commit comments

Comments
 (0)