diff --git a/packages/cli/src/modules/insights/insights-collection.service.ts b/packages/cli/src/modules/insights/insights-collection.service.ts index 291b8aeeff..5ee16e99d4 100644 --- a/packages/cli/src/modules/insights/insights-collection.service.ts +++ b/packages/cli/src/modules/insights/insights-collection.service.ts @@ -42,6 +42,11 @@ const shouldSkipMode: Record = { manual: true, }; +const MIN_RUNTIME = 0; + +// PostgreSQL INTEGER max (signed 32-bit) +const MAX_RUNTIME = 2 ** 31 - 1; + type BufferedInsight = Pick & { workflowId: string; workflowName: string; @@ -135,7 +140,11 @@ export class InsightsCollectionService { // run time event if (ctx.runData.stoppedAt) { - const value = ctx.runData.stoppedAt.getTime() - ctx.runData.startedAt.getTime(); + const runtimeMs = ctx.runData.stoppedAt.getTime() - ctx.runData.startedAt.getTime(); + if (runtimeMs < MIN_RUNTIME || runtimeMs > MAX_RUNTIME) { + this.logger.warn(`Invalid runtime detected: ${runtimeMs}ms, clamping to safe range`); + } + const value = Math.min(Math.max(runtimeMs, MIN_RUNTIME), MAX_RUNTIME); this.bufferedInsights.add({ ...commonWorkflowData, type: 'runtime_ms',