{"record":{"id":"96cd5d66f360f5e4","repo":"n8n-io/n8n","slug":"workflow-workflowid-not-found","errorCode":null,"errorMessage":"Workflow \"${workflowId}\" not found.","messagePattern":"Workflow \"(.+?)\" not found\\.","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/db/src/repositories/workflow.repository.ts","lineNumber":1499,"sourceCode":"\n\tasync findIn(workflowIds: string[]) {\n\t\treturn await this.find({\n\t\t\tselect: ['id', 'name'],\n\t\t\twhere: { id: In(workflowIds) },\n\t\t});\n\t}\n\n\tasync findWebhookBasedActiveWorkflows() {\n\t\treturn await (this.createQueryBuilder('workflow')\n\t\t\t.select('DISTINCT workflow.id, workflow.name')\n\t\t\t.innerJoin(WebhookEntity, 'webhook_entity', 'workflow.id = webhook_entity.workflowId')\n\t\t\t.execute() as Promise<Array<{ id: string; name: string }>>);\n\t}\n\n\tasync updateActiveState(workflowId: string, newState: boolean) {\n\t\tconst wfExists = await this.existsBy({ id: workflowId });\n\t\tif (!wfExists) {\n\t\t\tthrow new UserError(`Workflow \"${workflowId}\" not found.`);\n\t\t}\n\n\t\tif (newState) {\n\t\t\treturn await this.createQueryBuilder()\n\t\t\t\t.update(WorkflowEntity)\n\t\t\t\t.set({\n\t\t\t\t\tactiveVersionId: () => 'versionId',\n\t\t\t\t\tactive: true,\n\t\t\t\t})\n\t\t\t\t.where('id = :workflowId', { workflowId })\n\t\t\t\t.execute();\n\t\t} else {\n\t\t\treturn await this.update({ id: workflowId }, { active: false, activeVersionId: null });\n\t\t}\n\t}\n\n\t/**\n\t * Publish a specific version of a workflow","sourceCodeStart":1481,"sourceCodeEnd":1517,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/db/src/repositories/workflow.repository.ts#L1481-L1517","documentation":"UserError thrown by WorkflowRepository.updateActiveState() when no workflow exists with the given workflowId (checked via existsBy). The method flips active/activeVersionId; refusing on a missing workflow prevents writing a phantom update. Distinct from the publishVersion not-found at line 1528.","triggerScenarios":"Calling updateActiveState(id, bool) with an id that was deleted, never existed, or is malformed (not a UUID). Common in activation/deactivation flows, webhooks, and the active toggle API.","commonSituations":"UI 'activate' click racing with a delete; an API call with a stale workflow ID; a webhook re-activation job referencing a removed workflow; copy-paste ID typos; trying to activate an archived workflow via the wrong path.","solutions":["Confirm the workflow exists before toggling: `await workflowRepo.existsBy({ id })`.","If the workflow may have been deleted, treat 404 as a normal result and clean up dependent webhooks/triggers.","Validate the ID format upstream (UUID) to fail fast with a clearer message.","For background re-activation jobs, skip rather than throw on missing IDs."],"exampleFix":"// before\nawait workflowRepo.updateActiveState(workflowId, true);\n\n// after\nif (!(await workflowRepo.existsBy({ id: workflowId }))) {\n  return { status: 'not_found', workflowId };\n}\nawait workflowRepo.updateActiveState(workflowId, true);","handlingStrategy":"validation","validationCode":"if (!(await workflowRepository.existsBy({ id: workflowId }))) {\n  // do not call updateActiveState; return not_found\n}","typeGuard":"async function workflowIsActive(id: string): Promise<boolean> {\n  return await workflowRepository.existsBy({ id });\n}","tryCatchPattern":"try {\n  await workflowRepository.updateActiveState(workflowId, state);\n} catch (err) {\n  if (err instanceof UserError && /Workflow .* not found/.test(err.message)) {\n    // 404, and clean up dependent webhooks/triggers\n  } else throw err;\n}","preventionTips":["Existence-check before toggling active state.","Handle stale IDs gracefully in background re-activation jobs (skip, don't throw).","Validate UUID format upstream."],"tags":["workflow","not-found","activation","repository"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}