{"record":{"id":"48bee4f6c4d7829a","repo":"theonedev/onedev","slug":"allocated-agent-not-connected-to-current-server-p","errorCode":null,"errorMessage":"Allocated agent not connected to current server, please retry later","messagePattern":"Allocated agent not connected to current server, please retry later","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/agent/AgentHelper.java","lineNumber":46,"sourceCode":"\t\tvar token = testData.getToken();\n\t\tgetLogService().addLogger(token, logger);\n\t\ttry {\n\t\t\tString testServer = getClusterService().getLocalServerAddress();\n\t\t\tlogger.log(\"Pending resource allocation...\");\n\t\t\tgetResourceService().submitAgentTask(\n\t\t\t\t\tnull,\n\t\t\t\t\tAgentQuery.parse(agentQuery, true),\n\t\t\t\t\tresourceName,\n\t\t\t\t\tconcurrency,\n\t\t\t\t\t1,\n\t\t\t\t\tagentId -> {\n\t\t\t\t\t\tTaskLogger currentLogger = new ServerLogger(testServer, token);\n\t\t\t\t\t\tvar agentData = getSessionService().call(\n\t\t\t\t\t\t\t\t() -> getAgentService().load(agentId).getAgentData());\n\n\t\t\t\t\t\tSession agentSession = getAgentService().getAgentSession(agentId);\n\t\t\t\t\t\tif (agentSession == null) {\n\t\t\t\t\t\t\tthrow new ExplicitException(\n\t\t\t\t\t\t\t\t\t\"Allocated agent not connected to current server, please retry later\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcurrentLogger.log(String.format(\"Testing on agent '%s'...\", agentData.getName()));\n\n\t\t\t\t\t\tif (getLogService().getLogger(token) == null) {\n\t\t\t\t\t\t\tgetLogService().addLogger(token, currentLogger);\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\treturn testCallAgent(agentSession, testData, token);\n\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\tgetLogService().removeLogger(token);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn testCallAgent(agentSession, testData, token);\n\t\t\t\t\t\t}\n\t\t\t\t\t}).get();\n\t\t} catch (InterruptedException | ExecutionException e) {\n\t\t\tthrow new RuntimeException(e);","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/agent/AgentHelper.java#L28-L64","documentation":"When a build step runs 'test' on an allocated cloud agent, the server verifies the agent has an active session connected to the current (this) server. If the agent session lookup returns null the agent is not connected here, and an ExplicitException is thrown and logged to the build.","triggerScenarios":"Calling AgentHelper.test for an agent id that was allocated (assigned to a build/step) but whose websocket/agent session is not registered on the current server, e.g. after agent restart or in a cluster where the agent is connected to a different server node.","commonSituations":"Agent process crashed or was restarted mid-allocation, load balancer routed the build to a server node other than the one the agent connected to, network drop between agent and server, or a stale agent record.","solutions":["Retry the build/step later — the message itself says 'please retry later' once the agent reconnects.","Check the agent's status and logs; restart the agent so it re-establishes its session with the server.","In a cluster setup, verify the agent connects to the same server node handling the build (check load balancer/session affinity).","Verify network connectivity between agent and server port; fix dropped connections."],"exampleFix":"// retry pattern around test call\ntry {\n    agentHelper.test(...);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"Allocated agent not connected\")) {\n        // wait and retry or reschedule the job\n    }\n}","handlingStrategy":"retry","validationCode":"AgentSession s = getAgentService().getAgentSession(agentId);\nif (s == null) {\n    // reschedule the step instead of calling test\n}","typeGuard":null,"tryCatchPattern":"try {\n    agentHelper.test(agentId, token, ...);\n} catch (ExplicitException e) {\n    if (e.getMessage().contains(\"Allocated agent not connected\")) {\n        // wait/backoff and retry, or reschedule the job\n    }\n}","preventionTips":["Monitor agent connectivity and auto-restart disconnected agents.","Use session affinity so agents connect to the node serving their builds.","Health-check the agent before allocation."],"tags":["agent","session","ci","connectivity"],"backgroundTag":"connection-refused","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"}