{"record":{"id":"721cb1f58c0c1611","repo":"alibaba/nacos","slug":"agent-version-namespaceid-does-not-match-request","errorCode":null,"errorMessage":"Agent Version namespaceId does not match request","messagePattern":"Agent Version namespaceId does not match request","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPersistenceService.java","lineNumber":1062,"sourceCode":"            && !expectedStatus.equals(initialVersion.getStatus())) {\n            throw new IllegalArgumentException(\"initialVersion status must be \" + expectedStatus);\n        }\n    }\n    \n    private void validateOnlineVersionInputs(String namespaceId, String agentName,\n        AgentVersionDetail version, String preferredLatest) {\n        AgentValidationUtils.validateNamespaceId(namespaceId);\n        AgentValidationUtils.validateAgentName(agentName);\n        if (version == null) {\n            throw new IllegalArgumentException(\"Agent Version must not be null\");\n        }\n        AgentValidationUtils.validateVersion(version.getVersion());\n        if (version.getCallInterfaces() == null) {\n            throw new IllegalArgumentException(\"Online Agent Version must contain callInterfaces\");\n        }\n        if (version.getNamespaceId() != null\n            && !namespaceId.equals(version.getNamespaceId())) {\n            throw new IllegalArgumentException(\"Agent Version namespaceId does not match request\");\n        }\n        if (version.getAgentName() != null && !agentName.equals(version.getAgentName())) {\n            throw new IllegalArgumentException(\"Agent Version agentName does not match request\");\n        }\n        if (version.getStatus() != null\n            && !AiConstants.Agent.VERSION_STATUS_ONLINE.equals(version.getStatus())) {\n            throw new IllegalArgumentException(\"Agent Version status must be online\");\n        }\n        if (version.getContentDigest() != null || version.getCreateTime() != null\n            || version.getUpdateTime() != null) {\n            throw new IllegalArgumentException(\n                \"Agent Version must not contain read-only projection fields\");\n        }\n        if (preferredLatest != null && !version.getVersion().equals(preferredLatest)) {\n            throw new IllegalArgumentException(\"preferredLatest must target the created Version\");\n        }\n    }\n    ","sourceCodeStart":1044,"sourceCodeEnd":1080,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPersistenceService.java#L1044-L1080","documentation":"When an AgentVersionDetail submitted for online creation carries a non-null namespaceId, that value must match the namespaceId argument passed to createOnlineVersion. This prevents cross-namespace data leakage by ensuring the Version is authored into the namespace the caller is authorized for.","triggerScenarios":"Calling createOnlineVersion(namespaceId, agentName, version, preferredLatest) where version.getNamespaceId() is non-null and differs from the namespaceId parameter. The toOnlineVersion converter normally leaves namespaceId null (server fills it), so this fires only if a caller explicitly sets a mismatched namespaceId on the Version detail.","commonSituations":"A client copies a Version detail from one namespace and re-submits it in another without clearing namespaceId. A migration or import tool preserves the source namespaceId instead of letting the server assign it.","solutions":["Set version.setNamespaceId(null) before calling createOnlineVersion and let the server assign it.","Ensure version.getNamespaceId() equals the namespaceId parameter exactly (case-sensitive).","Do not reuse a Version detail read from a GET response without clearing server-populated fields."],"exampleFix":"// before — namespaceId carried over from a different context\nversion.setNamespaceId(\"staging\");\npersistenceService.createOnlineVersion(\"public\", name, version, null); // throws\n\n// after — let the server assign namespaceId\nversion.setNamespaceId(null);\npersistenceService.createOnlineVersion(\"public\", name, version, null);","handlingStrategy":"validation","validationCode":"if (version.getNamespaceId() != null && !namespaceId.equals(version.getNamespaceId())) {\n    throw new IllegalArgumentException(\"namespaceId mismatch: \" + namespaceId + \" vs \" + version.getNamespaceId());\n}","typeGuard":"boolean namespaceConsistent(String ns, AgentVersionDetail v) {\n    return v.getNamespaceId() == null || ns.equals(v.getNamespaceId());\n}","tryCatchPattern":null,"preventionTips":["Never reuse a Version detail from a GET response for a create call without clearing namespaceId.","Let the server assign namespaceId — leave it null on write payloads.","Treat namespaceId as a path/resource-identity field, not a writable body field."],"tags":["agent","ai-registry","validation","namespace","online-version"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}