{"record":{"id":"b87c223755098a06","repo":"theonedev/onedev","slug":"unable-to-find-agent","errorCode":null,"errorMessage":"Unable to find agent: ","messagePattern":"Unable to find agent: ","errorType":"exception","errorClass":"EntityNotFoundException","httpStatus":404,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/web/resource/AgentLogResource.java","lineNumber":41,"sourceCode":"import io.onedev.server.service.AgentService;\nimport io.onedev.server.model.Agent;\nimport io.onedev.server.security.SecurityUtils;\n\npublic class AgentLogResource extends AbstractResource {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\tprivate static final String PARAM_AGENT = \"agent\";\n\t\n\t@Override\n\tprotected ResourceResponse newResourceResponse(Attributes attributes) {\n\t\tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\n\t\tString agentName = attributes.getParameters().get(PARAM_AGENT).toString();\n\t\tAgent agent = OneDev.getInstance(AgentService.class).findByName(agentName);\n\t\tif (agent == null)\n\t\t\tthrow new EntityNotFoundException(\"Unable to find agent: \" + agentName);\n\t\t\n\t\tif (!agent.isOnline())\n\t\t\tthrow new ExplicitException(\"Unable to read log: agent is offline\");\n\t\t\n\t\tResourceResponse response = new ResourceResponse();\n\t\tresponse.setContentType(MimeTypes.OCTET_STREAM);\n\t\t\n\t\tresponse.disableCaching();\n\t\t\n\t\ttry {\n\t\t\tresponse.setFileName(URLEncoder.encode(\"agent-log.txt\", StandardCharsets.UTF_8.name()));\n\t\t} catch (UnsupportedEncodingException e) {\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t\tLong agentId = agent.getId();\n\t\tresponse.setWriteCallback(new WriteCallback() {\n\n\t\t\t@Override","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/web/resource/AgentLogResource.java#L23-L59","documentation":"AgentLogResource resolves the requested agent by the 'agent' parameter via AgentService.findByName; if no agent with that name is registered, it throws EntityNotFoundException(\"Unable to find agent: \" + agentName). The server cannot locate any agent matching the supplied name.","triggerScenarios":"GET on the agent log resource with an 'agent' parameter that does not match any registered agent name (typo, renamed agent, agent unregistered/deleted from the server).","commonSituations":"Agent was renamed or removed in Admin > Agents but old URLs/scripts still reference the old name; hard-coded agent names in automation scripts after re-provisioning; case/space mismatch between the parameter and registered name.","solutions":["Check the exact agent name under Admin > Agents and correct the 'agent' parameter in the request/URL.","Re-register the agent if it was deleted from the server.","Update any scripts or bookmarks that reference the old agent name after a rename."],"exampleFix":"// before\ncurl https://onedev/~agentlog?agent=build-agent-1  // deleted\n\n// after: use current registered name\ncurl https://onedev/~agentlog?agent=build-agent-2","handlingStrategy":"validation","validationCode":"// Confirm the agent exists (and its exact name) before requesting logs\nAgent agent = OneDev.getInstance(AgentService.class).findByName(agentName);\nif (agent == null)\n    throw new IllegalArgumentException(\"Unknown agent: \" + agentName);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch agent names dynamically from Admin > Agents / API rather than hard-coding.","Update scripts when agents are renamed or removed.","Match names exactly, including case and whitespace."],"tags":["agent","not-found","resource"],"backgroundTag":"entity-not-found","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"}