{"record":{"id":"0025c491540b9180","repo":"alibaba/nacos","slug":"20005","errorCode":"20005","errorMessage":"Prompt version already exists: {version}","messagePattern":"Prompt version already exists: (.+?)","errorType":"exception","errorClass":"NacosApiException","httpStatus":409,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java","lineNumber":969,"sourceCode":"            if (page == null || page.getPageItems() == null || page.getPageItems().isEmpty()) {\n                break;\n            }\n            all.addAll(page.getPageItems());\n            if (page.getPageItems().size() < pageSize) {\n                break;\n            }\n            pageNo++;\n        }\n        return all;\n    }\n    \n    private void checkVersionNotExists(String namespaceId, String promptKey, String version)\n        throws NacosException {\n        AiResourceVersion existing =\n            resourceManager.findVersion(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,\n                version);\n        if (existing != null) {\n            throw new NacosApiException(NacosException.CONFLICT, ErrorCode.RESOURCE_CONFLICT,\n                \"Prompt version already exists: \" + version);\n        }\n    }\n    \n    private String resolveNextVersion(String namespaceId, String promptKey) {\n        List<AiResourceVersion> allVersions = loadAllVersionRows(namespaceId, promptKey);\n        if (allVersions.isEmpty()) {\n            return DEFAULT_INITIAL_VERSION;\n        }\n        String maxVersion = null;\n        for (AiResourceVersion v : allVersions) {\n            if (v == null || !PromptVersionUtils.isValidVersion(v.getVersion())) {\n                continue;\n            }\n            if (maxVersion == null\n                || PromptVersionUtils.compareVersion(v.getVersion(), maxVersion) > 0) {\n                maxVersion = v.getVersion();\n            }","sourceCodeStart":951,"sourceCodeEnd":987,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java#L951-L987","documentation":"Thrown by checkVersionNotExists when resourceManager.findVersion finds an existing row for the given version. Version names must be unique within a prompt. HTTP 409 RESOURCE_CONFLICT (code 20005). Called during createDraft and fork-from-version flows.","triggerScenarios":"Calling createDraft with a targetVersion that already exists for this prompt; forking from an existing version and specifying a targetVersion that collides with a previously created version.","commonSituations":"Re-deploying a CI pipeline that hardcodes the same target version; forking without checking existing versions; two concurrent draft creations racing for the same version string.","solutions":["Choose a different, incrementally higher version number (e.g. bump the patch segment).","Omit targetVersion entirely to let resolveNextVersion auto-assign the next available version.","List existing versions via getPromptDetail before creating a draft to pick a non-conflicting version."],"exampleFix":"// before\nservice.createDraft(ns, key, null, \"1.0.0\", template, vars, null); // 1.0.0 exists\n\n// after: let server pick next version\nservice.createDraft(ns, key, null, null, template, vars, null); // auto 1.0.1\n// or specify explicitly\nservice.createDraft(ns, key, null, \"1.0.1\", template, vars, null);","handlingStrategy":"validation","validationCode":"// Check for existing versions before creating a draft\nPromptMetaInfo meta = service.getPromptDetail(ns, key);\nif (meta.getVersions().contains(targetVersion)) {\n    // pick a different version or omit targetVersion for auto-increment\n    return;\n}","typeGuard":"boolean versionIsFree = !service.getPromptDetail(ns, key).getVersions().contains(targetVersion);","tryCatchPattern":"try {\n    service.createDraft(ns, key, basedOn, targetVersion, template, vars, msg);\n} catch (NacosApiException e) {\n    if (e.getErrCode() == NacosException.CONFLICT) {\n        // version taken — bump and retry\n    }\n    throw e;\n}","preventionTips":["Omit targetVersion to let resolveNextVersion auto-assign the next available version.","In CI pipelines, compute the next version dynamically rather than hardcoding.","When forking, list existing versions first and choose a non-conflicting target."],"tags":["prompt","conflict","ai-registry","version","duplicate"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}