{"record":{"id":"cfadc0cea3ef21bd","repo":"alibaba/nacos","slug":"agent-version-mediatype-must-be-agent-version-med","errorCode":null,"errorMessage":"Agent Version mediaType must be {AGENT_VERSION_MEDIA_TYPE}","messagePattern":"Agent Version mediaType must be (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/storage/AgentVersionStorageDescriptorSerializer.java","lineNumber":169,"sourceCode":"     */\n    public static void validate(AgentVersionStorageDescriptor descriptor) {\n        if (descriptor == null) {\n            throw new IllegalArgumentException(\"Agent Version storage descriptor must not be null\");\n        }\n        String provider = descriptor.getProvider();\n        if (provider == null || provider.length() > MAX_PROVIDER_LENGTH\n            || !PROVIDER_PATTERN.matcher(provider).matches()) {\n            throw new IllegalArgumentException(\"Invalid Agent Version storage provider\");\n        }\n        validateRequiredText(\"key\", descriptor.getKey(), MAX_KEY_LENGTH);\n        validateOptionalText(\"keyFormat\", descriptor.getKeyFormat(), MAX_FORMAT_LENGTH);\n        validateOptionalText(\"agentNameCodec\", descriptor.getAgentNameCodec(), MAX_FORMAT_LENGTH);\n        if (descriptor.getContentDigest() == null\n            || !DIGEST_PATTERN.matcher(descriptor.getContentDigest()).matches()) {\n            throw new IllegalArgumentException(\"Invalid Agent Version contentDigest\");\n        }\n        if (!AGENT_VERSION_MEDIA_TYPE.equals(descriptor.getMediaType())) {\n            throw new IllegalArgumentException(\"Agent Version mediaType must be \"\n                + AGENT_VERSION_MEDIA_TYPE);\n        }\n        if (!Integer.valueOf(SCHEMA_VERSION).equals(descriptor.getSchemaVersion())) {\n            throw new IllegalArgumentException(\"Agent Version storage schemaVersion must be \"\n                + SCHEMA_VERSION);\n        }\n        Long size = descriptor.getSize();\n        if (size == null || size < 0 || size > MAX_CONTENT_SIZE) {\n            throw new IllegalArgumentException(\n                \"Agent Version storage size must be between 0 and \" + MAX_CONTENT_SIZE);\n        }\n        if (NACOS_CONFIG_PROVIDER.equals(provider)) {\n            if (!NACOS_CONFIG_KEY_FORMAT.equals(descriptor.getKeyFormat())) {\n                throw new IllegalArgumentException(\"nacos_config keyFormat must be \"\n                    + NACOS_CONFIG_KEY_FORMAT);\n            }\n            if (!RAD_ASCII_AGENT_NAME_CODEC.equals(descriptor.getAgentNameCodec())) {\n                throw new IllegalArgumentException(\"nacos_config agentNameCodec must be \"","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/storage/AgentVersionStorageDescriptorSerializer.java#L151-L187","documentation":"The mediaType field must equal exactly 'application/vnd.nacos.agent-version+json' (AgentVersionStorageDescriptor.MEDIA_TYPE). Any other value, including null or generic 'application/json', is rejected. The media type pins the descriptor payload format.","triggerScenarios":"validate()/serialize() on a descriptor whose mediaType is null, \"application/json\", or any other string. Fires on a stale/corrupted row too.","commonSituations":"Hardcoding 'application/json'; leaving mediaType unset; a descriptor from an older Nacos version that used a different media type.","solutions":["Set mediaType to AgentVersionStorageDescriptor.MEDIA_TYPE","Use AgentVersionStorageService.buildDescriptor/buildReplacementDescriptor, which set it correctly","Re-publish the version to regenerate the descriptor"],"exampleFix":"// before\ndescriptor.setMediaType(\"application/json\");\n// after\ndescriptor.setMediaType(AgentVersionStorageDescriptor.MEDIA_TYPE);","handlingStrategy":"validation","validationCode":"if (!AgentVersionStorageDescriptor.MEDIA_TYPE.equals(descriptor.getMediaType())) {\n    descriptor.setMediaType(AgentVersionStorageDescriptor.MEDIA_TYPE);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use AgentVersionStorageService.buildDescriptor, which sets mediaType correctly","Reference the MEDIA_TYPE constant, never a hardcoded string"],"tags":["java","nacos","ai-agent","validation","media-type","storage-descriptor"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}