{"record":{"id":"fbe1298de8ebac10","repo":"alibaba/nacos","slug":"duplicate-tag-tag","errorCode":null,"errorMessage":"Duplicate tag: {tag}","messagePattern":"Duplicate tag: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java","lineNumber":369,"sourceCode":"            && !AiConstants.Agent.VERSION_STATUS_REVIEWED.equals(status)\n            && !AiConstants.Agent.VERSION_STATUS_ONLINE.equals(status)\n            && !AiConstants.Agent.VERSION_STATUS_OFFLINE.equals(status)) {\n            throw new IllegalArgumentException(\"Invalid Agent Version status: \" + status);\n        }\n    }\n    \n    private static void validateTags(List<String> tags) {\n        if (tags == null) {\n            return;\n        }\n        if (tags.size() > MAX_TAGS) {\n            throw new IllegalArgumentException(\"tags exceeds \" + MAX_TAGS + \" items\");\n        }\n        Set<String> uniqueTags = new HashSet<String>();\n        for (String tag : tags) {\n            validateRequiredLength(tag, MAX_TAG_LENGTH, \"tag\");\n            if (!uniqueTags.add(tag)) {\n                throw new IllegalArgumentException(\"Duplicate tag: \" + tag);\n            }\n        }\n    }\n    \n    private static void validateExtensions(Map<String, Object> extensions) {\n        if (extensions == null) {\n            return;\n        }\n        if (extensions.size() > MAX_EXTENSIONS) {\n            throw new IllegalArgumentException(\n                \"extensions exceeds \" + MAX_EXTENSIONS + \" entries\");\n        }\n        for (String key : extensions.keySet()) {\n            validateRequiredLength(key, MAX_EXTENSION_KEY_LENGTH, \"extension key\");\n        }\n    }\n    \n    private static void validateVersionInfo(AgentVersionInfo versionInfo) {","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/api/src/main/java/com/alibaba/nacos/api/ai/utils/AgentModelValidator.java#L351-L387","documentation":"Thrown by validateTags when the same tag string appears more than once in the Agent's tags list. Tags must be a set, not a list; duplicates would create ambiguous filter and index behavior, so the validator rejects them after enforcing per-tag length.","triggerScenarios":"Submitting a tags list that contains the same string twice (exact case match), e.g. [\"llm\",\"chatbot\",\"llm\"]. Concatenating tag sources without set normalization.","commonSituations":"Merging tags from multiple systems that independently tag the same concept; retrying an update where the server already appended a tag the client re-sends; case differences (LLM vs llm) will NOT trigger this since the check is exact-match, but downstream index collisions may still surprise you.","solutions":["Deduplicate the tags list before submission using a LinkedHashSet to preserve order.","Normalize tag casing and trimming before dedup if your source data is inconsistent.","Audit tag producers so each source owns a non-overlapping namespace."],"exampleFix":"// before\nagent.setTags(Arrays.asList(\"llm\", \"chatbot\", \"llm\"));\n// after\nagent.setTags(new ArrayList<>(new LinkedHashSet<>(Arrays.asList(\"llm\", \"chatbot\", \"llm\"))));","handlingStrategy":"validation","validationCode":"static List<String> dedupTags(List<String> tags) {\n    if (tags == null) return List.of();\n    return new ArrayList<>(new LinkedHashSet<>(tags));\n}","typeGuard":"static boolean tagsAreUnique(List<String> tags) {\n    return tags == null || new HashSet<>(tags).size() == tags.size();\n}","tryCatchPattern":"try {\n    AgentModelValidator.validateAgent(agent);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Duplicate tag\")) {\n        agent.setTags(new ArrayList<>(new LinkedHashSet<>(agent.getTags())));\n    }\n}","preventionTips":["Normalize tags into a LinkedHashSet as soon as they are collected.","Trim and lowercase tags before dedup if casing is not significant.","Audit tag-merging code paths that combine multiple sources."],"tags":["ai-agent","validation","uniqueness","illegal-argument"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}