{"record":{"id":"38085beb148a9325","repo":"alibaba/nacos","slug":"20004","errorCode":"20004","errorMessage":"Base version not found: {basedOnVersion}","messagePattern":"Base version not found: (.+?)","errorType":"exception","errorClass":"NacosApiException","httpStatus":404,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java","lineNumber":180,"sourceCode":"            AiResourceTraceService.logSuccess(RESOURCE_TYPE_PROMPT, promptKey, version,\n                AiResourceTraceService.OP_CREATE_DRAFT, VisibilityHelper.resolveCurrentIdentity(),\n                VisibilityHelper.resolveClientIp());\n            \n            return version;\n        }\n        \n        // Existing prompt\n        VisibilityHelper.checkWritableResource(meta);\n        PromptVersionInfoPojo info = requireVersionInfo(meta);\n        ResourceVersionInfo resourceInfo = toResourceVersionInfo(info);\n        AiResourceManager.ensureNoWorkingVersion(resourceInfo, \"create draft\");\n        \n        if (StringUtils.isNotBlank(basedOnVersion)) {\n            // Fork from existing version\n            AiResourceVersion baseRow = resourceManager.findVersion(namespaceId, promptKey,\n                RESOURCE_TYPE_PROMPT, basedOnVersion);\n            if (baseRow == null) {\n                throw new NacosApiException(NacosException.NOT_FOUND, ErrorCode.RESOURCE_NOT_FOUND,\n                    \"Base version not found: \" + basedOnVersion);\n            }\n            PromptVersionInfo baseContent = loadPromptFromStorage(namespaceId, promptKey,\n                basedOnVersion, baseRow.getStorage());\n            String newVersion = StringUtils.isBlank(targetVersion)\n                ? incrementVersion(basedOnVersion) : targetVersion;\n            validateVersion(newVersion);\n            checkVersionNotExists(namespaceId, promptKey, newVersion);\n            \n            String storageJson = writePromptToStorage(namespaceId, promptKey, newVersion,\n                baseContent.getTemplate(), baseContent.getVariables(), null);\n            \n            String currentUser = VisibilityHelper.resolveCurrentIdentity();\n            resourceManager.insertVersionRow(namespaceId, promptKey, RESOURCE_TYPE_PROMPT,\n                StringUtils.isBlank(currentUser) ? DEFAULT_AUTHOR : currentUser,\n                VERSION_STATUS_DRAFT, newVersion, commitMsg, storageJson);\n            \n            resourceManager.markEditingVersionCas(namespaceId, meta, resourceInfo, newVersion,","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java#L162-L198","documentation":"Thrown by PromptOperationServiceImpl.createDraft when forking (basedOnVersion supplied) but resourceManager.findVersion returns null for that version — the base version to fork from does not exist for this prompt. Reported as RESOURCE_NOT_FOUND (HTTP 404). Note: listing shows code=20004 which is the RESOURCE_NOT_FOUND numeric code.","triggerScenarios":"createDraft with a basedOnVersion that was never published, was deleted, or is mistyped for the given promptKey.","commonSituations":"Stale version reference after a rollback; cross-environment copy where the source version is absent; typo in basedOnVersion; race where the version was deleted between a list and the fork.","solutions":["List the prompt's versions and use an existing one as basedOnVersion.","Verify the version string matches exactly (case, no whitespace).","If the base was deleted, fork from the latest remaining published version.","If you want a fresh draft from scratch, omit basedOnVersion and supply a template instead."],"exampleFix":"// before\npromptService.createDraft(ns, key, \"9.9.9\", null, ...); // base not found\n// after\nList<String> versions = listPromptVersions(ns, key);\nString base = versions.isEmpty() ? null : versions.get(versions.size() - 1);\npromptService.createDraft(ns, key, base, null, ...);","handlingStrategy":"validation","validationCode":"// Confirm basedOnVersion exists before forking\nif (basedOnVersion != null && !basedOnVersion.isBlank()) {\n    List<String> versions = promptService.listVersions(ns, promptKey);\n    if (!versions.contains(basedOnVersion)) {\n        throw new IllegalArgumentException(\"Unknown base version: \" + basedOnVersion);\n    }\n}\npromptService.createDraft(ns, promptKey, basedOn, target, template, vars, msg, desc, tags);","typeGuard":null,"tryCatchPattern":"try {\n    promptService.createDraft(ns, key, basedOn, target, template, vars, msg, desc, tags);\n} catch (NacosApiException e) {\n    if (e.getErrCode() == ErrorCode.RESOURCE_NOT_FOUND.getCode()\n        && e.getErrMsg().contains(\"Base version not found\")) {\n        // fork from the latest existing version instead\n        basedOn = listVersions(ns, key).stream().reduce((a, b) -> b).orElse(null);\n        promptService.createDraft(ns, key, basedOn, target, template, vars, msg, desc, tags);\n    } else { throw e; }\n}","preventionTips":["Populate basedOnVersion only from server-returned version lists.","Refresh the version list before forking to avoid stale references.","Scope version lookups by namespaceId."],"tags":["prompt","resource-not-found","version","fork","nacos-ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}