{"record":{"id":"a2971dd9c6725ea3","repo":"iflytek/astron-agent","slug":"model-name-existed","errorCode":"MODEL_NAME_EXISTED","errorMessage":"BusinessException(ResponseEnum.MODEL_NAME_EXISTED)","messagePattern":"BusinessException\\(ResponseEnum\\.MODEL_NAME_EXISTED\\)","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java","lineNumber":413,"sourceCode":"\n    private void saveOrUpdateModel(ModelValidationRequest request) {\n        final boolean isNew = (request.getId() == null);\n        final Long spaceId = SpaceInfoUtil.getSpaceId();\n\n        Model model;\n        if (isNew) {\n            // Duplicate name validation\n            LambdaQueryWrapper<Model> lqw = new LambdaQueryWrapper<Model>()\n                    .eq(Model::getName, request.getModelName())\n                    .eq(Model::getIsDeleted, 0);\n            if (spaceId != null) {\n                lqw.eq(Model::getSpaceId, spaceId);\n            } else {\n                lqw.eq(Model::getUid, request.getUid()).isNull(Model::getSpaceId);\n            }\n            Model exist = this.getOne(lqw);\n            if (exist != null) {\n                throw new BusinessException(ResponseEnum.MODEL_NAME_EXISTED);\n            }\n            model = new Model();\n            model.setUid(request.getUid());\n            model.setDomain(request.getDomain());\n            model.setCreateTime(new Date());\n        } else {\n            model =\n                    this.getOne(\n                            new LambdaQueryWrapper<Model>()\n                                    .eq(Model::getId, request.getId())\n                                    .eq(Model::getUid, request.getUid())\n                                    .eq(Model::getIsDeleted, 0));\n            if (model == null) {\n                throw new BusinessException(ResponseEnum.MODEL_NOT_EXIST);\n            }\n\n            // Handle workflow cleanup triggered by config deletion\n            List<Config> existConfigs =","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/model/ModelService.java#L395-L431","documentation":"MODEL_NAME_EXISTED is thrown by saveOrUpdateModel when creating a new model (no id in request) whose name already exists for the same owner/space scope. A LambdaQueryWrapper matches on uid (and spaceId when provided) plus the model name; a non-null hit means the name is taken and creation aborts.","triggerScenarios":"validateModel -> saveOrUpdateModel with a request lacking id but with modelName that already matches an existing model row for the same uid and spaceId (or uid with null spaceId for the personal scope).","commonSituations":"Trying to add a model with a name you already created in the same space; restoring/importing a model that duplicates an existing name; a renamed-then-recreated flow colliding with soft-deleted-looking duplicates (isDeleted=0 rows).","solutions":["Choose a different, unique model name within the space.","List existing models in the space first and reuse/update the existing model instead of creating a new one.","If you meant to update, include the model's id in the request so the update branch runs.","Check whether the duplicate is in the same spaceId vs personal (null spaceId) scope and move/rename accordingly."],"exampleFix":"// before\nPOST /model/save { \"modelName\": \"gpt4-main\" } // already exists in this space\n// after\nPOST /model/save { \"modelName\": \"gpt4-main-v2\" } // unique name","handlingStrategy":"try-catch","validationCode":"boolean nameTaken = modelService.listBySpace(spaceId, uid).stream().anyMatch(m -> m.getName().equals(request.getModelName()));\nif (nameTaken) throw new IllegalStateException(\"model name already used in this space\");","typeGuard":null,"tryCatchPattern":"try { modelService.validateModel(req); } catch (BusinessException e) { if (\"MODEL_NAME_EXISTED\".equals(e.getCode())) { suggestAlternativeName(req.getModelName()); } throw e; }","preventionTips":["Uniqueness-check names against the space's model list in the UI before submit.","Include the model id when the intent is update, not create.","Adopt naming conventions (suffixes) to avoid collisions in shared spaces."],"tags":["duplicate","uniqueness","model-management"],"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"}