Skip to content

Commit e1b532e

Browse files
committed
chore(workflows): scope the paused-row read to its workflow and reuse the mutability guard
- the execution-status paused-row read filters by workflowId as well - delete-workflow uses requireMutableWorkflow instead of an inline copy - polling webhook logs carry the webhook id in metadata
1 parent d45b05d commit e1b532e

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎apps/sim/lib/webhooks/polling/utils.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ export function throwIfAdmissionRefused(result: PolledWebhookEventResult): void
6464

6565
/** Logs a poll stopped by {@link PollAdmissionRefusedError} and reports it as skipped. */
6666
export function skipAdmissionRefusedPoll(logger: Logger, webhookId: string): 'skipped' {
67-
logger.info(`Execution admission refused webhook ${webhookId}; left its items for a later poll`)
67+
logger.info('Execution admission refused the webhook; left its items for a later poll', {
68+
webhookId,
69+
})
6870
return 'skipped'
6971
}
7072

@@ -175,12 +177,13 @@ export async function markWebhookFailed(webhookId: string, logger: Logger): Prom
175177
.returning({ isActive: webhook.isActive, wasActive: prior.wasActive })
176178

177179
if (result?.wasActive && !result.isActive) {
178-
logger.warn(
179-
`Webhook ${webhookId} auto-disabled after ${MAX_CONSECUTIVE_FAILURES} consecutive failures`
180-
)
180+
logger.warn('Webhook auto-disabled after consecutive failures', {
181+
webhookId,
182+
consecutiveFailures: MAX_CONSECUTIVE_FAILURES,
183+
})
181184
}
182185
} catch (err) {
183-
logger.error(`Failed to mark webhook ${webhookId} as failed:`, err)
186+
logger.error('Failed to mark webhook as failed', { webhookId, error: err })
184187
}
185188
}
186189

@@ -197,7 +200,7 @@ export async function markWebhookSuccess(webhookId: string, logger: Logger): Pro
197200
and(eq(webhook.id, webhookId), or(isNull(webhook.failedCount), ne(webhook.failedCount, 0)))
198201
)
199202
} catch (err) {
200-
logger.error(`Failed to mark webhook ${webhookId} as successful:`, err)
203+
logger.error('Failed to mark webhook as successful', { webhookId, error: err })
201204
}
202205
}
203206

@@ -322,7 +325,7 @@ export async function updateWebhookProviderConfig(
322325
})
323326
.where(eq(webhook.id, webhookId))
324327
} catch (err) {
325-
logger.error(`Failed to update webhook ${webhookId} config:`, err)
328+
logger.error('Failed to update webhook config', { webhookId, error: err })
326329
}
327330
}
328331

‎apps/sim/lib/workflows/application/delete-workflow.ts‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { AuditAction, AuditResourceType } from '@sim/audit'
22
import { resolvePrincipalAttribution } from '@sim/auth/principal'
33
import { createLogger } from '@sim/logger'
4-
import { assertWorkflowMutable, WorkflowLockedError } from '@sim/platform-authz/workflow'
5-
import { OrchestrationError } from '@/lib/core/orchestration/types'
64
import { notifyWorkflowDeleted, notifyWorkspaceWorkflowsChanged } from '@/lib/realtime/notify'
75
import { defineAuthorizedWorkflowUseCase } from '@/lib/workflows/application/authorized-workflow-use-case'
6+
import { requireMutableWorkflow } from '@/lib/workflows/application/mutability'
87
import { workflowOperations } from '@/lib/workflows/application/operations'
98
import { resolvePrincipalWorkflowContext } from '@/lib/workflows/application/principal-scope'
109
import { requireWorkflowTransition } from '@/lib/workflows/application/transition-result'
@@ -21,14 +20,7 @@ export const deleteWorkflow = defineAuthorizedWorkflowUseCase({
2120
operation: workflowOperations.delete,
2221
resolveContext: resolvePrincipalWorkflowContext<DeleteWorkflowInput>,
2322
async execute({ principal, context }) {
24-
try {
25-
await assertWorkflowMutable(context.workflowId)
26-
} catch (error) {
27-
if (error instanceof WorkflowLockedError) {
28-
throw new OrchestrationError('locked', error.message)
29-
}
30-
throw error
31-
}
23+
await requireMutableWorkflow(context.workflowId)
3224

3325
const transition = await deleteWorkflowRecord({
3426
workflowId: context.workflowId,

‎apps/sim/lib/workflows/executor/execution-status.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,12 @@ async function readWorkflowExecutionStatus(
493493
nextResumeAt: pausedExecutions.nextResumeAt,
494494
})
495495
.from(pausedExecutions)
496-
.where(eq(pausedExecutions.executionId, executionId))
496+
.where(
497+
and(
498+
eq(pausedExecutions.executionId, executionId),
499+
eq(pausedExecutions.workflowId, workflowId)
500+
)
501+
)
497502
.limit(1)
498503

499504
const isCurrentlyPaused =

0 commit comments

Comments
 (0)