{"record":{"id":"c4299e24e8d0e3d8","repo":"alibaba/nacos","slug":"agent-version-storage-size-must-be-between-0-and","errorCode":null,"errorMessage":"Agent Version storage size must be between 0 and {MAX_CONTENT_SIZE}","messagePattern":"Agent Version storage size must be between 0 and (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/com/alibaba/nacos/ai/service/agent/storage/AgentVersionStorageDescriptorSerializer.java","lineNumber":178,"sourceCode":"        }\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 \"\n                    + RAD_ASCII_AGENT_NAME_CODEC);\n            }\n        }\n    }\n    \n    private static void validateRequiredText(String field, String value, int maxLength) {\n        if (value == null || value.isEmpty() || value.length() > maxLength) {\n            throw new IllegalArgumentException(\"Invalid Agent Version storage \" + field);\n        }","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/ai/src/main/java/com/alibaba/nacos/ai/service/agent/storage/AgentVersionStorageDescriptorSerializer.java#L160-L196","documentation":"The size field is null, negative, or greater than 1048576 (MAX_CONTENT_SIZE, 1 MiB). The size must be a non-negative long within the 1 MiB cap and must match the actual persisted content byte length (which is re-verified in AgentVersionStorageService.load).","triggerScenarios":"validate()/serialize() on a descriptor whose size is null, -1, or > 1048576. Reached when content exceeds the 1 MiB limit, size is left unset, or the size no longer matches after a partial rewrite.","commonSituations":"Agent Version content larger than 1 MiB; size left null during construction; a rewrite that changed content length without updating size.","solutions":["Derive size from serializedContent.getSize() returned by AgentVersionContentSerializer","Reduce the Agent Version content below 1 MiB if it is too large","Ensure size matches the persisted byte length exactly (load() cross-checks it)"],"exampleFix":"// before\ndescriptor.setSize(null);\n// after\ndescriptor.setSize((long) serializedContent.getSize());","handlingStrategy":"validation","validationCode":"long size = serializedContent.getSize();\nif (size < 0 || size > AgentVersionContentSerializer.MAX_CONTENT_SIZE) {\n    throw new IllegalArgumentException(\"content size must be 0..\" + AgentVersionContentSerializer.MAX_CONTENT_SIZE);\n}\ndescriptor.setSize(size);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive size from AgentVersionContentSerializer's SerializedContent.getSize()","Enforce the 1 MiB content cap at the API boundary before serialization"],"tags":["java","nacos","ai-agent","validation","size-limit","storage-descriptor"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}