{"record":{"id":"d5b3c7e7fd1195ef","repo":"alibaba/nacos","slug":"agent-version-agentname-does-not-match-request","errorCode":null,"errorMessage":"Agent Version agentName does not match request","messagePattern":"Agent Version agentName 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":1065,"sourceCode":"    }\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    \n    private void validateAgentUpdateInputs(Agent replacement) {\n        if (replacement == null) {\n            throw new IllegalArgumentException(\"Agent replacement must not be null\");","sourceCodeStart":1047,"sourceCodeEnd":1083,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/AgentPersistenceService.java#L1047-L1083","documentation":"When an AgentVersionDetail submitted for online creation carries a non-null agentName, that value must match the agentName argument passed to createOnlineVersion. This ensures the Version is linked to the correct Agent resource and prevents accidental cross-Agent Version creation.","triggerScenarios":"Calling createOnlineVersion(namespaceId, agentName, version, preferredLatest) where version.getAgentName() is non-null and differs from the agentName parameter. The toOnlineVersion converter normally leaves agentName null, so this fires only when a caller explicitly sets a mismatched agentName.","commonSituations":"A client renames an Agent and resubmits a Version detail that still carries the old agentName. A copy-paste error between Agent creation requests puts the wrong agentName inside the version body.","solutions":["Set version.setAgentName(null) before calling createOnlineVersion and let the server assign it.","Ensure version.getAgentName() exactly matches the agentName parameter (case-sensitive).","Strip server-populated identity fields from Version details before re-submitting."],"exampleFix":"// before — agentName carried over from a different Agent\nversion.setAgentName(\"old-agent\");\npersistenceService.createOnlineVersion(ns, \"new-agent\", version, null); // throws\n\n// after — let the server assign agentName\nversion.setAgentName(null);\npersistenceService.createOnlineVersion(ns, \"new-agent\", version, null);","handlingStrategy":"validation","validationCode":"if (version.getAgentName() != null && !agentName.equals(version.getAgentName())) {\n    throw new IllegalArgumentException(\"agentName mismatch: \" + agentName);\n}","typeGuard":"boolean agentNameConsistent(String agentName, AgentVersionDetail v) {\n    return v.getAgentName() == null || agentName.equals(v.getAgentName());\n}","tryCatchPattern":null,"preventionTips":["Do not set agentName inside the Version detail for online creation — let the server fill it.","Clear all identity fields (namespaceId, agentName) when reusing a Version detail from a read."],"tags":["agent","ai-registry","validation","agent-name","online-version"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}