{"record":{"id":"60d523bafd29a561","repo":"alibaba/nacos","slug":"invalid-namespaceid-namespaceid","errorCode":null,"errorMessage":"Invalid namespaceId: {namespaceId}","messagePattern":"Invalid namespaceId: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentValidationUtils.java","lineNumber":76,"sourceCode":"    private static final Pattern CONTENT_DIGEST_PATTERN = Pattern.compile(\"sha256:[0-9a-f]{64}\");\n    \n    private static final Pattern MEDIA_TYPE_PATTERN = Pattern.compile(\"[!-~]+/[!-~]+\");\n    \n    private static final String INTERNAL_ENDPOINT_METADATA_PREFIX = \"__nacos.agent.endpoint.\";\n    \n    private AgentValidationUtils() {\n    }\n    \n    /**\n     * Validate a namespace identifier.\n     *\n     * @param namespaceId namespace identifier\n     * @throws IllegalArgumentException when invalid\n     */\n    public static void validateNamespaceId(String namespaceId) {\n        if (namespaceId == null || namespaceId.length() > MAX_NAMESPACE_LENGTH\n            || !NAMESPACE_PATTERN.matcher(namespaceId).matches()) {\n            throw new IllegalArgumentException(\"Invalid namespaceId: \" + namespaceId);\n        }\n    }\n    \n    /**\n     * Validate an Agent name without rewriting it.\n     *\n     * @param agentName Agent name\n     * @throws IllegalArgumentException when invalid\n     */\n    public static void validateAgentName(String agentName) {\n        if (agentName == null || agentName.isEmpty()\n            || agentName.length() > MAX_AGENT_NAME_LENGTH) {\n            throw new IllegalArgumentException(\"Invalid agentName: \" + agentName);\n        }\n        boolean containsNonSpace = false;\n        for (int i = 0; i < agentName.length(); i++) {\n            char current = agentName.charAt(i);\n            if (current < 0x20 || current > 0x7E) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentValidationUtils.java#L58-L94","documentation":"Thrown by AgentValidationUtils.validateNamespaceId when the namespace identifier is null, longer than MAX_NAMESPACE_LENGTH (128 characters), or does not fully match the pattern [A-Za-z0-9_-]+. Namespace IDs are the tenant/scope identifier used across the Agent (and RAD) APIs and must be a compact token of letters, digits, underscore, and hyphen only — no slashes, spaces, dots, colons, or unicode. This is the single source of truth reused by both AgentValidationUtils and EndpointNaturalKey.","triggerScenarios":"Any Agent API call (publish/update/query) or runtime snapshot push whose namespaceId is null/empty/too-long/contains-illegal-chars. Also reached indirectly via EndpointNaturalKey.of which calls validateNamespaceId. Common bad values: 'public' is fine, but 'my ns', 'ns/sub', 'ns:dev', '', or a CJK namespace all fail (empty fails because the + quantifier requires at least one char).","commonSituations":"Using a human-readable namespace label with spaces instead of the machine ID; including a path separator thinking namespaces are hierarchical; an empty string from a form field; a default-namespace placeholder that slipped through; unicode team names.","solutions":["Use a compact token matching [A-Za-z0-9_-]+ and <= 128 chars (e.g. 'prod', 'team_foo', 'us-east-1').","Use the reserved 'public' namespace when you intend the default/shared scope.","Strip/replace illegal characters: spaces -> '-', drop slashes/colons/dots.","Validate with AgentValidationUtils.validateNamespaceId(id) before any Agent API call."],"exampleFix":"// before\nagent.setNamespaceId(\"my team/prod\"); // space + slash -> rejected\nagent.setNamespaceId(\"\");             // empty -> rejected\n// after\nagent.setNamespaceId(\"my-team-prod\");\n// or default scope:\nagent.setNamespaceId(\"public\");","handlingStrategy":"validation","validationCode":"import com.alibaba.nacos.api.ai.utils.AgentValidationUtils;\nAgentValidationUtils.validateNamespaceId(namespaceId); // throws 'Invalid namespaceId: ...'","typeGuard":"import java.util.regex.Pattern;\nprivate static final Pattern NS = Pattern.compile(\"[A-Za-z0-9_-]+\");\nstatic boolean validNamespaceId(String id) {\n    return id != null && id.length() <= 128 && NS.matcher(id).matches();\n}","tryCatchPattern":"try {\n    AgentValidationUtils.validateNamespaceId(namespaceId);\n} catch (IllegalArgumentException e) {\n    // sanitize: replace illegal chars, then retry, or fall back to \"public\"\n}","preventionTips":["Namespace IDs: [A-Za-z0-9_-]+, <= 128 chars, no slashes/spaces/dots/unicode.","Use 'public' for the default/shared scope.","Slugify human names into ASCII tokens before using as namespaceId."],"tags":["ai-agent","validation","namespace","format"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}