{"record":{"id":"a231a06e12254780","repo":"alibaba/nacos","slug":"20005-a231a0","errorCode":"20005","errorMessage":"Meta update conflict, retry","messagePattern":"Meta update conflict, retry","errorType":"exception","errorClass":"NacosApiException","httpStatus":409,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java","lineNumber":155,"sourceCode":"            if (latest == null || latest.getMetaVersion() == null) {\n                return CasResult.META_LOST;\n            }\n            expected = latest.getMetaVersion();\n            onConflictRefresh.accept(newValue, latest);\n        }\n        return CasResult.MAX_RETRIES;\n    }\n    \n    /**\n     * Translate a non-SUCCESS CasResult into the appropriate exception for strict callers.\n     */\n    private void handleStrictCasResult(CasResult result) throws NacosException {\n        if (result == CasResult.META_LOST) {\n            throw new NacosApiException(NacosException.SERVER_ERROR, ErrorCode.SERVER_ERROR,\n                \"Meta cas failed\");\n        }\n        if (result == CasResult.MAX_RETRIES) {\n            throw new NacosApiException(NacosException.CONFLICT, ErrorCode.RESOURCE_CONFLICT,\n                \"Meta update conflict, retry\");\n        }\n    }\n    \n    /**\n     * CAS-update the versionInfo field of a resource meta row.\n     */\n    public void updateVersionInfoCas(String namespaceId, AiResource meta, ResourceVersionInfo info)\n        throws NacosException {\n        if (meta == null || meta.getMetaVersion() == null) {\n            throw new NacosApiException(NacosException.SERVER_ERROR, ErrorCode.SERVER_ERROR,\n                \"Meta version missing\");\n        }\n        AiResource newValue = buildVersionInfoUpdateValue(meta, info);\n        CasResult result =\n            doCasLoop(namespaceId, meta.getName(), meta.getType(), meta.getMetaVersion(), newValue,\n                (nv, latest) -> {\n                    nv.setStatus(latest.getStatus());","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java#L137-L173","documentation":"Thrown by handleStrictCasResult when doCasLoop returns CasResult.MAX_RETRIES — all MAX_WORKING_VERSION_RETRY (3) attempts to updateMetaCas failed due to continuous version conflicts. HTTP 409 RESOURCE_CONFLICT (code 20005). This means another writer updated the same resource meta on every retry attempt.","triggerScenarios":"High-concurrency writes to the same resource meta row: multiple requests simultaneously updating versionInfo or bizTags. Each failed CAS triggers a re-read and retry, but if 3 consecutive attempts all lose the race, this exception fires.","commonSituations":"Burst of concurrent publish/label/draft operations on the same prompt or agent; a batch job updating many versions of one resource in parallel; distributed clients racing on the same resource.","solutions":["Reduce write concurrency on the same resource — serialize or throttle updates.","Retry the entire operation with backoff after catching the CONFLICT exception.","Split large batch updates into smaller sequential operations.","If the workload is inherently concurrent, consider increasing MAX_WORKING_VERSION_RETRY (requires code change and testing)."],"exampleFix":"// before: unguarded concurrent update\nresourceManager.updateVersionInfoCas(ns, meta, info);\n\n// after: retry with backoff on conflict\nfor (int attempt = 0; attempt < 5; attempt++) {\n    try {\n        AiResource fresh = resourceManager.requireMeta(ns, name, type);\n        resourceManager.updateVersionInfoCas(ns, fresh, info);\n        break;\n    } catch (NacosApiException e) {\n        if (e.getErrCode() != NacosException.CONFLICT || attempt == 4) throw e;\n        Thread.sleep(100L * (attempt + 1));\n    }\n}","handlingStrategy":"retry","validationCode":"// Pre-check: reduce concurrency on the target resource before updating\n// (no code-level pre-check can prevent this — it requires workload design)","typeGuard":null,"tryCatchPattern":"for (int attempt = 0; attempt < 5; attempt++) {\n    try {\n        AiResource fresh = resourceManager.requireMeta(ns, name, type);\n        resourceManager.updateBizTagsCas(ns, fresh, tags);\n        break;\n    } catch (NacosApiException e) {\n        if (e.getErrCode() == NacosException.CONFLICT && attempt < 4) {\n            Thread.sleep(100L * (attempt + 1));\n            continue;\n        }\n        throw e;\n    }\n}","preventionTips":["Serialize or throttle concurrent writes to the same resource meta row.","Batch multiple field changes into a single CAS update rather than many small ones.","Monitor CAS contention metrics and scale horizontally (more resources) or reduce write frequency."],"tags":["ai-registry","conflict","cas","concurrency","retry"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}