{"record":{"id":"57d45aaa35fa0702","repo":"theonedev/onedev","slug":"token-already-used-by-another-agent","errorCode":null,"errorMessage":"Token already used by another agent","messagePattern":"Token already used by another agent","errorType":"validation","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/service/impl/DefaultAgentService.java","lineNumber":206,"sourceCode":"\t\t\tagent.setName(data.getName());\n\t\t\tagent.setCpuCount(data.getCpus());\n\t\t\tagent.setIpAddress(data.getIpAddress());\n\n\t\t\tAgentLastUsedDate lastUsedDate = new AgentLastUsedDate();\n\t\t\tagent.setLastUsedDate(lastUsedDate);\n\t\t\tdao.persist(lastUsedDate);\n\t\t\tdao.persist(agent);\n\t\t\t\n\t\t\tfor (Map.Entry<String, String> entry: data.getAttributes().entrySet()) {\n\t\t\t\tAgentAttribute attribute = new AgentAttribute();\n\t\t\t\tattribute.setAgent(agent);\n\t\t\t\tattribute.setName(entry.getKey());\n\t\t\t\tattribute.setValue(entry.getValue());\n\t\t\t\tattributeManager.create(attribute);\n\t\t\t\tagent.getAttributes().add(attribute);\n\t\t\t}\n\t\t} else if (agentSessions.containsKey(agent.getId())) {\n\t\t\tthrow new ExplicitException(\"Token already used by another agent\");\n\t\t} else {\n\t\t\tagent.setName(data.getName());\n\t\t\tagent.setOsName(data.getOsInfo().getOsName());\n\t\t\tagent.setOsVersion(data.getOsInfo().getOsVersion());\n\t\t\tagent.setOsArch(data.getOsInfo().getOsArch());\n\t\t\tagent.setIpAddress(data.getIpAddress());\n\t\t\tagent.setCpuCount(data.getCpus());\n\t\t\tdao.persist(agent);\n\t\t\tattributeManager.syncAttributes(agent, data.getAttributes());\n\t\t}\n\n\t\tagentServers.put(agent.getId(), clusterService.getLocalServerAddress());\n\t\tSession prevSession = agentSessions.put(agent.getId(), session);\n\t\tif (prevSession != null) {\n\t\t\ttry {\n\t\t\t\tprevSession.disconnect();\n\t\t\t} catch (IOException ignored) {\n\t\t\t}","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/service/impl/DefaultAgentService.java#L188-L224","documentation":"When an agent connects, its token is used to identify a unique agent; if the token is already registered to a different agent record, the connection is refused to prevent two agents sharing one identity.","triggerScenarios":"Thrown at server-core/src/main/java/io/onedev/server/service/impl/DefaultAgentService.java:206 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Regenerate a distinct token for this agent and update the agent's config.","Check for cloned agent containers/VMs reusing the same token."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}