AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(flows): webhook and polling triggers that fail to start a run now log the reason (#15450)
Bartosz Majewski0f167dee8b0d
diff --git a/brain/knowledge/data-storage-observability/index.md b/brain/knowledge/data-storage-observability/index.mdindex 5b15ba6a155..7d7dc7b8482 100644--- a/brain/knowledge/data-storage-observability/index.md+++ b/brain/knowledge/data-storage-observability/index.md@@ -38,6 +38,10 @@ Platform reporting: daily runs, active flows/users, time-saved estimates. `PlatfAll structured logging goes through **evlog** — one wide event per unit of work, one remote drain (Axiom / HyperDX / Loki / Better Stack / OTLP; first match wins). Metrics on ClickStack are **log-based**: dashboards and alerts query numeric fields (`durationMs`, `memRssMb`, `eventLoopDelayP99Ms`) on wide events. Both API and worker emit a 60s `system.snapshot` event with process RSS / heap / event-loop lag so those charts exist at all. BullMQ queue depth is the one signal exported as a **native OTLP gauge** (`bullmq.job.count`), because per-queue-per-state cardinality would bloat wide events. Worker CPU / RAM travels in-band on the poll healthcheck (not to ClickStack) and surfaces on `GET /v1/health/system`.+Gotchas:+- **The top-level `error` key belongs to the wide event, and a string you put there is silently thrown away.** `RequestLogger.error` ends with `context.error = errorObj`, built from whatever the call passed — so `log.error({ error: String(e) }, 'msg')` is overwritten by an object derived from `'msg'`, and the real error text is gone with no warning (GIT-1876; the same line shipped in `execute-polling.ts` for a year). Pass the **Error object** instead — `ap-logger` normalizes `obj.err ?? obj.error` through `toError` and hands it to the wide event, keeping name, message and stack — or, for an error that belongs to something else, name it after its owner (`engine: { status, error }`). The rule only bites the reserved top-level key; nested and descriptive error fields are safe.+- **The job logger already binds the request and flow ids, so handler logs rarely need to repeat them.** `executeJob` seeds each job's wide event with `requestId`, `project`, `platform`, `flow`, `flowVersion` and `job` from the job data. One exception worth knowing: `flowVersion` is bound from a `flowVersionId` field, and `WebhookJobData` calls it `flowVersionIdToRun` — so webhook jobs are the one case where the handler has to add `flowVersion: { id }` itself.+### Product TelemetryAnonymous product analytics to PostHog, from both the browser and the app container. Gated per platform by `platform_configuration.isProductTelemetryEnabled`, edited at Platform Admin > Account > Configurations; `AP_TELEMETRY_ENABLED` survives only as the value a platform's row is *born* with. See [000033](../decisions/000033-platform-configuration-rows-are-authoritative-and-created-on-first-read.md).diff --git a/brain/knowledge/eventing-webhooks/webhooks.md b/brain/knowledge/eventing-webhooks/webhooks.mdindex a61bfcdaf25..9a79aab0a02 100644--- a/brain/knowledge/eventing-webhooks/webhooks.md+++ b/brain/knowledge/eventing-webhooks/webhooks.md@@ -25,6 +25,7 @@ Webhooks are the primary entry point for event-driven flow execution from outsid- **Payload normalization** (`convertRequest`): multipart parts and binary bodies upload to the File service and the payload carries URLs; JSON/text pass through. `BINARY_CONTENT_TYPE_PATTERNS` covers `image/*`, `video/*`, `audio/*`, `application/pdf|zip|gzip|octet-stream` and `text/csv` (each also needs a `addContentTypeParser` entry in `webhook-module.ts` to stream rather than parse). Subflow linkage is read off `x-parent-run-id` / `x-fail-parent-on-failure`.### Gotchas+- **An async webhook's 200 means "queued", not "a run was created".** The `EXECUTE_WEBHOOK` job creates a run only when the trigger hook returns OK with a non-empty `output`. Three paths end the job OK with no run: the hook fails (USER_FAILURE or INTERNAL_ERROR), it returns no payloads (filtering, or rejected webhook auth, GIT-1749), or it times out in the sandbox. Each logs its reason since GIT-1876 (`no flow run created` / `returned no payloads`, with `webhook.requestId`), so a "200 but no run" report starts with the worker log for that request id. The payload is still lost; nothing retries it.- **Streaming ingestion**: webhook files stream straight to S3 (only when `FILE_STORAGE_LOCATION=S3`; DB storage still buffers to bytea). `attachFieldsToBody` is NOT registered globally — each multipart route must opt in (webhook uses `request.parts()`); a route expecting `ApMultipartFile` without the hook fails with `400 body/ Invalid input`.- **rawBody / signatures**: captured only for small signed types (JSON/XML/text) via a scoped `preParsing` hook. Streamed types (multipart, binary) forgo rawBody — multipart signature verification is a dropped trade-off.- **Size guard**: `AP_MAX_WEBHOOK_PAYLOAD_SIZE_MB` (default 5MB) → 413. Raw-binary bodies pipe through `enforceByteLimit`; oversized multipart parts are failed at end-of-stream (busboy flags `truncated` cleanly rather than erroring).diff --git a/packages/server/worker/src/lib/execute/jobs/execute-polling.ts b/packages/server/worker/src/lib/execute/jobs/execute-polling.tsindex f7cfe507eb1..69e872d169e 100644--- a/packages/server/worker/src/lib/execute/jobs/execute-polling.ts+++ b/packages/server/worker/src/lib/execute/jobs/execute-polling.ts@@ -1,7 +1,8 @@-import { isNil } from '@activepieces/core-utils'+import { isNil, toError } from '@activepieces/core-utils'import { EngineOperationType, EngineResponseStatus, ExecuteTriggerResponse, FlowVersion, PollingJobData, RunEnvironment, StreamStepProgress, TriggerHookType, WorkerJobType } from '@activepieces/shared'import { workerSettings } from '../../config/worker-settings'import { FireAndForgetJobResult, JobContext, JobHandler, JobResultKind } from '../types'+import { summarizeEngineError } from '../utils/engine-error-summary'import { recordTriggerRun } from '../utils/trigger-run-recorder'import { getWebhookUrl } from '../utils/webhook-url'@@ -10,6 +11,12 @@ export const executePollingJob: JobHandler<PollingJobData, FireAndForgetJobResulasync execute(ctx: JobContext, data: PollingJobData): Promise<FireAndForgetJobResult> {const timeoutInSeconds = workerSettings.getSettings().TRIGGER_TIMEOUT_SECONDS+ const pollingLogFields = {+ flow: { id: data.flowId },+ flowVersion: { id: data.flowVersionId },+ project: { id: data.projectId },+ }+const resolved = await ctx.resolver.resolve({ platformId: data.platformId, internalApiUrl: ctx.internalApiUrl, engineToken: ctx.engineToken, flow: { id: data.flowId, versionId: data.flowVersionId, projectId: data.projectId } })if (resolved.kind === 'flow-not-found') {@@ -60,13 +67,22 @@ export const executePollingJob: JobHandler<PollingJobData, FireAndForgetJobResul})}}+ else {+ const failureFields = { ...pollingLogFields, engine: { status: result.status, error: summarizeEngineError({ error: result.error }) } }+ if (result.status === EngineResponseStatus.USER_FAILURE) {+ ctx.log.warn(failureFields, 'Polling trigger hook failed, no flow run created')+ }+ else {+ ctx.log.error(failureFields, 'Polling trigger hook failed, no flow run created')+ }+ }await recordTriggerRun({ apiClient: ctx.apiClient, log: ctx.log, flowVersion, platformId: data.platformId, status: result.status, error: result.error })return { kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK, logs: result.logs }}catch (e) {- ctx.log.error({ error: String(e) }, 'Polling trigger failed, will retry on next scheduled cycle')+ ctx.log.error({ ...pollingLogFields, error: toError(e) }, 'Polling trigger failed, will retry on next scheduled cycle')await recordTriggerRun({ apiClient: ctx.apiClient, log: ctx.log, flowVersion, platformId: data.platformId, status: EngineResponseStatus.INTERNAL_ERROR })return { kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK }}diff --git a/packages/server/worker/src/lib/execute/jobs/execute-webhook.ts b/packages/server/worker/src/lib/execute/jobs/execute-webhook.tsindex 37eeca55efd..beff863aabe 100644--- a/packages/server/worker/src/lib/execute/jobs/execute-webhook.ts+++ b/packages/server/worker/src/lib/execute/jobs/execute-webhook.ts@@ -2,6 +2,7 @@ import { isNil, parseToJsonIfPossible, tryCatch } from '@activepieces/core-utilsimport { EngineOperationType, EngineResponseStatus, ExecuteTriggerResponse, FlowVersion, PieceTrigger, StreamStepProgress, TriggerHookType, WebhookJobData, WorkerJobType } from '@activepieces/shared'import { workerSettings } from '../../config/worker-settings'import { FireAndForgetJobResult, JobContext, JobHandler, JobResultKind } from '../types'+import { summarizeEngineError } from '../utils/engine-error-summary'import { isSandboxTimeout } from '../utils/sandbox-helpers'import { recordTriggerRun } from '../utils/trigger-run-recorder'import { getAppWebhookUrl, getWebhookUrl } from '../utils/webhook-url'@@ -46,6 +47,13 @@ export const executeWebhookJob: JobHandler<WebhookJobData, FireAndForgetJobResulconst { appWebhookUrl, webhookSecret } = getAppWebhookDetails(flowVersion, ctx.publicApiUrl, settings.APP_WEBHOOK_SECRETS)+ const webhookLogFields = {+ webhook: { requestId: data.requestId },+ flow: { id: data.flowId },+ flowVersion: { id: flowVersion.id },+ project: { id: data.projectId },+ }+let realExecutionStarted = falseconst { data: execResult, error } = await tryCatch(async () => {if (data.saveSampleData) {@@ -121,7 +129,12 @@ export const executeWebhookJob: JobHandler<WebhookJobData, FireAndForgetJobResulawait recordTriggerRun({ apiClient: ctx.apiClient, log: ctx.log, flowVersion, platformId: data.platformId, status: EngineResponseStatus.INTERNAL_ERROR })}if (isSandboxTimeout(error)) {- ctx.log.warn({ flowVersion: { id: data.flowVersionIdToRun } }, 'Webhook execution timed out in sandbox')+ if (data.execute) {+ ctx.log.error(webhookLogFields, 'Webhook execution timed out in sandbox, no flow run created')+ }+ else {+ ctx.log.warn(webhookLogFields, 'Webhook execution timed out in sandbox')+ }return { kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK }}throw error@@ -145,6 +158,18 @@ export const executeWebhookJob: JobHandler<WebhookJobData, FireAndForgetJobResulfailParentOnFailure: data.failParentOnFailure,})}+ else {+ ctx.log.info(webhookLogFields, 'Webhook trigger returned no payloads, skipping run creation')+ }+ }+ else {+ const failureFields = { ...webhookLogFields, engine: { status: execResult.status, error: summarizeEngineError({ error: execResult.error }) } }+ if (execResult.status === EngineResponseStatus.USER_FAILURE) {+ ctx.log.warn(failureFields, 'Webhook trigger hook failed, no flow run created')+ }+ else {+ ctx.log.error(failureFields, 'Webhook trigger hook failed, no flow run created')+ }}await recordTriggerRun({ apiClient: ctx.apiClient, log: ctx.log, flowVersion, platformId: data.platformId, status: execResult.status, error: execResult.error })diff --git a/packages/server/worker/src/lib/execute/utils/engine-error-summary.ts b/packages/server/worker/src/lib/execute/utils/engine-error-summary.tsnew file mode 100644index 00000000000..41651c255cc--- /dev/null+++ b/packages/server/worker/src/lib/execute/utils/engine-error-summary.ts@@ -0,0 +1,14 @@+import { isNil, tryParseFriendlyPieceError } from '@activepieces/core-utils'++export function summarizeEngineError({ error }: { error: string | undefined }): string | undefined {+ if (isNil(error)) {+ return undefined+ }+ const parsed = tryParseFriendlyPieceError(error)+ const summary = isNil(parsed)+ ? error+ : [parsed.errorName, parsed.message].filter((part) => !isNil(part)).join(': ')+ return summary.slice(0, MAX_ERROR_SUMMARY_LENGTH)+}++const MAX_ERROR_SUMMARY_LENGTH = 500diff --git a/packages/server/worker/test/lib/execute/jobs/execute-polling.test.ts b/packages/server/worker/test/lib/execute/jobs/execute-polling.test.tsnew file mode 100644index 00000000000..4e16d9dcf9c--- /dev/null+++ b/packages/server/worker/test/lib/execute/jobs/execute-polling.test.ts@@ -0,0 +1,159 @@+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { EngineResponseStatus, FlowTriggerType, FlowVersionState, WorkerJobType } from '@activepieces/shared'+import type { FlowVersion, PollingJobData } from '@activepieces/shared'++vi.mock('../../../../src/lib/config/worker-settings', () => ({+ workerSettings: {+ getSettings: vi.fn().mockReturnValue({ TRIGGER_TIMEOUT_SECONDS: 30 }),+ },+}))++import { executePollingJob } from '../../../../src/lib/execute/jobs/execute-polling'+import { JobResultKind } from '../../../../src/lib/execute/types'+import type { JobContext } from '../../../../src/lib/execute/types'++function makeFlowVersion(): FlowVersion {+ return {+ id: 'fv-1',+ created: '2024-01-01T00:00:00Z',+ updated: '2024-01-01T00:00:00Z',+ flowId: 'flow-1',+ displayName: 'Test Flow',+ trigger: {+ name: 'trigger_1',+ valid: true,+ displayName: 'New Row',+ lastUpdatedDate: '2024-01-01T00:00:00Z',+ type: FlowTriggerType.PIECE,+ settings: {+ pieceName: '@activepieces/piece-google-sheets',+ pieceVersion: '~0.1.0',+ triggerName: 'new_row',+ input: {},+ propertySettings: {},+ },+ },+ updatedBy: null,+ valid: true,+ schemaVersion: null,+ agentIds: [],+ state: FlowVersionState.LOCKED,+ connectionIds: [],+ backupFiles: null,+ notes: [],+ }+}++function makePollingJobData(): PollingJobData {+ return {+ projectId: 'proj-1',+ platformId: 'plat-1',+ schemaVersion: 4,+ flowVersionId: 'fv-1',+ flowId: 'flow-1',+ triggerType: FlowTriggerType.PIECE,+ jobType: WorkerJobType.EXECUTE_POLLING,+ }+}++function makeMockContext(opts?: { executeResult?: unknown, executeError?: unknown }): JobContext {+ return {+ jobId: 'job-1',+ log: {+ info: vi.fn(),+ warn: vi.fn(),+ error: vi.fn(),+ debug: vi.fn(),+ },+ apiClient: {+ submitPayloads: vi.fn(),+ recordTriggerRun: vi.fn(),+ },+ resolver: {+ resolve: vi.fn().mockResolvedValue({+ kind: 'ready',+ provision: { platformId: 'plat-1', pieces: [], codes: [], publicApiUrl: 'http://localhost:3000/api/', engineToken: 'test-token' },+ flowVersion: makeFlowVersion(),+ }),+ },+ runtime: {+ execute: opts?.executeError+ ? vi.fn().mockRejectedValue(opts.executeError)+ : vi.fn().mockResolvedValue(opts?.executeResult ?? { status: EngineResponseStatus.OK, response: { output: [] } }),+ },+ workerIndex: 0,+ engineToken: 'test-token',+ internalApiUrl: 'http://localhost:3000',+ publicApiUrl: 'http://localhost:4200',+ } as unknown as JobContext+}++const expectedBaseFields = {+ flow: { id: 'flow-1' },+ flowVersion: { id: 'fv-1' },+ project: { id: 'proj-1' },+}++describe('executePollingJob silent-drop visibility', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ })++ it('logs at error level with the engine error on a non-user engine failure and still completes OK', async () => {+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.INTERNAL_ERROR, response: undefined, error: 'engine exploded' } })++ const result = await executePollingJob.execute(ctx, makePollingJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining({+ ...expectedBaseFields,+ engine: { status: EngineResponseStatus.INTERNAL_ERROR, error: 'engine exploded' },+ }),+ expect.stringContaining('no flow run created'),+ )+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('logs at warn level when the trigger hook fails with USER_FAILURE', async () => {+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.USER_FAILURE, response: undefined, error: 'trigger threw' } })++ const result = await executePollingJob.execute(ctx, makePollingJobData())++ expect(ctx.log.error).not.toHaveBeenCalled()+ expect(ctx.log.warn).toHaveBeenCalledWith(+ expect.objectContaining({+ ...expectedBaseFields,+ engine: { status: EngineResponseStatus.USER_FAILURE, error: 'trigger threw' },+ }),+ expect.stringContaining('no flow run created'),+ )+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('logs a thrown engine failure as an Error so the wide event keeps its message and stack', async () => {+ const ctx = makeMockContext({ executeError: new Error('sandbox died') })++ const result = await executePollingJob.execute(ctx, makePollingJobData())++ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining({+ ...expectedBaseFields,+ error: expect.objectContaining({ message: 'sandbox died' }),+ }),+ expect.stringContaining('will retry'),+ )+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('does not log an empty poll result', async () => {+ const ctx = makeMockContext()++ const result = await executePollingJob.execute(ctx, makePollingJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.error).not.toHaveBeenCalled()+ expect(ctx.log.warn).not.toHaveBeenCalled()+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })+})diff --git a/packages/server/worker/test/lib/execute/jobs/execute-webhook.test.ts b/packages/server/worker/test/lib/execute/jobs/execute-webhook.test.tsnew file mode 100644index 00000000000..25a31227f1e--- /dev/null+++ b/packages/server/worker/test/lib/execute/jobs/execute-webhook.test.ts@@ -0,0 +1,244 @@+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { ActivepiecesError, ErrorCode } from '@activepieces/core-utils'+import { EngineResponseStatus, FlowTriggerType, FlowVersionState, RunEnvironment, TriggerRunStatus, WorkerJobType } from '@activepieces/shared'+import type { FlowVersion, WebhookJobData } from '@activepieces/shared'++vi.mock('../../../../src/lib/config/worker-settings', () => ({+ workerSettings: {+ getSettings: vi.fn().mockReturnValue({ TRIGGER_TIMEOUT_SECONDS: 30, APP_WEBHOOK_SECRETS: '{}' }),+ },+}))++import { executeWebhookJob } from '../../../../src/lib/execute/jobs/execute-webhook'+import { JobResultKind } from '../../../../src/lib/execute/types'+import type { JobContext } from '../../../../src/lib/execute/types'++function makeFlowVersion(): FlowVersion {+ return {+ id: 'fv-1',+ created: '2024-01-01T00:00:00Z',+ updated: '2024-01-01T00:00:00Z',+ flowId: 'flow-1',+ displayName: 'Test Flow',+ trigger: {+ name: 'trigger_1',+ valid: true,+ displayName: 'Catch Webhook',+ lastUpdatedDate: '2024-01-01T00:00:00Z',+ type: FlowTriggerType.PIECE,+ settings: {+ pieceName: '@activepieces/piece-webhook',+ pieceVersion: '~0.1.0',+ triggerName: 'catch_webhook',+ input: {},+ propertySettings: {},+ },+ },+ updatedBy: null,+ valid: true,+ schemaVersion: null,+ agentIds: [],+ state: FlowVersionState.LOCKED,+ connectionIds: [],+ backupFiles: null,+ notes: [],+ }+}++function makeWebhookJobData(overrides?: Partial<WebhookJobData>): WebhookJobData {+ return {+ projectId: 'proj-1',+ platformId: 'plat-1',+ schemaVersion: 4,+ requestId: 'req-1',+ payload: { type: 'inline', value: {} },+ runEnvironment: RunEnvironment.PRODUCTION,+ flowId: 'flow-1',+ saveSampleData: false,+ flowVersionIdToRun: 'fv-1',+ execute: true,+ jobType: WorkerJobType.EXECUTE_WEBHOOK,+ ...overrides,+ }+}++function makeMockContext(opts?: { executeResult?: unknown, executeError?: unknown }): JobContext {+ const runtime = {+ execute: opts?.executeError+ ? vi.fn().mockRejectedValue(opts.executeError)+ : vi.fn().mockResolvedValue(opts?.executeResult ?? { status: EngineResponseStatus.OK, response: { output: [{}] } }),+ }+ return {+ jobId: 'job-1',+ log: {+ info: vi.fn(),+ warn: vi.fn(),+ error: vi.fn(),+ debug: vi.fn(),+ },+ apiClient: {+ submitPayloads: vi.fn(),+ savePayloads: vi.fn(),+ recordTriggerRun: vi.fn(),+ },+ resolver: {+ resolve: vi.fn().mockResolvedValue({+ kind: 'ready',+ provision: { platformId: 'plat-1', pieces: [], codes: [], publicApiUrl: 'http://localhost:3000/api/', engineToken: 'test-token' },+ flowVersion: makeFlowVersion(),+ }),+ },+ runtime,+ workerIndex: 0,+ engineToken: 'test-token',+ internalApiUrl: 'http://localhost:3000',+ publicApiUrl: 'http://localhost:4200',+ } as unknown as JobContext+}++const expectedBaseFields = {+ webhook: { requestId: 'req-1' },+ flow: { id: 'flow-1' },+ flowVersion: { id: 'fv-1' },+ project: { id: 'proj-1' },+}++describe('executeWebhookJob silent-drop visibility', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ })++ it('logs at error level with the engine error on a non-user engine failure, records the failed trigger run, and still completes OK', async () => {+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.INTERNAL_ERROR, response: undefined, error: 'engine exploded', logs: 'engine-log-output' } })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining({+ ...expectedBaseFields,+ engine: { status: EngineResponseStatus.INTERNAL_ERROR, error: 'engine exploded' },+ }),+ expect.stringContaining('no flow run created'),+ )+ expect(ctx.apiClient.recordTriggerRun).toHaveBeenCalledWith(+ expect.objectContaining({ status: TriggerRunStatus.FAILED }),+ )+ expect(result).toEqual({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK, logs: 'engine-log-output' })+ })++ it('logs at warn level when the trigger hook fails with USER_FAILURE', async () => {+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.USER_FAILURE, response: undefined, error: 'trigger threw' } })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.error).not.toHaveBeenCalled()+ expect(ctx.log.warn).toHaveBeenCalledWith(+ expect.objectContaining({+ ...expectedBaseFields,+ engine: { status: EngineResponseStatus.USER_FAILURE, error: 'trigger threw' },+ }),+ expect.stringContaining('no flow run created'),+ )+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('logs at info level when the trigger returns an empty output and no run is created', async () => {+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.OK, response: { output: [] } } })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.info).toHaveBeenCalledWith(+ expect.objectContaining(expectedBaseFields),+ expect.stringContaining('no payloads'),+ )+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('logs at error level on sandbox timeout during real execution and still completes OK', async () => {+ const timeoutError = new ActivepiecesError({+ code: ErrorCode.SANDBOX_EXECUTION_TIMEOUT,+ params: { standardOutput: '', standardError: '' },+ })+ const ctx = makeMockContext({ executeError: timeoutError })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.apiClient.submitPayloads).not.toHaveBeenCalled()+ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining(expectedBaseFields),+ expect.stringContaining('timed out'),+ )+ expect(ctx.apiClient.recordTriggerRun).toHaveBeenCalledWith(+ expect.objectContaining({ status: TriggerRunStatus.FAILED }),+ )+ expect(result).toEqual({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('logs a sanitized engine error without request bodies or raw inspect data', async () => {+ const friendlyError = JSON.stringify({+ __apErrorVersion: 1,+ message: 'Auth failed',+ errorName: 'HttpError',+ requestBody: { apiKey: 'sk-super-secret' },+ raw: 'HttpError: Auth failed at request body {"apiKey":"sk-super-secret"}',+ })+ const ctx = makeMockContext({ executeResult: { status: EngineResponseStatus.INTERNAL_ERROR, response: undefined, error: friendlyError } })++ await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining({+ engine: { status: EngineResponseStatus.INTERNAL_ERROR, error: 'HttpError: Auth failed' },+ }),+ expect.stringContaining('no flow run created'),+ )+ })++ it('logs at error level when a sample-phase timeout also skips a required real run', async () => {+ const timeoutError = new ActivepiecesError({+ code: ErrorCode.SANDBOX_EXECUTION_TIMEOUT,+ params: { standardOutput: '', standardError: '' },+ })+ const ctx = makeMockContext({ executeError: timeoutError })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData({ saveSampleData: true, execute: true }))++ expect(ctx.log.error).toHaveBeenCalledWith(+ expect.objectContaining(expectedBaseFields),+ expect.stringContaining('no flow run created'),+ )+ expect(result).toEqual({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('keeps sandbox timeout at warn level for a sample-only capture where no run was expected', async () => {+ const timeoutError = new ActivepiecesError({+ code: ErrorCode.SANDBOX_EXECUTION_TIMEOUT,+ params: { standardOutput: '', standardError: '' },+ })+ const ctx = makeMockContext({ executeError: timeoutError })++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData({ saveSampleData: true, execute: false }))++ expect(ctx.log.error).not.toHaveBeenCalled()+ expect(ctx.log.warn).toHaveBeenCalledWith(+ expect.objectContaining(expectedBaseFields),+ expect.stringContaining('timed out'),+ )+ expect(result).toEqual({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })++ it('submits payloads and logs no error on the happy path', async () => {+ const ctx = makeMockContext()++ const result = await executeWebhookJob.execute(ctx, makeWebhookJobData())++ expect(ctx.apiClient.submitPayloads).toHaveBeenCalledOnce()+ expect(ctx.apiClient.submitPayloads).toHaveBeenCalledWith(expect.objectContaining({ httpRequestId: 'req-1', flowVersionId: 'fv-1' }))+ expect(ctx.log.error).not.toHaveBeenCalled()+ expect(ctx.log.warn).not.toHaveBeenCalled()+ expect(result).toMatchObject({ kind: JobResultKind.FIRE_AND_FORGET, status: EngineResponseStatus.OK })+ })+})diff --git a/packages/server/worker/test/lib/execute/utils/engine-error-summary.test.ts b/packages/server/worker/test/lib/execute/utils/engine-error-summary.test.tsnew file mode 100644index 00000000000..9f1d0b94dd4--- /dev/null+++ b/packages/server/worker/test/lib/execute/utils/engine-error-summary.test.ts@@ -0,0 +1,33 @@+import { describe, it, expect } from 'vitest'+import { summarizeEngineError } from '../../../../src/lib/execute/utils/engine-error-summary'++describe('summarizeEngineError', () => {+ it('returns undefined when the engine reported no error', () => {+ expect(summarizeEngineError({ error: undefined })).toBeUndefined()+ })++ it('keeps only the name and message of a friendly piece error', () => {+ const friendlyError = JSON.stringify({+ __apErrorVersion: 1,+ message: 'Auth failed',+ errorName: 'HttpError',+ requestBody: { apiKey: 'sk-super-secret' },+ })++ expect(summarizeEngineError({ error: friendlyError })).toBe('HttpError: Auth failed')+ })++ it('caps a friendly piece error, whose message is truncated at a far larger limit upstream', () => {+ const friendlyError = JSON.stringify({+ __apErrorVersion: 1,+ message: 'x'.repeat(2000),+ errorName: 'HttpError',+ })++ expect(summarizeEngineError({ error: friendlyError })?.length).toBe(500)+ })++ it('caps a raw engine error that is not a friendly piece error', () => {+ expect(summarizeEngineError({ error: 'y'.repeat(2000) })?.length).toBe(500)+ })+})