alibaba/nacos · error · NacosException

Failed to delete legacy latest mirror for prompt: {promptKey

Error message

Failed to delete legacy latest mirror for prompt: {promptKey}

What it means

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.

Source

Thrown at ai/src/main/java/com/alibaba/nacos/ai/service/prompt/PromptOperationServiceImpl.java:484

        schedulePromptIndexMaintenance(namespaceId, promptKey);
    }
    
    private void schedulePromptIndexMaintenance(String namespaceId, String promptKey) {
        resourceIndexMaintenanceService.schedule(namespaceId, RESOURCE_TYPE_PROMPT, promptKey);
    }
    
    private void deleteLegacyLatestMirror(String namespaceId, String promptKey)
        throws NacosException {
        try {
            final String latestDataId = PromptVersionUtils.buildDataId(promptKey);
            configOperationService.deleteConfig(latestDataId, Constants.Prompt.PROMPT_GROUP,
                namespaceId, null, null,
                "nacos", null);
        } catch (Exception e) {
            if (e instanceof NacosException) {
                throw (NacosException) e;
            }
            throw new NacosException(NacosException.SERVER_ERROR,
                "Failed to delete legacy latest mirror for prompt: " + promptKey, e);
        }
    }
    
    @Override
    public PromptMetaInfo getPromptDetail(String namespaceId, String promptKey)
        throws NacosException {
        AiResource meta = requireMeta(namespaceId, promptKey);
        PromptVersionInfoPojo versionInfo = requireVersionInfo(meta);
        
        PromptMetaInfo detail = new PromptMetaInfo();
        detail.setPromptKey(promptKey);
        detail.setDescription(meta.getDesc());
        detail.setLatestVersion(
            versionInfo.getLabels() != null ? versionInfo.getLabels().get(LABEL_LATEST) : null);
        detail.setEditingVersion(versionInfo.getEditingVersion());
        detail.setReviewingVersion(versionInfo.getReviewingVersion());
        detail.setOnlineCnt(versionInfo.getOnlineCnt());

View on GitHub (pinned to 9b989acdf1)

Solutions

  1. Check the config service / storage backend health and retry the prompt deletion once healthy.
  2. Inspect the wrapped cause (the NacosException's cause) in logs for the real failure.
  3. If the legacy mirror is already gone or corrupt, remove the orphaned config row manually and retry.
  4. Upgrade/migrate away from the legacy mirror layout if it is no longer needed so this cleanup is skipped.

Example fix

// before
try {
    promptService.deletePrompt(ns, key); // legacy mirror delete fails -> 500
} catch (NacosException e) { ... }
// after: verify config backend, then retry; inspect cause
try {
    promptService.deletePrompt(ns, key);
} catch (NacosException e) {
    log.error("cause: {}", e.getCause()); // real failure
    if (configServiceHealthy()) { /* retry once */ }
}
Defensive patterns

Strategy: retry

Validate before calling

// Check config service health before deleting a prompt with a legacy mirror
if (hasLegacyMirror(ns, promptKey) && !configServiceHealthy()) {
    throw new IllegalStateException("Config service unavailable; retry later");
}
promptService.deletePrompt(ns, promptKey);

Try / catch

try {
    promptService.deletePrompt(ns, key);
} catch (NacosException e) {
    if (e.getErrCode() == NacosException.SERVER_ERROR
        && e.getErrMsg().contains("legacy latest mirror")) {
        log.error("mirror delete failed; cause=", e.getCause());
        // retry once the config backend is healthy
        if (awaitConfigHealthy()) { promptService.deletePrompt(ns, key); }
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/3f17c939ced6c870. Report an issue: GitHub.