{"record":{"id":"3f17c939ced6c870","repo":"alibaba/nacos","slug":"failed-to-delete-legacy-latest-mirror-for-prompt","errorCode":null,"errorMessage":"Failed to delete legacy latest mirror for prompt: {promptKey}","messagePattern":"Failed to delete legacy latest mirror for prompt: (.+?)","errorType":"exception","errorClass":"NacosException","httpStatus":500,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java","lineNumber":484,"sourceCode":"        schedulePromptIndexMaintenance(namespaceId, promptKey);\n    }\n    \n    private void schedulePromptIndexMaintenance(String namespaceId, String promptKey) {\n        resourceIndexMaintenanceService.schedule(namespaceId, RESOURCE_TYPE_PROMPT, promptKey);\n    }\n    \n    private void deleteLegacyLatestMirror(String namespaceId, String promptKey)\n        throws NacosException {\n        try {\n            final String latestDataId = PromptVersionUtils.buildDataId(promptKey);\n            configOperationService.deleteConfig(latestDataId, Constants.Prompt.PROMPT_GROUP,\n                namespaceId, null, null,\n                \"nacos\", null);\n        } catch (Exception e) {\n            if (e instanceof NacosException) {\n                throw (NacosException) e;\n            }\n            throw new NacosException(NacosException.SERVER_ERROR,\n                \"Failed to delete legacy latest mirror for prompt: \" + promptKey, e);\n        }\n    }\n    \n    @Override\n    public PromptMetaInfo getPromptDetail(String namespaceId, String promptKey)\n        throws NacosException {\n        AiResource meta = requireMeta(namespaceId, promptKey);\n        PromptVersionInfoPojo versionInfo = requireVersionInfo(meta);\n        \n        PromptMetaInfo detail = new PromptMetaInfo();\n        detail.setPromptKey(promptKey);\n        detail.setDescription(meta.getDesc());\n        detail.setLatestVersion(\n            versionInfo.getLabels() != null ? versionInfo.getLabels().get(LABEL_LATEST) : null);\n        detail.setEditingVersion(versionInfo.getEditingVersion());\n        detail.setReviewingVersion(versionInfo.getReviewingVersion());\n        detail.setOnlineCnt(versionInfo.getOnlineCnt());","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java#L466-L502","documentation":"Thrown by PromptOperationServiceImpl.deleteLegacyLatestMirror when deleting the legacy 'latest mirror' config (nacos-ai-prompt group) via configOperationService.deleteConfig fails with a non-NacosException. The legacy mirror is an older storage layout compatibility artifact; failure to delete it during prompt deletion is wrapped as a SERVER_ERROR (HTTP 500). If the underlying cause is itself a NacosException it is rethrown unwrapped.","triggerScenarios":"Deleting a prompt triggers cleanup of its legacy latest-mirror config, and the underlying config delete throws an unexpected runtime/storage exception (not a NacosException).","commonSituations":"Config service backend (DB or filesystem) unreachable or throwing during delete; storage plugin error; serialization or null pointer inside the config delete path; partial outage while deleting a prompt that has a legacy mirror.","solutions":["Check the config service / storage backend health and retry the prompt deletion once healthy.","Inspect the wrapped cause (the NacosException's cause) in logs for the real failure.","If the legacy mirror is already gone or corrupt, remove the orphaned config row manually and retry.","Upgrade/migrate away from the legacy mirror layout if it is no longer needed so this cleanup is skipped."],"exampleFix":"// before\ntry {\n    promptService.deletePrompt(ns, key); // legacy mirror delete fails -> 500\n} catch (NacosException e) { ... }\n// after: verify config backend, then retry; inspect cause\ntry {\n    promptService.deletePrompt(ns, key);\n} catch (NacosException e) {\n    log.error(\"cause: {}\", e.getCause()); // real failure\n    if (configServiceHealthy()) { /* retry once */ }\n}","handlingStrategy":"retry","validationCode":"// Check config service health before deleting a prompt with a legacy mirror\nif (hasLegacyMirror(ns, promptKey) && !configServiceHealthy()) {\n    throw new IllegalStateException(\"Config service unavailable; retry later\");\n}\npromptService.deletePrompt(ns, promptKey);","typeGuard":null,"tryCatchPattern":"try {\n    promptService.deletePrompt(ns, key);\n} catch (NacosException e) {\n    if (e.getErrCode() == NacosException.SERVER_ERROR\n        && e.getErrMsg().contains(\"legacy latest mirror\")) {\n        log.error(\"mirror delete failed; cause=\", e.getCause());\n        // retry once the config backend is healthy\n        if (awaitConfigHealthy()) { promptService.deletePrompt(ns, key); }\n    } else { throw e; }\n}","preventionTips":["Monitor config/storage backend health and avoid prompt deletion during outages.","Inspect the wrapped cause in logs to find the real storage failure.","Migrate away from the legacy mirror layout so cleanup is not triggered.","Idempotently retry deletion after backend recovery."],"tags":["prompt","server-error","storage","legacy","delete","config-service","nacos-ai"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}