{"record":{"id":"ccde2e6cf453581d","repo":"alibaba/nacos","slug":"invalid-agent-resource-status-status","errorCode":null,"errorMessage":"Invalid Agent resource status: {status}","messagePattern":"Invalid Agent resource status: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/model/agent/AgentAdminRequestUtils.java","lineNumber":43,"sourceCode":" * @author Nacos\n */\nfinal class AgentAdminRequestUtils {\n    \n    private AgentAdminRequestUtils() {\n    }\n    \n    static void validateIdentity(String agentName) {\n        AgentValidationUtils.validateAgentName(agentName);\n    }\n    \n    static void validateVersion(String version) {\n        AgentValidationUtils.validateVersion(version);\n    }\n    \n    static void validateWritableStatus(String status) {\n        if (!AiConstants.Agent.RESOURCE_STATUS_ENABLE.equals(status)\n            && !AiConstants.Agent.RESOURCE_STATUS_DISABLE.equals(status)) {\n            throw new IllegalArgumentException(\"Invalid Agent resource status: \" + status);\n        }\n    }\n    \n    static boolean isBlank(String value) {\n        if (value == null) {\n            return true;\n        }\n        for (int i = 0; i < value.length(); i++) {\n            if (!Character.isWhitespace(value.charAt(i))) {\n                return false;\n            }\n        }\n        return true;\n    }\n}\n","sourceCodeStart":25,"sourceCodeEnd":59,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/model/agent/AgentAdminRequestUtils.java#L25-L59","documentation":"AgentAdminRequestUtils.validateWritableStatus rejects any status string that is not exactly AiConstants.Agent.RESOURCE_STATUS_ENABLE or RESOURCE_STATUS_DISABLE. This is an XOR check on the two allowed writable status values for Agent resources.","triggerScenarios":"Passing a status like 'ENABLED', 'enabled', 'on', 'off', '1', '0', or any arbitrary string to a draft/status update request that calls validateWritableStatus internally. Case sensitivity matters: only the exact constant values are accepted.","commonSituations":"Frontend or API client sends 'enabled' (lowercase) instead of the canonical constant. A migration script uses different status vocabulary. Misreading the API docs and guessing status values.","solutions":["Use AiConstants.Agent.RESOURCE_STATUS_ENABLE and RESOURCE_STATUS_DISABLE constants directly instead of hardcoding strings.","Map incoming user-facing values to the canonical constants before building the request.","Check the exact constant values in AiConstants.Agent if unsure of casing."],"exampleFix":"// before\nrequest.setStatus(\"enabled\"); // wrong casing\n\n// after\nimport com.alibaba.nacos.api.ai.constant.AiConstants;\nrequest.setStatus(AiConstants.Agent.RESOURCE_STATUS_ENABLE);","handlingStrategy":"validation","validationCode":"private static final Set<String> VALID_STATUSES = Set.of(\n    AiConstants.Agent.RESOURCE_STATUS_ENABLE,\n    AiConstants.Agent.RESOURCE_STATUS_DISABLE);\n\nif (!VALID_STATUSES.contains(status)) {\n    throw new IllegalArgumentException(\n        \"Status must be ENABLE or DISABLE, got: \" + status);\n}","typeGuard":"public static boolean isValidAgentStatus(String status) {\n    return AiConstants.Agent.RESOURCE_STATUS_ENABLE.equals(status)\n        || AiConstants.Agent.RESOURCE_STATUS_DISABLE.equals(status);\n}","tryCatchPattern":"try {\n    request.validate();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Invalid Agent resource status\")) {\n        // map to canonical status or return 400 to caller\n        return ResponseEntity.badRequest().body(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Always use AiConstants.Agent constants instead of string literals.","Validate at the API boundary before constructing request objects.","Document the exact accepted status values in your API contract."],"tags":["agent-admin","validation","status","ai-constants"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}