{"record":{"id":"1fd5af451f5c422b","repo":"alibaba/spring-ai-alibaba","slug":"id-1fd5af","errorCode":null,"errorMessage":"重复的模型 id: ","messagePattern":"重复的模型 id: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java","lineNumber":132,"sourceCode":"    private void validateYamlModel(YamlModel m, Set<Long> ids, Set<String> names) {\n        if (m.id == null) {\n            throw new IllegalArgumentException(\"模型缺少 id\");\n        }\n        if (m.name == null || m.name.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 name\");\n        }\n        if (m.provider == null || m.provider.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 provider\");\n        }\n        if (m.modelName == null || m.modelName.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 modelName\");\n        }\n        //        if (m.baseUrl == null || m.baseUrl.isBlank()) throw new IllegalArgumentException(\"模型缺少 baseUrl\");\n        if (m.apiKey == null || m.apiKey.isBlank()) {\n            throw new IllegalArgumentException(\"模型缺少 apiKey\");\n        }\n        if (!ids.add(m.id)) {\n            throw new IllegalArgumentException(\"重复的模型 id: \" + m.id);\n        }\n        if (!names.add(m.name)) {\n            throw new IllegalArgumentException(\"重复的模型 name: \" + m.name);\n        }\n        if (m.status == null) {\n            m.status = 1;\n        }\n    }\n    \n    private ModelConfigDO toEntity(YamlModel m) {\n        ModelConfigDO.ModelConfigDOBuilder b = ModelConfigDO.builder().id(m.id).name(m.name)\n                .provider(m.provider.toLowerCase()).modelName(m.modelName).baseUrl(m.baseUrl)\n                .apiKey(environment != null ? environment.resolvePlaceholders(m.apiKey) : m.apiKey).status(m.status)\n                .createTime(LocalDateTime.now()).updateTime(LocalDateTime.now());\n        \n        if (m.defaultParameters != null) {\n            try {\n                b.defaultParameters(new ObjectMapper().writeValueAsString(m.defaultParameters));","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/repository/impl/FileModelConfigRepository.java#L114-L150","documentation":"validateYamlModel enforces that every model entry in the YAML file has a unique id, using an ids Set: if Set.add(m.id) returns false, the id was already used and this IllegalArgumentException is thrown. Duplicate ids would make id-based lookups (findById) ambiguous, so loading is aborted.","triggerScenarios":"Calling loadFromFile when two or more model entries in the YAML share the same id value.","commonSituations":"Copy-pasting an existing model block to add a new model and forgetting to change the id; merging config files from two environments; a bad manual edit or a file watcher reload picking up a partially merged file.","solutions":["Open the models YAML and give each entry a distinct numeric id","Search the file for the duplicated id reported in the message and rename/remove one occurrence","If generating entries programmatically, ensure the id generator/increment is applied per entry","Restart or trigger reload after fixing so startWatchService picks up the corrected file"],"exampleFix":"// before (models.yml)\nmodels:\n  - id: 1\n    name: qwen-max\n  - id: 1\n    name: deepseek-v3\n// after\nmodels:\n  - id: 1\n    name: qwen-max\n  - id: 2\n    name: deepseek-v3","handlingStrategy":"validation","validationCode":"// Java: pre-validate ids before writing the YAML\nSet<Object> seen = new HashSet<>();\nfor (var m : models) {\n    if (!seen.add(m.getId())) {\n        throw new IllegalStateException(\"Duplicate model id in config: \" + m.getId());\n    }\n}","typeGuard":"boolean isUniqueId(m, Set<Object> seen) { return m != null && m.getId() != null && seen.add(m.getId()); }","tryCatchPattern":"try {\n    repository.loadFromFile(path);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"重复的模型 id\")) {\n        log.error(\"Fix duplicate model id in {}: {}\", path, e.getMessage());\n    }\n}","preventionTips":["Generate ids programmatically with an auto-increment or UUID instead of hand-editing","When copy-pasting model blocks, always update id first","Lint the models YAML in CI for duplicate ids/names before deployment"],"tags":["configuration","duplicate","yaml","unique-constraint"],"backgroundTag":"invalid-config-value","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}