{"record":{"id":"5ed54a902fc44049","repo":"iflytek/astron-agent","slug":"workflow-name-existed","errorCode":"WORKFLOW_NAME_EXISTED","errorMessage":"WORKFLOW_NAME_EXISTED","messagePattern":"WORKFLOW_NAME_EXISTED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"warning","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/workflow/WorkflowService.java","lineNumber":1077,"sourceCode":"    /**\n     * Create workflow: first call core \"add protocol\", then store locally.\n     *\n     * @param createReq Create request parameters\n     * @param request HTTP request\n     * @return Created workflow\n     */\n    public Workflow create(WorkflowReq createReq, HttpServletRequest request) {\n        // Name duplication check (isolated by space)\n        final Long spaceId = createReq.getSpaceId();\n        Workflow one = getOne(\n                Wrappers.lambdaQuery(Workflow.class)\n                        .eq(Workflow::getName, createReq.getName())\n                        .eq(spaceId == null, Workflow::getUid, UserInfoManagerHandler.getUserId())\n                        .eq(spaceId != null, Workflow::getSpaceId, spaceId)\n                        .eq(Workflow::getDeleted, false)\n                        .last(\"limit 1\"));\n        if (one != null) {\n            throw new BusinessException(ResponseEnum.WORKFLOW_NAME_EXISTED);\n        }\n\n        createReq.setAppId(commonConfig.getAppId());\n        if (Boolean.TRUE.equals(createReq.getCommonUser())) {\n            // Dedicated cloud commonUser logic\n            createReq.setAppId(commonConfig.getAppId());\n            createReq.setDomain(\"generalv3.5\");\n        }\n\n        // Core system - add protocol, return flowId\n        ApiResult<String> addResult = callProtocolAdd(createReq);\n        if (addResult.code() != 0) {\n            throw new BusinessException(ResponseEnum.RESPONSE_FAILED, addResult.message());\n        }\n\n        // Product side database storage\n        Workflow workflow = new Workflow();\n        org.springframework.beans.BeanUtils.copyProperties(createReq, workflow);","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/workflow/WorkflowService.java#L1059-L1095","documentation":"WorkflowService throws BusinessException(WORKFLOW_NAME_EXISTED) when creating a workflow whose name already exists in the same scope. A MyBatis-Plus query checks for an existing non-deleted workflow matching the requested name within the current user's scope (uid when no spaceId, space otherwise); if found, creation is rejected. This enforces unique workflow names per user/space.","triggerScenarios":"Calling workflow create with createReq.getName() equal to an existing non-deleted workflow name owned by the same user (spaceId == null) or within the same space (spaceId != null). The duplicate check uses .last(\"limit 1\") so the first match aborts the create.","commonSituations":"User retries a create after a prior partial failure, creates workflows with default/template names, API clients that don't dedupe names, or a name left over from a soft-deleted flow that was restored.","solutions":["Rename the workflow in the request to a unique value within the user/space scope","Query existing workflows for the target name before calling create and surface a friendly conflict to the user","If the old workflow is abandoned, delete it (soft delete) and recreate","Check whether spaceId vs uid scoping causes a false conflict when mixing personal and space workflows"],"exampleFix":"// before\nworkflowService.create(req); // name may collide\n// after\nif (workflowService.existsByNameAndSpace(req.getName(), spaceId)) {\n    throw new UserVisibleException(\"Workflow name already in use\");\n}\nworkflowService.create(req);","handlingStrategy":"validation","validationCode":"boolean nameTaken = workflowService.count(new LambdaQueryWrapper<Workflow>()\n        .eq(Workflow::getName, name)\n        .eq(spaceId == null, Workflow::getUid, userId)\n        .eq(spaceId != null, Workflow::getSpaceId, spaceId)\n        .eq(Workflow::getDeleted, false)) > 0;\nif (nameTaken) throw new IllegalArgumentException(\"workflow name already in use\");","typeGuard":null,"tryCatchPattern":"try {\n    workflowService.create(req);\n} catch (BusinessException e) {\n    if (\"WORKFLOW_NAME_EXISTED\".equals(e.getCode())) {\n        promptUserToRename();\n    } else throw e;\n}","preventionTips":["Generate unique default names (append timestamp/suffix) for quick-create flows","Pre-check names client-side against the space's workflow list","After soft-deleting, suggest renaming on recreate","Never hardcode workflow names in automation scripts"],"tags":["workflow","duplicate-name","business-validation"],"backgroundTag":"file-already-exists","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}