{"record":{"id":"65feed289b77cac7","repo":"alibaba/nacos","slug":"server-error-65feed","errorCode":"SERVER_ERROR","errorMessage":"Failed to update scope for {type}: {name}","messagePattern":"Failed to update scope for (.+?): (.+?)","errorType":"exception","errorClass":"NacosApiException","httpStatus":500,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java","lineNumber":1160,"sourceCode":"        if (labels == null || labels.isEmpty()) {\n            return;\n        }\n        labels.keySet().removeIf(label -> AiResourceConstants.LABEL_LATEST.equalsIgnoreCase(label));\n    }\n    \n    /**\n     * Update the scope of a resource (requireMeta + checkWritable + persist).\n     */\n    public void doUpdateScope(String namespaceId, String name, String type, String scope)\n        throws NacosException {\n        AiResource meta = requireMeta(namespaceId, name, type);\n        VisibilityHelper.checkWritableResource(meta);\n        boolean ok =\n            aiResourcePersistService.updateScope(namespaceId, name, type, scope.toUpperCase());\n        if (!ok) {\n            LOGGER.error(\"Failed to update scope for {} {}, namespace: {}, scope: {}\", type, name,\n                namespaceId, scope);\n            throw new NacosApiException(NacosException.SERVER_ERROR, ErrorCode.SERVER_ERROR,\n                \"Failed to update scope for \" + type + \": \" + name);\n        }\n        AiResourceTraceService.logSuccess(type, name, null, AiResourceTraceService.OP_UPDATE_SCOPE,\n            VisibilityHelper.resolveCurrentIdentity(), VisibilityHelper.resolveClientIp(),\n            \"scope=\" + scope);\n    }\n    \n    /**\n     * Toggle a single version's online/offline status, adjust meta onlineCnt and maintain\n     * service-managed labels.\n     *\n     * @return the version row if a status change occurred, or {@code null} if already in the target status\n     */\n    public AiResourceVersion toggleVersionOnlineStatus(String namespaceId, AiResource meta,\n        ResourceVersionInfo info, String version, boolean online) throws NacosException {\n        String name = meta.getName();\n        String type = meta.getType();\n        AiResourceVersion v =","sourceCodeStart":1142,"sourceCodeEnd":1178,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/resource/AiResourceManager.java#L1142-L1178","documentation":"Thrown by doUpdateScope when aiResourcePersistService.updateScope returns false, meaning the SQL update affected zero rows. This indicates the resource matched by (namespace, name, type) was not found at persist time, or a concurrent modification prevented the update. Maps to SERVER_ERROR (500).","triggerScenarios":"Update-scope API on a resource that does not exist (requireMeta passed but the row vanished before updateScope ran), or a persistence-layer bug/concurrent delete. The earlier requireMeta check passing then updateScope failing implies a race or store inconsistency.","commonSituations":"Resource deleted between the requireMeta read and the updateScope write; DB connectivity glitch causing a partial update; stale cache causing requireMeta to see a ghost row.","solutions":["Retry the operation after confirming the resource still exists.","Check server logs (LOGGER.error line records type/name/namespace/scope) for the exact failing tuple.","Investigate the persistence layer if the resource clearly exists but updateScope keeps returning false.","Ensure no concurrent delete is racing the scope update."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    manager.doUpdateScope(ns, name, type, scope);\n} catch (NacosApiException e) {\n    if (e.getErrCode() == NacosException.SERVER_ERROR) {\n        // re-check existence, then retry once; escalate if it persists\n    } else { throw e; }\n}","preventionTips":["Confirm the resource still exists immediately before updateScope.","Watch server logs for the recorded type/name/namespace/scope tuple on failure.","Investigate persistence-layer consistency if the error recurs for an existing resource."],"tags":["ai-registry","scope","persistence","server-error","concurrency"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}