{"record":{"id":"c01685fa56c8e1fa","repo":"n8n-io/n8n","slug":"failed-to-find-workflow-with-id-workflowid","errorCode":null,"errorMessage":"Failed to find workflow with ID \"${workflowId}\"","messagePattern":"Failed to find workflow with ID \"(.+?)\"","errorType":"exception","errorClass":"WorkflowActivationError","httpStatus":null,"severity":"warning","filePath":"packages/cli/src/active-workflow-manager.ts","lineNumber":534,"sourceCode":"\t * Active triggers, poll triggers, and schedule triggers are registered as\n\t * active in memory at `ActiveWorkflowTriggers`, but webhook triggers are registered\n\t * by being entered in the `webhook_entity` table, since webhooks do not\n\t * require continuous execution.\n\t *\n\t * Returns whether this operation added webhooks and/or non-webhook triggers.\n\t */\n\tasync add(\n\t\tworkflowId: WorkflowId,\n\t\tactivationMode: WorkflowActivateMode,\n\t\texistingWorkflow?: WorkflowEntity,\n\t\t{ shouldPublish } = { shouldPublish: true },\n\t) {\n\t\tconst added = { webhooks: false, triggersAndPollers: false };\n\n\t\tconst dbWorkflow = existingWorkflow ?? (await this.workflowRepository.findById(workflowId));\n\n\t\tif (!dbWorkflow) {\n\t\t\tthrow new WorkflowActivationError(`Failed to find workflow with ID \"${workflowId}\"`, {\n\t\t\t\tlevel: 'warning',\n\t\t\t});\n\t\t}\n\n\t\tif (dbWorkflow.isArchived) {\n\t\t\tthis.logger.debug('Cannot publish archived Workflow', { workflowId: dbWorkflow.id });\n\t\t\treturn added;\n\t\t}\n\n\t\tif (this.instanceSettings.isMultiMain && shouldPublish) {\n\t\t\tif (!dbWorkflow?.activeVersionId) {\n\t\t\t\tthrow new UnexpectedError('Active version ID not found for workflow', {\n\t\t\t\t\textra: { workflowId },\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tvoid this.publisher.publishCommand({\n\t\t\t\tcommand: 'add-webhooks-triggers-and-pollers',","sourceCodeStart":516,"sourceCodeEnd":552,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/cli/src/active-workflow-manager.ts#L516-L552","documentation":"Thrown by ActiveWorkflowManager.add() when activating/publishing a workflow: it looks up the workflow by ID in the database (or accepts a passed-in entity), and if none is found it throws a WorkflowActivationError at 'warning' level. This typically means the workflow was deleted between a request to activate it and the activation attempt, or the ID is wrong/stale.","triggerScenarios":"Calling the activation path (PUT /workflows/:id/activate, manual activate, or startup activation of active workflows) for an ID that no longer exists in the workflow table; passing a stale ID from a cached client; race where another user deletes the workflow concurrently.","commonSituations":"UI shows a workflow that was deleted in another tab/session; startup re-activation of a workflow removed while the instance was down; API client caching an ID past deletion; imported/Restored backup referencing missing IDs.","solutions":["Verify the workflow exists: re-fetch the workflow list and confirm the ID before activating.","If the workflow was deleted, inform the user and remove the stale reference (e.g. discard the cached ID).","Handle the WorkflowActivationError at the call site and surface a 'workflow not found' message rather than retrying."],"exampleFix":"// before\nawait activeWorkflowManager.add(workflowId, 'activate');\n\n// after\nconst wf = await workflowRepository.findById(workflowId);\nif (!wf) throw new NotFoundError(`Workflow ${workflowId} not found`);\nawait activeWorkflowManager.add(workflowId, 'activate', wf);","handlingStrategy":"validation","validationCode":"const wf = await workflowRepository.findById(workflowId);\nif (!wf) {\n  throw new NotFoundError(`Workflow ${workflowId} not found`);\n}\nawait activeWorkflowManager.add(workflowId, 'activate', wf);","typeGuard":"function workflowExists(wf: unknown): wf is WorkflowEntity {\n  return wf != null;\n}","tryCatchPattern":"try {\n  await activeWorkflowManager.add(workflowId, 'activate');\n} catch (e) {\n  if (e instanceof WorkflowActivationError && /Failed to find workflow/.test(e.message)) {\n    // surface 'not found' to user; do not retry\n    return { status: 404 };\n  }\n  throw e;\n}","preventionTips":["Re-fetch the workflow list before activating to confirm the ID still exists.","Pass the existing WorkflowEntity to add() when you already have it, to avoid a second lookup race.","Discard cached IDs after deletion."],"tags":["activation","workflow","database","not-found"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}